Merge "Thumbnail/Suggest view type support remote action" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
index 68111d2..54c2383 100644
--- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
@@ -22,6 +22,8 @@
 import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview;
 import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY;
 
+import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
+
 import android.animation.AnimatorSet;
 import android.animation.ValueAnimator;
 import android.content.Intent;
@@ -307,4 +309,10 @@
     public void setHintUserWillBeActive() {
         addActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE);
     }
+
+    @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        InteractionJankMonitorWrapper.init(getWindow().getDecorView());
+    }
 }
diff --git a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java
index 199cf63..75355c9 100644
--- a/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java
+++ b/quickstep/src/com/android/launcher3/LauncherAnimationRunner.java
@@ -34,8 +34,7 @@
 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
 
 @TargetApi(Build.VERSION_CODES.P)
-public abstract class LauncherAnimationRunner implements RemoteAnimationRunnerCompat,
-        WrappedAnimationRunnerImpl {
+public abstract class LauncherAnimationRunner implements RemoteAnimationRunnerCompat {
 
     private static final String TAG = "LauncherAnimationRunner";
 
diff --git a/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
index dddcc86..d453bc3 100644
--- a/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/QuickstepAppTransitionManagerImpl.java
@@ -66,6 +66,7 @@
 
 import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
 import com.android.launcher3.allapps.AllAppsTransitionController;
+import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.dragndrop.DragLayer;
 import com.android.launcher3.shortcuts.DeepShortcutView;
@@ -81,6 +82,7 @@
 import com.android.quickstep.util.SurfaceTransactionApplier;
 import com.android.systemui.shared.system.ActivityCompat;
 import com.android.systemui.shared.system.ActivityOptionsCompat;
+import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
 import com.android.systemui.shared.system.QuickStepContract;
 import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
 import com.android.systemui.shared.system.RemoteAnimationDefinitionCompat;
@@ -791,6 +793,36 @@
                 == PackageManager.PERMISSION_GRANTED;
     }
 
+    private void addCujInstrumentation(Animator anim, int cuj, String transition) {
+        if (Trace.isEnabled()) {
+            anim.addListener(new AnimationSuccessListener() {
+                @Override
+                public void onAnimationStart(Animator animation) {
+                    Trace.beginAsyncSection(transition, 0);
+                    InteractionJankMonitorWrapper.begin(cuj);
+                    super.onAnimationStart(animation);
+                }
+
+                @Override
+                public void onAnimationCancel(Animator animation) {
+                    super.onAnimationCancel(animation);
+                    InteractionJankMonitorWrapper.cancel(cuj);
+                }
+
+                @Override
+                public void onAnimationSuccess(Animator animator) {
+                    InteractionJankMonitorWrapper.end(cuj);
+                }
+
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    super.onAnimationEnd(animation);
+                    Trace.endAsyncSection(TRANSITION_OPEN_LAUNCHER, 0);
+                }
+            });
+        }
+    }
+
     /**
      * Remote animation runner for animation from the app to Launcher, including recents.
      */
@@ -855,21 +887,9 @@
                 // is initialized.
                 if (launcherIsATargetWithMode(appTargets, MODE_OPENING)
                         || mLauncher.isForceInvisible()) {
-                    if (Trace.isEnabled()) {
-                        anim.addListener(new AnimatorListenerAdapter() {
-                            @Override
-                            public void onAnimationStart(Animator animation) {
-                                Trace.beginAsyncSection(TRANSITION_OPEN_LAUNCHER, 0);
-                                super.onAnimationStart(animation);
-                            }
-
-                            @Override
-                            public void onAnimationEnd(Animator animation) {
-                                super.onAnimationEnd(animation);
-                                Trace.endAsyncSection(TRANSITION_OPEN_LAUNCHER, 0);
-                            }
-                        });
-                    }
+                    addCujInstrumentation(
+                            anim, InteractionJankMonitorWrapper.CUJ_APP_CLOSE_TO_HOME,
+                            TRANSITION_OPEN_LAUNCHER);
                     // Only register the content animation for cancellation when state changes
                     mLauncher.getStateManager().setCurrentAnimation(anim);
 
@@ -938,25 +958,12 @@
                         launcherClosing);
             }
 
-            if (Trace.isEnabled()) {
-                final String section =
-                        launchingFromRecents
-                                ? TRANSITION_LAUNCH_FROM_RECENTS : TRANSITION_LAUNCH_FROM_ICON;
-
-                anim.addListener(new AnimatorListenerAdapter() {
-                    @Override
-                    public void onAnimationStart(Animator animation) {
-                        Trace.beginAsyncSection(section, 0);
-                        super.onAnimationStart(animation);
-                    }
-
-                    @Override
-                    public void onAnimationEnd(Animator animation) {
-                        super.onAnimationEnd(animation);
-                        Trace.endAsyncSection(section, 0);
-                    }
-                });
-            }
+            addCujInstrumentation(anim,
+                    launchingFromRecents
+                            ? InteractionJankMonitorWrapper.CUJ_APP_LAUNCH_FROM_RECENTS
+                            : InteractionJankMonitorWrapper.CUJ_APP_LAUNCH_FROM_ICON,
+                    launchingFromRecents
+                            ? TRANSITION_LAUNCH_FROM_RECENTS : TRANSITION_LAUNCH_FROM_ICON);
 
             if (launcherClosing) {
                 anim.addListener(mForceInvisibleListener);
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 6774433..5e05a7d 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -97,6 +97,7 @@
 import com.android.systemui.shared.recents.model.ThumbnailData;
 import com.android.systemui.shared.system.ActivityManagerWrapper;
 import com.android.systemui.shared.system.InputConsumerController;
+import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
 import com.android.systemui.shared.system.LatencyTrackerCompat;
 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
 import com.android.systemui.shared.system.TaskInfoCompat;
@@ -1130,10 +1131,12 @@
         anim.addOnUpdateListener((r, p) -> {
             updateSysUiFlags(Math.max(p, mCurrentShift.value));
         });
+        final int cuj = InteractionJankMonitorWrapper.CUJ_APP_CLOSE_TO_HOME;
         anim.addAnimatorListener(new AnimationSuccessListener() {
             @Override
             public void onAnimationStart(Animator animation) {
                 Trace.beginAsyncSection(TRANSITION_OPEN_LAUNCHER, 0);
+                InteractionJankMonitorWrapper.begin(cuj);
                 if (mActivity != null) {
                     removeLiveTileOverlay();
                 }
@@ -1147,6 +1150,13 @@
                 // Make sure recents is in its final state
                 maybeUpdateRecentsAttachedState(false);
                 mActivityInterface.onSwipeUpToHomeComplete(mDeviceState);
+                InteractionJankMonitorWrapper.end(cuj);
+            }
+
+            @Override
+            public void onAnimationCancel(Animator animation) {
+                super.onAnimationCancel(animation);
+                InteractionJankMonitorWrapper.cancel(cuj);
             }
 
             @Override
diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java
index 0e32c95..2f55f14 100644
--- a/quickstep/src/com/android/quickstep/RecentsActivity.java
+++ b/quickstep/src/com/android/quickstep/RecentsActivity.java
@@ -41,7 +41,10 @@
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.InvariantDeviceProfile;
 import com.android.launcher3.LauncherAnimationRunner;
+import com.android.launcher3.LauncherAnimationRunner.AnimationResult;
 import com.android.launcher3.R;
+import com.android.launcher3.WrappedAnimationRunnerImpl;
+import com.android.launcher3.WrappedLauncherAnimationRunner;
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.anim.PendingAnimation;
 import com.android.launcher3.compat.AccessibilityManagerCompat;
@@ -87,6 +90,9 @@
 
     private StateManager<RecentsState> mStateManager;
 
+    // Strong refs to runners which are cleared when the activity is destroyed
+    private WrappedAnimationRunnerImpl mActivityLaunchAnimationRunner;
+
     /**
      * Init drag layer and overview panel views.
      */
@@ -169,8 +175,11 @@
         }
 
         final TaskView taskView = (TaskView) v;
-        RemoteAnimationRunnerCompat runner = new LauncherAnimationRunner(mUiHandler,
-                true /* startAtFrontOfQueue */) {
+        mActivityLaunchAnimationRunner = new WrappedAnimationRunnerImpl() {
+            @Override
+            public Handler getHandler() {
+                return mUiHandler;
+            }
 
             @Override
             public void onCreateAnimation(RemoteAnimationTargetCompat[] appTargets,
@@ -181,8 +190,10 @@
                 result.setAnimation(anim, RecentsActivity.this);
             }
         };
+        final LauncherAnimationRunner wrapper = new WrappedLauncherAnimationRunner<>(
+                mActivityLaunchAnimationRunner, true /* startAtFrontOfQueue */);
         return ActivityOptionsCompat.makeRemoteAnimation(new RemoteAnimationAdapterCompat(
-                runner, RECENTS_LAUNCH_DURATION,
+                wrapper, RECENTS_LAUNCH_DURATION,
                 RECENTS_LAUNCH_DURATION - STATUS_BAR_TRANSITION_DURATION
                         - STATUS_BAR_TRANSITION_PRE_DELAY));
     }
@@ -287,6 +298,7 @@
     protected void onDestroy() {
         super.onDestroy();
         ACTIVITY_TRACKER.onActivityDestroyed(this);
+        mActivityLaunchAnimationRunner = null;
     }
 
     @Override
diff --git a/quickstep/src/com/android/quickstep/util/RemoteAnimationProvider.java b/quickstep/src/com/android/quickstep/util/RemoteAnimationProvider.java
index 04308c8..19c6588 100644
--- a/quickstep/src/com/android/quickstep/util/RemoteAnimationProvider.java
+++ b/quickstep/src/com/android/quickstep/util/RemoteAnimationProvider.java
@@ -21,6 +21,8 @@
 import android.os.Handler;
 
 import com.android.launcher3.LauncherAnimationRunner;
+import com.android.launcher3.LauncherAnimationRunner.AnimationResult;
+import com.android.launcher3.WrappedAnimationRunnerImpl;
 import com.android.launcher3.WrappedLauncherAnimationRunner;
 import com.android.systemui.shared.system.ActivityOptionsCompat;
 import com.android.systemui.shared.system.RemoteAnimationAdapterCompat;
@@ -28,14 +30,17 @@
 
 public abstract class RemoteAnimationProvider {
 
-    LauncherAnimationRunner mAnimationRunner;
+    WrappedAnimationRunnerImpl mAnimationRunner;
 
     public abstract AnimatorSet createWindowAnimation(RemoteAnimationTargetCompat[] appTargets,
             RemoteAnimationTargetCompat[] wallpaperTargets);
 
     ActivityOptions toActivityOptions(Handler handler, long duration, Context context) {
-        mAnimationRunner = new LauncherAnimationRunner(handler,
-                false /* startAtFrontOfQueue */) {
+        mAnimationRunner = new WrappedAnimationRunnerImpl() {
+            @Override
+            public Handler getHandler() {
+                return handler;
+            }
 
             @Override
             public void onCreateAnimation(RemoteAnimationTargetCompat[] appTargets,
@@ -45,7 +50,6 @@
         };
         final LauncherAnimationRunner wrapper = new WrappedLauncherAnimationRunner(
                 mAnimationRunner, false /* startAtFrontOfQueue */);
-
         return ActivityOptionsCompat.makeRemoteAnimation(
                 new RemoteAnimationAdapterCompat(wrapper, duration, 0));
     }
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index c0d5882..2b4520b 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -49,7 +49,6 @@
 import android.util.TimingLogger;
 
 import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.LauncherAppWidgetProviderInfo;
 import com.android.launcher3.LauncherModel;
 import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.Utilities;
@@ -307,7 +306,6 @@
         final PackageManagerHelper pmHelper = new PackageManagerHelper(context);
         final boolean isSafeMode = pmHelper.isSafeMode();
         final boolean isSdCardReady = Utilities.isBootCompleted();
-        final WidgetManagerHelper widgetHelper = new WidgetManagerHelper(context);
 
         boolean clearDb = false;
         try {
@@ -393,7 +391,6 @@
 
                 WorkspaceItemInfo info;
                 LauncherAppWidgetInfo appWidgetInfo;
-                LauncherAppWidgetProviderInfo widgetProviderInfo;
                 Intent intent;
                 String targetPkg;
 
@@ -723,19 +720,6 @@
                                             + appWidgetInfo.spanX + "x" + appWidgetInfo.spanY);
                                     continue;
                                 }
-                                widgetProviderInfo =
-                                        widgetHelper.getLauncherAppWidgetInfo(appWidgetId);
-                                if (widgetProviderInfo != null
-                                        && (appWidgetInfo.spanX < widgetProviderInfo.minSpanX
-                                        || appWidgetInfo.spanY < widgetProviderInfo.minSpanY)) {
-                                    // This can happen when display size changes.
-                                    c.markDeleted("Widget removed, min sizes not met: "
-                                            + "span=" + appWidgetInfo.spanX + "x"
-                                            + appWidgetInfo.spanY + " minSpan="
-                                            + widgetProviderInfo.minSpanX + "x"
-                                            + widgetProviderInfo.minSpanY);
-                                    continue;
-                                }
                                 if (!c.isOnWorkspaceOrHotseat()) {
                                     c.markDeleted("Widget found where container != " +
                                             "CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!");