Merge "Update FloatingIconView to display PreloadIconDrawables during swipe home animations." into sc-dev
diff --git a/quickstep/src/com/android/launcher3/search/SearchResultThumbnailView.java b/quickstep/src/com/android/launcher3/search/SearchResultThumbnailView.java
index b1cbe7d..dd95461 100644
--- a/quickstep/src/com/android/launcher3/search/SearchResultThumbnailView.java
+++ b/quickstep/src/com/android/launcher3/search/SearchResultThumbnailView.java
@@ -23,6 +23,7 @@
 import android.graphics.drawable.BitmapDrawable;
 import android.util.AttributeSet;
 import android.view.View;
+import android.view.ViewGroup;
 
 import androidx.core.graphics.drawable.RoundedBitmapDrawable;
 import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
@@ -56,6 +57,14 @@
     }
 
     @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        setOnFocusChangeListener(Launcher.getLauncher(getContext()).getFocusHandler());
+        setOnClickListener(this);
+        setOnLongClickListener(this);
+    }
+
+    @Override
     public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
         mSearchTarget = parentTarget;
         Bitmap bitmap;
@@ -65,6 +74,9 @@
                 parentTarget.getPackageName(),
                 parentTarget.getUserHandle(),
                 parentTarget.getSearchAction().getTitle());
+        itemInfo.setIntent(parentTarget.getSearchAction().getIntent());
+        itemInfo.setPendingIntent(parentTarget.getSearchAction().getPendingIntent());
+
         bitmap = ((BitmapDrawable) itemInfo.getIcon()
                 .loadDrawable(getContext())).getBitmap();
         // crop
diff --git a/quickstep/src/com/android/launcher3/search/SearchTargetUtil.java b/quickstep/src/com/android/launcher3/search/SearchTargetUtil.java
index ceef429..95f4f58 100644
--- a/quickstep/src/com/android/launcher3/search/SearchTargetUtil.java
+++ b/quickstep/src/com/android/launcher3/search/SearchTargetUtil.java
@@ -112,6 +112,7 @@
         Intent intent = new Intent(Intent.ACTION_VIEW)
                 .setData(Uri.parse("uri blah blah"))
                 .setType("image/*")
+                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
         Bitmap bitmap = Bitmap.createBitmap(1000, 500, Bitmap.Config.ARGB_8888);
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 5a2d6da..39a3a7c 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1451,7 +1451,10 @@
     private void finishCurrentTransitionToRecents() {
         if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
             mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED);
-            mRecentsView.getRunningTaskView().setIsClickableAsLiveTile(true);
+            final TaskView runningTaskView = mRecentsView.getRunningTaskView();
+            if (runningTaskView != null) {
+                runningTaskView.setIsClickableAsLiveTile(true);
+            }
         } else if (!hasTargets() || mRecentsAnimationController == null) {
             // If there are no targets or the animation not started, then there is nothing to finish
             mStateCallback.setStateOnUiThread(STATE_CURRENT_TASK_FINISHED);
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 12ce9f3..f681d75 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -607,8 +607,9 @@
      */
     public boolean updateIsSeascape(Context context) {
         if (isVerticalBarLayout()) {
-            boolean isSeascape = DisplayController.getDefaultDisplay(context).getInfo().rotation
-                    == Surface.ROTATION_270;
+            // Check an up-to-date info.
+            boolean isSeascape = DisplayController.getDefaultDisplay(context)
+                    .createInfoForContext(context).rotation == Surface.ROTATION_270;
             if (mIsSeascape != isSeascape) {
                 mIsSeascape = isSeascape;
                 return true;
diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java
index 355c949..3b7bcc2 100644
--- a/src/com/android/launcher3/util/DisplayController.java
+++ b/src/com/android/launcher3/util/DisplayController.java
@@ -31,6 +31,8 @@
 
 import androidx.annotation.VisibleForTesting;
 
+import com.android.launcher3.Utilities;
+
 import java.util.ArrayList;
 
 /**
@@ -179,23 +181,35 @@
             return mInfo;
         }
 
+        /** Creates and up-to-date DisplayController.Info for the given context. */
+        public Info createInfoForContext(Context context) {
+            Display display = Utilities.ATLEAST_R
+                    ? context.getDisplay()
+                    : context
+                        .getSystemService(DisplayManager.class)
+                        .getDisplay(mId);
+            return display == null
+                    ? new Info(context)
+                    : new Info(context, display);
+        }
+
         protected void handleOnChange() {
             Info oldInfo = mInfo;
-            Info info = new Info(mDisplayContext);
+            Info newInfo = createInfoForContext(mDisplayContext);
 
             int change = 0;
-            if (info.hasDifferentSize(oldInfo)) {
+            if (newInfo.hasDifferentSize(oldInfo)) {
                 change |= CHANGE_SIZE;
             }
-            if (oldInfo.rotation != info.rotation) {
+            if (newInfo.rotation != oldInfo.rotation) {
                 change |= CHANGE_ROTATION;
             }
-            if (info.singleFrameMs != oldInfo.singleFrameMs) {
+            if (newInfo.singleFrameMs != oldInfo.singleFrameMs) {
                 change |= CHANGE_FRAME_DELAY;
             }
 
             if (change != 0) {
-                mInfo = info;
+                mInfo = newInfo;
                 final int flags = change;
                 MAIN_EXECUTOR.execute(() -> notifyChange(flags));
             }