Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0a98c70 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Optimizations for Vibrator#performHapticFeedback" into main

parents cfa96407 aa0b3e0d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,5 +41,5 @@ interface IVibratorManagerService {
    // There is no order guarantee with respect to the two-way APIs above like
    // vibrate/isVibrating/cancel.
    oneway void performHapticFeedback(int uid, int deviceId, String opPkg, int constant,
            boolean always, String reason, IBinder token);
            boolean always, String reason);
}
+3 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ public class SystemVibratorManager extends VibratorManager {

    private final IVibratorManagerService mService;
    private final Context mContext;
    private final int mUid;
    private final Binder mToken = new Binder();
    private final Object mLock = new Object();
    @GuardedBy("mLock")
@@ -56,6 +57,7 @@ public class SystemVibratorManager extends VibratorManager {
    public SystemVibratorManager(Context context) {
        super(context);
        mContext = context;
        mUid = Process.myUid();
        mService = IVibratorManagerService.Stub.asInterface(
                ServiceManager.getService(Context.VIBRATOR_MANAGER_SERVICE));
    }
@@ -152,8 +154,7 @@ public class SystemVibratorManager extends VibratorManager {
        }
        try {
            mService.performHapticFeedback(
                    Process.myUid(), mContext.getDeviceId(), mPackageName, constant, always, reason,
                    mToken);
                    mUid, mContext.getDeviceId(), mPackageName, constant, always, reason);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to perform haptic feedback.", e);
        }
+7 −3
Original line number Diff line number Diff line
@@ -403,9 +403,13 @@ public class VibratorManagerService extends IVibratorManagerService.Stub {

    @Override // Binder call
    public void performHapticFeedback(
            int uid, int deviceId, String opPkg, int constant, boolean always, String reason,
            IBinder token) {
        performHapticFeedbackInternal(uid, deviceId, opPkg, constant, always, reason, token);
            int uid, int deviceId, String opPkg, int constant, boolean always, String reason) {
        // Note that the `performHapticFeedback` method does not take a token argument from the
        // caller, and instead, uses this service as the token. This is to mitigate performance
        // impact that would otherwise be caused due to marshal latency. Haptic feedback effects are
        // short-lived, so we don't need to cancel when the process dies.
        performHapticFeedbackInternal(
                uid, deviceId, opPkg, constant, always, reason, /* token= */ this);
    }

    /**
+11 −0
Original line number Diff line number Diff line
@@ -1397,6 +1397,17 @@ public class VibratorManagerServiceTest {
        assertTrue(mVibratorProviders.get(1).getAllEffectSegments().isEmpty());
    }

    @Test
    public void performHapticFeedback_usesServiceAsToken() throws Exception {
        VibratorManagerService service = createSystemReadyService();

        HalVibration vibration =
                performHapticFeedbackAndWaitUntilFinished(
                        service, HapticFeedbackConstants.SCROLL_TICK, /* always= */ true);

        assertTrue(vibration.callerToken == service);
    }

    @Test
    public void vibrate_withIntensitySettings_appliesSettingsToScaleVibrations() throws Exception {
        int defaultNotificationIntensity =