Merge "Showing alert dialog when shortcut version higher than the App" into tm-dev
diff --git a/Android.bp b/Android.bp
index b3027bc..a523a62 100644
--- a/Android.bp
+++ b/Android.bp
@@ -107,6 +107,7 @@
         "androidx.cardview_cardview",
         "com.google.android.material_material",
         "iconloader_base",
+        "modules-utils-build",
     ],
     manifest: "AndroidManifest-common.xml",
     sdk_version: "current",
diff --git a/go/quickstep/res/values-pt-rPT/strings.xml b/go/quickstep/res/values-pt-rPT/strings.xml
index 7041f41..e64f520 100644
--- a/go/quickstep/res/values-pt-rPT/strings.xml
+++ b/go/quickstep/res/values-pt-rPT/strings.xml
@@ -10,9 +10,9 @@
     <string name="dialog_settings" msgid="6564397136021186148">"DEFINIÇÕES"</string>
     <string name="niu_actions_confirmation_title" msgid="3863451714863526143">"Traduza ou ouça o texto no ecrã"</string>
     <string name="niu_actions_confirmation_text" msgid="2105271481950866089">"Informações como o texto no ecrã, endereços Web e capturas de ecrã podem ser partilhadas com a Google.\n\nPara alterar as informações que partilha, aceda a "<b>"Definições &gt; Apps &gt; App predefinidas &gt; App de assistente digital"</b>"."</string>
-    <string name="assistant_not_selected_title" msgid="5017072974603345228">"Escolha um assistente para utilizar esta funcionalidade"</string>
+    <string name="assistant_not_selected_title" msgid="5017072974603345228">"Escolha um assistente para usar esta funcionalidade"</string>
     <string name="assistant_not_selected_text" msgid="3244613673884359276">"Para ouvir ou traduzir o texto no ecrã, escolha uma app de assistente digital nas Definições"</string>
-    <string name="assistant_not_supported_title" msgid="1675788067597484142">"Mude de assistente para utilizar esta funcionalidade"</string>
+    <string name="assistant_not_supported_title" msgid="1675788067597484142">"Mude de assistente para usar esta funcionalidade"</string>
     <string name="assistant_not_supported_text" msgid="1708031078549268884">"Para ouvir ou traduzir o texto no ecrã, mude de app de assistente digital nas Definições"</string>
     <string name="tooltip_listen" msgid="7634466447860989102">"Toque aqui para ouvir o texto neste ecrã"</string>
     <string name="tooltip_translate" msgid="4184845868901542567">"Toque aqui para traduzir o texto neste ecrã"</string>
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
index 8e31a74..e02a9d7 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
@@ -19,6 +19,7 @@
 import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
 
+import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
 import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
 
 import android.content.ComponentCallbacks;
@@ -41,7 +42,6 @@
 import com.android.launcher3.statemanager.StatefulActivity;
 import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider;
 import com.android.launcher3.util.DisplayController;
-import com.android.launcher3.util.DisplayController.Info;
 import com.android.launcher3.util.SettingsCache;
 import com.android.launcher3.util.SimpleBroadcastReceiver;
 import com.android.quickstep.RecentsActivity;
@@ -55,7 +55,7 @@
 /**
  * Class to manage taskbar lifecycle
  */
-public class TaskbarManager implements DisplayController.DisplayInfoChangeListener {
+public class TaskbarManager {
 
     private static final Uri USER_SETUP_COMPLETE_URI = Settings.Secure.getUriFor(
             Settings.Secure.USER_SETUP_COMPLETE);
@@ -91,8 +91,15 @@
      * navigation mode, that callback gets called too soon, before it's internal navigation mode
      * reflects the current one.
      * DisplayController's callback is delayed enough to get the correct nav mode value
+     *
+     * We also use density change here because DeviceProfile has had a chance to update it's state
+     * whereas density for component callbacks registered in this class don't update DeviceProfile.
+     * Confused? Me too. Make it less confusing (TODO: b/227669780)
+     *
+     * Flags used with {@link #mDispInfoChangeListener}
      */
-    private static final int CHANGE_FLAGS = CHANGE_NAVIGATION_MODE;
+    private static final int CHANGE_FLAGS = CHANGE_NAVIGATION_MODE | CHANGE_DENSITY;
+    private final DisplayController.DisplayInfoChangeListener mDispInfoChangeListener;
 
     private boolean mUserUnlocked = false;
 
@@ -105,6 +112,7 @@
                 SystemUiProxy.INSTANCE.get(mContext), new Handler());
         mUserSetupCompleteListener = isUserSetupComplete -> recreateTaskbar();
         mNavBarKidsModeListener = isNavBarKidsMode -> recreateTaskbar();
+        // TODO(b/227669780): Consolidate this w/ DisplayController callbacks
         mComponentCallbacks = new ComponentCallbacks() {
             private Configuration mOldConfig = mContext.getResources().getConfiguration();
 
@@ -116,7 +124,7 @@
                 int configDiff = mOldConfig.diff(newConfig);
                 int configsRequiringRecreate = ActivityInfo.CONFIG_ASSETS_PATHS
                         | ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_UI_MODE
-                        | ActivityInfo.CONFIG_DENSITY | ActivityInfo.CONFIG_SCREEN_SIZE;
+                        | ActivityInfo.CONFIG_SCREEN_SIZE;
                 boolean requiresRecreate = (configDiff & configsRequiringRecreate) != 0;
                 if ((configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0
                         && mTaskbarActivityContext != null && dp != null) {
@@ -151,8 +159,12 @@
             public void onLowMemory() { }
         };
         mShutdownReceiver = new SimpleBroadcastReceiver(i -> destroyExistingTaskbar());
-
-        mDisplayController.addChangeListener(this);
+        mDispInfoChangeListener = (context, info, flags) -> {
+            if ((flags & CHANGE_FLAGS) != 0) {
+                recreateTaskbar();
+            }
+        };
+        mDisplayController.addChangeListener(mDispInfoChangeListener);
         SettingsCache.INSTANCE.get(mContext).register(USER_SETUP_COMPLETE_URI,
                 mUserSetupCompleteListener);
         SettingsCache.INSTANCE.get(mContext).register(NAV_BAR_KIDS_MODE,
@@ -163,13 +175,6 @@
         recreateTaskbar();
     }
 
-    @Override
-    public void onDisplayInfoChanged(Context context, Info info, int flags) {
-        if ((flags & CHANGE_FLAGS) != 0) {
-            recreateTaskbar();
-        }
-    }
-
     private void destroyExistingTaskbar() {
         if (mTaskbarActivityContext != null) {
             mTaskbarActivityContext.onDestroy();
@@ -310,7 +315,7 @@
      */
     public void destroy() {
         destroyExistingTaskbar();
-        mDisplayController.removeChangeListener(this);
+        mDisplayController.removeChangeListener(mDispInfoChangeListener);
         SettingsCache.INSTANCE.get(mContext).unregister(USER_SETUP_COMPLETE_URI,
                 mUserSetupCompleteListener);
         SettingsCache.INSTANCE.get(mContext).unregister(NAV_BAR_KIDS_MODE,
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java
index 86c42ca..4d3b057 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NavBarToHomeTouchController.java
@@ -21,7 +21,7 @@
 import static com.android.launcher3.LauncherAnimUtils.newCancelListener;
 import static com.android.launcher3.LauncherState.ALL_APPS;
 import static com.android.launcher3.LauncherState.NORMAL;
-import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
+import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PULL_BACK_PROGRESS;
 import static com.android.launcher3.anim.AnimatorListeners.forSuccessCallback;
 import static com.android.launcher3.anim.Interpolators.DEACCEL_3;
 import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_EDU;
@@ -147,7 +147,7 @@
             AbstractFloatingView.closeOpenContainer(mLauncher, AbstractFloatingView.TYPE_TASK_MENU);
         } else if (mStartState == ALL_APPS) {
             AllAppsTransitionController allAppsController = mLauncher.getAllAppsController();
-            builder.setFloat(allAppsController, ALL_APPS_PROGRESS,
+            builder.setFloat(allAppsController, ALL_APPS_PULL_BACK_PROGRESS,
                     -mPullbackDistance / allAppsController.getShiftRange(), PULLBACK_INTERPOLATOR);
 
             // Slightly fade out all apps content to further distinguish from scrolling.
diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
index 6b15807..99a2d6f 100644
--- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
@@ -155,7 +155,7 @@
     public void setInsets(Rect insets) {
         mInsets.set(insets);
         updateVerticalMargin(DisplayController.getNavigationMode(getContext()));
-        updatePaddingAndTranslations();
+        updatePadding();
     }
 
     public void updateHiddenFlags(@ActionsHiddenFlags int visibilityFlags, boolean enable) {
@@ -199,10 +199,9 @@
     }
 
     /**
-     * Aligns OverviewActionsView vertically with and offsets horizontal position based on
-     * 3 button nav container in taskbar.
+     * Offsets OverviewActionsView horizontal position based on 3 button nav container in taskbar.
      */
-    private void updatePaddingAndTranslations() {
+    private void updatePadding() {
         boolean alignFor3ButtonTaskbar = mDp.isTaskbarPresent &&
                 DisplayController.getNavigationMode(getContext()) == THREE_BUTTONS;
         if (alignFor3ButtonTaskbar) {
@@ -213,20 +212,8 @@
             } else {
                 setPadding(mInsets.left, 0, mInsets.right + additionalPadding, 0);
             }
-
-            // Align vertically, using taskbar height + mDp.taskbarOffsetY() to estimate where
-            // the button nav top is.
-            int marginBottom = getOverviewActionsBottomMarginPx(
-                    DisplayController.getNavigationMode(getContext()), mDp);
-            int actionsTop =
-                    (mDp.heightPx - marginBottom - mInsets.bottom) - mDp.overviewActionsHeight;
-            int navTop = mDp.heightPx - (mDp.taskbarSize + mDp.getTaskbarOffsetY());
-            int transY = navTop - actionsTop + ((mDp.taskbarSize - mDp.overviewActionsHeight) / 2);
-            setTranslationY(transY);
         } else {
             setPadding(mInsets.left, 0, mInsets.right, 0);
-            setTranslationX(0);
-            setTranslationY(0);
         }
     }
 
@@ -287,19 +274,28 @@
 
     /** Get the bottom margin associated with the action buttons in Overview. */
     public static int getOverviewActionsBottomMarginPx(NavigationMode mode, DeviceProfile dp) {
-        int inset = dp.getInsets().bottom;
+        int bottomInset = dp.getInsets().bottom;
 
         if (dp.isVerticalBarLayout()) {
-            return inset;
+            return bottomInset;
         }
 
-        // Actions button will be aligned with nav buttons in updatePaddingAndTranslations().
         if (mode == NavigationMode.THREE_BUTTONS) {
-            return dp.overviewActionsMarginThreeButtonPx + inset;
+            int bottomMargin = dp.overviewActionsMarginThreeButtonPx + bottomInset;
+            if (dp.isTaskbarPresent) {
+                // Align vertically, using taskbar height + mDp.taskbarOffsetY() to estimate where
+                // the button nav top is.
+                int actionsTop = (dp.heightPx - bottomMargin - bottomInset)
+                        - dp.overviewActionsHeight;
+                int navTop = dp.heightPx - (dp.taskbarSize + dp.getTaskbarOffsetY());
+                bottomMargin -=
+                        navTop - actionsTop + ((dp.taskbarSize - dp.overviewActionsHeight) / 2);
+            }
+            return bottomMargin;
         }
 
         // There is no bottom inset when taskbar is present, use stashed taskbar as padding instead.
         return dp.overviewActionsBottomMarginGesturePx
-                + (dp.isTaskbarPresent ? dp.stashedTaskbarSize : inset);
+                + (dp.isTaskbarPresent ? dp.stashedTaskbarSize : bottomInset);
     }
 }
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index 602dd6d..eb347f2 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -38,10 +38,10 @@
 
 <!-- Hotseat -->
     <dimen name="dynamic_grid_hotseat_side_padding">0dp</dimen>
-    <dimen name="spring_loaded_hotseat_top_margin">97dp</dimen>
+    <dimen name="spring_loaded_hotseat_top_margin">65dp</dimen>
 
 <!-- Dragging -->
-    <dimen name="drop_target_top_margin">34dp</dimen>
+    <dimen name="drop_target_top_margin">64dp</dimen>
     <dimen name="drop_target_bottom_margin">16dp</dimen>
     <dimen name="drop_target_button_drawable_horizontal_padding">16dp</dimen>
     <dimen name="drop_target_button_drawable_vertical_padding">16dp</dimen>
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 3ec211a..fad8c95 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -28,11 +28,11 @@
     <dimen name="drop_target_button_drawable_horizontal_padding">24dp</dimen>
     <dimen name="drop_target_button_drawable_vertical_padding">20dp</dimen>
     <dimen name="drop_target_button_gap">32dp</dimen>
-    <dimen name="drop_target_top_margin">32dp</dimen>
-    <dimen name="drop_target_bottom_margin">32dp</dimen>
+    <dimen name="drop_target_top_margin">110dp</dimen>
+    <dimen name="drop_target_bottom_margin">48dp</dimen>
 
 <!-- Hotseat -->
-    <dimen name="spring_loaded_hotseat_top_margin">164dp</dimen>
+    <dimen name="spring_loaded_hotseat_top_margin">108dp</dimen>
 
 <!-- Widget picker-->
     <dimen name="widget_list_horizontal_margin">30dp</dimen>
diff --git a/res/values-tr/strings.xml b/res/values-tr/strings.xml
index ae4c310..97d02d0 100644
--- a/res/values-tr/strings.xml
+++ b/res/values-tr/strings.xml
@@ -52,7 +52,7 @@
     <string name="widgets_full_sheet_work_tab" msgid="3767150027110633765">"İş"</string>
     <string name="widget_category_conversations" msgid="8894438636213590446">"Görüşmeler"</string>
     <string name="widget_education_header" msgid="4874760613775913787">"Faydalı bilgiler parmaklarınızın ucunda"</string>
-    <string name="widget_education_content" msgid="1731667670753497052">"Uygulamaları açmadan bilgi almak için ana ekranınıza widget\'lar ekleyebilirsiniz"</string>
+    <string name="widget_education_content" msgid="1731667670753497052">"Uygulama açmadan bilgi almak için ana ekranınıza widget ekleyebilirsiniz"</string>
     <string name="reconfigurable_widget_education_tip" msgid="6336962690888067057">"Widget ayarlarını değiştirmek için dokunun"</string>
     <string name="widget_education_close_button" msgid="8676165703104836580">"Anladım"</string>
     <string name="widget_reconfigure_button_content_description" msgid="8811472721881205250">"Widget ayarlarını değiştir"</string>
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 9241c45..6d39857 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -74,7 +74,6 @@
 
 import androidx.annotation.NonNull;
 import androidx.core.graphics.ColorUtils;
-import androidx.core.os.BuildCompat;
 
 import com.android.launcher3.dragndrop.FolderAdaptiveIcon;
 import com.android.launcher3.graphics.GridCustomizationsProvider;
@@ -94,6 +93,7 @@
 import com.android.launcher3.views.ActivityContext;
 import com.android.launcher3.views.BaseDragLayer;
 import com.android.launcher3.widget.PendingAddShortcutInfo;
+import com.android.modules.utils.build.SdkLevel;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -126,11 +126,11 @@
 
     public static final boolean ATLEAST_Q = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
 
-    public static final boolean ATLEAST_R = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R;
+    public static final boolean ATLEAST_R = SdkLevel.isAtLeastR();
 
-    public static final boolean ATLEAST_S = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
+    public static final boolean ATLEAST_S = SdkLevel.isAtLeastS();
 
-    public static final boolean ATLEAST_T = BuildCompat.isAtLeastT();
+    public static final boolean ATLEAST_T = SdkLevel.isAtLeastT();
 
     /**
      * Set on a motion event dispatched from the nav bar. See {@link MotionEvent#setEdgeFlags(int)}.
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index cdc313f..8662d00 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -44,6 +44,7 @@
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.statemanager.StateManager.StateHandler;
 import com.android.launcher3.states.StateAnimationConfig;
+import com.android.launcher3.util.UiThreadHelper;
 import com.android.launcher3.views.ScrimView;
 
 /**
@@ -75,6 +76,21 @@
                 }
             };
 
+    public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PULL_BACK_PROGRESS =
+            new FloatProperty<AllAppsTransitionController>("allAppsPullBackProgress") {
+
+                @Override
+                public Float get(AllAppsTransitionController controller) {
+                    return controller.mPullBackProgress;
+                }
+
+                @Override
+                public void setValue(AllAppsTransitionController controller, float progress) {
+                    controller.setPullBackProgress(progress);
+                }
+            };
+
+
     private ActivityAllAppsContainerView<Launcher> mAppsView;
 
     private final Launcher mLauncher;
@@ -88,15 +104,17 @@
     // When {@link mProgress} is 1, all apps container is pulled down.
     private float mShiftRange;      // changes depending on the orientation
     private float mProgress;        // [0, 1], mShiftRange * mProgress = shiftCurrent
+    private float mPullBackProgress;  // [0, 1], mShiftRange * mPullBackProgress = shiftCurrent
 
     private ScrimView mScrimView;
+    private View mPullBackView;
 
     public AllAppsTransitionController(Launcher l) {
         mLauncher = l;
         DeviceProfile dp = mLauncher.getDeviceProfile();
         setShiftRange(dp.allAppsShiftRange);
         mProgress = 1f;
-
+        mPullBackProgress = 1f;
         mIsVerticalLayout = dp.isVerticalBarLayout();
         mLauncher.addOnDeviceProfileChangeListener(this);
     }
@@ -114,6 +132,8 @@
             mLauncher.getHotseat().setTranslationY(0);
             mLauncher.getWorkspace().getPageIndicator().setTranslationY(0);
         }
+
+        mPullBackView = dp.isTablet ? mAppsView.getRecyclerViewContainer() : mAppsView;
     }
 
     /**
@@ -133,12 +153,19 @@
         return mProgress;
     }
 
+    private void setPullBackProgress(float progress) {
+        mPullBackProgress = progress;
+        mPullBackView.setTranslationY(mPullBackProgress * mShiftRange);
+    }
+
     /**
      * Sets the vertical transition progress to {@param state} and updates all the dependent UI
      * accordingly.
      */
     @Override
     public void setState(LauncherState state) {
+        // Always reset pull back progress when switching states.
+        setPullBackProgress(0f);
         setProgress(state.getVerticalProgress(mLauncher));
         setAlphas(state, new StateAnimationConfig(), NO_ANIM_PROPERTY_SETTER);
         onProgressAnimationEnd();
@@ -151,6 +178,12 @@
     @Override
     public void setStateWithAnimation(LauncherState toState,
             StateAnimationConfig config, PendingAnimation builder) {
+        if (NORMAL.equals(toState) && mLauncher.isInState(ALL_APPS)) {
+            UiThreadHelper.hideKeyboardAsync(mLauncher, mLauncher.getAppsView().getWindowToken());
+        }
+
+        // Always reset pull back progress when switching states.
+        setPullBackProgress(0f);
         float targetProgress = toState.getVerticalProgress(mLauncher);
         if (Float.compare(mProgress, targetProgress) == 0) {
             setAlphas(toState, config, builder);
@@ -212,6 +245,8 @@
                             | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
         }
         mAppsView.setScrimView(scrimView);
+        mPullBackView = mLauncher.getDeviceProfile().isTablet
+                ? mAppsView.getRecyclerViewContainer() : mAppsView;
     }
 
     /**