diff --git a/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java b/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java index 057b48bb2b..49945263a4 100644 --- a/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java +++ b/go/quickstep/src/com/android/quickstep/FallbackActivityControllerHelper.java @@ -26,6 +26,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.userevent.nano.LauncherLogProto; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.RemoteAnimationTargetSet; import com.android.quickstep.views.IconRecentsView; @@ -85,13 +86,13 @@ public final class FallbackActivityControllerHelper extends @Override public ActivityInitListener createActivityInitListener( BiPredicate onInitListener) { - return new RecentsActivityTracker(onInitListener); + return new ActivityInitListener(onInitListener, RecentsActivity.ACTIVITY_TRACKER); } @Nullable @Override public RecentsActivity getCreatedActivity() { - return RecentsActivityTracker.getCurrentActivity(); + return RecentsActivity.ACTIVITY_TRACKER.getCreatedActivity(); } @Nullable diff --git a/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java b/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java index b0d9cda6bc..8993b67005 100644 --- a/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java +++ b/go/quickstep/src/com/android/quickstep/LauncherActivityControllerHelper.java @@ -55,7 +55,7 @@ public final class LauncherActivityControllerHelper extends GoActivityControlHel } @Override - public ActivityInitListener createActivityInitListener( + public LauncherInitListener createActivityInitListener( BiPredicate onInitListener) { return new LauncherInitListener(onInitListener); } diff --git a/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java b/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java index 216972cba2..9c409ccca5 100644 --- a/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java +++ b/go/quickstep/src/com/android/quickstep/OverviewCommandHelper.java @@ -27,8 +27,8 @@ import android.view.ViewConfiguration; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.userevent.nano.LauncherLogProto; -import com.android.quickstep.ActivityControlHelper.ActivityInitListener; import com.android.quickstep.AppToOverviewAnimationProvider.AppToOverviewAnimationListener; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.views.IconRecentsView; import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.LatencyTrackerCompat; @@ -104,7 +104,7 @@ public class OverviewCommandHelper { private final long mToggleClickedTime = SystemClock.uptimeMillis(); private boolean mUserEventLogged; - private ActivityInitListener mListener; + private ActivityInitListener mListener; public RecentsActivityCommand() { mHelper = mOverviewComponentObserver.getActivityControlHelper(); diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/LauncherInitListenerEx.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/LauncherInitListenerEx.java index c5c4add6b2..76050d57bd 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/LauncherInitListenerEx.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/LauncherInitListenerEx.java @@ -27,7 +27,7 @@ public class LauncherInitListenerEx extends LauncherInitListener { } @Override - protected boolean init(Launcher launcher, boolean alreadyOnHome) { + public boolean init(Launcher launcher, boolean alreadyOnHome) { PredictionUiStateManager.INSTANCE.get(launcher).switchClient(Client.OVERVIEW); return super.init(launcher, alreadyOnHome); } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java index 7196f7c6f3..d524b5d25c 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandler.java @@ -57,10 +57,10 @@ import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.graphics.RotationMode; import com.android.launcher3.views.FloatingIconView; -import com.android.quickstep.ActivityControlHelper.ActivityInitListener; import com.android.quickstep.ActivityControlHelper.HomeAnimationFactory; import com.android.quickstep.SysUINavigationMode.Mode; import com.android.quickstep.inputconsumers.InputConsumer; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.ClipAnimationHelper; import com.android.quickstep.util.ClipAnimationHelper.TransformParams; import com.android.quickstep.util.RectFSpringAnim; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java index 8c5a78823a..33180a9654 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityControllerHelper.java @@ -35,6 +35,7 @@ import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.quickstep.fallback.FallbackRecentsView; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.RemoteAnimationTargetSet; import com.android.quickstep.views.RecentsView; @@ -177,13 +178,13 @@ public final class FallbackActivityControllerHelper implements @Override public ActivityInitListener createActivityInitListener( BiPredicate onInitListener) { - return new RecentsActivityTracker(onInitListener); + return new ActivityInitListener(onInitListener, RecentsActivity.ACTIVITY_TRACKER); } @Nullable @Override public RecentsActivity getCreatedActivity() { - return RecentsActivityTracker.getCurrentActivity(); + return BaseRecentsActivity.ACTIVITY_TRACKER.getCreatedActivity(); } @Nullable diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java index 0d3d119594..e7005a62ef 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java @@ -50,7 +50,6 @@ import androidx.annotation.UiThread; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherInitListenerEx; import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherStateManager; @@ -61,6 +60,7 @@ import com.android.launcher3.uioverrides.states.OverviewState; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.views.FloatingIconView; import com.android.quickstep.SysUINavigationMode.Mode; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.StaggeredWorkspaceAnim; import com.android.quickstep.views.LauncherRecentsView; @@ -404,11 +404,7 @@ public final class LauncherActivityControllerHelper implements ActivityControlHe @Nullable @Override public Launcher getCreatedActivity() { - LauncherAppState app = LauncherAppState.getInstanceNoCreate(); - if (app == null) { - return null; - } - return (Launcher) app.getModel().getCallback(); + return Launcher.ACTIVITY_TRACKER.getCreatedActivity(); } @Nullable diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java index 6a06de9569..6df9ce5736 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java @@ -25,14 +25,12 @@ import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.os.SystemClock; -import android.util.Log; import android.view.ViewConfiguration; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.logging.UserEventDispatcher; -import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.userevent.nano.LauncherLogProto; -import com.android.quickstep.ActivityControlHelper.ActivityInitListener; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.TaskView; import com.android.systemui.shared.system.ActivityManagerWrapper; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java index bebd45daa2..4a9aa2d9a8 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/RecentsActivity.java @@ -38,11 +38,11 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAnimationRunner; import com.android.launcher3.R; import com.android.launcher3.anim.Interpolators; +import com.android.launcher3.util.ObjectWrapper; import com.android.launcher3.views.BaseDragLayer; import com.android.quickstep.fallback.FallbackRecentsView; import com.android.quickstep.fallback.RecentsRootView; import com.android.quickstep.util.ClipAnimationHelper; -import com.android.quickstep.util.ObjectWrapper; import com.android.quickstep.views.TaskView; import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.system.ActivityOptionsCompat; diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/FallbackNoButtonInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/FallbackNoButtonInputConsumer.java index e0ff8afe65..6275d21dc0 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/FallbackNoButtonInputConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/FallbackNoButtonInputConsumer.java @@ -38,6 +38,7 @@ import android.os.Bundle; import com.android.launcher3.R; import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimatorPlaybackController; +import com.android.launcher3.util.ObjectWrapper; import com.android.quickstep.ActivityControlHelper.HomeAnimationFactory; import com.android.quickstep.AnimatedFloat; import com.android.quickstep.BaseSwipeUpHandler; @@ -47,7 +48,6 @@ import com.android.quickstep.RecentsActivity; import com.android.quickstep.RecentsModel; import com.android.quickstep.SwipeSharedState; import com.android.quickstep.fallback.FallbackRecentsView; -import com.android.quickstep.util.ObjectWrapper; import com.android.quickstep.util.RectFSpringAnim; import com.android.quickstep.util.SwipeAnimationTargetSet; import com.android.quickstep.views.TaskView; diff --git a/quickstep/src/com/android/launcher3/LauncherInitListener.java b/quickstep/src/com/android/launcher3/LauncherInitListener.java index 272d1175b1..663b1252d3 100644 --- a/quickstep/src/com/android/launcher3/LauncherInitListener.java +++ b/quickstep/src/com/android/launcher3/LauncherInitListener.java @@ -19,29 +19,25 @@ import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; -import android.os.Bundle; import android.os.CancellationSignal; import android.os.Handler; -import com.android.launcher3.states.InternalStateHandler; -import com.android.quickstep.ActivityControlHelper.ActivityInitListener; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.RemoteAnimationProvider; import java.util.function.BiPredicate; @TargetApi(Build.VERSION_CODES.P) -public class LauncherInitListener extends InternalStateHandler implements ActivityInitListener { - - private final BiPredicate mOnInitListener; +public class LauncherInitListener extends ActivityInitListener { private RemoteAnimationProvider mRemoteAnimationProvider; public LauncherInitListener(BiPredicate onInitListener) { - mOnInitListener = onInitListener; + super(onInitListener, Launcher.ACTIVITY_TRACKER); } @Override - protected boolean init(Launcher launcher, boolean alreadyOnHome) { + public boolean init(Launcher launcher, boolean alreadyOnHome) { if (mRemoteAnimationProvider != null) { QuickstepAppTransitionManagerImpl appTransitionManager = (QuickstepAppTransitionManagerImpl) launcher.getAppTransitionManager(); @@ -63,28 +59,19 @@ public class LauncherInitListener extends InternalStateHandler implements Activi }, cancellationSignal); } launcher.deferOverlayCallbacksUntilNextResumeOrStop(); - return mOnInitListener.test(launcher, alreadyOnHome); - } - - @Override - public void register() { - initWhenReady(); + return super.init(launcher, alreadyOnHome); } @Override public void unregister() { mRemoteAnimationProvider = null; - clearReference(); + super.unregister(); } @Override public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider, Context context, Handler handler, long duration) { mRemoteAnimationProvider = animProvider; - - register(); - - Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle(); - context.startActivity(addToIntent(new Intent((intent))), options); + super.registerAndStartActivity(intent, animProvider, context, handler, duration); } } diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java index 609fb26d40..2d4b136139 100644 --- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java +++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java @@ -17,12 +17,10 @@ package com.android.quickstep; import android.annotation.TargetApi; import android.content.Context; -import android.content.Intent; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.os.Build; -import android.os.Handler; import android.view.MotionEvent; import android.view.View; import android.view.animation.Interpolator; @@ -34,7 +32,7 @@ import androidx.annotation.UiThread; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.anim.AnimatorPlaybackController; -import com.android.quickstep.util.RemoteAnimationProvider; +import com.android.quickstep.util.ActivityInitListener; import com.android.quickstep.util.RemoteAnimationTargetSet; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; @@ -99,16 +97,6 @@ public interface ActivityControlHelper { default void closeOverlay() { } - interface ActivityInitListener { - - void register(); - - void unregister(); - - void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider, - Context context, Handler handler, long duration); - } - interface AnimationFactory { enum ShelfAnimState { diff --git a/quickstep/src/com/android/quickstep/BaseRecentsActivity.java b/quickstep/src/com/android/quickstep/BaseRecentsActivity.java index 1ac7ed4a3c..71833ad418 100644 --- a/quickstep/src/com/android/quickstep/BaseRecentsActivity.java +++ b/quickstep/src/com/android/quickstep/BaseRecentsActivity.java @@ -28,6 +28,7 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.R; import com.android.launcher3.uioverrides.UiFactory; +import com.android.launcher3.util.ActivityTracker; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.Themes; @@ -43,6 +44,7 @@ import java.io.PrintWriter; */ public abstract class BaseRecentsActivity extends BaseDraggingActivity { + public static ActivityTracker ACTIVITY_TRACKER = new ActivityTracker<>(); private Configuration mOldConfig; @Override @@ -55,7 +57,7 @@ public abstract class BaseRecentsActivity extends BaseDraggingActivity { getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW, Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText)); - RecentsActivityTracker.onRecentsActivityCreate(this); + ACTIVITY_TRACKER.handleCreate((RecentsActivity) this); } /** @@ -132,13 +134,13 @@ public abstract class BaseRecentsActivity extends BaseDraggingActivity { @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - RecentsActivityTracker.onRecentsActivityNewIntent(this); + ACTIVITY_TRACKER.handleNewIntent(this, intent); } @Override protected void onDestroy() { super.onDestroy(); - RecentsActivityTracker.onRecentsActivityDestroy(this); + ACTIVITY_TRACKER.onActivityDestroyed(this); } @Override diff --git a/quickstep/src/com/android/quickstep/RecentsActivityTracker.java b/quickstep/src/com/android/quickstep/RecentsActivityTracker.java deleted file mode 100644 index 4d1d9ef8a7..0000000000 --- a/quickstep/src/com/android/quickstep/RecentsActivityTracker.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.quickstep; - -import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; - -import com.android.quickstep.ActivityControlHelper.ActivityInitListener; -import com.android.quickstep.util.RemoteAnimationProvider; - -import java.lang.ref.WeakReference; -import java.util.function.BiPredicate; - -/** - * Utility class to track create/destroy for some {@link BaseRecentsActivity}. - */ -@TargetApi(Build.VERSION_CODES.P) -public class RecentsActivityTracker implements ActivityInitListener { - - private static WeakReference sCurrentActivity = - new WeakReference<>(null); - private static final Scheduler sScheduler = new Scheduler(); - - private final BiPredicate mOnInitListener; - - public RecentsActivityTracker(BiPredicate onInitListener) { - mOnInitListener = onInitListener; - } - - @Override - public void register() { - sScheduler.schedule(this); - } - - @Override - public void unregister() { - sScheduler.clearReference(this); - } - - private boolean init(T activity, boolean visible) { - return mOnInitListener.test(activity, visible); - } - - public static T getCurrentActivity() { - return (T) sCurrentActivity.get(); - } - - @Override - public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider, - Context context, Handler handler, long duration) { - register(); - - Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle(); - context.startActivity(intent, options); - } - - public static void onRecentsActivityCreate(BaseRecentsActivity activity) { - sCurrentActivity = new WeakReference<>(activity); - sScheduler.initIfPending(activity, false); - } - - - public static void onRecentsActivityNewIntent(BaseRecentsActivity activity) { - sScheduler.initIfPending(activity, activity.isStarted()); - } - - public static void onRecentsActivityDestroy(BaseRecentsActivity activity) { - if (sCurrentActivity.get() == activity) { - sCurrentActivity.clear(); - } - } - - - private static class Scheduler implements Runnable { - - private WeakReference mPendingTracker = new WeakReference<>(null); - - public synchronized void schedule(RecentsActivityTracker tracker) { - mPendingTracker = new WeakReference<>(tracker); - MAIN_EXECUTOR.execute(this); - } - - @Override - public void run() { - BaseRecentsActivity activity = sCurrentActivity.get(); - if (activity != null) { - initIfPending(activity, activity.isStarted()); - } - } - - public synchronized boolean initIfPending(BaseRecentsActivity activity, - boolean alreadyOnHome) { - RecentsActivityTracker tracker = mPendingTracker.get(); - if (tracker != null) { - if (!tracker.init(activity, alreadyOnHome)) { - mPendingTracker.clear(); - } - return true; - } - return false; - } - - public synchronized boolean clearReference(RecentsActivityTracker tracker) { - if (mPendingTracker.get() == tracker) { - mPendingTracker.clear(); - return true; - } - return false; - } - } -} diff --git a/quickstep/src/com/android/quickstep/util/ActivityInitListener.java b/quickstep/src/com/android/quickstep/util/ActivityInitListener.java new file mode 100644 index 0000000000..fe37d609b4 --- /dev/null +++ b/quickstep/src/com/android/quickstep/util/ActivityInitListener.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep.util; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; + +import com.android.launcher3.BaseActivity; +import com.android.launcher3.util.ActivityTracker; +import com.android.launcher3.util.ActivityTracker.SchedulerCallback; + +import java.util.function.BiPredicate; + +public class ActivityInitListener implements SchedulerCallback { + + private final BiPredicate mOnInitListener; + private final ActivityTracker mActivityTracker; + + public ActivityInitListener(BiPredicate onInitListener, + ActivityTracker tracker) { + mOnInitListener = onInitListener; + mActivityTracker = tracker; + } + + @Override + public boolean init(T activity, boolean alreadyOnHome) { + return mOnInitListener.test(activity, alreadyOnHome); + } + + public void register() { + mActivityTracker.schedule(this); + } + + public void unregister() { + mActivityTracker.clearReference(this); + } + + public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider, + Context context, Handler handler, long duration) { + register(); + + Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle(); + context.startActivity(addToIntent(new Intent((intent))), options); + } +} diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 4f8b20e0b4..9326e95dea 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -113,7 +113,6 @@ import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.qsb.QsbContainerView; -import com.android.launcher3.states.InternalStateHandler; import com.android.launcher3.states.RotationHelper; import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.uioverrides.DejankBinderTracker; @@ -124,6 +123,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ActivityResultInfo; +import com.android.launcher3.util.ActivityTracker; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; @@ -176,6 +176,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, Callbacks, LauncherProviderChangeListener, UserEventDelegate, InvariantDeviceProfile.OnIDPChangeListener, PluginListener { public static final String TAG = "Launcher"; + + public static final ActivityTracker ACTIVITY_TRACKER = new ActivityTracker<>(); + static final boolean LOGD = false; static final boolean DEBUG_STRICT_MODE = false; @@ -359,7 +362,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, mAppTransitionManager = LauncherAppTransitionManager.newInstance(this); - boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent()); + boolean internalStateHandled = ACTIVITY_TRACKER.handleCreate(this); if (internalStateHandled) { if (savedInstanceState != null) { // InternalStateHandler has already set the appropriate state. @@ -1444,8 +1447,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL) && AbstractFloatingView.getTopOpenView(this) == null; boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction()); - boolean internalStateHandled = InternalStateHandler - .handleNewIntent(this, intent, isStarted()); + boolean internalStateHandled = ACTIVITY_TRACKER.handleNewIntent(this, intent); if (isActionMain) { if (!internalStateHandled) { @@ -1535,6 +1537,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, @Override public void onDestroy() { super.onDestroy(); + ACTIVITY_TRACKER.onActivityDestroyed(this); unregisterReceiver(mScreenOffReceiver); mWorkspace.removeFolderListeners(); diff --git a/src/com/android/launcher3/allapps/DiscoveryBounce.java b/src/com/android/launcher3/allapps/DiscoveryBounce.java index 8c596269de..dc2f7bdc9e 100644 --- a/src/com/android/launcher3/allapps/DiscoveryBounce.java +++ b/src/com/android/launcher3/allapps/DiscoveryBounce.java @@ -31,12 +31,10 @@ import android.view.MotionEvent; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; -import com.android.launcher3.LauncherStateManager; import com.android.launcher3.LauncherStateManager.StateListener; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.compat.UserManagerCompat; -import com.android.launcher3.states.InternalStateHandler; /** * Abstract base class of floating view responsible for showing discovery bounce animation @@ -181,7 +179,7 @@ public class DiscoveryBounce extends AbstractFloatingView { if (withDelay) { new Handler().postDelayed(() -> showForOverviewIfNeeded(launcher, false), DELAY_MS); return; - } else if (InternalStateHandler.hasPending() + } else if (Launcher.ACTIVITY_TRACKER.hasPending() || AbstractFloatingView.getTopOpenView(launcher) != null) { // TODO: Move these checks to the top and call this method after invalidate handler. return; diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java index 9fb10905f8..b8981b6a3c 100644 --- a/src/com/android/launcher3/dragndrop/AddItemActivity.java +++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java @@ -45,6 +45,7 @@ import android.view.View.OnTouchListener; import com.android.launcher3.BaseActivity; import com.android.launcher3.InstallShortcutReceiver; import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetHost; import com.android.launcher3.LauncherAppWidgetProviderInfo; @@ -176,7 +177,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener .setPackage(getPackageName()) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); - listener.initWhenReady(); + Launcher.ACTIVITY_TRACKER.schedule(listener); startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle()); mFinishOnPause = true; diff --git a/src/com/android/launcher3/dragndrop/BaseItemDragListener.java b/src/com/android/launcher3/dragndrop/BaseItemDragListener.java index 1b08723f63..75693c63d0 100644 --- a/src/com/android/launcher3/dragndrop/BaseItemDragListener.java +++ b/src/com/android/launcher3/dragndrop/BaseItemDragListener.java @@ -36,8 +36,7 @@ import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Launcher; import com.android.launcher3.R; -import com.android.launcher3.states.InternalStateHandler; -import com.android.launcher3.testing.TestProtocol; +import com.android.launcher3.util.ActivityTracker.SchedulerCallback; import com.android.launcher3.widget.PendingItemDragHelper; import java.util.UUID; @@ -45,8 +44,8 @@ import java.util.UUID; /** * {@link DragSource} for handling drop from a different window. */ -public abstract class BaseItemDragListener extends InternalStateHandler implements - View.OnDragListener, DragSource, DragOptions.PreDragCondition { +public abstract class BaseItemDragListener implements View.OnDragListener, DragSource, + DragOptions.PreDragCondition, SchedulerCallback { private static final String TAG = "BaseItemDragListener"; @@ -165,7 +164,7 @@ public abstract class BaseItemDragListener extends InternalStateHandler implemen } protected void postCleanup() { - clearReference(); + Launcher.ACTIVITY_TRACKER.clearReference(this); if (mLauncher != null) { // Remove any drag params from the launcher intent since the drag operation is complete. Intent newIntent = new Intent(mLauncher.getIntent()); diff --git a/src/com/android/launcher3/states/InternalStateHandler.java b/src/com/android/launcher3/states/InternalStateHandler.java deleted file mode 100644 index a23cd6d2e3..0000000000 --- a/src/com/android/launcher3/states/InternalStateHandler.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3.states; - -import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; - -import android.content.Intent; -import android.os.Binder; -import android.os.Bundle; -import android.os.IBinder; - -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAppState; -import com.android.launcher3.model.BgDataModel.Callbacks; - -import java.lang.ref.WeakReference; - -/** - * Utility class to sending state handling logic to Launcher from within the same process. - * - * Extending {@link Binder} ensures that the platform maintains a single instance of each object - * which allows this object to safely navigate the system process. - */ -public abstract class InternalStateHandler extends Binder { - - public static final String EXTRA_STATE_HANDLER = "launcher.state_handler"; - - private static final Scheduler sScheduler = new Scheduler(); - - /** - * Initializes the handler when the launcher is ready. - * @return true if the handler wants to stay alive. - */ - protected abstract boolean init(Launcher launcher, boolean alreadyOnHome); - - public final Intent addToIntent(Intent intent) { - Bundle extras = new Bundle(); - extras.putBinder(EXTRA_STATE_HANDLER, this); - intent.putExtras(extras); - return intent; - } - - public final void initWhenReady() { - sScheduler.schedule(this); - } - - public boolean clearReference() { - return sScheduler.clearReference(this); - } - - public static boolean hasPending() { - return sScheduler.hasPending(); - } - - public static boolean handleCreate(Launcher launcher, Intent intent) { - return handleIntent(launcher, intent, false, false); - } - - public static boolean handleNewIntent(Launcher launcher, Intent intent, boolean alreadyOnHome) { - return handleIntent(launcher, intent, alreadyOnHome, true); - } - - private static boolean handleIntent( - Launcher launcher, Intent intent, boolean alreadyOnHome, boolean explicitIntent) { - boolean result = false; - if (intent != null && intent.getExtras() != null) { - IBinder stateBinder = intent.getExtras().getBinder(EXTRA_STATE_HANDLER); - if (stateBinder instanceof InternalStateHandler) { - InternalStateHandler handler = (InternalStateHandler) stateBinder; - if (!handler.init(launcher, alreadyOnHome)) { - intent.getExtras().remove(EXTRA_STATE_HANDLER); - } - result = true; - } - } - if (!result && !explicitIntent) { - result = sScheduler.initIfPending(launcher, alreadyOnHome); - } - return result; - } - - private static class Scheduler implements Runnable { - - private WeakReference mPendingHandler = new WeakReference<>(null); - - public void schedule(InternalStateHandler handler) { - synchronized (this) { - mPendingHandler = new WeakReference<>(handler); - } - MAIN_EXECUTOR.execute(this); - } - - @Override - public void run() { - LauncherAppState app = LauncherAppState.getInstanceNoCreate(); - if (app == null) { - return; - } - Callbacks cb = app.getModel().getCallback(); - if (!(cb instanceof Launcher)) { - return; - } - Launcher launcher = (Launcher) cb; - initIfPending(launcher, launcher.isStarted()); - } - - public boolean initIfPending(Launcher launcher, boolean alreadyOnHome) { - InternalStateHandler pendingHandler = mPendingHandler.get(); - if (pendingHandler != null) { - if (!pendingHandler.init(launcher, alreadyOnHome)) { - clearReference(pendingHandler); - } - return true; - } - return false; - } - - public boolean clearReference(InternalStateHandler handler) { - synchronized (this) { - if (mPendingHandler.get() == handler) { - mPendingHandler.clear(); - return true; - } - return false; - } - } - - public boolean hasPending() { - return mPendingHandler.get() != null; - } - } -} \ No newline at end of file diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java index abf90e22c8..852928b416 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -24,7 +24,6 @@ import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Resources; import android.view.WindowManager; -import android.view.WindowManager.LayoutParams; import com.android.launcher3.Launcher; import com.android.launcher3.R; @@ -59,7 +58,9 @@ public class RotationHelper implements OnSharedPreferenceChangeListener { private boolean mAutoRotateEnabled; /** - * Rotation request made by {@link InternalStateHandler}. This supersedes any other request. + * Rotation request made by + * {@link com.android.launcher3.util.ActivityTracker.SchedulerCallback}. + * This supersedes any other request. */ private int mStateHandlerRequest = REQUEST_NONE; /** diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index a71a53b927..619293bd84 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -56,8 +56,7 @@ public class TestInformationHandler implements ResourceBasedOverride { mDeviceProfile = InvariantDeviceProfile.INSTANCE. get(context).getDeviceProfile(context); mLauncherAppState = LauncherAppState.getInstanceNoCreate(); - mLauncher = mLauncherAppState != null ? - (Launcher) mLauncherAppState.getModel().getCallback() : null; + mLauncher = Launcher.ACTIVITY_TRACKER.getCreatedActivity(); } public Bundle call(String method) { diff --git a/src/com/android/launcher3/util/ActivityTracker.java b/src/com/android/launcher3/util/ActivityTracker.java new file mode 100644 index 0000000000..e85a4e8058 --- /dev/null +++ b/src/com/android/launcher3/util/ActivityTracker.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.util; + +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; + +import android.content.Intent; +import android.os.Bundle; +import android.os.IBinder; + +import androidx.annotation.Nullable; + +import com.android.launcher3.BaseActivity; + +import java.lang.ref.WeakReference; + +/** + * Helper class to statically track activity creation + */ +public final class ActivityTracker implements Runnable { + + private WeakReference mCurrentActivity = new WeakReference<>(null); + private WeakReference> mPendingCallback = new WeakReference<>(null); + + private static final String EXTRA_SCHEDULER_CALLBACK = "launcher.scheduler_callback"; + + @Nullable + public R getCreatedActivity() { + return (R) mCurrentActivity.get(); + } + + public void onActivityDestroyed(T activity) { + if (mCurrentActivity.get() == activity) { + mCurrentActivity.clear(); + } + } + + public void schedule(SchedulerCallback callback) { + synchronized (this) { + mPendingCallback = new WeakReference<>((SchedulerCallback) callback); + } + MAIN_EXECUTOR.execute(this); + } + + @Override + public void run() { + T activity = mCurrentActivity.get(); + if (activity != null) { + initIfPending(activity, activity.isStarted()); + } + } + + public boolean initIfPending(T activity, boolean alreadyOnHome) { + SchedulerCallback pendingCallback = mPendingCallback.get(); + if (pendingCallback != null) { + if (!pendingCallback.init(activity, alreadyOnHome)) { + clearReference(pendingCallback); + } + return true; + } + return false; + } + + public boolean clearReference(SchedulerCallback handler) { + synchronized (this) { + if (mPendingCallback.get() == handler) { + mPendingCallback.clear(); + return true; + } + return false; + } + } + + public boolean hasPending() { + return mPendingCallback.get() != null; + } + + public boolean handleCreate(T activity) { + mCurrentActivity = new WeakReference<>(activity); + return handleIntent(activity, activity.getIntent(), false, false); + } + + public boolean handleNewIntent(T activity, Intent intent) { + return handleIntent(activity, intent, activity.isStarted(), true); + } + + private boolean handleIntent( + T activity, Intent intent, boolean alreadyOnHome, boolean explicitIntent) { + boolean result = false; + if (intent != null && intent.getExtras() != null) { + IBinder stateBinder = intent.getExtras().getBinder(EXTRA_SCHEDULER_CALLBACK); + if (stateBinder instanceof ObjectWrapper) { + SchedulerCallback handler = + ((ObjectWrapper) stateBinder).get(); + if (!handler.init(activity, alreadyOnHome)) { + intent.getExtras().remove(EXTRA_SCHEDULER_CALLBACK); + } + result = true; + } + } + if (!result && !explicitIntent) { + result = initIfPending(activity, alreadyOnHome); + } + return result; + } + + public interface SchedulerCallback { + + boolean init(T activity, boolean alreadyOnHome); + + default Intent addToIntent(Intent intent) { + Bundle extras = new Bundle(); + extras.putBinder(EXTRA_SCHEDULER_CALLBACK, ObjectWrapper.wrap(this)); + intent.putExtras(extras); + return intent; + } + } +} diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/ObjectWrapper.java b/src/com/android/launcher3/util/ObjectWrapper.java similarity index 96% rename from quickstep/recents_ui_overrides/src/com/android/quickstep/util/ObjectWrapper.java rename to src/com/android/launcher3/util/ObjectWrapper.java index abfe3adbff..b69243117a 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/ObjectWrapper.java +++ b/src/com/android/launcher3/util/ObjectWrapper.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.quickstep.util; +package com.android.launcher3.util; import android.os.Binder; import android.os.IBinder;