Merge "Remove the shadow under PendingAppWidgetHostView." into sc-v2-dev
diff --git a/lint-baseline-launcher3.xml b/lint-baseline-launcher3.xml
index e77c889..94345a6 100644
--- a/lint-baseline-launcher3.xml
+++ b/lint-baseline-launcher3.xml
@@ -584,4 +584,15 @@
             column="17"/>
     </issue>
 
+    <issue
+        id="NewApi"
+        message="Call requires API level 27 (current min is 26): `android.app.WallpaperManager#getWallpaperColors`"
+        errorLine1="                    : WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM);"
+        errorLine2="                                                            ~~~~~~~~~~~~~~~~~~">
+        <location
+            file="packages/apps/Launcher3/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java"
+            line="288"
+            column="61"/>
+    </issue>
+
 </issues>
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 9dd4cf0..b8a38ad 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1542,7 +1542,8 @@
      * and unloads the associated task data for tasks that are no longer visible.
      */
     public void loadVisibleTaskData(@TaskView.TaskDataChanges int dataChanges) {
-        if (!mOverviewStateEnabled || mTaskListChangeId == -1) {
+        boolean hasLeftOverview = !mOverviewStateEnabled && mScroller.isFinished();
+        if (hasLeftOverview || mTaskListChangeId == -1) {
             // Skip loading visible task data if we've already left the overview state, or if the
             // task list hasn't been loaded yet (the task views will not reflect the task list)
             return;
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index 1da8028..94778a2 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -15,6 +15,7 @@
  */
 package com.android.launcher3.graphics;
 
+import static android.app.WallpaperManager.FLAG_SYSTEM;
 import static android.view.View.MeasureSpec.EXACTLY;
 import static android.view.View.MeasureSpec.makeMeasureSpec;
 import static android.view.View.VISIBLE;
@@ -27,6 +28,7 @@
 import android.annotation.TargetApi;
 import android.app.Fragment;
 import android.app.WallpaperColors;
+import android.app.WallpaperManager;
 import android.appwidget.AppWidgetHost;
 import android.appwidget.AppWidgetHostView;
 import android.appwidget.AppWidgetProviderInfo;
@@ -214,7 +216,7 @@
 
     public LauncherPreviewRenderer(Context context,
             InvariantDeviceProfile idp,
-            WallpaperColors wallpaperColors) {
+            WallpaperColors wallpaperColorsOverride) {
 
         super(context);
         mUiHandler = new Handler(Looper.getMainLooper());
@@ -280,16 +282,18 @@
                 mDp.workspacePadding.bottom);
         mWorkspaceScreens.put(FIRST_SCREEN_ID, firstScreen);
 
-        if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) {
-            mAppWidgetHost = new LauncherPreviewAppWidgetHost(context);
-            mWallpaperColorResources =  wallpaperColors != null
-                    ? LocalColorExtractor.newInstance(context)
-                            .generateColorsOverride(wallpaperColors)
-                    : null;
+        if (Utilities.ATLEAST_S) {
+            WallpaperColors wallpaperColors = wallpaperColorsOverride != null
+                    ? wallpaperColorsOverride
+                    : WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM);
+            mWallpaperColorResources = LocalColorExtractor.newInstance(context)
+                    .generateColorsOverride(wallpaperColors);
         } else {
-            mAppWidgetHost = null;
             mWallpaperColorResources = null;
         }
+        mAppWidgetHost = FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()
+                ? new LauncherPreviewAppWidgetHost(context)
+                : null;
     }
 
     /** Populate preview and render it. */
@@ -405,6 +409,10 @@
             view.updateAppWidget(null);
         }
 
+        if (mWallpaperColorResources != null) {
+            view.setColorResources(mWallpaperColorResources);
+        }
+
         view.setTag(info);
         addInScreenFromBind(view, info);
     }
@@ -537,12 +545,9 @@
         }
     }
 
-    private class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView {
+    private static class LauncherPreviewAppWidgetHostView extends BaseLauncherAppWidgetHostView {
         private LauncherPreviewAppWidgetHostView(Context context) {
             super(context);
-            if (Utilities.ATLEAST_S && mWallpaperColorResources != null) {
-                setColorResources(mWallpaperColorResources);
-            }
         }
 
         @Override
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index ef809d5..1e7f8a5 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -207,6 +207,11 @@
     public LauncherInstrumentation(Instrumentation instrumentation) {
         mInstrumentation = instrumentation;
         mDevice = UiDevice.getInstance(instrumentation);
+        try {
+            mDevice.executeShellCommand("am wait-for-broadcast-idle");
+        } catch (IOException e) {
+            log("Failed to wait for broadcast idle");
+        }
 
         // Launcher should run in test harness so that custom accessibility protocol between
         // Launcher and TAPL is enabled. In-process tests enable this protocol with a direct call