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

Commit 8ad161c7 authored by Holly Sun's avatar Holly Sun
Browse files

[omni] Make LPH duration and touch slop dynamically configured.

The override duration and slop multiplier can be set from Launcher. Pass this
value from launcher to sysui through SystemUiProxy.
The logic for touch slop follows NavHandleLongPressInputConsumer (https://source.corp.google.com/h/googleplex-android/platform/superproject/main/+/main:packages/apps/Launcher3/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java;l=116).

Bug: 330446188
Bug: 330444720
Bug: 311356563
Test: manual
Flag: legacy OVERRIDE_LPNH_LPH_THRESHOLDS disabled
Change-Id: Ifd22a1070837c09631f8177aeee499cfbbb15f6e
parent ab57e5b3
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -155,5 +155,10 @@ interface ISystemUiProxy {
     */
    oneway void animateNavBarLongPress(boolean isTouchDown, boolean shrink, long durationMs) = 54;

    // Next id = 55
    /**
     * Set the override value for home button long press duration in ms and slop multiplier.
     */
    oneway void setOverrideHomeButtonLongPress(long duration, float slopMultiplier) = 55;

    // Next id = 56
}
+75 −4
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.InternalInsetsInfo;
import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
@@ -186,6 +187,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
    /** Allow some time inbetween the long press for back and recents. */
    private static final int LOCK_TO_APP_GESTURE_TOLERANCE = 200;
    private static final long AUTODIM_TIMEOUT_MS = 2250;
    private static final float QUICKSTEP_TOUCH_SLOP_RATIO_TWO_BUTTON = 3f;

    private final Context mContext;
    private final Bundle mSavedState;
@@ -223,6 +225,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
    private final int mNavColorSampleMargin;
    private EdgeBackGestureHandler mEdgeBackGestureHandler;
    private NavigationBarFrame mFrame;
    private MotionEvent mCurrentDownEvent;

    private @WindowVisibleState int mNavigationBarWindowState = WINDOW_STATE_SHOWING;

@@ -238,6 +241,8 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
    private int mLayoutDirection;

    private Optional<Long> mHomeButtonLongPressDurationMs;
    private Optional<Long> mOverrideHomeButtonLongPressDurationMs = Optional.empty();
    private Optional<Float> mOverrideHomeButtonLongPressSlopMultiplier = Optional.empty();

    /** @see android.view.WindowInsetsController#setSystemBarsAppearance(int, int) */
    private @Appearance int mAppearance;
@@ -404,6 +409,25 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
            mView.getHomeHandle().animateLongPress(isTouchDown, shrink, durationMs);
        }

        @Override
        public void setOverrideHomeButtonLongPress(long duration, float slopMultiplier) {
            mOverrideHomeButtonLongPressDurationMs = Optional.of(duration)
                    .filter(value -> value > 0);
            mOverrideHomeButtonLongPressSlopMultiplier = Optional.of(slopMultiplier)
                    .filter(value -> value > 0);
            if (mOverrideHomeButtonLongPressDurationMs.isPresent()) {
                Log.d(TAG, "Receive duration override: "
                        + mOverrideHomeButtonLongPressDurationMs.get());
            }
            if (mOverrideHomeButtonLongPressSlopMultiplier.isPresent()) {
                Log.d(TAG, "Receive slop multiplier override: "
                        + mOverrideHomeButtonLongPressSlopMultiplier.get());
            }
            if (mView != null) {
                reconfigureHomeLongClick();
            }
        }

        @Override
        public void onHomeRotationEnabled(boolean enabled) {
            mView.getRotationButtonController().setHomeRotationEnabled(enabled);
@@ -1016,7 +1040,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        if (mView.getHomeButton().getCurrentView() == null) {
            return;
        }
        if (mHomeButtonLongPressDurationMs.isPresent() || !mLongPressHomeEnabled) {
        if (mHomeButtonLongPressDurationMs.isPresent()
                || mOverrideHomeButtonLongPressDurationMs.isPresent()
                || mOverrideHomeButtonLongPressSlopMultiplier.isPresent()
                || !mLongPressHomeEnabled) {
            mView.getHomeButton().getCurrentView().setLongClickable(false);
            mView.getHomeButton().getCurrentView().setHapticFeedbackEnabled(false);
            mView.getHomeButton().setOnLongClickListener(null);
@@ -1038,6 +1065,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        pw.println("  mStartingQuickSwitchRotation=" + mStartingQuickSwitchRotation);
        pw.println("  mCurrentRotation=" + mCurrentRotation);
        pw.println("  mHomeButtonLongPressDurationMs=" + mHomeButtonLongPressDurationMs);
        pw.println("  mOverrideHomeButtonLongPressDurationMs="
                + mOverrideHomeButtonLongPressDurationMs);
        pw.println("  mOverrideHomeButtonLongPressSlopMultiplier="
                + mOverrideHomeButtonLongPressSlopMultiplier);
        pw.println("  mLongPressHomeEnabled=" + mLongPressHomeEnabled);
        pw.println("  mNavigationBarWindowState="
                + windowStateToString(mNavigationBarWindowState));
@@ -1331,6 +1362,10 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        final Optional<CentralSurfaces> centralSurfacesOptional = mCentralSurfacesOptionalLazy.get();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (mCurrentDownEvent != null) {
                    mCurrentDownEvent.recycle();
                }
                mCurrentDownEvent = MotionEvent.obtain(event);
                mHomeBlockedThisTouch = false;
                if (mTelecomManagerOptional.isPresent()
                        && mTelecomManagerOptional.get().isRinging()) {
@@ -1342,10 +1377,46 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
                    }
                }
                if (mLongPressHomeEnabled) {
                    if (mOverrideHomeButtonLongPressDurationMs.isPresent()) {
                        Log.d(TAG, "ACTION_DOWN Launcher override duration: "
                                + mOverrideHomeButtonLongPressDurationMs.get());
                        mHandler.postDelayed(mOnVariableDurationHomeLongClick,
                                mOverrideHomeButtonLongPressDurationMs.get());
                    } else if (mOverrideHomeButtonLongPressSlopMultiplier.isPresent()) {
                        // If override timeout doesn't exist but override touch slop exists, we use
                        // system default long press duration
                        Log.d(TAG, "ACTION_DOWN default duration: "
                                + ViewConfiguration.getLongPressTimeout());
                        mHandler.postDelayed(mOnVariableDurationHomeLongClick,
                                ViewConfiguration.getLongPressTimeout());
                    } else {
                        mHomeButtonLongPressDurationMs.ifPresent(longPressDuration -> {
                        mHandler.postDelayed(mOnVariableDurationHomeLongClick, longPressDuration);
                            Log.d(TAG, "ACTION_DOWN original duration: " + longPressDuration);
                            mHandler.postDelayed(mOnVariableDurationHomeLongClick,
                                    longPressDuration);
                        });
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (!mHandler.hasCallbacks(mOnVariableDurationHomeLongClick)) {
                    Log.w(TAG, "No callback. Don't handle touch slop.");
                    break;
                }
                float customSlopMultiplier = mOverrideHomeButtonLongPressSlopMultiplier.orElse(1f);
                float touchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
                float calculatedTouchSlop =
                        customSlopMultiplier * QUICKSTEP_TOUCH_SLOP_RATIO_TWO_BUTTON * touchSlop;
                float touchSlopSquared = calculatedTouchSlop * calculatedTouchSlop;

                float dx = event.getX() - mCurrentDownEvent.getX();
                float dy = event.getY() - mCurrentDownEvent.getY();
                double distanceSquared = (dx * dx) + (dy * dy);
                if (distanceSquared > touchSlopSquared) {
                    Log.i(TAG, "Touch slop passed. Abort.");
                    mView.abortCurrentGesture();
                    mHandler.removeCallbacks(mOnVariableDurationHomeLongClick);
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
+14 −0
Original line number Diff line number Diff line
@@ -258,6 +258,12 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                    notifyAnimateNavBarLongPress(isTouchDown, shrink, durationMs));
        }

        @Override
        public void setOverrideHomeButtonLongPress(long duration, float slopMultiplier) {
            verifyCallerAndClearCallingIdentityPostMain("setOverrideHomeButtonLongPress",
                    () -> notifySetOverrideHomeButtonLongPress(duration, slopMultiplier));
        }

        @Override
        public void onBackPressed() {
            verifyCallerAndClearCallingIdentityPostMain("onBackPressed", () -> {
@@ -947,6 +953,12 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        }
    }

    private void notifySetOverrideHomeButtonLongPress(long duration, float slopMultiplier) {
        for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) {
            mConnectionCallbacks.get(i).setOverrideHomeButtonLongPress(duration, slopMultiplier);
        }
    }

    public void notifyAssistantVisibilityChanged(float visibility) {
        try {
            if (mOverviewProxy != null) {
@@ -1104,6 +1116,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        default void startAssistant(Bundle bundle) {}
        default void setAssistantOverridesRequested(int[] invocationTypes) {}
        default void animateNavBarLongPress(boolean isTouchDown, boolean shrink, long durationMs) {}
        /** Set override of home button long press duration and touch slop multiplier. */
        default void setOverrideHomeButtonLongPress(long override, float slopMultiplier) {}
    }

    /**