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
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
index b500c3e..9bb7e67 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.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.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.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 @@
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 @@
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 @@
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 009b1bd..e1bb8ca 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java
@@ -1183,11 +1183,6 @@
}
@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 4dfa81d..a18db5d 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -24,6 +24,8 @@
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.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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
private void reset() {
mStateCallback.setStateOnUiThread(STATE_HANDLER_INVALIDATED);
if (mActivity != null) {
- mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
+ mActivity.removeEventCallback(EVENT_DESTROYED, mLauncherOnDestroyCallback);
}
}
@@ -1991,6 +1985,9 @@
* 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 d7b3431..cdadd71 100644
--- a/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java
+++ b/quickstep/src/com/android/quickstep/util/TaskRemovedDuringLaunchListener.java
@@ -18,11 +18,13 @@
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 @@
* 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 @@
* 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 @@
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 05a6452..1049314 100644
--- a/src/com/android/launcher3/BaseActivity.java
+++ b/src/com/android/launcher3/BaseActivity.java
@@ -29,7 +29,6 @@
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.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 @@
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 @@
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,6 +246,8 @@
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)
@@ -239,6 +255,12 @@
}
@Override
+ protected void onDestroy() {
+ super.onDestroy();
+ mEventCallbacks[EVENT_DESTROYED].executeAllAndClear();
+ }
+
+ @Override
protected void onPause() {
setPaused();
super.onPause();
@@ -258,7 +280,6 @@
} else {
removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
}
-
}
protected void registerBackDispatcher() {
@@ -364,9 +385,15 @@
}
/**
- * 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 808cf70..f8ed4df 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.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 @@
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 @@
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 @@
}
}
- @Override
- protected void onResume() {
- super.onResume();
- mOnResumeCallbacks.executeAllAndClear();
- }
-
- public void addOnResumeCallback(Runnable callback) {
- mOnResumeCallbacks.add(callback);
- }
-
@MainThread
@Override
public void onColorHintsChanged(int colorHints) {
@@ -146,42 +131,24 @@
@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();
DisplayController.INSTANCE.get(this).removeChangeListener(this);
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 6560e16..78f2862 100644
--- a/src/com/android/launcher3/DropTargetHandler.kt
+++ b/src/com/android/launcher3/DropTargetHandler.kt
@@ -2,6 +2,7 @@
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 @@
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 9255ff4..fe8faec 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -688,7 +688,7 @@
private void switchOverlay(Supplier<LauncherOverlayManager> overlaySupplier) {
if (mOverlayManager != null) {
- mOverlayManager.onActivityDestroyed(this);
+ mOverlayManager.onActivityDestroyed();
}
mOverlayManager = overlaySupplier.get();
if (getRootView().isAttachedToWindow()) {
@@ -1029,7 +1029,7 @@
if (mDeferOverlayCallbacks) {
checkIfOverlayStillDeferred();
} else {
- mOverlayManager.onActivityStopped(this);
+ mOverlayManager.onActivityStopped();
}
hideKeyboard();
logStopAndResume(false /* isResume */);
@@ -1043,7 +1043,7 @@
TraceHelper.INSTANCE.beginSection(ON_START_EVT);
super.onStart();
if (!mDeferOverlayCallbacks) {
- mOverlayManager.onActivityStarted(this);
+ mOverlayManager.onActivityStarted();
}
mAppWidgetHolder.setActivityStarted(true);
@@ -1112,15 +1112,15 @@
// 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 @@
if (mDeferOverlayCallbacks) {
scheduleDeferredCheck();
} else {
- mOverlayManager.onActivityResumed(this);
+ mOverlayManager.onActivityResumed();
}
DragView.removeAllViews(this);
@@ -1238,7 +1238,7 @@
mDropTargetBar.animateToVisibility(false);
if (!mDeferOverlayCallbacks) {
- mOverlayManager.onActivityPaused(this);
+ mOverlayManager.onActivityPaused();
}
mAppWidgetHolder.setActivityResumed(false);
}
@@ -1683,7 +1683,6 @@
}
super.onSaveInstanceState(outState);
- mOverlayManager.onActivitySaveInstanceState(this, outState);
}
@Override
@@ -1709,7 +1708,7 @@
clearPendingBinds();
LauncherAppState.getIDP(this).removeOnChangeListener(this);
- mOverlayManager.onActivityDestroyed(this);
+ mOverlayManager.onActivityDestroyed();
}
public LauncherAccessibilityDelegate getAccessibilityDelegate() {
@@ -1742,7 +1741,7 @@
try {
super.startIntentSenderForResult(intent, requestCode,
fillInIntent, flagsMask, flagsValues, extraFlags, options);
- } catch (IntentSender.SendIntentException e) {
+ } catch (Exception e) {
throw new ActivityNotFoundException();
}
}
@@ -2004,7 +2003,7 @@
// 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 644537b..f6e0c57 100644
--- a/src/com/android/launcher3/util/RunnableList.java
+++ b/src/com/android/launcher3/util/RunnableList.java
@@ -25,9 +25,7 @@
private ArrayList<Runnable> 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 @@
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 6b27503..54cc0bc 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 @@
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 {