Merge "Stash the bar after settling in Overview" into sc-v2-dev
diff --git a/src/com/android/launcher3/ExtendedEditText.java b/src/com/android/launcher3/ExtendedEditText.java
index 21bc479..92432a8 100644
--- a/src/com/android/launcher3/ExtendedEditText.java
+++ b/src/com/android/launcher3/ExtendedEditText.java
@@ -26,7 +26,6 @@
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
 
-import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.views.ActivityContext;
 
 
@@ -99,18 +98,6 @@
         }
     }
 
-    /**
-     * Sets whether EditText background should be visible
-     * @param maxAlpha defines the maximum alpha the background should animates to
-     */
-    public void setBackgroundVisibility(boolean visible, float maxAlpha) {}
-
-    /**
-     * Returns whether a visible background is set on EditText
-     */
-    public boolean getBackgroundVisibility() {
-        return getBackground() != null;
-    }
 
     public void showKeyboard() {
         mShowImeAfterFirstLayout = !showSoftInput();
@@ -150,9 +137,6 @@
         if (!TextUtils.isEmpty(getText())) {
             setText("");
         }
-        if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
-            return;
-        }
         if (isFocused()) {
             View nextFocus = focusSearch(View.FOCUS_DOWN);
             if (nextFocus != null) {
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index d663480..03e4ee7 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -199,6 +199,7 @@
         public static final int CONTAINER_WIDGETS_TRAY = -105;
         public static final int CONTAINER_BOTTOM_WIDGETS_TRAY = -112;
         public static final int CONTAINER_PIN_WIDGETS = -113;
+        public static final int CONTAINER_WALLPAPERS = -114;
         // Represents search results view.
         public static final int CONTAINER_SEARCH_RESULTS = -106;
         public static final int CONTAINER_SHORTCUTS = -107;
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index e779ee8..ee5f7e4 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -59,7 +59,6 @@
 import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
 import com.android.launcher3.DragSource;
 import com.android.launcher3.DropTarget.DragObject;
-import com.android.launcher3.ExtendedEditText;
 import com.android.launcher3.Insettable;
 import com.android.launcher3.InsettableFrameLayout;
 import com.android.launcher3.R;
@@ -624,6 +623,9 @@
         for (int i = 0; i < mAH.length; i++) {
             mAH[i].padding.top = padding;
             mAH[i].applyPadding();
+            if (mAH[i].recyclerView != null) {
+                mAH[i].recyclerView.scrollToTop();
+            }
         }
         mHeaderTop = mHeader.getTop();
     }
@@ -639,6 +641,7 @@
 
     public void onClearSearchResult() {
         mIsSearching = false;
+        mHeader.setCollapsed(false);
         rebindAdapters();
         getActiveRecyclerView().scrollToTop();
     }
@@ -814,14 +817,13 @@
             invalidateHeader();
         }
         if (mSearchUiManager.getEditText() != null) {
-            ExtendedEditText editText = mSearchUiManager.getEditText();
-            boolean bgVisible = editText.getBackgroundVisibility();
+            boolean bgVisible = mSearchUiManager.getBackgroundVisibility();
             if (scrolledOffset == 0 && !mIsSearching) {
                 bgVisible = true;
             } else if (scrolledOffset > mHeaderThreshold) {
                 bgVisible = false;
             }
-            editText.setBackgroundVisibility(bgVisible, 1 - prog);
+            mSearchUiManager.setBackgroundVisibility(bgVisible, 1 - prog);
         }
     }
 
diff --git a/src/com/android/launcher3/allapps/FloatingHeaderRow.java b/src/com/android/launcher3/allapps/FloatingHeaderRow.java
index 9bf6043..6ff2132 100644
--- a/src/com/android/launcher3/allapps/FloatingHeaderRow.java
+++ b/src/com/android/launcher3/allapps/FloatingHeaderRow.java
@@ -47,6 +47,8 @@
 
     /**
      * Scrolls the content vertically.
+     * @param scroll scrolled distance in pixels for active recyclerview.
+     * @param isScrolledOut bool to determine if row is scrolled out of view
      */
     void setVerticalScroll(int scroll, boolean isScrolledOut);
 
diff --git a/src/com/android/launcher3/allapps/SearchUiManager.java b/src/com/android/launcher3/allapps/SearchUiManager.java
index 924a392..7478b53 100644
--- a/src/com/android/launcher3/allapps/SearchUiManager.java
+++ b/src/com/android/launcher3/allapps/SearchUiManager.java
@@ -49,6 +49,19 @@
     ExtendedEditText getEditText();
 
     /**
+     * Sets whether EditText background should be visible
+     * @param maxAlpha defines the maximum alpha the background should animates to
+     */
+    default void setBackgroundVisibility(boolean visible, float maxAlpha) {}
+
+    /**
+     * Returns whether a visible background is set on EditText
+     */
+    default boolean getBackgroundVisibility() {
+        return false;
+    }
+
+    /**
      * sets highlight result's title
      */
     default void setFocusedResultTitle(@Nullable  CharSequence title) { }
diff --git a/src/com/android/launcher3/model/DeviceGridState.java b/src/com/android/launcher3/model/DeviceGridState.java
index e2df16d..0fc4c2d 100644
--- a/src/com/android/launcher3/model/DeviceGridState.java
+++ b/src/com/android/launcher3/model/DeviceGridState.java
@@ -119,12 +119,23 @@
     }
 
     @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        DeviceGridState that = (DeviceGridState) o;
-        return mNumHotseat == that.mNumHotseat
-                && deviceTypeCompatible(mDeviceType, that.mDeviceType)
-                && Objects.equals(mGridSizeString, that.mGridSizeString);
+    public String toString() {
+        return "DeviceGridState{"
+                + "mGridSizeString='" + mGridSizeString + '\''
+                + ", mNumHotseat=" + mNumHotseat
+                + ", mDeviceType=" + mDeviceType
+                + '}';
+    }
+
+    /**
+     * Returns true if the database from another DeviceGridState can be loaded into the current
+     * DeviceGridState without migration, or false otherwise.
+     */
+    public boolean isCompatible(DeviceGridState other) {
+        if (this == other) return true;
+        if (other == null) return false;
+        return mNumHotseat == other.mNumHotseat
+                && deviceTypeCompatible(mDeviceType, other.mDeviceType)
+                && Objects.equals(mGridSizeString, other.mGridSizeString);
     }
 }
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
index e7d0749..fc86cf8 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTaskV2.java
@@ -103,7 +103,13 @@
      * Check given a new IDP, if migration is necessary.
      */
     public static boolean needsToMigrate(Context context, InvariantDeviceProfile idp) {
-        return !new DeviceGridState(idp).equals(new DeviceGridState(context));
+        DeviceGridState idpGridState = new DeviceGridState(idp);
+        DeviceGridState contextGridState = new DeviceGridState(context);
+        boolean needsToMigrate = !idpGridState.isCompatible(contextGridState);
+        // TODO: Revert this change after b/200010396 is fixed
+        Log.d(TAG, "Migration is needed. idpGridState: " + idpGridState
+                + ", contextGridState: " + contextGridState);
+        return needsToMigrate;
     }
 
     /** See {@link #migrateGridIfNeeded(Context, InvariantDeviceProfile)} */