Merge "Search UI clean up" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
index 54c2383..44d43c6 100644
--- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
+++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java
@@ -26,10 +26,12 @@
 
 import android.animation.AnimatorSet;
 import android.animation.ValueAnimator;
+import android.app.ActivityOptions;
 import android.content.Intent;
 import android.content.IntentSender;
 import android.os.Bundle;
 import android.os.CancellationSignal;
+import android.view.View;
 
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.model.WellbeingModel;
@@ -51,6 +53,7 @@
 import com.android.quickstep.views.OverviewActionsView;
 import com.android.quickstep.views.RecentsView;
 import com.android.systemui.shared.system.ActivityManagerWrapper;
+import com.android.systemui.shared.system.ActivityOptionsCompat;
 import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
 
 import java.util.stream.Stream;
@@ -306,6 +309,15 @@
                 Stream.of(WellbeingModel.SHORTCUT_FACTORY));
     }
 
+    @Override
+    public ActivityOptions getActivityLaunchOptions(View v) {
+        ActivityOptions activityOptions = super.getActivityLaunchOptions(v);
+        if (activityOptions != null && mLastTouchUpTime > 0) {
+            ActivityOptionsCompat.setLauncherSourceInfo(activityOptions, mLastTouchUpTime);
+        }
+        return activityOptions;
+    }
+
     public void setHintUserWillBeActive() {
         addActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE);
     }
diff --git a/quickstep/src/com/android/launcher3/model/WellbeingModel.java b/quickstep/src/com/android/launcher3/model/WellbeingModel.java
index a9fc1aa..995c4b0 100644
--- a/quickstep/src/com/android/launcher3/model/WellbeingModel.java
+++ b/quickstep/src/com/android/launcher3/model/WellbeingModel.java
@@ -148,6 +148,12 @@
             if (!FeatureFlags.ENABLE_MINIMAL_DEVICE.get()) {
                 return;
             }
+
+            // Temporary bug fix for b/169771796. Wellbeing provides the layout configuration when
+            // minimal device is enabled. We always want to reload the configuration from Wellbeing
+            // since the layout configuration might have changed.
+            mContext.deleteDatabase(DB_NAME_MINIMAL_DEVICE);
+
             final Bundle extras = new Bundle();
             String dbFile;
             if (isInMinimalDeviceMode()) {
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 1154964..cc109f6 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1339,7 +1339,7 @@
                 if (taskView != null && !mCanceled) {
                     // Defer finishing the animation until the next launcher frame with the
                     // new thumbnail
-                    finishTransitionPosted = ViewUtils.postDraw(taskView,
+                    finishTransitionPosted = ViewUtils.postFrameDrawn(taskView,
                             () -> mStateCallback.setStateOnUiThread(STATE_SCREENSHOT_CAPTURED),
                             this::isCanceled);
                 }
diff --git a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
index a46de1f..7406dea 100644
--- a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
+++ b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
@@ -261,7 +261,7 @@
             mTransformParams
                     .setTargetAlpha(getWindowAlpha(progress))
                     .setCornerRadius(cornerRadius)
-                    .setShadowRadius(mMaxShadowRadius);
+                    .setShadowRadius(shadowRadius);
 
             mTransformParams.applySurfaceParams(mTransformParams.createSurfaceParams(this));
             mAnimationFactory.update(currentRect, progress, mMatrix.mapRadius(cornerRadius));
diff --git a/quickstep/src/com/android/quickstep/ViewUtils.java b/quickstep/src/com/android/quickstep/ViewUtils.java
index cbb6ad4..184ab17 100644
--- a/quickstep/src/com/android/quickstep/ViewUtils.java
+++ b/quickstep/src/com/android/quickstep/ViewUtils.java
@@ -15,21 +15,23 @@
  */
 package com.android.quickstep;
 
-import android.graphics.Canvas;
+import android.os.Handler;
 import android.view.View;
 
-import com.android.systemui.shared.system.WindowCallbacksCompat;
+import com.android.launcher3.Utilities;
+import com.android.systemui.shared.system.ViewRootImplCompat;
 
 import java.util.function.BooleanSupplier;
+import java.util.function.LongConsumer;
 
 /**
  * Utility class for helpful methods related to {@link View} objects.
  */
 public class ViewUtils {
 
-    /** See {@link #postDraw(View, Runnable, BooleanSupplier)}} */
-    public static boolean postDraw(View view, Runnable onFinishRunnable) {
-        return postDraw(view, onFinishRunnable, () -> false);
+    /** See {@link #postFrameDrawn(View, Runnable, BooleanSupplier)}} */
+    public static boolean postFrameDrawn(View view, Runnable onFinishRunnable) {
+        return postFrameDrawn(view, onFinishRunnable, () -> false);
     }
 
     /**
@@ -38,37 +40,55 @@
      *
      * @param onFinishRunnable runnable to be run right after the view finishes drawing.
      */
-    public static boolean postDraw(View view, Runnable onFinishRunnable, BooleanSupplier canceled) {
-        // Defer finishing the animation until the next launcher frame with the
-        // new thumbnail
-        return new WindowCallbacksCompat(view) {
-            // The number of frames to defer until we actually finish the animation
-            private int mDeferFrameCount = 2;
+    public static boolean postFrameDrawn(
+            View view, Runnable onFinishRunnable, BooleanSupplier canceled) {
+        return new FrameHandler(view, onFinishRunnable, canceled).schedule();
+    }
 
-            @Override
-            public void onPostDraw(Canvas canvas) {
-                // If we were cancelled after this was attached, do not update
-                // the state.
-                if (canceled.getAsBoolean()) {
-                    detach();
-                    return;
-                }
+    private static class FrameHandler implements LongConsumer {
 
-                if (mDeferFrameCount > 0) {
-                    mDeferFrameCount--;
-                    // Workaround, detach and reattach to invalidate the root node for
-                    // another draw
-                    detach();
-                    attach();
-                    view.invalidate();
-                    return;
-                }
+        final ViewRootImplCompat mViewRoot;
+        final Runnable mFinishCallback;
+        final BooleanSupplier mCancelled;
+        final Handler mHandler;
 
-                if (onFinishRunnable != null) {
-                    onFinishRunnable.run();
-                }
-                detach();
+        int mDeferFrameCount = 1;
+
+        FrameHandler(View view, Runnable finishCallback, BooleanSupplier cancelled) {
+            mViewRoot = new ViewRootImplCompat(view);
+            mFinishCallback = finishCallback;
+            mCancelled = cancelled;
+            mHandler = new Handler();
+        }
+
+        @Override
+        public void accept(long l) {
+            Utilities.postAsyncCallback(mHandler, this::onFrame);
+        }
+
+        private void onFrame() {
+            if (mCancelled.getAsBoolean()) {
+                return;
             }
-        }.attach();
+
+            if (mDeferFrameCount > 0) {
+                mDeferFrameCount--;
+                schedule();
+                return;
+            }
+
+            if (mFinishCallback != null) {
+                mFinishCallback.run();
+            }
+        }
+
+        private boolean schedule() {
+            if (mViewRoot.isValid()) {
+                mViewRoot.registerRtFrameCallback(this);
+                mViewRoot.getView().invalidate();
+                return true;
+            }
+            return false;
+        }
     }
 }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 65a445b..2158e03 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -2452,7 +2452,7 @@
             } else {
                 taskView.getThumbnail().refresh();
             }
-            ViewUtils.postDraw(taskView, onFinishRunnable);
+            ViewUtils.postFrameDrawn(taskView, onFinishRunnable);
         } else {
             onFinishRunnable.run();
         }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 4b75a33..ab8d7a5 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -77,6 +77,7 @@
 import android.os.Parcelable;
 import android.os.Process;
 import android.os.StrictMode;
+import android.os.SystemClock;
 import android.text.TextUtils;
 import android.text.method.TextKeyListener;
 import android.util.Log;
@@ -350,7 +351,7 @@
     private boolean mDeferOverlayCallbacks;
     private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred;
 
-    private long mLastTouchUpTime = -1;
+    protected long mLastTouchUpTime = -1;
     private boolean mTouchInProgress;
 
     private SafeCloseable mUserChangedCallbackCloseable;
@@ -1828,7 +1829,7 @@
                 mTouchInProgress = true;
                 break;
             case MotionEvent.ACTION_UP:
-                mLastTouchUpTime = System.currentTimeMillis();
+                mLastTouchUpTime = ev.getEventTime();
                 // Follow through
             case MotionEvent.ACTION_CANCEL:
                 mTouchInProgress = false;
@@ -2461,7 +2462,7 @@
         if (mDragController.isDragging()) {
             return false;
         } else {
-            return (System.currentTimeMillis() - mLastTouchUpTime)
+            return (SystemClock.uptimeMillis() - mLastTouchUpTime)
                     > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
         }
     }