From 0e3948a5fd9aba6e8622afa93395afa76fbe7b17 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 26 Dec 2024 21:08:26 -0800 Subject: [PATCH] Removing RotationTouchHelper state management from RecentsAnimationDeviceState RotationTouchHelper is a singleton and can manage its lifecycle statically Bug: 386288280 Test: Presubmit Flag: EXEMPT refactor Change-Id: I3e3105ac982ec716d5e2ee10f459d3e1cf55cd0d --- .../uioverrides/QuickstepLauncher.java | 7 +- .../android/quickstep/AbsSwipeUpHandler.java | 21 +++-- .../quickstep/BaseContainerInterface.java | 7 +- .../quickstep/FallbackActivityInterface.java | 16 ++-- .../quickstep/FallbackSwipeHandler.java | 7 +- .../quickstep/FallbackWindowInterface.java | 17 ++-- .../android/quickstep/InputConsumerUtils.kt | 9 +- .../quickstep/LauncherActivityInterface.java | 18 ++-- .../quickstep/LauncherSwipeHandlerV2.java | 9 +- .../RecentsAnimationDeviceState.java | 46 +++------- .../quickstep/RotationTouchHelper.java | 84 ++++--------------- .../quickstep/SwipeUpAnimationLogic.java | 12 ++- .../quickstep/TouchInteractionService.java | 11 ++- .../fallback/FallbackRecentsView.java | 6 +- .../window/RecentsWindowSwipeHandler.java | 13 ++- .../AccessibilityInputConsumer.java | 12 +-- .../DeviceLockedInputConsumer.java | 9 +- .../OtherActivityInputConsumer.java | 3 +- .../SwipeUpGestureTutorialController.java | 10 +-- .../SplitWithKeyboardShortcutController.java | 12 +-- .../quickstep/views/LauncherRecentsView.java | 6 +- .../android/quickstep/views/RecentsView.java | 12 ++- .../quickstep/AbsSwipeUpHandlerTestCase.java | 10 +-- .../FallbackSwipeHandlerTestCase.java | 1 - .../quickstep/LauncherSwipeHandlerV2Test.kt | 10 ++- .../LauncherSwipeHandlerV2TestCase.java | 1 - .../RecentsWindowSwipeHandlerTestCase.java | 1 - .../quickstep/FallbackRecentsTest.java | 3 - .../quickstep/InputConsumerUtilsTest.java | 3 +- .../quickstep/TaskAnimationManagerTest.java | 10 +-- 30 files changed, 130 insertions(+), 256 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 70c53fac95..3469e2fab0 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -170,7 +170,6 @@ import com.android.launcher3.widget.LauncherWidgetHolder; import com.android.quickstep.OverviewCommandHelper; import com.android.quickstep.OverviewComponentObserver; import com.android.quickstep.OverviewComponentObserver.OverviewChangeListener; -import com.android.quickstep.RecentsAnimationDeviceState; import com.android.quickstep.RecentsModel; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.TaskUtils; @@ -282,7 +281,6 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, getDepthController(), getStatsLogManager(), systemUiProxy, RecentsModel.INSTANCE.get(this), () -> onStateBack()); - RecentsAnimationDeviceState deviceState = new RecentsAnimationDeviceState(asContext()); if (DesktopModeStatus.canEnterDesktopMode(this)) { mDesktopRecentsTransitionController = new DesktopRecentsTransitionController( getStateManager(), systemUiProxy, getIApplicationThread(), @@ -290,8 +288,8 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, } overviewPanel.init(mActionsView, mSplitSelectStateController, mDesktopRecentsTransitionController); - mSplitWithKeyboardShortcutController = new SplitWithKeyboardShortcutController(this, - mSplitSelectStateController, deviceState); + mSplitWithKeyboardShortcutController = new SplitWithKeyboardShortcutController( + this, mSplitSelectStateController); mSplitToWorkspaceController = new SplitToWorkspaceController(this, mSplitSelectStateController); mActionsView.updateDimension(getDeviceProfile(), overviewPanel.getLastComputedTaskSize()); @@ -566,7 +564,6 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, super.onDestroy(); mHotseatPredictionController.destroy(); - mSplitWithKeyboardShortcutController.onDestroy(); if (mViewCapture != null) mViewCapture.close(); removeBackAnimationCallback(mSplitSelectStateController.getSplitBackHandler()); } diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 03394efd6e..67d20aacc3 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -196,6 +196,7 @@ public abstract class AbsSwipeUpHandler< // Fraction of the scroll and transform animation in which the current task fades out private static final float KQS_TASK_FADE_ANIMATION_FRACTION = 0.4f; + protected final RecentsAnimationDeviceState mDeviceState; protected final BaseContainerInterface mContainerInterface; protected final InputConsumerProxy mInputConsumerProxy; protected final ContextInitListener mContextInitListener; @@ -371,12 +372,13 @@ public abstract class AbsSwipeUpHandler< private final MSDLPlayerWrapper mMSDLPlayerWrapper; - public AbsSwipeUpHandler(Context context, RecentsAnimationDeviceState deviceState, + public AbsSwipeUpHandler(Context context, TaskAnimationManager taskAnimationManager, GestureState gestureState, long touchTimeMs, boolean continuingLastGesture, InputConsumerController inputConsumer, MSDLPlayerWrapper msdlPlayerWrapper) { - super(context, deviceState, gestureState); + super(context, gestureState); + mDeviceState = RecentsAnimationDeviceState.INSTANCE.get(mContext); mContainerInterface = gestureState.getContainerInterface(); mContextInitListener = mContainerInterface.createActivityInitListener(this::onActivityInit); @@ -594,7 +596,7 @@ public abstract class AbsSwipeUpHandler< // as that will set the state as BACKGROUND_APP, overriding the animation to NORMAL. if (mGestureState.getEndTarget() != HOME) { Runnable initAnimFactory = () -> { - mAnimationFactory = mContainerInterface.prepareRecentsUI(mDeviceState, + mAnimationFactory = mContainerInterface.prepareRecentsUI( mWasLauncherAlreadyVisible, this::onAnimatorPlaybackControllerCreated); maybeUpdateRecentsAttachedState(false /* animate */); if (mGestureState.getEndTarget() != null) { @@ -660,12 +662,9 @@ public abstract class AbsSwipeUpHandler< mGestureState.getContainerInterface().setOnDeferredActivityLaunchCallback( mOnDeferredActivityLaunch); - mGestureState.runOnceAtState(STATE_END_TARGET_SET, - () -> { - mDeviceState.getRotationTouchHelper() - .onEndTargetCalculated(mGestureState.getEndTarget(), - mContainerInterface); - }); + mGestureState.runOnceAtState(STATE_END_TARGET_SET, () -> + RotationTouchHelper.INSTANCE.get(mContext) + .onEndTargetCalculated(mGestureState.getEndTarget(), mContainerInterface)); notifyGestureStarted(); } @@ -705,7 +704,7 @@ public abstract class AbsSwipeUpHandler< if (mRecentsView == null) { return; } - mRecentsView.onGestureAnimationStart(runningTasks, mDeviceState.getRotationTouchHelper()); + mRecentsView.onGestureAnimationStart(runningTasks); TaskView currentPageTaskView = mRecentsView.getCurrentPageTaskView(); if (currentPageTaskView != null) { mPreviousTaskViewType = currentPageTaskView.getType(); @@ -1980,7 +1979,7 @@ public abstract class AbsSwipeUpHandler< } // Make sure recents is in its final state maybeUpdateRecentsAttachedState(false); - mContainerInterface.onSwipeUpToHomeComplete(mDeviceState); + mContainerInterface.onSwipeUpToHomeComplete(); } }); if (mRecentsAnimationTargets != null) { diff --git a/quickstep/src/com/android/quickstep/BaseContainerInterface.java b/quickstep/src/com/android/quickstep/BaseContainerInterface.java index e2ebaa5c4d..b20518cf48 100644 --- a/quickstep/src/com/android/quickstep/BaseContainerInterface.java +++ b/quickstep/src/com/android/quickstep/BaseContainerInterface.java @@ -131,7 +131,7 @@ public abstract class BaseContainerInterface callback); public abstract ContextInitListener createActivityInitListener( @@ -151,11 +151,10 @@ public abstract class BaseContainerInterface callback) { - notifyRecentsOfOrientation(deviceState.getRotationTouchHelper()); + notifyRecentsOfOrientation(); DefaultAnimationFactory factory = new DefaultAnimationFactory(callback); factory.initBackgroundStateUI(); return factory; @@ -142,12 +142,12 @@ public final class FallbackActivityInterface extends } @Override - public void onExitOverview(RotationTouchHelper deviceState, Runnable exitRunnable) { + public void onExitOverview(Runnable exitRunnable) { final StateManager stateManager = getCreatedContainer().getStateManager(); if (stateManager.getState() == HOME) { exitRunnable.run(); - notifyRecentsOfOrientation(deviceState); + notifyRecentsOfOrientation(); return; } @@ -158,7 +158,7 @@ public final class FallbackActivityInterface extends // Are we going from Recents to Workspace? if (toState == HOME) { exitRunnable.run(); - notifyRecentsOfOrientation(deviceState); + notifyRecentsOfOrientation(); stateManager.removeStateListener(this); } } @@ -197,11 +197,9 @@ public final class FallbackActivityInterface extends } } - private void notifyRecentsOfOrientation(RotationTouchHelper rotationTouchHelper) { + private void notifyRecentsOfOrientation() { // reset layout on swipe to home - RecentsView recentsView = getCreatedContainer().getOverviewPanel(); - recentsView.setLayoutRotation(rotationTouchHelper.getCurrentActiveRotation(), - rotationTouchHelper.getDisplayRotation()); + getCreatedContainer().getOverviewPanel().reapplyActiveRotation(); } @Override diff --git a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java index 1e857cacf7..331580c9d2 100644 --- a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java @@ -101,11 +101,11 @@ public class FallbackSwipeHandler extends private boolean mAppCanEnterPip; - public FallbackSwipeHandler(Context context, RecentsAnimationDeviceState deviceState, + public FallbackSwipeHandler(Context context, TaskAnimationManager taskAnimationManager, GestureState gestureState, long touchTimeMs, boolean continuingLastGesture, InputConsumerController inputConsumer, MSDLPlayerWrapper msdlPlayerWrapper) { - super(context, deviceState, taskAnimationManager, gestureState, touchTimeMs, + super(context, taskAnimationManager, gestureState, touchTimeMs, continuingLastGesture, inputConsumer, msdlPlayerWrapper); mRunningOverHome = mGestureState.getRunningTask() != null @@ -216,8 +216,7 @@ public class FallbackSwipeHandler extends if (mRunningOverHome) { if (DisplayController.getNavigationMode(mContext).hasGestures) { mRecentsView.onGestureAnimationStartOnHome( - mGestureState.getRunningTask().getPlaceholderTasks(), - mDeviceState.getRotationTouchHelper()); + mGestureState.getRunningTask().getPlaceholderTasks()); } } else { super.notifyGestureAnimationStartToRecents(); diff --git a/quickstep/src/com/android/quickstep/FallbackWindowInterface.java b/quickstep/src/com/android/quickstep/FallbackWindowInterface.java index f7836b0331..35630ef57f 100644 --- a/quickstep/src/com/android/quickstep/FallbackWindowInterface.java +++ b/quickstep/src/com/android/quickstep/FallbackWindowInterface.java @@ -80,10 +80,9 @@ public final class FallbackWindowInterface extends BaseWindowInterface{ /** 6 */ @Override - public BaseWindowInterface.AnimationFactory prepareRecentsUI(RecentsAnimationDeviceState - deviceState, boolean activityVisible, + public BaseWindowInterface.AnimationFactory prepareRecentsUI(boolean activityVisible, Consumer callback) { - notifyRecentsOfOrientation(deviceState.getRotationTouchHelper()); + notifyRecentsOfOrientation(); BaseWindowInterface.DefaultAnimationFactory factory = new BaseWindowInterface.DefaultAnimationFactory(callback); factory.initBackgroundStateUI(); @@ -153,12 +152,12 @@ public final class FallbackWindowInterface extends BaseWindowInterface{ } @Override - public void onExitOverview(RotationTouchHelper deviceState, Runnable exitRunnable) { + public void onExitOverview(Runnable exitRunnable) { final StateManager stateManager = getCreatedContainer().getStateManager(); if (stateManager.getState() == HOME) { exitRunnable.run(); - notifyRecentsOfOrientation(deviceState); + notifyRecentsOfOrientation(); return; } @@ -169,7 +168,7 @@ public final class FallbackWindowInterface extends BaseWindowInterface{ // Are we going from Recents to Workspace? if (toState == HOME) { exitRunnable.run(); - notifyRecentsOfOrientation(deviceState); + notifyRecentsOfOrientation(); stateManager.removeStateListener(this); } } @@ -208,11 +207,9 @@ public final class FallbackWindowInterface extends BaseWindowInterface{ } } - private void notifyRecentsOfOrientation(RotationTouchHelper rotationTouchHelper) { + private void notifyRecentsOfOrientation() { // reset layout on swipe to home - RecentsView recentsView = getCreatedContainer().getOverviewPanel(); - recentsView.setLayoutRotation(rotationTouchHelper.getCurrentActiveRotation(), - rotationTouchHelper.getDisplayRotation()); + ((RecentsView) getCreatedContainer().getOverviewPanel()).reapplyActiveRotation(); } @Override diff --git a/quickstep/src/com/android/quickstep/InputConsumerUtils.kt b/quickstep/src/com/android/quickstep/InputConsumerUtils.kt index 558178ffe0..c340c92085 100644 --- a/quickstep/src/com/android/quickstep/InputConsumerUtils.kt +++ b/quickstep/src/com/android/quickstep/InputConsumerUtils.kt @@ -332,14 +332,7 @@ object InputConsumerUtils { reasonPrefix, SUBSTRING_PREFIX, ) - base = - AccessibilityInputConsumer( - context, - deviceState, - gestureState, - base, - inputMonitorCompat, - ) + base = AccessibilityInputConsumer(context, deviceState, base, inputMonitorCompat) } } else { val reasonPrefix = "device is not in gesture navigation mode" diff --git a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java index d193feec65..ac0aa76ad5 100644 --- a/quickstep/src/com/android/quickstep/LauncherActivityInterface.java +++ b/quickstep/src/com/android/quickstep/LauncherActivityInterface.java @@ -80,7 +80,7 @@ public final class LauncherActivityInterface extends } @Override - public void onSwipeUpToHomeComplete(RecentsAnimationDeviceState deviceState) { + public void onSwipeUpToHomeComplete() { QuickstepLauncher launcher = getCreatedContainer(); if (launcher == null) { return; @@ -93,7 +93,7 @@ public final class LauncherActivityInterface extends MAIN_EXECUTOR.getHandler().post(launcher.getStateManager()::reapplyState); launcher.getRootView().setForceHideBackArrow(false); - notifyRecentsOfOrientation(deviceState.getRotationTouchHelper()); + notifyRecentsOfOrientation(); } @Override @@ -106,9 +106,9 @@ public final class LauncherActivityInterface extends } @Override - public AnimationFactory prepareRecentsUI(RecentsAnimationDeviceState deviceState, + public AnimationFactory prepareRecentsUI( boolean activityVisible, Consumer callback) { - notifyRecentsOfOrientation(deviceState.getRotationTouchHelper()); + notifyRecentsOfOrientation(); DefaultAnimationFactory factory = new DefaultAnimationFactory(callback) { @Override protected void createBackgroundToOverviewAnim(QuickstepLauncher activity, @@ -227,7 +227,7 @@ public final class LauncherActivityInterface extends @Override - public void onExitOverview(RotationTouchHelper deviceState, Runnable exitRunnable) { + public void onExitOverview(Runnable exitRunnable) { final StateManager stateManager = getCreatedContainer().getStateManager(); stateManager.addStateListener( @@ -237,18 +237,16 @@ public final class LauncherActivityInterface extends // Are we going from Recents to Workspace? if (toState == LauncherState.NORMAL) { exitRunnable.run(); - notifyRecentsOfOrientation(deviceState); + notifyRecentsOfOrientation(); stateManager.removeStateListener(this); } } }); } - private void notifyRecentsOfOrientation(RotationTouchHelper rotationTouchHelper) { + private void notifyRecentsOfOrientation() { // reset layout on swipe to home - RecentsView recentsView = getCreatedContainer().getOverviewPanel(); - recentsView.setLayoutRotation(rotationTouchHelper.getCurrentActiveRotation(), - rotationTouchHelper.getDisplayRotation()); + ((RecentsView) getCreatedContainer().getOverviewPanel()).reapplyActiveRotation(); } @Override diff --git a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java index 7af061886d..c60d3e8d23 100644 --- a/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java +++ b/quickstep/src/com/android/quickstep/LauncherSwipeHandlerV2.java @@ -67,11 +67,10 @@ import java.util.List; public class LauncherSwipeHandlerV2 extends AbsSwipeUpHandler< QuickstepLauncher, RecentsView, LauncherState> { - public LauncherSwipeHandlerV2(Context context, RecentsAnimationDeviceState deviceState, - TaskAnimationManager taskAnimationManager, GestureState gestureState, long touchTimeMs, - boolean continuingLastGesture, InputConsumerController inputConsumer, - MSDLPlayerWrapper msdlPlayerWrapper) { - super(context, deviceState, taskAnimationManager, gestureState, touchTimeMs, + public LauncherSwipeHandlerV2(Context context, TaskAnimationManager taskAnimationManager, + GestureState gestureState, long touchTimeMs, boolean continuingLastGesture, + InputConsumerController inputConsumer, MSDLPlayerWrapper msdlPlayerWrapper) { + super(context, taskAnimationManager, gestureState, touchTimeMs, continuingLastGesture, inputConsumer, msdlPlayerWrapper); } diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index e2964490f9..d4305a5469 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -67,7 +67,9 @@ import androidx.annotation.VisibleForTesting; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener; import com.android.launcher3.util.DisplayController.Info; +import com.android.launcher3.util.MainThreadInitializedObject; import com.android.launcher3.util.NavigationMode; +import com.android.launcher3.util.SafeCloseable; import com.android.launcher3.util.SettingsCache; import com.android.quickstep.TopTaskTracker.CachedTaskInfo; import com.android.quickstep.util.ActiveGestureLog; @@ -88,9 +90,8 @@ import java.util.ArrayList; /** * Manages the state of the system during a swipe up gesture. */ -public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, ExclusionListener { - - private static final String TAG = "RecentsAnimationDeviceState"; +public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, ExclusionListener, + SafeCloseable { static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode"; @@ -98,6 +99,9 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E private static final float QUICKSTEP_TOUCH_SLOP_RATIO_TWO_BUTTON = 3f; private static final float QUICKSTEP_TOUCH_SLOP_RATIO_GESTURAL = 1.414f; + public static MainThreadInitializedObject INSTANCE = + new MainThreadInitializedObject<>(RecentsAnimationDeviceState::new); + private final Context mContext; private final DisplayController mDisplayController; @@ -130,41 +134,21 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E private @NonNull Region mExclusionRegion = GestureExclusionManager.EMPTY_REGION; private boolean mExclusionListenerRegistered; - public RecentsAnimationDeviceState(Context context) { - this(context, false, GestureExclusionManager.INSTANCE); - } - - public RecentsAnimationDeviceState(Context context, boolean isInstanceForTouches) { - this(context, isInstanceForTouches, GestureExclusionManager.INSTANCE); + private RecentsAnimationDeviceState(Context context) { + this(context, GestureExclusionManager.INSTANCE); } @VisibleForTesting RecentsAnimationDeviceState(Context context, GestureExclusionManager exclusionManager) { - this(context, false, exclusionManager); - } - - /** - * @param isInstanceForTouches {@code true} if this is the persistent instance being used for - * gesture touch handling - */ - RecentsAnimationDeviceState( - Context context, boolean isInstanceForTouches, - GestureExclusionManager exclusionManager) { mContext = context; mDisplayController = DisplayController.INSTANCE.get(context); mExclusionManager = exclusionManager; mContextualSearchStateManager = ContextualSearchStateManager.INSTANCE.get(context); mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false); mRotationTouchHelper = RotationTouchHelper.INSTANCE.get(context); - if (isInstanceForTouches) { - // rotationTouchHelper doesn't get initialized after being destroyed, so only destroy - // if primary TouchInteractionService instance needs to be destroyed. - mRotationTouchHelper.init(); - runOnDestroy(mRotationTouchHelper::destroy); - } // Register for exclusion updates - runOnDestroy(() -> unregisterExclusionListener()); + runOnDestroy(this::unregisterExclusionListener); // Register for display changes changes mDisplayController.addChangeListener(this); @@ -225,10 +209,8 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E mOnDestroyActions.add(action); } - /** - * Cleans up all the registered listeners and receivers. - */ - public void destroy() { + @Override + public void close() { for (Runnable r : mOnDestroyActions) { r.run(); } @@ -603,10 +585,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E return mPipIsActive; } - public RotationTouchHelper getRotationTouchHelper() { - return mRotationTouchHelper; - } - /** Returns whether IME is rendering nav buttons, and IME is currently showing. */ public boolean isImeRenderingNavButtons() { return mCanImeRenderGesturalNavButtons && mMode == NO_BUTTON diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java index 909cc35d2b..f54b6554fd 100644 --- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java +++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java @@ -47,7 +47,6 @@ import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListeners; import java.io.PrintWriter; -import java.util.ArrayList; /** * Helper class for transforming touch events @@ -57,16 +56,14 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(RotationTouchHelper::new); - private OrientationTouchTransformer mOrientationTouchTransformer; - private DisplayController mDisplayController; - private int mDisplayId; + private final OrientationTouchTransformer mOrientationTouchTransformer; + private final DisplayController mDisplayController; + private final int mDisplayId; private int mDisplayRotation; - private final ArrayList mOnDestroyActions = new ArrayList<>(); - private NavigationMode mMode = THREE_BUTTONS; - private TaskStackChangeListener mFrozenTaskListener = new TaskStackChangeListener() { + private final TaskStackChangeListener mFrozenTaskListener = new TaskStackChangeListener() { @Override public void onRecentTaskListFrozenChanged(boolean frozen) { mTaskListFrozen = frozen; @@ -93,7 +90,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose } }; - private Runnable mExitOverviewRunnable = new Runnable() { + private final Runnable mExitOverviewRunnable = new Runnable() { @Override public void run() { mInOverview = false; @@ -107,7 +104,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose * rotates rotates the device to match that orientation, this triggers calls to sysui to adjust * the navbar. */ - private OrientationEventListener mOrientationListener; + private final OrientationEventListener mOrientationListener; private int mSensorRotation = ROTATION_0; /** * This is the configuration of the foreground app or the app that will be in the foreground @@ -120,7 +117,6 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose * would indicate the user's intention to rotate the foreground app. */ private boolean mPrioritizeDeviceRotation = false; - private Runnable mOnDestroyFrozenTaskRunnable; /** * Set to true when user swipes to recents. In recents, we ignore the state of the recents * task list being frozen or not to allow the user to keep interacting with nav bar rotation @@ -131,23 +127,8 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose private boolean mTaskListFrozen; private final Context mContext; - /** - * Keeps track of whether destroy has been called for this instance. Mainly used for TAPL tests - * where multiple instances of RotationTouchHelper are being created. b/177316094 - */ - private boolean mNeedsInit = true; - private RotationTouchHelper(Context context) { mContext = context; - if (mNeedsInit) { - init(); - } - } - - public void init() { - if (!mNeedsInit) { - return; - } mDisplayController = DisplayController.INSTANCE.get(mContext); Resources resources = mContext.getResources(); mDisplayId = DEFAULT_DISPLAY; @@ -158,8 +139,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose // Register for navigation mode changes mDisplayController.addChangeListener(this); DisplayController.Info info = mDisplayController.getInfo(); - onDisplayInfoChangedInternal(info, CHANGE_ALL, hasGestures(info.getNavigationMode())); - runOnDestroy(() -> mDisplayController.removeChangeListener(this)); + onDisplayInfoChanged(context, info, CHANGE_ALL); mOrientationListener = new OrientationEventListener(mContext) { @Override @@ -180,40 +160,14 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose } } }; - runOnDestroy(() -> mOrientationListener.disable()); - mNeedsInit = false; - } - - private void setupOrientationSwipeHandler() { - TaskStackChangeListeners.getInstance().registerTaskStackListener(mFrozenTaskListener); - mOnDestroyFrozenTaskRunnable = () -> TaskStackChangeListeners.getInstance() - .unregisterTaskStackListener(mFrozenTaskListener); - runOnDestroy(mOnDestroyFrozenTaskRunnable); - } - - private void destroyOrientationSwipeHandlerCallback() { - TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mFrozenTaskListener); - mOnDestroyActions.remove(mOnDestroyFrozenTaskRunnable); - } - - private void runOnDestroy(Runnable action) { - mOnDestroyActions.add(action); } @Override public void close() { - destroy(); - } - - /** - * Cleans up all the registered listeners and receivers. - */ - public void destroy() { - for (Runnable r : mOnDestroyActions) { - r.run(); - } - mNeedsInit = true; - mOnDestroyActions.clear(); + mDisplayController.removeChangeListener(this); + mOrientationListener.disable(); + TaskStackChangeListeners.getInstance() + .unregisterTaskStackListener(mFrozenTaskListener); } public boolean isTaskListFrozen() { @@ -264,10 +218,6 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose @Override public void onDisplayInfoChanged(Context context, Info info, int flags) { - onDisplayInfoChangedInternal(info, flags, false); - } - - private void onDisplayInfoChangedInternal(Info info, int flags, boolean forceRegister) { if ((flags & (CHANGE_ROTATION | CHANGE_ACTIVE_SCREEN | CHANGE_NAVIGATION_MODE | CHANGE_SUPPORTED_BOUNDS)) != 0) { mDisplayRotation = info.rotation; @@ -300,12 +250,12 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose mOrientationTouchTransformer.setNavigationMode(newMode, mDisplayController.getInfo(), mContext.getResources()); - if (forceRegister || (!hasGestures(mMode) && hasGestures(newMode))) { - setupOrientationSwipeHandler(); - } else if (hasGestures(mMode) && !hasGestures(newMode)) { - destroyOrientationSwipeHandlerCallback(); + TaskStackChangeListeners.getInstance() + .unregisterTaskStackListener(mFrozenTaskListener); + if (hasGestures(newMode)) { + TaskStackChangeListeners.getInstance() + .registerTaskStackListener(mFrozenTaskListener); } - mMode = newMode; } } @@ -363,7 +313,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener, SafeClose // If we're in landscape w/o ever quickswitching, show the navbar in landscape enableMultipleRegions(true); } - containerInterface.onExitOverview(this, mExitOverviewRunnable); + containerInterface.onExitOverview(mExitOverviewRunnable); } else if (endTarget == GestureState.GestureEndTarget.HOME || endTarget == GestureState.GestureEndTarget.ALL_APPS) { enableMultipleRegions(false); diff --git a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java index f813d9a12e..f5593b0ad5 100644 --- a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java +++ b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java @@ -58,7 +58,7 @@ import java.util.Arrays; import java.util.function.Consumer; public abstract class SwipeUpAnimationLogic implements - RecentsAnimationCallbacks.RecentsAnimationListener{ + RecentsAnimationCallbacks.RecentsAnimationListener { protected static final Rect TEMP_RECT = new Rect(); protected final RemoteTargetGluer mTargetGluer; @@ -66,7 +66,6 @@ public abstract class SwipeUpAnimationLogic implements protected DeviceProfile mDp; protected final Context mContext; - protected final RecentsAnimationDeviceState mDeviceState; protected final GestureState mGestureState; protected RemoteTargetHandle[] mRemoteTargetHandles; @@ -85,20 +84,19 @@ public abstract class SwipeUpAnimationLogic implements protected boolean mIsSwipeForSplit; - public SwipeUpAnimationLogic(Context context, RecentsAnimationDeviceState deviceState, - GestureState gestureState) { + public SwipeUpAnimationLogic(Context context, GestureState gestureState) { mContext = context; - mDeviceState = deviceState; mGestureState = gestureState; updateIsGestureForSplit(TopTaskTracker.INSTANCE.get(context) .getRunningSplitTaskIds().length); mTargetGluer = new RemoteTargetGluer(mContext, mGestureState.getContainerInterface()); mRemoteTargetHandles = mTargetGluer.getRemoteTargetHandles(); + RotationTouchHelper rotationTouchHelper = RotationTouchHelper.INSTANCE.get(context); runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTaskViewSimulator().getOrientationState().update( - mDeviceState.getRotationTouchHelper().getCurrentActiveRotation(), - mDeviceState.getRotationTouchHelper().getDisplayRotation() + rotationTouchHelper.getCurrentActiveRotation(), + rotationTouchHelper.getDisplayRotation() )); } diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index aea02afedc..a06029b013 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -552,8 +552,8 @@ public class TouchInteractionService extends Service { // Initialize anything here that is needed in direct boot mode. // Everything else should be initialized in onUserUnlocked() below. mMainChoreographer = Choreographer.getInstance(); - mDeviceState = new RecentsAnimationDeviceState(this, true); - mRotationTouchHelper = mDeviceState.getRotationTouchHelper(); + mDeviceState = RecentsAnimationDeviceState.INSTANCE.get(this); + mRotationTouchHelper = RotationTouchHelper.INSTANCE.get(this); mAllAppsActionManager = new AllAppsActionManager( this, UI_HELPER_EXECUTOR, this::createAllAppsPendingIntent); mTrackpadsConnected = new ActiveTrackpadList(this, () -> { @@ -715,7 +715,6 @@ public class TouchInteractionService extends Service { mOverviewComponentObserver.removeOverviewChangeListener(mOverviewChangeListener); } disposeEventHandlers("TouchInteractionService onDestroy()"); - mDeviceState.destroy(); SystemUiProxy.INSTANCE.get(this).clearProxy(); mAllAppsActionManager.onDestroy(); @@ -1158,21 +1157,21 @@ public class TouchInteractionService extends Service { private AbsSwipeUpHandler createLauncherSwipeHandler( GestureState gestureState, long touchTimeMs) { - return new LauncherSwipeHandlerV2(this, mDeviceState, mTaskAnimationManager, + return new LauncherSwipeHandlerV2(this, mTaskAnimationManager, gestureState, touchTimeMs, mTaskAnimationManager.isRecentsAnimationRunning(), mInputConsumer, MSDLPlayerWrapper.INSTANCE.get(this)); } private AbsSwipeUpHandler createFallbackSwipeHandler( GestureState gestureState, long touchTimeMs) { - return new FallbackSwipeHandler(this, mDeviceState, mTaskAnimationManager, + return new FallbackSwipeHandler(this, mTaskAnimationManager, gestureState, touchTimeMs, mTaskAnimationManager.isRecentsAnimationRunning(), mInputConsumer, MSDLPlayerWrapper.INSTANCE.get(this)); } private AbsSwipeUpHandler createRecentsWindowSwipeHandler( GestureState gestureState, long touchTimeMs) { - return new RecentsWindowSwipeHandler(this, mDeviceState, mTaskAnimationManager, + return new RecentsWindowSwipeHandler(this, mTaskAnimationManager, gestureState, touchTimeMs, mTaskAnimationManager.isRecentsAnimationRunning(), mInputConsumer, MSDLPlayerWrapper.INSTANCE.get(this)); } diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java index b76e39a533..76da4af5be 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -45,7 +45,6 @@ import com.android.launcher3.util.SplitConfigurationOptions.SplitSelectSource; import com.android.quickstep.BaseContainerInterface; import com.android.quickstep.FallbackActivityInterface; import com.android.quickstep.GestureState; -import com.android.quickstep.RotationTouchHelper; import com.android.quickstep.fallback.window.RecentsDisplayModel; import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.SplitSelectStateController; @@ -114,12 +113,11 @@ public class FallbackRecentsView 0 ? homeTask[0] : null; - onGestureAnimationStart(homeTask, rotationTouchHelper); + onGestureAnimationStart(homeTask); } /** diff --git a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java index afc88792d6..12bae538b2 100644 --- a/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/fallback/window/RecentsWindowSwipeHandler.java @@ -66,7 +66,6 @@ import com.android.launcher3.util.MSDLPlayerWrapper; import com.android.quickstep.AbsSwipeUpHandler; import com.android.quickstep.GestureState; import com.android.quickstep.RecentsAnimationController; -import com.android.quickstep.RecentsAnimationDeviceState; import com.android.quickstep.RecentsAnimationTargets; import com.android.quickstep.TaskAnimationManager; import com.android.quickstep.fallback.FallbackRecentsView; @@ -110,11 +109,10 @@ public class RecentsWindowSwipeHandler extends AbsSwipeUpHandler mContextInitListener; @@ -180,7 +179,8 @@ public abstract class AbsSwipeUpHandlerTestCase< @Before public void setUpRecentsContainer() { - mTaskAnimationManager = new TaskAnimationManager(mContext, mRecentsAnimationDeviceState); + mTaskAnimationManager = new TaskAnimationManager(mContext, + RecentsAnimationDeviceState.INSTANCE.get(mContext)); RecentsViewContainer recentsContainer = getRecentsContainer(); RECENTS_VIEW recentsView = getRecentsView(); @@ -198,12 +198,6 @@ public abstract class AbsSwipeUpHandlerTestCase< }).when(recentsContainer).runOnBindToTouchInteractionService(any()); } - @Before - public void setUpRecentsAnimationDeviceState() { - runOnMainSync(() -> - mRecentsAnimationDeviceState = new RecentsAnimationDeviceState(mContext, true)); - } - @Test public void testInitWhenReady_registersActivityInitListener() { String reasonString = "because i said so"; diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java index d4eb8e2668..3489519e74 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/FallbackSwipeHandlerTestCase.java @@ -44,7 +44,6 @@ public class FallbackSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase< long touchTimeMs, boolean continuingLastGesture) { return new FallbackSwipeHandler( mContext, - mRecentsAnimationDeviceState, mTaskAnimationManager, mGestureState, touchTimeMs, diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt index 41877c9359..d01c82cc3c 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt @@ -40,7 +40,6 @@ import org.mockito.Mockito.spy import org.mockito.junit.MockitoJUnit import org.mockito.kotlin.eq import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever @SmallTest @RunWith(AndroidJUnit4::class) @@ -74,15 +73,18 @@ class LauncherSwipeHandlerV2Test { .bindSystemUiProxy(systemUiProxy) .bindRecentsDisplayModel(recentsDisplayModel) ) - + sandboxContext.putObject( + RotationTouchHelper.INSTANCE, + mock(RotationTouchHelper::class.java), + ) val deviceState = mock(RecentsAnimationDeviceState::class.java) - whenever(deviceState.rotationTouchHelper).thenReturn(mock(RotationTouchHelper::class.java)) + sandboxContext.putObject(RecentsAnimationDeviceState.INSTANCE, deviceState) + gestureState = spy(GestureState(OverviewComponentObserver.INSTANCE.get(sandboxContext), 0)) underTest = LauncherSwipeHandlerV2( sandboxContext, - deviceState, taskAnimationManager, gestureState, 0, diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java index fc6acfd065..e6c5a6c4de 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2TestCase.java @@ -73,7 +73,6 @@ public class LauncherSwipeHandlerV2TestCase extends AbsSwipeUpHandlerTestCase< long touchTimeMs, boolean continuingLastGesture) { return new LauncherSwipeHandlerV2( mContext, - mRecentsAnimationDeviceState, mTaskAnimationManager, mGestureState, touchTimeMs, diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java index 40fefae32c..dcb45e5ef0 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/RecentsWindowSwipeHandlerTestCase.java @@ -62,7 +62,6 @@ public class RecentsWindowSwipeHandlerTestCase extends AbsSwipeUpHandlerTestCase boolean continuingLastGesture) { return new RecentsWindowSwipeHandler( mContext, - mRecentsAnimationDeviceState, mTaskAnimationManager, mGestureState, touchTimeMs, diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 5bb2fad38b..a4c9ef2d5c 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -333,13 +333,11 @@ public class FallbackRecentsTest { private class OverviewUpdateHandler implements OverviewChangeListener { - final RecentsAnimationDeviceState mRads; final OverviewComponentObserver mObserver; final CountDownLatch mChangeCounter; OverviewUpdateHandler() { Context ctx = getInstrumentation().getTargetContext(); - mRads = new RecentsAnimationDeviceState(ctx); mObserver = OverviewComponentObserver.INSTANCE.get(ctx); mChangeCounter = new CountDownLatch(1); if (mObserver.getHomeIntent().getComponent() @@ -358,7 +356,6 @@ public class FallbackRecentsTest { void destroy() { mObserver.removeOverviewChangeListener(this); - mRads.destroy(); } } } diff --git a/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java b/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java index 160c57806e..3c5e1e8345 100644 --- a/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java +++ b/quickstep/tests/src/com/android/quickstep/InputConsumerUtilsTest.java @@ -127,6 +127,8 @@ public class InputConsumerUtilsTest { @Before public void setupMainThreadInitializedObjects() { mContext.putObject(LockedUserState.INSTANCE, mLockedUserState); + mContext.putObject(RotationTouchHelper.INSTANCE, mock(RotationTouchHelper.class)); + mContext.putObject(RecentsAnimationDeviceState.INSTANCE, mDeviceState); } @Before @@ -193,7 +195,6 @@ public class InputConsumerUtilsTest { when(mDeviceState.canStartSystemGesture()).thenReturn(true); when(mDeviceState.isFullyGesturalNavMode()).thenReturn(true); when(mDeviceState.getNavBarPosition()).thenReturn(mock(NavBarPosition.class)); - when(mDeviceState.getRotationTouchHelper()).thenReturn(mock(RotationTouchHelper.class)); } @After diff --git a/quickstep/tests/src/com/android/quickstep/TaskAnimationManagerTest.java b/quickstep/tests/src/com/android/quickstep/TaskAnimationManagerTest.java index 098b4178b4..a87c3289bc 100644 --- a/quickstep/tests/src/com/android/quickstep/TaskAnimationManagerTest.java +++ b/quickstep/tests/src/com/android/quickstep/TaskAnimationManagerTest.java @@ -46,18 +46,12 @@ public class TaskAnimationManagerTest { private SystemUiProxy mSystemUiProxy; private TaskAnimationManager mTaskAnimationManager; - protected RecentsAnimationDeviceState mRecentsAnimationDeviceState; - - @Before - public void setUpRecentsAnimationDeviceState() { - runOnMainSync(() -> - mRecentsAnimationDeviceState = new RecentsAnimationDeviceState(mContext, true)); - } @Before public void setUp() { MockitoAnnotations.initMocks(this); - mTaskAnimationManager = new TaskAnimationManager(mContext, mRecentsAnimationDeviceState) { + mTaskAnimationManager = new TaskAnimationManager(mContext, + RecentsAnimationDeviceState.INSTANCE.get(mContext)) { @Override SystemUiProxy getSystemUiProxy() { return mSystemUiProxy;