From e82a20a44dd254df8f1c1138687e20b6c0ec5d39 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 19 Oct 2023 13:52:49 -0700 Subject: [PATCH] Removing some dependencies on Activity > Removing activtiy from overlay callbacks > Removing usage on activtiyLifecycleCallbacks and managing the callbacks ourselves Bug: 306225896 Test: Existing tests cover the lifecycle changes Flag: N/A Change-Id: I79941e364328eecdc8a72cac4d35b75d50a25319 --- .../launcher3/taskbar/TaskbarManager.java | 47 +++++++++---------- .../uioverrides/QuickstepLauncher.java | 5 -- .../android/quickstep/AbsSwipeUpHandler.java | 39 +++++++-------- .../util/TaskRemovedDuringLaunchListener.java | 46 +++++++++--------- src/com/android/launcher3/BaseActivity.java | 35 ++++++++++++-- .../launcher3/BaseDraggingActivity.java | 37 +-------------- .../android/launcher3/DropTargetHandler.kt | 3 +- src/com/android/launcher3/Launcher.java | 25 +++++----- .../android/launcher3/util/RunnableList.java | 11 +++-- .../shared/LauncherOverlayManager.java | 27 +++-------- 10 files changed, 122 insertions(+), 153 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index b500c3e98f..9bb7e672cf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -21,6 +21,7 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; +import static com.android.launcher3.BaseActivity.EVENT_DESTROYED; import static com.android.launcher3.LauncherState.OVERVIEW; import static com.android.launcher3.config.FeatureFlags.enableTaskbarNoRecreate; import static com.android.launcher3.util.DisplayController.TASKBAR_NOT_DESTROYED_TAG; @@ -30,7 +31,6 @@ import static com.android.quickstep.util.SystemActionConstants.ACTION_SHOW_TASKB import static com.android.quickstep.util.SystemActionConstants.SYSTEM_ACTION_ID_TASKBAR; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.PendingIntent; import android.content.ComponentCallbacks; import android.content.Context; @@ -61,7 +61,6 @@ import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider; import com.android.launcher3.uioverrides.QuickstepLauncher; -import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.SettingsCache; import com.android.launcher3.util.SimpleBroadcastReceiver; @@ -145,27 +144,25 @@ public class TaskbarManager { private final SimpleBroadcastReceiver mTaskbarBroadcastReceiver = new SimpleBroadcastReceiver(this::showTaskbarFromBroadcast); - private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks = - new ActivityLifecycleCallbacksAdapter() { - @Override - public void onActivityDestroyed(Activity activity) { - if (mActivity != activity) return; - if (mActivity != null) { - mActivity.removeOnDeviceProfileChangeListener( - mDebugActivityDeviceProfileChanged); - Log.d(TASKBAR_NOT_DESTROYED_TAG, - "unregistering activity lifecycle callbacks from " - + "onActivityDestroyed."); - mActivity.unregisterActivityLifecycleCallbacks(this); - } - mActivity = null; - debugWhyTaskbarNotDestroyed("clearActivity"); - if (mTaskbarActivityContext != null) { - mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT); - } - mUnfoldProgressProvider.setSourceProvider(null); - } - }; + private final Runnable mActivityOnDestroyCallback = new Runnable() { + @Override + public void run() { + if (mActivity != null) { + mActivity.removeOnDeviceProfileChangeListener( + mDebugActivityDeviceProfileChanged); + Log.d(TASKBAR_NOT_DESTROYED_TAG, + "unregistering activity lifecycle callbacks from " + + "onActivityDestroyed."); + mActivity.removeEventCallback(EVENT_DESTROYED, this); + } + mActivity = null; + debugWhyTaskbarNotDestroyed("clearActivity"); + if (mTaskbarActivityContext != null) { + mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT); + } + mUnfoldProgressProvider.setSourceProvider(null); + } + }; UnfoldTransitionProgressProvider.TransitionProgressListener mUnfoldTransitionProgressListener = new UnfoldTransitionProgressProvider.TransitionProgressListener() { @@ -371,7 +368,7 @@ public class TaskbarManager { mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged); Log.d(TASKBAR_NOT_DESTROYED_TAG, "registering activity lifecycle callbacks from setActivity()."); - mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks); + mActivity.addEventCallback(EVENT_DESTROYED, mActivityOnDestroyCallback); UnfoldTransitionProgressProvider unfoldTransitionProgressProvider = getUnfoldTransitionProgressProviderForActivity(activity); if (unfoldTransitionProgressProvider != null) { @@ -547,7 +544,7 @@ public class TaskbarManager { Log.d(TASKBAR_NOT_DESTROYED_TAG, "unregistering activity lifecycle callbacks from " + "removeActivityCallbackAndListeners()."); - mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks); + mActivity.removeEventCallback(EVENT_DESTROYED, mActivityOnDestroyCallback); UnfoldTransitionProgressProvider unfoldTransitionProgressProvider = getUnfoldTransitionProgressProviderForActivity(mActivity); if (unfoldTransitionProgressProvider != null) { diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 009b1bd286..e1bb8ca3b1 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -1182,11 +1182,6 @@ public class QuickstepLauncher extends Launcher { } } - @Override - public void tryClearAccessibilityFocus(View view) { - view.clearAccessibilityFocus(); - } - @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 4dfa81dd4e..a18db5d290 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -24,6 +24,8 @@ import static android.widget.Toast.LENGTH_SHORT; import static com.android.app.animation.Interpolators.ACCELERATE_DECELERATE; import static com.android.app.animation.Interpolators.DECELERATE; import static com.android.app.animation.Interpolators.OVERSHOOT_1_2; +import static com.android.launcher3.BaseActivity.EVENT_DESTROYED; +import static com.android.launcher3.BaseActivity.EVENT_STARTED; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_STATE_HANDLER; import static com.android.launcher3.BaseActivity.STATE_HANDLER_INVISIBILITY_FLAGS; import static com.android.launcher3.LauncherPrefs.ALL_APPS_OVERVIEW_THRESHOLD; @@ -62,7 +64,6 @@ import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ValueAnimator; import android.annotation.TargetApi; -import android.app.Activity; import android.app.ActivityManager; import android.app.TaskInfo; import android.app.WindowConfiguration; @@ -109,7 +110,6 @@ import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.taskbar.TaskbarThresholdUtils; import com.android.launcher3.taskbar.TaskbarUIController; import com.android.launcher3.uioverrides.QuickstepLauncher; -import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.SafeCloseable; import com.android.launcher3.util.TraceHelper; @@ -184,19 +184,13 @@ public abstract class AbsSwipeUpHandler, protected MultiStateCallback mStateCallback; protected boolean mCanceled; private boolean mRecentsViewScrollLinked = false; - private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks = - new ActivityLifecycleCallbacksAdapter() { - @Override - public void onActivityDestroyed(Activity activity) { - if (mActivity != activity) { - return; - } - ActiveGestureLog.INSTANCE.addLog("Launcher destroyed", LAUNCHER_DESTROYED); - mRecentsView = null; - mActivity = null; - mStateCallback.clearState(STATE_LAUNCHER_PRESENT); - } - }; + + private final Runnable mLauncherOnDestroyCallback = () -> { + ActiveGestureLog.INSTANCE.addLog("Launcher destroyed", LAUNCHER_DESTROYED); + mRecentsView = null; + mActivity = null; + mStateCallback.clearState(STATE_LAUNCHER_PRESENT); + }; private static int FLAG_COUNT = 0; private static int getNextStateFlag(String name) { @@ -317,6 +311,7 @@ public abstract class AbsSwipeUpHandler, private final int mSplashMainWindowShiftLength; private final Runnable mOnDeferredActivityLaunch = this::onDeferredActivityLaunch; + private final Runnable mLauncherOnStartCallback = this::onLauncherStart; private SwipePipToHomeAnimator mSwipePipToHomeAnimator; protected boolean mIsSwipingPipToHome; @@ -490,6 +485,7 @@ public abstract class AbsSwipeUpHandler, mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED); return true; } + resetLauncherListeners(); // The launcher may have been recreated as a result of device rotation. int oldState = mStateCallback.getState() & ~LAUNCHER_UI_STATES; @@ -513,7 +509,7 @@ public abstract class AbsSwipeUpHandler, if (alreadyOnHome) { onLauncherStart(); } else { - activity.runOnceOnStart(this::onLauncherStart); + activity.addEventCallback(EVENT_STARTED, mLauncherOnStartCallback); } // Set up a entire animation lifecycle callback to notify the current recents view when @@ -538,9 +534,8 @@ public abstract class AbsSwipeUpHandler, setupRecentsViewUi(); mRecentsView.runOnPageScrollsInitialized(this::linkRecentsViewScroll); - activity.runOnBindToTouchInteractionService(this::onLauncherBindToService); - - mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks); + mActivity.runOnBindToTouchInteractionService(this::onLauncherBindToService); + mActivity.addEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback); return true; } @@ -1854,7 +1849,6 @@ public abstract class AbsSwipeUpHandler, if (mActivity != null) { // In the off chance that the gesture ends before Launcher is started, we should clear // the callback here so that it doesn't update with the wrong state - mActivity.clearRunOnceOnStartCallback(); resetLauncherListeners(); } if (mGestureState.isRecentsAnimationRunning() && mGestureState.getEndTarget() != null @@ -1920,7 +1914,7 @@ public abstract class AbsSwipeUpHandler, private void reset() { mStateCallback.setStateOnUiThread(STATE_HANDLER_INVALIDATED); if (mActivity != null) { - mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks); + mActivity.removeEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback); } } @@ -1991,6 +1985,9 @@ public abstract class AbsSwipeUpHandler, * continued quick switch gesture, which cancels the previous handler but doesn't invalidate it. */ private void resetLauncherListeners() { + mActivity.removeEventCallback(EVENT_STARTED, mLauncherOnStartCallback); + mActivity.removeEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback); + mActivity.getRootView().setOnApplyWindowInsetsListener(null); if (mRecentsView != null) { diff --git a/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java b/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java index d7b3431234..cdadd711a8 100644 --- a/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java +++ b/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java @@ -18,11 +18,13 @@ package com.android.quickstep.util; import static android.app.ActivityTaskManager.INVALID_TASK_ID; -import android.app.Activity; +import static com.android.launcher3.BaseActivity.EVENT_DESTROYED; +import static com.android.launcher3.BaseActivity.EVENT_RESUMED; +import static com.android.launcher3.BaseActivity.EVENT_STOPPED; import androidx.annotation.NonNull; -import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter; +import com.android.launcher3.BaseActivity; import com.android.quickstep.RecentsModel; /** @@ -34,19 +36,28 @@ import com.android.quickstep.RecentsModel; * If we hit either of those signals and the task is no longer valid, then the registered failure * callback will be notified. */ -public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbacksAdapter { +public class TaskRemovedDuringLaunchListener { - private Activity mActivity; + private BaseActivity mActivity; private int mLaunchedTaskId = INVALID_TASK_ID; private Runnable mTaskLaunchFailedCallback = null; + private final Runnable mUnregisterCallback = this::unregister; + private final Runnable mResumeCallback = this::checkTaskLaunchFailed; + /** * Registers a failure listener callback if it detects a scenario in which an app launch * failed before the transition finished. */ - public void register(Activity activity, int launchedTaskId, + public void register(BaseActivity activity, int launchedTaskId, @NonNull Runnable taskLaunchFailedCallback) { - activity.registerActivityLifecycleCallbacks(this); + // The normal task launch case, Launcher stops and updates its state correctly + activity.addEventCallback(EVENT_STOPPED, mUnregisterCallback); + // The transition hasn't finished but Launcher was resumed, check if the launch failed + activity.addEventCallback(EVENT_RESUMED, mResumeCallback); + // If we somehow don't get any of the above signals, then just unregister this listener + activity.addEventCallback(EVENT_DESTROYED, mUnregisterCallback); + mActivity = activity; mLaunchedTaskId = launchedTaskId; mTaskLaunchFailedCallback = taskLaunchFailedCallback; @@ -56,7 +67,10 @@ public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbac * Unregisters the failure listener. */ private void unregister() { - mActivity.unregisterActivityLifecycleCallbacks(this); + mActivity.removeEventCallback(EVENT_STOPPED, mUnregisterCallback); + mActivity.removeEventCallback(EVENT_RESUMED, mResumeCallback); + mActivity.removeEventCallback(EVENT_DESTROYED, mUnregisterCallback); + mActivity = null; mLaunchedTaskId = INVALID_TASK_ID; mTaskLaunchFailedCallback = null; @@ -70,24 +84,6 @@ public class TaskRemovedDuringLaunchListener implements ActivityLifecycleCallbac checkTaskLaunchFailed(); } - @Override - public void onActivityStopped(Activity activity) { - // The normal task launch case, Launcher stops and updates its state correctly - unregister(); - } - - @Override - public void onActivityResumed(Activity activity) { - // The transition hasn't finished but Launcher was resumed, check if the launch failed - checkTaskLaunchFailed(); - } - - @Override - public void onActivityDestroyed(Activity activity) { - // If we somehow don't get any of the above signals, then just unregister this listener - unregister(); - } - private void checkTaskLaunchFailed() { if (mLaunchedTaskId != INVALID_TASK_ID) { final int launchedTaskId = mLaunchedTaskId; diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index 05a6452d2e..1049314016 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -29,7 +29,6 @@ import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; -import android.view.View; import android.window.OnBackInvokedDispatcher; import androidx.annotation.IntDef; @@ -38,6 +37,7 @@ import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.shared.TestProtocol; +import com.android.launcher3.util.RunnableList; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.ViewCache; import com.android.launcher3.views.ActivityContext; @@ -153,6 +153,18 @@ public abstract class BaseActivity extends Activity implements ActivityContext { private final ViewCache mViewCache = new ViewCache(); + @Retention(SOURCE) + @IntDef({EVENT_STARTED, EVENT_RESUMED, EVENT_STOPPED, EVENT_DESTROYED}) + public @interface ActivityEvent { } + public static final int EVENT_STARTED = 0; + public static final int EVENT_RESUMED = 1; + public static final int EVENT_STOPPED = 2; + public static final int EVENT_DESTROYED = 3; + + // Callback array that corresponds to events defined in @ActivityEvent + private final RunnableList[] mEventCallbacks = + {new RunnableList(), new RunnableList(), new RunnableList(), new RunnableList()}; + @Override public ViewCache getViewCache() { return mViewCache; @@ -205,12 +217,14 @@ public abstract class BaseActivity extends Activity implements ActivityContext { protected void onStart() { addActivityFlags(ACTIVITY_STATE_STARTED); super.onStart(); + mEventCallbacks[EVENT_STARTED].executeAllAndClear(); } @Override protected void onResume() { setResumed(); super.onResume(); + mEventCallbacks[EVENT_RESUMED].executeAllAndClear(); } @Override @@ -232,12 +246,20 @@ public abstract class BaseActivity extends Activity implements ActivityContext { removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE); mForceInvisible = 0; super.onStop(); + mEventCallbacks[EVENT_STOPPED].executeAllAndClear(); + // Reset the overridden sysui flags used for the task-swipe launch animation, this is a // catch all for if we do not get resumed (and therefore not paused below) getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0); } + @Override + protected void onDestroy() { + super.onDestroy(); + mEventCallbacks[EVENT_DESTROYED].executeAllAndClear(); + } + @Override protected void onPause() { setPaused(); @@ -258,7 +280,6 @@ public abstract class BaseActivity extends Activity implements ActivityContext { } else { removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); } - } protected void registerBackDispatcher() { @@ -364,9 +385,15 @@ public abstract class BaseActivity extends Activity implements ActivityContext { } /** - * Attempts to clear accessibility focus on {@param view}. + * Adds a callback for the provided activity event */ - public void tryClearAccessibilityFocus(View view) { + public void addEventCallback(@ActivityEvent int event, Runnable callback) { + mEventCallbacks[event].add(callback); + } + + /** Removes a previously added callback */ + public void removeEventCallback(@ActivityEvent int event, Runnable callback) { + mEventCallbacks[event].remove(callback); } public interface MultiWindowModeChangedListener { diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index 808cf70a50..f8ed4df453 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -38,7 +38,6 @@ 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.OnColorHintListener; -import com.android.launcher3.util.RunnableList; import com.android.launcher3.util.Themes; import com.android.launcher3.util.TraceHelper; import com.android.launcher3.util.WallpaperColorHints; @@ -51,8 +50,6 @@ import com.android.launcher3.util.WindowBounds; public abstract class BaseDraggingActivity extends BaseActivity implements OnColorHintListener, DisplayInfoChangeListener { - private static final String TAG = "BaseDraggingActivity"; - // When starting an action mode, setting this tag will cause the action mode to be cancelled // automatically when user interacts with the launcher. public static final Object AUTO_CANCEL_ACTION_MODE = new Object(); @@ -60,8 +57,6 @@ public abstract class BaseDraggingActivity extends BaseActivity private ActionMode mCurrentActionMode; protected boolean mIsSafeModeEnabled; - private Runnable mOnStartCallback; - private final RunnableList mOnResumeCallbacks = new RunnableList(); private int mThemeRes = R.style.AppTheme; @Override @@ -81,16 +76,6 @@ public abstract class BaseDraggingActivity extends BaseActivity } } - @Override - protected void onResume() { - super.onResume(); - mOnResumeCallbacks.executeAllAndClear(); - } - - public void addOnResumeCallback(Runnable callback) { - mOnResumeCallbacks.add(callback); - } - @MainThread @Override public void onColorHintsChanged(int colorHints) { @@ -146,27 +131,17 @@ public abstract class BaseDraggingActivity extends BaseActivity @NonNull public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) { ActivityOptionsWrapper wrapper = super.getActivityLaunchOptions(v, item); - addOnResumeCallback(wrapper.onEndCallback::executeAllAndDestroy); + addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy); return wrapper; } @Override public ActivityOptionsWrapper makeDefaultActivityOptions(int splashScreenStyle) { ActivityOptionsWrapper wrapper = super.makeDefaultActivityOptions(splashScreenStyle); - addOnResumeCallback(wrapper.onEndCallback::executeAllAndDestroy); + addEventCallback(EVENT_RESUMED, wrapper.onEndCallback::executeAllAndDestroy); return wrapper; } - @Override - protected void onStart() { - super.onStart(); - - if (mOnStartCallback != null) { - mOnStartCallback.run(); - mOnStartCallback = null; - } - } - @Override protected void onDestroy() { super.onDestroy(); @@ -174,14 +149,6 @@ public abstract class BaseDraggingActivity extends BaseActivity WallpaperColorHints.get(this).unregisterOnColorsChangedListener(this); } - public void runOnceOnStart(Runnable action) { - mOnStartCallback = action; - } - - public void clearRunOnceOnStartCallback() { - mOnStartCallback = null; - } - protected void onDeviceProfileInitiated() { if (mDeviceProfile.isVerticalBarLayout()) { mDeviceProfile.updateIsSeascape(this); diff --git a/src/com/android/launcher3/DropTargetHandler.kt b/src/com/android/launcher3/DropTargetHandler.kt index 6560e16b52..78f2862548 100644 --- a/src/com/android/launcher3/DropTargetHandler.kt +++ b/src/com/android/launcher3/DropTargetHandler.kt @@ -2,6 +2,7 @@ package com.android.launcher3 import android.content.ComponentName import android.view.View +import com.android.launcher3.BaseDraggingActivity.EVENT_RESUMED import com.android.launcher3.DropTarget.DragObject import com.android.launcher3.SecondaryDropTarget.DeferredOnComplete import com.android.launcher3.dragndrop.DragLayer @@ -32,7 +33,7 @@ class DropTargetHandler(launcher: Launcher) { if (d.dragSource is SecondaryDropTarget.DeferredOnComplete) { target?.let { deferred.mPackageName = it.packageName - mLauncher.addOnResumeCallback { deferred.onLauncherResume() } + mLauncher.addEventCallback(EVENT_RESUMED) { deferred.onLauncherResume() } } ?: deferred.sendFailure() } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 9255ff490b..fe8faec92f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -688,7 +688,7 @@ public class Launcher extends StatefulActivity private void switchOverlay(Supplier overlaySupplier) { if (mOverlayManager != null) { - mOverlayManager.onActivityDestroyed(this); + mOverlayManager.onActivityDestroyed(); } mOverlayManager = overlaySupplier.get(); if (getRootView().isAttachedToWindow()) { @@ -1029,7 +1029,7 @@ public class Launcher extends StatefulActivity if (mDeferOverlayCallbacks) { checkIfOverlayStillDeferred(); } else { - mOverlayManager.onActivityStopped(this); + mOverlayManager.onActivityStopped(); } hideKeyboard(); logStopAndResume(false /* isResume */); @@ -1043,7 +1043,7 @@ public class Launcher extends StatefulActivity TraceHelper.INSTANCE.beginSection(ON_START_EVT); super.onStart(); if (!mDeferOverlayCallbacks) { - mOverlayManager.onActivityStarted(this); + mOverlayManager.onActivityStarted(); } mAppWidgetHolder.setActivityStarted(true); @@ -1112,15 +1112,15 @@ public class Launcher extends StatefulActivity // Move the client to the correct state. Calling the same method twice is no-op. if (isStarted()) { - mOverlayManager.onActivityStarted(this); + mOverlayManager.onActivityStarted(); } if (hasBeenResumed()) { - mOverlayManager.onActivityResumed(this); + mOverlayManager.onActivityResumed(); } else { - mOverlayManager.onActivityPaused(this); + mOverlayManager.onActivityPaused(); } if (!isStarted()) { - mOverlayManager.onActivityStopped(this); + mOverlayManager.onActivityStopped(); } } @@ -1220,7 +1220,7 @@ public class Launcher extends StatefulActivity if (mDeferOverlayCallbacks) { scheduleDeferredCheck(); } else { - mOverlayManager.onActivityResumed(this); + mOverlayManager.onActivityResumed(); } DragView.removeAllViews(this); @@ -1238,7 +1238,7 @@ public class Launcher extends StatefulActivity mDropTargetBar.animateToVisibility(false); if (!mDeferOverlayCallbacks) { - mOverlayManager.onActivityPaused(this); + mOverlayManager.onActivityPaused(); } mAppWidgetHolder.setActivityResumed(false); } @@ -1683,7 +1683,6 @@ public class Launcher extends StatefulActivity } super.onSaveInstanceState(outState); - mOverlayManager.onActivitySaveInstanceState(this, outState); } @Override @@ -1709,7 +1708,7 @@ public class Launcher extends StatefulActivity clearPendingBinds(); LauncherAppState.getIDP(this).removeOnChangeListener(this); - mOverlayManager.onActivityDestroyed(this); + mOverlayManager.onActivityDestroyed(); } public LauncherAccessibilityDelegate getAccessibilityDelegate() { @@ -1742,7 +1741,7 @@ public class Launcher extends StatefulActivity try { super.startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, options); - } catch (IntentSender.SendIntentException e) { + } catch (Exception e) { throw new ActivityNotFoundException(); } } @@ -2004,7 +2003,7 @@ public class Launcher extends StatefulActivity // Workaround an issue where the WM launch animation is clobbered when finishing the // recents animation into launcher. Defer launching the activity until Launcher is // next resumed. - addOnResumeCallback(() -> { + addEventCallback(EVENT_RESUMED, () -> { RunnableList actualResult = startActivitySafely(v, intent, item); if (actualResult != null) { actualResult.add(result::executeAllAndDestroy); diff --git a/src/com/android/launcher3/util/RunnableList.java b/src/com/android/launcher3/util/RunnableList.java index 644537bce1..f6e0c57fb2 100644 --- a/src/com/android/launcher3/util/RunnableList.java +++ b/src/com/android/launcher3/util/RunnableList.java @@ -25,9 +25,7 @@ public class RunnableList { private ArrayList mList = null; private boolean mDestroyed = false; - /** - * Ads a runnable to this list - */ + /** Adds a runnable to this list */ public void add(Runnable runnable) { if (runnable == null) { return; @@ -42,6 +40,13 @@ public class RunnableList { mList.add(runnable); } + /** Removes a previously added runnable */ + public void remove(Runnable runnable) { + if (mList != null) { + mList.remove(runnable); + } + } + /** * Destroys the list, executing any pending callbacks. All new callbacks are * immediately executed diff --git a/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java b/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java index 6b27503afb..54cc0bc755 100644 --- a/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java +++ b/src_plugins/com/android/systemui/plugins/shared/LauncherOverlayManager.java @@ -15,16 +15,12 @@ */ package com.android.systemui.plugins.shared; -import android.app.Activity; -import android.app.Application; -import android.os.Bundle; - import java.io.PrintWriter; /** * Interface to control the overlay on Launcher */ -public interface LauncherOverlayManager extends Application.ActivityLifecycleCallbacks { +public interface LauncherOverlayManager { default void onDeviceProvideChanged() { } @@ -41,26 +37,15 @@ public interface LauncherOverlayManager extends Application.ActivityLifecycleCal default void hideOverlay(int duration) { } - @Override - default void onActivityCreated(Activity activity, Bundle bundle) { } + default void onActivityStarted() { } - @Override - default void onActivityStarted(Activity activity) { } + default void onActivityResumed() { } - @Override - default void onActivityResumed(Activity activity) { } + default void onActivityPaused() { } - @Override - default void onActivityPaused(Activity activity) { } + default void onActivityStopped() { } - @Override - default void onActivityStopped(Activity activity) { } - - @Override - default void onActivitySaveInstanceState(Activity activity, Bundle bundle) { } - - @Override - default void onActivityDestroyed(Activity activity) { } + default void onActivityDestroyed() { } interface LauncherOverlay {