Merge "Add flags for new restore icon treatment" into tm-qpr-dev
diff --git a/quickstep/src/com/android/quickstep/TaskIconCache.java b/quickstep/src/com/android/quickstep/TaskIconCache.java
index dc60875..7c05a10 100644
--- a/quickstep/src/com/android/quickstep/TaskIconCache.java
+++ b/quickstep/src/com/android/quickstep/TaskIconCache.java
@@ -249,12 +249,13 @@
     private BitmapInfo getBitmapInfo(Drawable drawable, int userId,
             int primaryColor, boolean isInstantApp) {
         try (BaseIconFactory bif = getIconFactory()) {
-            bif.disableColorExtraction();
             bif.setWrapperBackgroundColor(primaryColor);
 
             // User version code O, so that the icon is always wrapped in an adaptive icon container
             return bif.createBadgedIconBitmap(drawable,
-                    new IconOptions().setUser(UserHandle.of(userId)).setInstantApp(isInstantApp));
+                    new IconOptions().setUser(UserHandle.of(userId))
+                            .setInstantApp(isInstantApp)
+                            .setExtractedColor(0));
         }
     }
 
diff --git a/src/com/android/launcher3/ExtendedEditText.java b/src/com/android/launcher3/ExtendedEditText.java
index 11f2020..c59f25d 100644
--- a/src/com/android/launcher3/ExtendedEditText.java
+++ b/src/com/android/launcher3/ExtendedEditText.java
@@ -18,6 +18,7 @@
 import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.SHOW;
 
 import android.content.Context;
+import android.graphics.Rect;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.DragEvent;
@@ -27,12 +28,17 @@
 
 import com.android.launcher3.views.ActivityContext;
 
+import java.util.HashSet;
+import java.util.Set;
+
 
 /**
  * The edit text that reports back when the back key has been pressed.
  * Note: AppCompatEditText doesn't fully support #displayCompletions and #onCommitCompletion
  */
 public class ExtendedEditText extends EditText {
+    private final Set<OnFocusChangeListener> mOnFocusChangeListeners = new HashSet<>();
+
     private boolean mForceDisableSuggestions = false;
 
     /**
@@ -129,4 +135,28 @@
             setText("");
         }
     }
+
+    /**
+     * This method should be preferred to {@link #setOnFocusChangeListener(OnFocusChangeListener)},
+     * as it allows for multiple listeners from different sources.
+     */
+    public void addOnFocusChangeListener(OnFocusChangeListener listener) {
+        mOnFocusChangeListeners.add(listener);
+    }
+
+    /**
+     * Removes the given listener from the set of registered focus listeners, or does nothing if it
+     * wasn't registered in the first place.
+     */
+    public void removeOnFocusChangeListener(OnFocusChangeListener listener) {
+        mOnFocusChangeListeners.remove(listener);
+    }
+
+    @Override
+    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
+        super.onFocusChanged(focused, direction, previouslyFocusedRect);
+        for (OnFocusChangeListener listener : mOnFocusChangeListeners) {
+            listener.onFocusChange(this, focused);
+        }
+    }
 }
diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
index 4d58eb0..4427a49 100644
--- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
+++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java
@@ -67,7 +67,7 @@
         mInput.addTextChangedListener(this);
         mInput.setOnEditorActionListener(this);
         mInput.setOnBackKeyListener(this);
-        mInput.setOnFocusChangeListener(this);
+        mInput.addOnFocusChangeListener(this);
         mSearchAlgorithm = searchAlgorithm;
     }
 
@@ -153,6 +153,7 @@
         mCallback.clearSearchResult();
         mInput.reset();
         mQuery = null;
+        mInput.removeOnFocusChangeListener(this);
     }
 
     /**
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index cc2119f..3e1c0eb 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -124,6 +124,10 @@
             "FOLDER_NAME_MAJORITY_RANKING", true,
             "Suggests folder names based on majority based ranking.");
 
+    public static final BooleanFlag INJECT_FALLBACK_APP_CORPUS_RESULTS = new DeviceFlag(
+            "INJECT_FALLBACK_APP_CORPUS_RESULTS", false, "Inject "
+            + "fallback app corpus result when AiAi fails to return it.");
+
     public static final BooleanFlag ASSISTANT_GIVES_LAUNCHER_FOCUS = getDebugFlag(
             "ASSISTANT_GIVES_LAUNCHER_FOCUS", false,
             "Allow Launcher to handle nav bar gestures while Assistant is running over it");
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 99822da..94eea35 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -282,7 +282,6 @@
         mFolderName = findViewById(R.id.folder_name);
         mFolderName.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.folderLabelTextSizePx);
         mFolderName.setOnBackKeyListener(this);
-        mFolderName.setOnFocusChangeListener(this);
         mFolderName.setOnEditorActionListener(this);
         mFolderName.setSelectAllOnFocus(true);
         mFolderName.setInputType(mFolderName.getInputType()
@@ -457,6 +456,13 @@
         // the folder itself.
         requestFocus();
         super.onAttachedToWindow();
+        mFolderName.addOnFocusChangeListener(this);
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+        mFolderName.removeOnFocusChangeListener(this);
     }
 
     @Override
diff --git a/src/com/android/launcher3/icons/ShortcutCachingLogic.java b/src/com/android/launcher3/icons/ShortcutCachingLogic.java
index 9a86ede..bb7248f 100644
--- a/src/com/android/launcher3/icons/ShortcutCachingLogic.java
+++ b/src/com/android/launcher3/icons/ShortcutCachingLogic.java
@@ -32,6 +32,7 @@
 import androidx.annotation.Nullable;
 
 import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.icons.BaseIconFactory.IconOptions;
 import com.android.launcher3.icons.cache.CachingLogic;
 import com.android.launcher3.shortcuts.ShortcutKey;
 import com.android.launcher3.util.Themes;
@@ -76,9 +77,8 @@
             Drawable unbadgedDrawable = ShortcutCachingLogic.getIcon(
                     context, info, LauncherAppState.getIDP(context).fillResIconDpi);
             if (unbadgedDrawable == null) return BitmapInfo.LOW_RES_INFO;
-            return new BitmapInfo(
-                    li.createScaledBitmap(unbadgedDrawable, BaseIconFactory.MODE_WITH_SHADOW),
-                    Themes.getColorAccent(context));
+            return li.createBadgedIconBitmap(unbadgedDrawable,
+                    new IconOptions().setExtractedColor(Themes.getColorAccent(context)));
         }
     }
 
diff --git a/tests/res/xml/shortcuts.xml b/tests/res/xml/shortcuts.xml
index bdc22f9..fde0dbb 100644
--- a/tests/res/xml/shortcuts.xml
+++ b/tests/res/xml/shortcuts.xml
@@ -2,6 +2,7 @@
 <shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
     <shortcut
         android:shortcutId="shortcut1"
+        android:icon="@drawable/test_theme_icon"
         android:shortcutShortLabel="@string/shortcut1">
         <intent android:action="com.android.launcher3.intent.action.test_shortcut"/>
     </shortcut>
diff --git a/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java b/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
index e66810c..57731d0 100644
--- a/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
+++ b/tests/src/com/android/launcher3/ui/workspace/ThemeIconsTest.java
@@ -32,6 +32,7 @@
 import com.android.launcher3.icons.ThemedIconDrawable;
 import com.android.launcher3.tapl.HomeAllApps;
 import com.android.launcher3.tapl.HomeAppIcon;
+import com.android.launcher3.tapl.HomeAppIconMenuItem;
 import com.android.launcher3.ui.AbstractLauncherUiTest;
 import com.android.launcher3.ui.TaplTestsLauncher3;
 
@@ -49,6 +50,8 @@
 public class ThemeIconsTest extends AbstractLauncherUiTest {
 
     private static final String APP_NAME = "ThemeIconTestActivity";
+    private static final String SHORTCUT_APP_NAME = "LauncherTestApp";
+    private static final String SHORTCUT_NAME = "Shortcut 1";
 
     @Test
     public void testIconWithoutTheme() throws Exception {
@@ -60,9 +63,28 @@
 
         try {
             HomeAppIcon icon = allApps.getAppIcon(APP_NAME);
-            executeOnLauncher(l -> verifyIconTheme(l.getAppsView(), false));
+            executeOnLauncher(l -> verifyIconTheme(APP_NAME, l.getAppsView(), false));
             icon.dragToWorkspace(false, false);
-            executeOnLauncher(l -> verifyIconTheme(l.getWorkspace(), false));
+            executeOnLauncher(l -> verifyIconTheme(APP_NAME, l.getWorkspace(), false));
+        } finally {
+            allApps.unfreeze();
+        }
+    }
+
+    @Test
+    public void testShortcutIconWithoutTheme() throws Exception {
+        setThemeEnabled(false);
+        TaplTestsLauncher3.initialize(this);
+
+        HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
+        allApps.freeze();
+
+        try {
+            HomeAppIcon icon = allApps.getAppIcon(SHORTCUT_APP_NAME);
+            HomeAppIconMenuItem shortcutItem =
+                    (HomeAppIconMenuItem) icon.openDeepShortcutMenu().getMenuItem(SHORTCUT_NAME);
+            shortcutItem.dragToWorkspace(false, false);
+            executeOnLauncher(l -> verifyIconTheme(SHORTCUT_NAME, l.getWorkspace(), false));
         } finally {
             allApps.unfreeze();
         }
@@ -78,15 +100,34 @@
 
         try {
             HomeAppIcon icon = allApps.getAppIcon(APP_NAME);
-            executeOnLauncher(l -> verifyIconTheme(l.getAppsView(), false));
+            executeOnLauncher(l -> verifyIconTheme(APP_NAME, l.getAppsView(), false));
             icon.dragToWorkspace(false, false);
-            executeOnLauncher(l -> verifyIconTheme(l.getWorkspace(), true));
+            executeOnLauncher(l -> verifyIconTheme(APP_NAME, l.getWorkspace(), true));
         } finally {
             allApps.unfreeze();
         }
     }
 
-    private void verifyIconTheme(ViewGroup parent, boolean isThemed) {
+    @Test
+    public void testShortcutIconWithTheme() throws Exception {
+        setThemeEnabled(true);
+        TaplTestsLauncher3.initialize(this);
+
+        HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
+        allApps.freeze();
+
+        try {
+            HomeAppIcon icon = allApps.getAppIcon(SHORTCUT_APP_NAME);
+            HomeAppIconMenuItem shortcutItem =
+                    (HomeAppIconMenuItem) icon.openDeepShortcutMenu().getMenuItem(SHORTCUT_NAME);
+            shortcutItem.dragToWorkspace(false, false);
+            executeOnLauncher(l -> verifyIconTheme(SHORTCUT_NAME, l.getWorkspace(), true));
+        } finally {
+            allApps.unfreeze();
+        }
+    }
+
+    private void verifyIconTheme(String title, ViewGroup parent, boolean isThemed) {
         // Find the app icon
         Queue<View> viewQueue = new ArrayDeque<>();
         viewQueue.add(parent);
@@ -100,7 +141,7 @@
                 }
             } else if (view instanceof BubbleTextView) {
                 BubbleTextView btv = (BubbleTextView) view;
-                if (APP_NAME.equals(btv.getText())) {
+                if (title.equals(btv.getText())) {
                     icon = btv;
                     break;
                 }