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

Commit 9a3d604e authored by Simon Bowden's avatar Simon Bowden
Browse files

Make the binder call in performHapticFeedback asynchronous.

Controlled by a build flag in ViewRootImpl.

This changes the return value to be true whenever it gets to dispatching
to binder - therefore it will no longer be false if the device has no
vibrator or if the HapticFeedbackConstant has no implementation. The
benefit is that the method should no longer have delays (including
binder scheduling ones) that can introduce jank on the UI thread.

The return code is currently undocumented and can be affected by a large
number of variables, so it seems unlikely to usefully deduce something
from it at runtime. In any case, the app would be better off, for
example, doing a one-off check separately, rather than a dynamic check
every time in this method that's asking to be called in the UI thread.

Bug: 264566815
Test: presubmit
Change-Id: I1c41ae26a1a9f0ad5a97b20d14a72d39ed8668ee
parent 2e48cd23
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -152,6 +152,12 @@ interface IWindowSession {
    @UnsupportedAppUsage
    boolean performHapticFeedback(int effectId, boolean always);

    /**
     * Called by attached views to perform predefined haptic feedback without requiring VIBRATE
     * permission.
     */
    oneway void performHapticFeedbackAsync(int effectId, boolean always);

    /**
     * Initiate the drag operation itself
     *
+15 −1
Original line number Diff line number Diff line
@@ -278,6 +278,14 @@ public final class ViewRootImpl implements ViewParent,
     */
    private static final boolean ENABLE_INPUT_LATENCY_TRACKING = true;

    /**
     * Controls whether to use the new oneway performHapticFeedback call. This returns
     * true in a few more conditions, but doesn't affect which haptics happen. Notably, it
     * makes the call to performHapticFeedback non-blocking, which reduces potential UI jank.
     * This is intended as a temporary flag, ultimately becoming permanently 'true'.
     */
    private static final boolean USE_ASYNC_PERFORM_HAPTIC_FEEDBACK = true;

    /**
     * Whether the caption is drawn by the shell.
     * @hide
@@ -8566,7 +8574,13 @@ public final class ViewRootImpl implements ViewParent,
        }

        try {
            if (USE_ASYNC_PERFORM_HAPTIC_FEEDBACK) {
                mWindowSession.performHapticFeedbackAsync(effectId, always);
                return true;
            } else {
                // Original blocking binder call path.
                return mWindowSession.performHapticFeedback(effectId, always);
            }
        } catch (RemoteException e) {
            return false;
        }
+5 −0
Original line number Diff line number Diff line
@@ -465,6 +465,11 @@ public class WindowlessWindowManager implements IWindowSession {
        return false;
    }

    @Override
    public void performHapticFeedbackAsync(int effectId, boolean always) {
        performHapticFeedback(effectId, always);
    }

    @Override
    public android.os.IBinder performDrag(android.view.IWindow window, int flags,
            android.view.SurfaceControl surface, int touchSource, float touchX, float touchY,
+5 −0
Original line number Diff line number Diff line
@@ -310,6 +310,11 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        }
    }

    @Override
    public void performHapticFeedbackAsync(int effectId, boolean always) {
        performHapticFeedback(effectId, always);
    }

    /* Drag/drop */

    @Override