diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 4c5e6556b8..3ef317bc1b 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -169,6 +169,7 @@ import com.android.launcher3.util.TouchController; 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; @@ -224,7 +225,6 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, SystemProperties.getBoolean("persist.debug.trace_layouts", false); private static final String TRACE_RELAYOUT_CLASS = SystemProperties.get("persist.debug.trace_request_layout_class", null); - public static final boolean GO_LOW_RAM_RECENTS_ENABLED = false; protected static final String RING_APPEAR_ANIMATION_PREFIX = "RingAppearAnimation\t"; @@ -264,7 +264,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, private boolean mIsOverlayVisible; - private final Runnable mOverviewTargetChangeRunnable = this::onOverviewTargetChanged; + private final OverviewChangeListener mOverviewChangeListener = this::onOverviewTargetChanged; public static QuickstepLauncher getLauncher(Context context) { return fromContext(context); @@ -283,9 +283,6 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, systemUiProxy, RecentsModel.INSTANCE.get(this), () -> onStateBack()); RecentsAnimationDeviceState deviceState = new RecentsAnimationDeviceState(asContext()); - // TODO(b/337863494): Explore use of the same OverviewComponentObserver across launcher - OverviewComponentObserver overviewComponentObserver = new OverviewComponentObserver( - asContext(), deviceState); if (DesktopModeStatus.canEnterDesktopMode(this)) { mDesktopRecentsTransitionController = new DesktopRecentsTransitionController( getStateManager(), systemUiProxy, getIApplicationThread(), @@ -294,7 +291,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, overviewPanel.init(mActionsView, mSplitSelectStateController, mDesktopRecentsTransitionController); mSplitWithKeyboardShortcutController = new SplitWithKeyboardShortcutController(this, - mSplitSelectStateController, overviewComponentObserver, deviceState); + mSplitSelectStateController, deviceState); mSplitToWorkspaceController = new SplitToWorkspaceController(this, mSplitSelectStateController); mActionsView.updateDimension(getDeviceProfile(), overviewPanel.getLastComputedTaskSize()); @@ -307,8 +304,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, mTISBindHelper = new TISBindHelper(this, this::onTISConnected); mDepthController = new DepthController(this); if (DesktopModeStatus.canEnterDesktopModeOrShowAppHandle(this)) { - mSplitSelectStateController.initSplitFromDesktopController(this, - overviewComponentObserver); + mSplitSelectStateController.initSplitFromDesktopController(this); } mHotseatPredictionController = new HotseatPredictionController(this); @@ -556,10 +552,8 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, mUnfoldTransitionProgressProvider.destroy(); } - TISBinder binder = mTISBindHelper.getBinder(); - if (binder != null) { - binder.unregisterOverviewTargetChangeListener(mOverviewTargetChangeRunnable); - } + OverviewComponentObserver.INSTANCE.get(this) + .removeOverviewChangeListener(mOverviewChangeListener); mTISBindHelper.onDestroy(); if (mLauncherUnfoldAnimationController != null) { @@ -701,6 +695,8 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, QuickstepOnboardingPrefs.setup(this); View.setTraceLayoutSteps(TRACE_LAYOUTS); View.setTracedRequestLayoutClassClass(TRACE_RELAYOUT_CLASS); + OverviewComponentObserver.INSTANCE.get(this) + .addOverviewChangeListener(mOverviewChangeListener); } @Override @@ -1051,7 +1047,7 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, } } - private void onOverviewTargetChanged() { + private void onOverviewTargetChanged(boolean isHomeAndOverviewSame) { QuickstepTransitionManager transitionManager = getAppTransitionManager(); if (transitionManager != null) { transitionManager.onOverviewTargetChange(); @@ -1064,7 +1060,6 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, taskbarManager.setActivity(this); } mTISBindHelper.setPredictiveBackToHomeInProgress(mIsPredictiveBackToHomeInProgress); - binder.registerOverviewTargetChangeListener(mOverviewTargetChangeRunnable); } @Override diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java index 1fc0401a13..64c11299d4 100644 --- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java +++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java @@ -19,6 +19,7 @@ package com.android.quickstep; import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_CHANGED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; +import static android.view.Display.DEFAULT_DISPLAY; import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; @@ -41,6 +42,11 @@ import androidx.annotation.UiThread; import com.android.launcher3.Flags; import com.android.launcher3.R; +import com.android.launcher3.dagger.ApplicationContext; +import com.android.launcher3.dagger.LauncherAppComponent; +import com.android.launcher3.dagger.LauncherAppSingleton; +import com.android.launcher3.util.DaggerSingletonObject; +import com.android.launcher3.util.DaggerSingletonTracker; import com.android.launcher3.util.SimpleBroadcastReceiver; import com.android.quickstep.fallback.window.RecentsDisplayModel; import com.android.quickstep.util.ActiveGestureProtoLogProxy; @@ -48,16 +54,23 @@ import com.android.systemui.shared.system.PackageManagerWrapper; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.List; import java.util.Objects; -import java.util.function.Consumer; +import java.util.concurrent.CopyOnWriteArrayList; + +import javax.inject.Inject; /** * Class to keep track of the current overview component based off user preferences and app updates * and provide callers the relevant classes. */ +@LauncherAppSingleton public final class OverviewComponentObserver { private static final String TAG = "OverviewComponentObserver"; + public static final DaggerSingletonObject INSTANCE = + new DaggerSingletonObject<>(LauncherAppComponent::getOverviewComponentObserver); + // We register broadcast receivers on main thread to avoid missing updates. private final SimpleBroadcastReceiver mUserPreferenceChangeReceiver = new SimpleBroadcastReceiver(MAIN_EXECUTOR, this::updateOverviewTargets); @@ -65,14 +78,16 @@ public final class OverviewComponentObserver { new SimpleBroadcastReceiver(MAIN_EXECUTOR, this::updateOverviewTargets); private final Context mContext; - private final RecentsAnimationDeviceState mDeviceState; + private final RecentsDisplayModel mRecentsDisplayModel; + private final Intent mCurrentHomeIntent; private final Intent mMyHomeIntent; private final Intent mFallbackIntent; private final SparseIntArray mConfigChangesMap = new SparseIntArray(); private final String mSetupWizardPkg; - private Consumer mOverviewChangeListener = b -> { }; + private final List mOverviewChangeListeners = + new CopyOnWriteArrayList<>(); private String mUpdateRegisteredPackage; private BaseContainerInterface mContainerInterface; @@ -81,10 +96,13 @@ public final class OverviewComponentObserver { private boolean mIsDefaultHome; private boolean mIsHomeDisabled; - - public OverviewComponentObserver(Context context, RecentsAnimationDeviceState deviceState) { + @Inject + public OverviewComponentObserver( + @ApplicationContext Context context, + RecentsDisplayModel recentsDisplayModel, + DaggerSingletonTracker lifecycleTracker) { mContext = context; - mDeviceState = deviceState; + mRecentsDisplayModel = recentsDisplayModel; mCurrentHomeIntent = createHomeIntent(); mMyHomeIntent = new Intent(mCurrentHomeIntent).setPackage(mContext.getPackageName()); ResolveInfo info = context.getPackageManager().resolveActivity(mMyHomeIntent, 0); @@ -108,21 +126,27 @@ public final class OverviewComponentObserver { mUserPreferenceChangeReceiver.register(mContext, ACTION_PREFERRED_ACTIVITY_CHANGED); updateOverviewTargets(); + + lifecycleTracker.addCloseable(this::onDestroy); + } + + /** Adds a listener for changes in {@link #isHomeAndOverviewSame()} */ + public void addOverviewChangeListener(OverviewChangeListener overviewChangeListener) { + mOverviewChangeListeners.add(overviewChangeListener); + } + + /** Removes a previously added listener */ + public void removeOverviewChangeListener(OverviewChangeListener overviewChangeListener) { + mOverviewChangeListeners.remove(overviewChangeListener); } /** - * Sets a listener for changes in {@link #isHomeAndOverviewSame()} + * Called to set home enabled/disabled state via systemUI + * @param isHomeDisabled */ - public void setOverviewChangeListener(Consumer overviewChangeListener) { - // TODO(b/337861962): This method should be able to support multiple listeners instead of - // one so that we can reuse the same instance of this class across multiple places - mOverviewChangeListener = overviewChangeListener; - } - - /** Called on {@link TouchInteractionService#onSystemUiFlagsChanged} */ - @UiThread - public void onSystemUiStateChanged() { - if (mDeviceState.isHomeDisabled() != mIsHomeDisabled) { + public void setHomeDisabled(boolean isHomeDisabled) { + if (isHomeDisabled != mIsHomeDisabled) { + mIsHomeDisabled = isHomeDisabled; updateOverviewTargets(); } } @@ -146,7 +170,6 @@ public final class OverviewComponentObserver { defaultHome = null; } - mIsHomeDisabled = mDeviceState.isHomeDisabled(); mIsDefaultHome = Objects.equals(mMyHomeIntent.getComponent(), defaultHome); // Set assistant visibility to 0 from launcher's perspective, ensures any elements that @@ -182,8 +205,7 @@ public final class OverviewComponentObserver { if (Flags.enableLauncherOverviewInWindow() || Flags.enableFallbackOverviewInWindow()) { mContainerInterface = - RecentsDisplayModel.getINSTANCE().get(mContext) - .getFallbackWindowInterface(mDeviceState.getDisplayId()); + mRecentsDisplayModel.getFallbackWindowInterface(DEFAULT_DISPLAY); } else { mContainerInterface = FallbackActivityInterface.INSTANCE; } @@ -206,13 +228,13 @@ public final class OverviewComponentObserver { ACTION_PACKAGE_CHANGED, ACTION_PACKAGE_REMOVED); } } - mOverviewChangeListener.accept(mIsHomeAndOverviewSame); + mOverviewChangeListeners.forEach(l -> l.onOverviewTargetChange(mIsHomeAndOverviewSame)); } /** * Clean up any registered receivers. */ - public void onDestroy() { + private void onDestroy() { mUserPreferenceChangeReceiver.unregisterReceiverSafely(mContext); unregisterOtherHomeAppUpdateReceiver(); } @@ -296,11 +318,7 @@ public final class OverviewComponentObserver { */ public static void startHomeIntentSafely(@NonNull Context context, @Nullable Bundle options, @NonNull String reason) { - RecentsAnimationDeviceState deviceState = new RecentsAnimationDeviceState(context); - OverviewComponentObserver observer = new OverviewComponentObserver(context, deviceState); - Intent intent = observer.getHomeIntent(); - observer.onDestroy(); - deviceState.destroy(); + Intent intent = OverviewComponentObserver.INSTANCE.get(context).getHomeIntent(); startHomeIntentSafely(context, intent, options, reason); } @@ -320,6 +338,17 @@ public final class OverviewComponentObserver { } } + /** + * Interface for listening to overview changes + */ + public interface OverviewChangeListener { + + /** + * Called when the overview target changes + */ + void onOverviewTargetChange(boolean isHomeAndOverviewSame); + } + private static Intent createHomeIntent() { return new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_HOME) diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index a5d2f3e3a2..a04ff2ea44 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -204,29 +204,15 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { @Override protected WindowInsets getWindowInsets() { - RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(mContext); - OverviewComponentObserver observer = new OverviewComponentObserver(mContext, rads); - try { - RecentsViewContainer container = observer.getContainerInterface().getCreatedContainer(); - WindowInsets insets = container == null - ? null : container.getRootView().getRootWindowInsets(); - - return insets == null ? super.getWindowInsets() : insets; - } finally { - observer.onDestroy(); - rads.destroy(); - } + RecentsViewContainer container = getRecentsViewContainer(); + WindowInsets insets = container == null + ? null : container.getRootView().getRootWindowInsets(); + return insets == null ? super.getWindowInsets() : insets; } private RecentsViewContainer getRecentsViewContainer() { - RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(mContext); - OverviewComponentObserver observer = new OverviewComponentObserver(mContext, rads); - try { - return observer.getContainerInterface().getCreatedContainer(); - } finally { - observer.onDestroy(); - rads.destroy(); - } + return OverviewComponentObserver.INSTANCE.get(mContext) + .getContainerInterface().getCreatedContainer(); } @Override diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 9de96c7ed8..fbe4c70f30 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -90,6 +90,7 @@ import com.android.launcher3.util.SafeCloseable; import com.android.launcher3.util.ScreenOnTracker; import com.android.launcher3.util.TraceHelper; import com.android.quickstep.OverviewCommandHelper.CommandType; +import com.android.quickstep.OverviewComponentObserver.OverviewChangeListener; import com.android.quickstep.fallback.window.RecentsWindowSwipeHandler; import com.android.quickstep.inputconsumers.BubbleBarInputConsumer; import com.android.quickstep.inputconsumers.OneHandedModeInputConsumer; @@ -103,7 +104,6 @@ import com.android.quickstep.views.RecentsViewContainer; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; import com.android.systemui.shared.statusbar.phone.BarTransitions; -import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver; import com.android.systemui.shared.system.InputConsumerController; import com.android.systemui.shared.system.InputMonitorCompat; @@ -124,7 +124,6 @@ import com.android.wm.shell.startingsurface.IStartingWindow; import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; -import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; @@ -150,8 +149,6 @@ public class TouchInteractionService extends Service { private final WeakReference mTis; - private final Set mOnOverviewTargetChangeListeners = new HashSet<>(); - private TISBinder(TouchInteractionService tis) { mTis = new WeakReference<>(tis); } @@ -498,28 +495,11 @@ public class TouchInteractionService extends Service { tis -> tis.mDeviceState.setGestureBlockingTaskId(taskId)); } - /** Registers a listener to be run on Overview Target updates. */ - public void registerOverviewTargetChangeListener(@NonNull Runnable listener) { - mOnOverviewTargetChangeListeners.add(listener); - } - - /** Unregisters an OverviewTargetChange listener. */ - public void unregisterOverviewTargetChangeListener(@NonNull Runnable listener) { - mOnOverviewTargetChangeListeners.remove(listener); - } - - protected void onOverviewTargetChange() { - Set listeners = new HashSet<>(mOnOverviewTargetChangeListeners); - for (Runnable listener : listeners) { - listener.run(); - } - } - /** Refreshes the current overview target. */ public void refreshOverviewTarget() { executeForTouchInteractionService(tis -> { tis.mAllAppsActionManager.onDestroy(); - tis.onOverviewTargetChange(tis.mOverviewComponentObserver.isHomeAndOverviewSame()); + tis.onOverviewTargetChanged(tis.mOverviewComponentObserver.isHomeAndOverviewSame()); }); } } @@ -601,6 +581,7 @@ public class TouchInteractionService extends Service { private final Runnable mUserUnlockedRunnable = this::onUserUnlocked; private final ScreenOnTracker.ScreenOnListener mScreenOnListener = this::onScreenOnChanged; + private final OverviewChangeListener mOverviewChangeListener = this::onOverviewTargetChanged; private final TaskbarNavButtonCallbacks mNavCallbacks = new TaskbarNavButtonCallbacks() { @Override @@ -619,7 +600,6 @@ public class TouchInteractionService extends Service { } }; - private ActivityManagerWrapper mAM; private OverviewCommandHelper mOverviewCommandHelper; private OverviewComponentObserver mOverviewComponentObserver; private InputConsumerController mInputConsumer; @@ -654,7 +634,6 @@ 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(); - mAM = ActivityManagerWrapper.getInstance(); mDeviceState = new RecentsAnimationDeviceState(this, true); mRotationTouchHelper = mDeviceState.getRotationTouchHelper(); mAllAppsActionManager = new AllAppsActionManager( @@ -724,7 +703,7 @@ public class TouchInteractionService extends Service { Log.d(TAG, "onUserUnlocked: userId=" + getUserId() + " instance=" + System.identityHashCode(this)); mTaskAnimationManager = new TaskAnimationManager(this, mDeviceState); - mOverviewComponentObserver = new OverviewComponentObserver(this, mDeviceState); + mOverviewComponentObserver = OverviewComponentObserver.INSTANCE.get(this); mOverviewCommandHelper = new OverviewCommandHelper(this, mOverviewComponentObserver, mTaskAnimationManager); mResetGestureInputConsumer = new ResetGestureInputConsumer( @@ -740,8 +719,8 @@ public class TouchInteractionService extends Service { // new ModelPreload().start(this); resetHomeBounceSeenOnQuickstepEnabledFirstTime(); - mOverviewComponentObserver.setOverviewChangeListener(this::onOverviewTargetChange); - onOverviewTargetChange(mOverviewComponentObserver.isHomeAndOverviewSame()); + mOverviewComponentObserver.addOverviewChangeListener(mOverviewChangeListener); + onOverviewTargetChanged(mOverviewComponentObserver.isHomeAndOverviewSame()); mTaskbarManager.onUserUnlocked(); } @@ -766,7 +745,7 @@ public class TouchInteractionService extends Service { } } - private void onOverviewTargetChange(boolean isHomeAndOverviewSame) { + private void onOverviewTargetChanged(boolean isHomeAndOverviewSame) { mAllAppsActionManager.setHomeAndOverviewSame(isHomeAndOverviewSame); RecentsViewContainer newOverviewContainer = mOverviewComponentObserver.getContainerInterface().getCreatedContainer(); @@ -778,7 +757,6 @@ public class TouchInteractionService extends Service { mTaskbarManager.setRecentsViewContainer(newOverviewContainer); } } - mTISBinder.onOverviewTargetChange(); } private PendingIntent createAllAppsPendingIntent() { @@ -797,7 +775,7 @@ public class TouchInteractionService extends Service { if (LockedUserState.get(this).isUserUnlocked()) { long systemUiStateFlags = mDeviceState.getSystemUiStateFlags(); SystemUiProxy.INSTANCE.get(this).setLastSystemUiStateFlags(systemUiStateFlags); - mOverviewComponentObserver.onSystemUiStateChanged(); + mOverviewComponentObserver.setHomeDisabled(mDeviceState.isHomeDisabled()); mTaskbarManager.onSystemUiFlagsChanged(systemUiStateFlags); mTaskAnimationManager.onSystemUiFlagsChanged(lastSysUIFlags, systemUiStateFlags); } @@ -818,7 +796,8 @@ public class TouchInteractionService extends Service { sIsInitialized = false; if (LockedUserState.get(this).isUserUnlocked()) { mInputConsumer.unregisterInputConsumer(); - mOverviewComponentObserver.onDestroy(); + mOverviewComponentObserver.setHomeDisabled(false); + mOverviewComponentObserver.removeOverviewChangeListener(mOverviewChangeListener); } disposeEventHandlers("TouchInteractionService onDestroy()"); mDeviceState.destroy(); diff --git a/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java b/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java index 4255372461..20a66dd58f 100644 --- a/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java +++ b/quickstep/src/com/android/quickstep/dagger/QuickstepBaseAppComponent.java @@ -19,6 +19,7 @@ package com.android.quickstep.dagger; import com.android.launcher3.dagger.LauncherAppComponent; import com.android.launcher3.dagger.LauncherBaseAppComponent; import com.android.launcher3.model.WellbeingModel; +import com.android.quickstep.OverviewComponentObserver; import com.android.quickstep.SystemUiProxy; import com.android.quickstep.fallback.window.RecentsDisplayModel; import com.android.quickstep.util.AsyncClockEventDelegate; @@ -40,4 +41,6 @@ public interface QuickstepBaseAppComponent extends LauncherBaseAppComponent { SystemUiProxy getSystemUiProxy(); RecentsDisplayModel getRecentsDisplayModel(); + + OverviewComponentObserver getOverviewComponentObserver(); } diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index 99c2c1c52b..4995e77564 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -70,6 +70,8 @@ import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.taskbar.TaskbarManager; import com.android.launcher3.util.Executors; import com.android.quickstep.GestureState; +import com.android.quickstep.OverviewComponentObserver; +import com.android.quickstep.OverviewComponentObserver.OverviewChangeListener; import com.android.quickstep.TouchInteractionService.TISBinder; import com.android.quickstep.util.LottieAnimationColorUtils; import com.android.quickstep.util.TISBindHelper; @@ -121,7 +123,7 @@ public class AllSetActivity extends Activity { private TextView mHintView; - private final Runnable mOverviewTargetChangeRunnable = this::onOverviewTargetChanged; + private final OverviewChangeListener mOverviewChangeListener = this::onOverviewTargetChange; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -197,6 +199,9 @@ public class AllSetActivity extends Activity { setUpBackgroundAnimation(getDP().isTablet); getIDP().addOnChangeListener(mOnIDPChangeListener); + + OverviewComponentObserver.INSTANCE.get(this) + .addOverviewChangeListener(mOverviewChangeListener); } private InvariantDeviceProfile getIDP() { @@ -286,7 +291,6 @@ public class AllSetActivity extends Activity { private void onTISConnected(TISBinder binder) { setSetupUIVisible(isResumed()); binder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null); - binder.registerOverviewTargetChangeListener(mOverviewTargetChangeRunnable); binder.preloadOverviewForSUWAllSet(); TaskbarManager taskbarManager = binder.getTaskbarManager(); if (taskbarManager != null) { @@ -294,11 +298,10 @@ public class AllSetActivity extends Activity { } } - private void onOverviewTargetChanged() { + private void onOverviewTargetChange(boolean isHomeAndOverviewSame) { TISBinder binder = mTISBindHelper.getBinder(); if (binder != null) { binder.preloadOverviewForSUWAllSet(); - binder.unregisterOverviewTargetChangeListener(mOverviewTargetChangeRunnable); } } @@ -318,7 +321,6 @@ public class AllSetActivity extends Activity { if (binder != null) { setSetupUIVisible(false); binder.setSwipeUpProxy(null); - binder.unregisterOverviewTargetChangeListener(mOverviewTargetChangeRunnable); } } @@ -346,6 +348,8 @@ public class AllSetActivity extends Activity { if (!isChangingConfigurations()) { dispatchLauncherAnimStartEnd(); } + OverviewComponentObserver.INSTANCE.get(this) + .removeOverviewChangeListener(mOverviewChangeListener); } private AnimatedFloat createSwipeUpProxy(GestureState state) { diff --git a/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java index e462706c98..1c4e7a7eb7 100644 --- a/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java +++ b/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java @@ -86,10 +86,8 @@ abstract class SwipeUpGestureTutorialController extends TutorialController { SwipeUpGestureTutorialController(TutorialFragment tutorialFragment, TutorialType tutorialType) { super(tutorialFragment, tutorialType); RecentsAnimationDeviceState deviceState = new RecentsAnimationDeviceState(mContext); - OverviewComponentObserver observer = new OverviewComponentObserver(mContext, deviceState); mTaskViewSwipeUpAnimation = new ViewSwipeUpAnimation(mContext, deviceState, - new GestureState(observer, -1)); - observer.onDestroy(); + new GestureState(OverviewComponentObserver.INSTANCE.get(mContext), -1)); deviceState.destroy(); DeviceProfile dp = InvariantDeviceProfile.INSTANCE.get(mContext) diff --git a/quickstep/src/com/android/quickstep/util/ContextualSearchInvoker.kt b/quickstep/src/com/android/quickstep/util/ContextualSearchInvoker.kt index 3be8ea6c6b..724fa404a2 100644 --- a/quickstep/src/com/android/quickstep/util/ContextualSearchInvoker.kt +++ b/quickstep/src/com/android/quickstep/util/ContextualSearchInvoker.kt @@ -34,7 +34,6 @@ import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LAUN import com.android.quickstep.BaseContainerInterface import com.android.quickstep.DeviceConfigWrapper import com.android.quickstep.OverviewComponentObserver -import com.android.quickstep.RecentsAnimationDeviceState import com.android.quickstep.SystemUiProxy import com.android.quickstep.TopTaskTracker import com.android.quickstep.views.RecentsView @@ -212,14 +211,7 @@ internal constructor( @VisibleForTesting fun getRecentsContainerInterface(): BaseContainerInterface<*, *>? { - val rads = RecentsAnimationDeviceState(context) - val observer = OverviewComponentObserver(context, rads) - try { - return observer.containerInterface - } finally { - observer.onDestroy() - rads.destroy() - } + return OverviewComponentObserver.INSTANCE.get(context).containerInterface } /** diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java index 1eb91ae047..c524286c3e 100644 --- a/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java +++ b/quickstep/src/com/android/quickstep/util/SplitSelectStateController.java @@ -583,10 +583,8 @@ public class SplitSelectStateController { /** * Init {@code SplitFromDesktopController} */ - public void initSplitFromDesktopController(QuickstepLauncher launcher, - OverviewComponentObserver overviewComponentObserver) { - initSplitFromDesktopController( - new SplitFromDesktopController(launcher, overviewComponentObserver)); + public void initSplitFromDesktopController(QuickstepLauncher launcher) { + initSplitFromDesktopController(new SplitFromDesktopController(launcher)); } @VisibleForTesting @@ -853,10 +851,9 @@ public class SplitSelectStateController { private DesktopSplitSelectListenerImpl mSplitSelectListener; private Drawable mAppIcon; - public SplitFromDesktopController(QuickstepLauncher launcher, - OverviewComponentObserver overviewComponentObserver) { + public SplitFromDesktopController(QuickstepLauncher launcher) { mLauncher = launcher; - mOverviewComponentObserver = overviewComponentObserver; + mOverviewComponentObserver = OverviewComponentObserver.INSTANCE.get(launcher); mSplitPlaceholderSize = mLauncher.getResources().getDimensionPixelSize( R.dimen.split_placeholder_size); mSplitPlaceholderInset = mLauncher.getResources().getDimensionPixelSize( diff --git a/quickstep/src/com/android/quickstep/util/SplitWithKeyboardShortcutController.java b/quickstep/src/com/android/quickstep/util/SplitWithKeyboardShortcutController.java index 744c08cc3c..0ba408399e 100644 --- a/quickstep/src/com/android/quickstep/util/SplitWithKeyboardShortcutController.java +++ b/quickstep/src/com/android/quickstep/util/SplitWithKeyboardShortcutController.java @@ -63,12 +63,11 @@ public class SplitWithKeyboardShortcutController { public SplitWithKeyboardShortcutController(QuickstepLauncher launcher, SplitSelectStateController controller, - OverviewComponentObserver overviewComponentObserver, RecentsAnimationDeviceState deviceState) { mLauncher = launcher; mController = controller; mDeviceState = deviceState; - mOverviewComponentObserver = overviewComponentObserver; + mOverviewComponentObserver = OverviewComponentObserver.INSTANCE.get(launcher); mSplitPlaceholderSize = mLauncher.getResources().getDimensionPixelSize( R.dimen.split_placeholder_size); @@ -106,7 +105,6 @@ public class SplitWithKeyboardShortcutController { } public void onDestroy() { - mOverviewComponentObserver.onDestroy(); mDeviceState.destroy(); } diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt index 50ba55c365..41877c9359 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt @@ -77,8 +77,7 @@ class LauncherSwipeHandlerV2Test { val deviceState = mock(RecentsAnimationDeviceState::class.java) whenever(deviceState.rotationTouchHelper).thenReturn(mock(RotationTouchHelper::class.java)) - - gestureState = spy(GestureState(OverviewComponentObserver(sandboxContext, deviceState), 0)) + gestureState = spy(GestureState(OverviewComponentObserver.INSTANCE.get(sandboxContext), 0)) underTest = LauncherSwipeHandlerV2( diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 695211ba32..5bb2fad38b 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -64,6 +64,7 @@ import com.android.launcher3.util.rule.ScreenRecordRule; import com.android.launcher3.util.rule.TestIsolationRule; import com.android.launcher3.util.rule.TestStabilityRule; import com.android.launcher3.util.rule.ViewCaptureRule; +import com.android.quickstep.OverviewComponentObserver.OverviewChangeListener; import com.android.quickstep.fallback.window.RecentsWindowManager; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsViewContainer; @@ -330,7 +331,7 @@ public class FallbackRecentsTest { return recentsViewContainer.getOverviewPanel().getTaskViewCount(); } - private class OverviewUpdateHandler { + private class OverviewUpdateHandler implements OverviewChangeListener { final RecentsAnimationDeviceState mRads; final OverviewComponentObserver mObserver; @@ -339,19 +340,24 @@ public class FallbackRecentsTest { OverviewUpdateHandler() { Context ctx = getInstrumentation().getTargetContext(); mRads = new RecentsAnimationDeviceState(ctx); - mObserver = new OverviewComponentObserver(ctx, mRads); + mObserver = OverviewComponentObserver.INSTANCE.get(ctx); mChangeCounter = new CountDownLatch(1); if (mObserver.getHomeIntent().getComponent() .getPackageName().equals(mOtherLauncherActivity.packageName)) { // Home already same mChangeCounter.countDown(); } else { - mObserver.setOverviewChangeListener(b -> mChangeCounter.countDown()); + mObserver.addOverviewChangeListener(this); } } + @Override + public void onOverviewTargetChange(boolean isHomeAndOverviewSame) { + mChangeCounter.countDown(); + } + void destroy() { - mObserver.onDestroy(); + mObserver.removeOverviewChangeListener(this); mRads.destroy(); } }