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

Commit a85365c2 authored by Winson Chung's avatar Winson Chung
Browse files

13/ Rely on the device state's navigation mode

- Rely on the device state navigation mode instead of tracking it
  independently in various places

Bug: 141886704
Change-Id: I421c1fa11ca7362aff8e2388a2b5d427b39af3e9
parent 7caa5191
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
    protected float mDragLengthFactor = 1;

    protected final Context mContext;
    protected final RecentsAnimationDeviceState mDeviceState;
    protected final GestureState mGestureState;
    protected final OverviewComponentObserver mOverviewComponentObserver;
    protected final BaseActivityInterface<T> mActivityInterface;
@@ -106,7 +107,6 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
    protected final TransformParams mTransformParams = new TransformParams();

    private final Vibrator mVibrator;
    protected final Mode mMode;

    // Shift in the range of [0, 1].
    // 0 => preview snapShot is completely visible, and hotseat is completely translated down
@@ -135,10 +135,11 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
    protected boolean mCanceled;
    protected int mFinishingRecentsAnimationForNewTaskId = -1;

    protected BaseSwipeUpHandler(Context context, GestureState gestureState,
            OverviewComponentObserver overviewComponentObserver,
    protected BaseSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState,
            GestureState gestureState, OverviewComponentObserver overviewComponentObserver,
            RecentsModel recentsModel, InputConsumerController inputConsumer, int runningTaskId) {
        mContext = context;
        mDeviceState = deviceState;
        mGestureState = gestureState;
        mOverviewComponentObserver = overviewComponentObserver;
        mActivityInterface = gestureState.getActivityInterface();
@@ -147,7 +148,6 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
                mActivityInterface.createActivityInitListener(this::onActivityInit);
        mRunningTaskId = runningTaskId;
        mInputConsumer = inputConsumer;
        mMode = SysUINavigationMode.getMode(context);

        mAppWindowAnimationHelper = new AppWindowAnimationHelper(context);
        mPageSpacing = context.getResources().getDimensionPixelSize(R.dimen.recents_page_spacing);
@@ -348,7 +348,7 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
            mAppWindowAnimationHelper.updateHomeBounds(getStackBounds(dp));
        }
        mAppWindowAnimationHelper.updateTargetRect(TEMP_RECT);
        if (mMode == Mode.NO_BUTTON) {
        if (mDeviceState.isFullyGesturalNavMode()) {
            // We can drag all the way to the top of the screen.
            mDragLengthFactor = (float) dp.heightPx / mTransitionDragLength;
        }
+20 −27
Original line number Diff line number Diff line
@@ -63,8 +63,6 @@ import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.util.TraceHelper;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.SysUINavigationMode.NavigationModeChangeListener;
import com.android.quickstep.inputconsumers.AccessibilityInputConsumer;
import com.android.quickstep.inputconsumers.AssistantInputConsumer;
import com.android.quickstep.inputconsumers.DeviceLockedInputConsumer;
@@ -114,8 +112,7 @@ class ArgList extends LinkedList<String> {
 * Service connected by system-UI for handling touch interaction.
 */
@TargetApi(Build.VERSION_CODES.Q)
public class TouchInteractionService extends Service implements
        NavigationModeChangeListener, PluginListener<OverscrollPlugin> {
public class TouchInteractionService extends Service implements PluginListener<OverscrollPlugin> {

    private static final String TAG = "TouchInteractionService";

@@ -269,20 +266,18 @@ public class TouchInteractionService extends Service implements

    private InputMonitorCompat mInputMonitorCompat;
    private InputEventReceiver mInputEventReceiver;
    private Mode mMode = Mode.THREE_BUTTONS;

    @Override
    public void onCreate() {
        super.onCreate();
        mDeviceState = new RecentsAnimationDeviceState(this);
        mDeviceState.runOnUserUnlocked(this::onUserUnlocked);

        // Initialize anything here that is needed in direct boot mode.
        // Everything else should be initialized in onUserUnlocked() below.
        mMainChoreographer = Choreographer.getInstance();
        mAM = ActivityManagerWrapper.getInstance();
        mDeviceState = new RecentsAnimationDeviceState(this);
        mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
        mDeviceState.runOnUserUnlocked(this::onUserUnlocked);

        onNavigationModeChanged(SysUINavigationMode.INSTANCE.get(this).addModeChangeListener(this));
        sConnected = true;

        PluginManagerWrapper.INSTANCE.get(getBaseContext()).addPluginListener(this,
@@ -308,7 +303,7 @@ public class TouchInteractionService extends Service implements
            Log.d(TestProtocol.NO_BACKGROUND_TO_OVERVIEW_TAG, "initInputMonitor 1");
        }
        disposeEventHandlers();
        if (!mMode.hasGestures || !SystemUiProxy.INSTANCE.get(this).isActive()) {
        if (mDeviceState.isButtonNavMode() || !SystemUiProxy.INSTANCE.get(this).isActive()) {
            return;
        }
        if (TestProtocol.sDebugTracing) {
@@ -327,12 +322,10 @@ public class TouchInteractionService extends Service implements
        mDeviceState.updateGestureTouchRegions();
    }

    @Override
    public void onNavigationModeChanged(Mode newMode) {
        if (TestProtocol.sDebugTracing) {
            Log.d(TestProtocol.NO_BACKGROUND_TO_OVERVIEW_TAG, "onNavigationModeChanged " + newMode);
        }
        mMode = newMode;
    /**
     * Called when the navigation mode changes, guaranteed to be after the device state has updated.
     */
    private void onNavigationModeChanged(SysUINavigationMode.Mode mode) {
        initInputMonitor();
        resetHomeBounceSeenOnQuickstepEnabledFirstTime();
    }
@@ -369,7 +362,7 @@ public class TouchInteractionService extends Service implements
    }

    private void resetHomeBounceSeenOnQuickstepEnabledFirstTime() {
        if (!mDeviceState.isUserUnlocked() || !mMode.hasGestures) {
        if (!mDeviceState.isUserUnlocked() || mDeviceState.isButtonNavMode()) {
            // Skip if not yet unlocked (can't read user shared prefs) or if the current navigation
            // mode doesn't have gestures
            return;
@@ -417,7 +410,6 @@ public class TouchInteractionService extends Service implements
        }
        disposeEventHandlers();
        mDeviceState.destroy();
        SysUINavigationMode.INSTANCE.get(this).removeModeChangeListener(this);
        SystemUiProxy.INSTANCE.get(this).setProxy(null);

        sConnected = false;
@@ -453,7 +445,8 @@ public class TouchInteractionService extends Service implements

                ActiveGestureLog.INSTANCE.addLog("setInputConsumer", mConsumer.getType());
                mUncheckedConsumer = mConsumer;
            } else if (mDeviceState.isUserUnlocked() && mMode == Mode.NO_BUTTON
            } else if (mDeviceState.isUserUnlocked()
                    && mDeviceState.isFullyGesturalNavMode()
                    && mDeviceState.canTriggerAssistantAction(event)) {
                // Do not change mConsumer as if there is an ongoing QuickSwitch gesture, we should
                // not interrupt it. QuickSwitch assumes that interruption can only happen if the
@@ -494,7 +487,7 @@ public class TouchInteractionService extends Service implements
                || previousGestureState.isRecentsAnimationRunning()
                        ? newBaseConsumer(previousGestureState, newGestureState, event)
                        : mResetGestureInputConsumer;
        if (mMode == Mode.NO_BUTTON) {
        if (mDeviceState.isFullyGesturalNavMode()) {
            if (mDeviceState.canTriggerAssistantAction(event)) {
                base = new AssistantInputConsumer(this, newGestureState, base, mInputMonitorCompat);
            }
@@ -584,7 +577,8 @@ public class TouchInteractionService extends Service implements
        final boolean shouldDefer;
        final BaseSwipeUpHandler.Factory factory;

        if (mMode == Mode.NO_BUTTON && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
        if (mDeviceState.isFullyGesturalNavMode()
                && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
            shouldDefer = previousGestureState.getFinishingRecentsAnimationTaskId() < 0;
            factory = mFallbackNoButtonFactory;
        } else {
@@ -601,7 +595,7 @@ public class TouchInteractionService extends Service implements

    private InputConsumer createDeviceLockedInputConsumer(GestureState gestureState,
            RunningTaskInfo taskInfo) {
        if (mMode == Mode.NO_BUTTON && taskInfo != null) {
        if (mDeviceState.isFullyGesturalNavMode() && taskInfo != null) {
            return new DeviceLockedInputConsumer(this, mDeviceState, mTaskAnimationManager,
                    gestureState, mInputMonitorCompat, taskInfo.taskId);
        } else {
@@ -641,7 +635,7 @@ public class TouchInteractionService extends Service implements
        if (!mDeviceState.isUserUnlocked()) {
            return;
        }
        if (!mMode.hasGestures && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
        if (mDeviceState.isButtonNavMode() && !mOverviewComponentObserver.isHomeAndOverviewSame()) {
            // Prevent the overview from being started before the real home on first boot.
            return;
        }
@@ -708,7 +702,6 @@ public class TouchInteractionService extends Service implements
            // Dump everything
            mDeviceState.dump(pw);
            pw.println("TouchState:");
            pw.println("  navMode=" + mMode);
            boolean resumed = mOverviewComponentObserver != null
                    && mOverviewComponentObserver.getActivityInterface().isResumed();
            pw.println("  resumed=" + resumed);
@@ -748,9 +741,9 @@ public class TouchInteractionService extends Service implements
    private BaseSwipeUpHandler createFallbackNoButtonSwipeHandler(GestureState gestureState,
            RunningTaskInfo runningTask, long touchTimeMs, boolean continuingLastGesture,
            boolean isLikelyToStartNewTask) {
        return new FallbackNoButtonInputConsumer(this, gestureState, mOverviewComponentObserver,
                runningTask, mRecentsModel, mInputConsumer, isLikelyToStartNewTask,
                continuingLastGesture);
        return new FallbackNoButtonInputConsumer(this, mDeviceState, gestureState,
                mOverviewComponentObserver, runningTask, mRecentsModel, mInputConsumer,
                isLikelyToStartNewTask, continuingLastGesture);
    }

    protected boolean shouldNotifyBackGesture() {
+9 −13
Original line number Diff line number Diff line
@@ -157,9 +157,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
     */
    private static final int LOG_NO_OP_PAGE_INDEX = -1;

    private final RecentsAnimationDeviceState mDeviceState;
    private final TaskAnimationManager mTaskAnimationManager;
    private final GestureState mGestureState;

    // Either RectFSpringAnim (if animating home) or ObjectAnimator (from mCurrentShift) otherwise
    private RunningWindowAnim mRunningWindowAnim;
@@ -198,11 +196,9 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
            RunningTaskInfo runningTaskInfo, long touchTimeMs,
            OverviewComponentObserver overviewComponentObserver, boolean continuingLastGesture,
            InputConsumerController inputConsumer, RecentsModel recentsModel) {
        super(context, gestureState, overviewComponentObserver, recentsModel, inputConsumer,
                runningTaskInfo.id);
        mDeviceState = deviceState;
        super(context, deviceState, gestureState, overviewComponentObserver, recentsModel,
                inputConsumer, runningTaskInfo.id);
        mTaskAnimationManager = taskAnimationManager;
        mGestureState = gestureState;
        mTouchTimeMs = touchTimeMs;
        mContinuingLastGesture = continuingLastGesture;
        initStateCallbacks();
@@ -444,7 +440,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
     * Note this method has no effect unless the navigation mode is NO_BUTTON.
     */
    private void maybeUpdateRecentsAttachedState(boolean animate) {
        if (mMode != Mode.NO_BUTTON || mRecentsView == null) {
        if (!mDeviceState.isFullyGesturalNavMode() || mRecentsView == null) {
            return;
        }
        RemoteAnimationTargetCompat runningTaskTarget = mRecentsAnimationTargets == null
@@ -546,7 +542,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
        final boolean passed = mCurrentShift.value >= MIN_PROGRESS_FOR_OVERVIEW;
        if (passed != mPassedOverviewThreshold) {
            mPassedOverviewThreshold = passed;
            if (mMode != Mode.NO_BUTTON) {
            if (!mDeviceState.isFullyGesturalNavMode()) {
                performHapticFeedback();
            }
        }
@@ -730,7 +726,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
        if (!isFling) {
            if (isCancel) {
                endTarget = LAST_TASK;
            } else if (mMode == Mode.NO_BUTTON) {
            } else if (mDeviceState.isFullyGesturalNavMode()) {
                if (mIsShelfPeeking) {
                    endTarget = RECENTS;
                } else if (goingToNewTask) {
@@ -751,9 +747,9 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
            boolean willGoToNewTaskOnSwipeUp =
                    goingToNewTask && Math.abs(velocity.x) > Math.abs(endVelocity);

            if (mMode == Mode.NO_BUTTON && isSwipeUp && !willGoToNewTaskOnSwipeUp) {
            if (mDeviceState.isFullyGesturalNavMode() && isSwipeUp && !willGoToNewTaskOnSwipeUp) {
                endTarget = HOME;
            } else if (mMode == Mode.NO_BUTTON && isSwipeUp && !mIsShelfPeeking) {
            } else if (mDeviceState.isFullyGesturalNavMode() && isSwipeUp && !mIsShelfPeeking) {
                // If swiping at a diagonal, base end target on the faster velocity.
                endTarget = NEW_TASK;
            } else if (isSwipeUp) {
@@ -793,7 +789,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
            float minFlingVelocity = mContext.getResources()
                    .getDimension(R.dimen.quickstep_fling_min_velocity);
            if (Math.abs(endVelocity) > minFlingVelocity && mTransitionDragLength > 0) {
                if (endTarget == RECENTS && mMode != Mode.NO_BUTTON) {
                if (endTarget == RECENTS && !mDeviceState.isFullyGesturalNavMode()) {
                    Interpolators.OvershootParams overshoot = new Interpolators.OvershootParams(
                            startShift, endShift, endShift, endVelocity / 1000,
                            mTransitionDragLength, mContext);
@@ -839,7 +835,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
                }
                duration = Math.max(duration, mRecentsView.getScroller().getDuration());
            }
            if (mMode == Mode.NO_BUTTON) {
            if (mDeviceState.isFullyGesturalNavMode()) {
                setShelfState(ShelfAnimState.OVERVIEW, interpolator, duration);
            }
        } else if (endTarget == NEW_TASK || endTarget == LAST_TASK) {
+5 −4
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.quickstep.MultiStateCallback;
import com.android.quickstep.OverviewComponentObserver;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.RecentsAnimationController;
import com.android.quickstep.RecentsAnimationDeviceState;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.util.RectFSpringAnim;
@@ -112,13 +113,13 @@ public class FallbackNoButtonInputConsumer extends
    private final PointF mEndVelocityPxPerMs = new PointF(0, 0.5f);
    private RunningWindowAnim mFinishAnimation;

    public FallbackNoButtonInputConsumer(Context context, GestureState gestureState,
            OverviewComponentObserver overviewComponentObserver,
    public FallbackNoButtonInputConsumer(Context context, RecentsAnimationDeviceState deviceState,
            GestureState gestureState, OverviewComponentObserver overviewComponentObserver,
            RunningTaskInfo runningTaskInfo, RecentsModel recentsModel,
            InputConsumerController inputConsumer,
            boolean isLikelyToStartNewTask, boolean continuingLastGesture) {
        super(context, gestureState, overviewComponentObserver, recentsModel, inputConsumer,
                runningTaskInfo.id);
        super(context, deviceState, gestureState, overviewComponentObserver, recentsModel,
                inputConsumer, runningTaskInfo.id);
        mLauncherAlpha.value = 1;

        mRunningTaskInfo = runningTaskInfo;
+1 −5
Original line number Diff line number Diff line
@@ -54,8 +54,6 @@ import com.android.quickstep.GestureState;
import com.android.quickstep.InputConsumer;
import com.android.quickstep.RecentsAnimationCallbacks;
import com.android.quickstep.RecentsAnimationDeviceState;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.TaskAnimationManager;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.CachedEventDispatcher;
@@ -85,7 +83,6 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
    private final CachedEventDispatcher mRecentsViewDispatcher = new CachedEventDispatcher();
    private final RunningTaskInfo mRunningTask;
    private final InputMonitorCompat mInputMonitorCompat;
    private final SysUINavigationMode.Mode mMode;
    private final BaseActivityInterface mActivityInterface;

    private final BaseSwipeUpHandler.Factory mHandlerFactory;
@@ -137,7 +134,6 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
        mGestureState = gestureState;
        mMainThreadHandler = new Handler(Looper.getMainLooper());
        mRunningTask = runningTaskInfo;
        mMode = SysUINavigationMode.getMode(base);
        mHandlerFactory = handlerFactory;
        mActivityInterface = mGestureState.getActivityInterface();

@@ -293,7 +289,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
                        mInteractionHandler.updateDisplacement(displacement - mStartDisplacement);
                    }

                    if (mMode == Mode.NO_BUTTON) {
                    if (mDeviceState.isFullyGesturalNavMode()) {
                        mMotionPauseDetector.setDisallowPause(upDist < mMotionPauseMinDisplacement
                                || isLikelyToStartNewTask);
                        mMotionPauseDetector.addPosition(displacement, ev.getEventTime());
Loading