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

Commit deee0d06 authored by Holly Sun's avatar Holly Sun
Browse files

[omni] Implement 2-stage for LPNH.

Use existing override duration and touch slop multiplier values for the 1st stage. Times `TWO_STAGE_MULTIPLIER` for the 2nd stage.
See http://shortn/_WqYj0buH7R

Bug: 330446193
Test: manual
Flag: legacy ENABLE_LPNH_TWO_STAGES disabled
Change-Id: Ic200f431524578d17fd98ebfbc65e44e0971e31c
parent c072d44b
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -44,9 +44,26 @@ class DeviceConfigWrapper private constructor(propReader: PropReader) {
            "Enable AGSA override for LPNH and LPH timeout and touch slop"
        )

    val lpnhTimeoutMs =
        propReader.get("LPNH_TIMEOUT_MS", 450, "Controls lpnh timeout in milliseconds")

    val lpnhSlopPercentage =
        propReader.get("LPNH_SLOP_PERCENTAGE", 100, "Controls touch slop percentage for lpnh")

    val enableLpnhTwoStages =
        propReader.get(
            "ENABLE_LPNH_TWO_STAGES",
            false,
            "Enable two stage for LPNH duration and touch slop"
        )

    val twoStageMultiplier =
        propReader.get(
            "TWO_STAGE_MULTIPLIER",
            2,
            "Extends the duration and touch slop if the initial slop is passed"
        )

    val animateLpnh = propReader.get("ANIMATE_LPNH", false, "Animates navbar when long pressing")

    val shrinkNavHandleOnPress =
@@ -56,9 +73,6 @@ class DeviceConfigWrapper private constructor(propReader: PropReader) {
            "Shrinks navbar when long pressing if ANIMATE_LPNH is enabled"
        )

    val lpnhTimeoutMs =
        propReader.get("LPNH_TIMEOUT_MS", 450, "Controls lpnh timeout in milliseconds")

    val enableLongPressNavHandle =
        propReader.get(
            "ENABLE_LONG_PRESS_NAV_HANDLE",
+48 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LONG_PRESS_NAVBAR;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LONG_PRESS_STASHED_TASKBAR;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.LogConfig.NAV_HANDLE_LONG_PRESS;

import android.content.Context;
import android.util.Log;
@@ -43,14 +44,19 @@ import com.android.systemui.shared.system.InputMonitorCompat;
public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {

    private static final String TAG = "NavHandleLongPressIC";
    private static final boolean DEBUG_NAV_HANDLE = Utilities.isPropertyEnabled(
            NAV_HANDLE_LONG_PRESS);

    private final NavHandleLongPressHandler mNavHandleLongPressHandler;
    private final float mNavHandleWidth;
    private final float mScreenWidth;

    private final Runnable mTriggerLongPress = this::triggerLongPress;
    private final float mTouchSlopSquared;
    private final float mTouchSlopSquaredOriginal;
    private float mTouchSlopSquared;
    private final float mOuterTouchSlopSquared;
    private final int mLongPressTimeout;
    private final int mOuterLongPressTimeout;
    private final boolean mDeepPressEnabled;
    private final NavHandle mNavHandle;
    private final StatsLogManager mStatsLogManager;
@@ -65,13 +71,23 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
        super(delegate, inputMonitor);
        mScreenWidth = DisplayController.INSTANCE.get(context).getInfo().currentSize.x;
        mDeepPressEnabled = DeviceConfigWrapper.get().getEnableLpnhDeepPress();
        int twoStageMultiplier = DeviceConfigWrapper.get().getTwoStageMultiplier();
        AssistStateManager assistStateManager = AssistStateManager.INSTANCE.get(context);
        if (assistStateManager.getLPNHDurationMillis().isPresent()) {
            mLongPressTimeout = assistStateManager.getLPNHDurationMillis().get().intValue();
        } else {
            mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
        }
        mTouchSlopSquared = deviceState.getSquaredTouchSlop();
        mOuterLongPressTimeout = mLongPressTimeout * twoStageMultiplier;
        mTouchSlopSquaredOriginal = deviceState.getSquaredTouchSlop();
        mTouchSlopSquared = mTouchSlopSquaredOriginal;
        mOuterTouchSlopSquared = mTouchSlopSquared * (twoStageMultiplier * twoStageMultiplier);
        if (DEBUG_NAV_HANDLE) {
            Log.d(TAG, "mLongPressTimeout=" + mLongPressTimeout);
            Log.d(TAG, "mOuterLongPressTimeout=" + mOuterLongPressTimeout);
            Log.d(TAG, "mTouchSlopSquared=" + mTouchSlopSquared);
            Log.d(TAG, "mOuterTouchSlopSquared=" + mOuterTouchSlopSquared);
        }
        mNavHandle = navHandle;
        mNavHandleWidth = navHandle.getNavHandleWidth(context);
        mNavHandleLongPressHandler = NavHandleLongPressHandler.newInstance(context);
@@ -109,22 +125,44 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
                    mCurrentDownEvent.recycle();
                }
                mCurrentDownEvent = MotionEvent.obtain(ev);
                mTouchSlopSquared = mTouchSlopSquaredOriginal;
                mDeepPressLogged = false;
                if (isInNavBarHorizontalArea(ev.getRawX())) {
                    mNavHandleLongPressHandler.onTouchStarted(mNavHandle);
                    MAIN_EXECUTOR.getHandler().postDelayed(mTriggerLongPress, mLongPressTimeout);
                }
                if (DEBUG_NAV_HANDLE) {
                    Log.d(TAG, "ACTION_DOWN");
                }
            }
            case MotionEvent.ACTION_MOVE -> {
                if (!MAIN_EXECUTOR.getHandler().hasCallbacks(mTriggerLongPress)) {
                    break;
                }

                float touchSlopSquared = mTouchSlopSquared;
                float dx = ev.getX() - mCurrentDownEvent.getX();
                float dy = ev.getY() - mCurrentDownEvent.getY();
                double distanceSquared = (dx * dx) + (dy * dy);
                if (distanceSquared > touchSlopSquared) {
                if (DEBUG_NAV_HANDLE) {
                    Log.d(TAG, "ACTION_MOVE distanceSquared=" + distanceSquared);
                }
                if (DeviceConfigWrapper.get().getEnableLpnhTwoStages()) {
                    if (mTouchSlopSquared < distanceSquared
                            && distanceSquared <= mOuterTouchSlopSquared) {
                        MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
                        int delay = mOuterLongPressTimeout
                                - (int) (ev.getEventTime() - ev.getDownTime());
                        MAIN_EXECUTOR.getHandler().postDelayed(mTriggerLongPress, delay);
                        mTouchSlopSquared = mOuterTouchSlopSquared;
                        if (DEBUG_NAV_HANDLE) {
                            Log.d(TAG, "Touch in middle region!");
                        }
                    }
                }
                if (distanceSquared > mTouchSlopSquared) {
                    if (DEBUG_NAV_HANDLE) {
                        Log.d(TAG, "Touch slop out. mTouchSlopSquared=" + mTouchSlopSquared);
                    }
                    cancelLongPress("touch slop passed");
                }
            }
@@ -153,6 +191,9 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
    }

    private void triggerLongPress() {
        if (DEBUG_NAV_HANDLE) {
            Log.d(TAG, "triggerLongPress");
        }
        String runningPackage = mTopTaskTracker.getCachedTopTask(
                /* filterOnlyVisibleRecents */ true).getPackageName();
        mStatsLogManager.logger().withPackageName(runningPackage).log(
@@ -175,6 +216,9 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
    }

    private void cancelLongPress(String reason) {
        if (DEBUG_NAV_HANDLE) {
            Log.d(TAG, "cancelLongPress");
        }
        MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
        mNavHandleLongPressHandler.onTouchFinished(mNavHandle, reason);
    }
+5 −0
Original line number Diff line number Diff line
@@ -65,4 +65,9 @@ public class LogConfig {
     * When turned on, we enable AGA related session summary logging.
     */
    public static final String AGA_SESSION_SUMMARY_LOG = "AGASessionSummaryLog";

    /**
     * When turned on, we enable long press nav handle related logging.
     */
    public static final String NAV_HANDLE_LONG_PRESS = "NavHandleLongPress";
}