Snap for 7472272 from d352253c2da74639c18d87acffc12b41906bcb09 to sc-v2-release

Change-Id: I2fd0c32830fa188e3b24046e47343e177d8fb222
diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
index 255ba1e..7d0afe1 100644
--- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
@@ -90,12 +90,17 @@
         mHotseatController.init();
         mLauncher.setTaskbarUIController(this);
         mKeyguardController = taskbarControllers.taskbarKeyguardController;
+
         onLauncherResumedOrPaused(mLauncher.hasBeenResumed());
         mIconAlignmentForResumedState.finishAnimation();
+        onIconAlignmentRatioChanged();
     }
 
     @Override
     protected void onDestroy() {
+        mIconAlignmentForResumedState.finishAnimation();
+        mIconAlignmentForGestureState.finishAnimation();
+
         mHotseatController.cleanup();
         setTaskbarViewVisible(true);
         mLauncher.getHotseat().setIconsAlpha(1f);
diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
index d40242c..2facd44 100644
--- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java
@@ -105,7 +105,7 @@
             return true;
         };
 
-        if (mContext.canShowNavButtons()) {
+        if (mContext.isThreeButtonNav()) {
             initButtons(mStartContainer, mEndContainer, mControllers.navButtonController);
 
             // Animate taskbar background when IME shows
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
index 106ebe5..4142610 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
@@ -161,8 +161,8 @@
         mWindowManager.addView(mDragLayer, mWindowLayoutParams);
     }
 
-    public boolean canShowNavButtons() {
-        return ENABLE_THREE_BUTTON_TASKBAR && mNavMode == Mode.THREE_BUTTONS;
+    public boolean isThreeButtonNav() {
+        return mNavMode == Mode.THREE_BUTTONS;
     }
 
     @Override
@@ -215,7 +215,7 @@
     }
 
     public void updateSysuiStateFlags(int systemUiStateFlags, boolean forceUpdate) {
-        if (!canShowNavButtons()) {
+        if (!isThreeButtonNav()) {
             return;
         }
         mControllers.navbarButtonsViewController.updateStateForSysuiFlags(
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
index 157053e..c48c28b 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
@@ -61,7 +61,7 @@
      */
     public void init() {
         navbarButtonsViewController.init(this);
-        if (taskbarActivityContext.canShowNavButtons()) {
+        if (taskbarActivityContext.isThreeButtonNav()) {
             rotationButtonController.init();
         }
         taskbarDragLayerController.init(this);
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java
index 743619b..db5c387 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java
@@ -93,7 +93,7 @@
          */
         public void updateInsetsTouchability(InsetsInfo insetsInfo) {
             insetsInfo.touchableRegion.setEmpty();
-            if (mActivity.canShowNavButtons()) {
+            if (mActivity.isThreeButtonNav()) {
                 // Always have nav buttons be touchable
                 mControllers.navbarButtonsViewController.addVisibleButtonsRegion(
                         mTaskbarDragLayer, insetsInfo.touchableRegion);
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarKeyguardController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarKeyguardController.java
index b7799d8..2936bd2 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarKeyguardController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarKeyguardController.java
@@ -57,7 +57,7 @@
         mKeyguardSysuiFlags = interestingKeyguardFlags;
 
         mBouncerShowing = bouncerShowing;
-        if (!mContext.canShowNavButtons()) {
+        if (!mContext.isThreeButtonNav()) {
             // For gesture nav we don't need to deal with bouncer or showing taskbar when locked
             return;
         }
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 34a21fe..d373cf4 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -28,6 +28,7 @@
 import static com.android.launcher3.util.PackageManagerHelper.hasShortcutsPermission;
 import static com.android.launcher3.util.PackageManagerHelper.isSystemApp;
 
+import android.annotation.SuppressLint;
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.ComponentName;
 import android.content.ContentResolver;
@@ -40,6 +41,7 @@
 import android.content.pm.PackageInstaller.SessionInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ShortcutInfo;
+import android.graphics.Point;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.UserHandle;
@@ -50,6 +52,8 @@
 import android.util.LongSparseArray;
 import android.util.TimingLogger;
 
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.InvariantDeviceProfile;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel;
 import com.android.launcher3.LauncherSettings;
@@ -756,6 +760,9 @@
                                 if (widgetProviderInfo != null
                                         && (appWidgetInfo.spanX < widgetProviderInfo.minSpanX
                                         || appWidgetInfo.spanY < widgetProviderInfo.minSpanY)) {
+                                    logDeleteWidgetInfo(mApp.getInvariantDeviceProfile(),
+                                            widgetProviderInfo);
+
                                     // This can happen when display size changes.
                                     c.markDeleted("Widget removed, min sizes not met: "
                                             + "span=" + appWidgetInfo.spanX + "x"
@@ -982,6 +989,51 @@
                 && (provider.provider.getPackageName() != null);
     }
 
+    @SuppressLint("NewApi") // Already added API check.
+    private static void logDeleteWidgetInfo(InvariantDeviceProfile idp,
+            LauncherAppWidgetProviderInfo widgetProviderInfo) {
+        FileLog.d(TAG, "Deleting " + widgetProviderInfo.getComponent()
+                + " due to min size constraint");
+        Point cellSize = new Point();
+        for (DeviceProfile deviceProfile : idp.supportedProfiles) {
+            deviceProfile.getCellSize(cellSize);
+            FileLog.d(TAG, "DeviceProfile available width: " + deviceProfile.availableWidthPx
+                    + ", available height: " + deviceProfile.availableHeightPx
+                    + ", cellLayoutBorderSpacingPx: " + deviceProfile.cellLayoutBorderSpacingPx
+                    + ", cellSize: " + cellSize);
+        }
+
+        StringBuilder widgetDimension = new StringBuilder();
+        widgetDimension.append("Widget dimensions:\n")
+                .append("minResizeWidth: ")
+                .append(widgetProviderInfo.minResizeWidth)
+                .append("\n")
+                .append("minResizeHeight: ")
+                .append(widgetProviderInfo.minResizeHeight)
+                .append("\n")
+                .append("defaultWidth: ")
+                .append(widgetProviderInfo.minWidth)
+                .append("\n")
+                .append("defaultHeight: ")
+                .append(widgetProviderInfo.minHeight)
+                .append("\n");
+        if (Utilities.ATLEAST_S) {
+            widgetDimension.append("targetCellWidth: ")
+                    .append(widgetProviderInfo.targetCellWidth)
+                    .append("\n")
+                    .append("targetCellHeight: ")
+                    .append(widgetProviderInfo.targetCellHeight)
+                    .append("\n")
+                    .append("maxResizeWidth: ")
+                    .append(widgetProviderInfo.maxResizeWidth)
+                    .append("\n")
+                    .append("maxResizeHeight: ")
+                    .append(widgetProviderInfo.maxResizeHeight)
+                    .append("\n");
+        }
+        FileLog.d(TAG, widgetDimension.toString());
+    }
+
     private static void logASplit(final TimingLogger logger, final String label) {
         logger.addSplit(label);
         if (DEBUG) {
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
index 50ab422..70ed02f 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java
@@ -16,9 +16,6 @@
 
 package com.android.launcher3.widget;
 
-import static com.android.launcher3.Utilities.getBoundsForViewInDragLayer;
-import static com.android.launcher3.Utilities.setRect;
-
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.Context;
 import android.content.res.Configuration;
@@ -51,6 +48,7 @@
 import com.android.launcher3.Utilities;
 import com.android.launcher3.Workspace;
 import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.keyboard.ViewGroupFocusHelper;
 import com.android.launcher3.model.data.ItemInfo;
 import com.android.launcher3.model.data.LauncherAppWidgetInfo;
 import com.android.launcher3.util.Executors;
@@ -102,7 +100,6 @@
     private final Rect mCurrentWidgetSize = new Rect();
     private final Rect mWidgetSizeAtDrag = new Rect();
 
-    private final float[] mTmpFloatArray = new float[4];
     private final RectF mTempRectF = new RectF();
     private final Rect mEnforcedRectangle = new Rect();
     private final float mEnforcedCornerRadius;
@@ -117,6 +114,7 @@
         }
     };
     private final Object mUpdateLock = new Object();
+    private final ViewGroupFocusHelper mDragLayerRelativeCoordinateHelper;
     private long mDeferUpdatesUntilMillis = 0;
     private RemoteViews mMostRecentRemoteViews;
 
@@ -137,6 +135,7 @@
         mColorExtractor.setListener(this);
 
         mEnforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(getContext());
+        mDragLayerRelativeCoordinateHelper = new ViewGroupFocusHelper(mLauncher.getDragLayer());
     }
 
     @Override
@@ -325,15 +324,9 @@
 
         mIsScrollable = checkScrollableRecursively(this);
         if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo) {
-            mCurrentWidgetSize.left = left;
-            mCurrentWidgetSize.right = right;
-            mCurrentWidgetSize.top = top;
-            mCurrentWidgetSize.bottom = bottom;
 
             LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) getTag();
-            getBoundsForViewInDragLayer(mLauncher.getDragLayer(), (View) getParent(),
-                    mCurrentWidgetSize, true, mTmpFloatArray, mTempRectF);
-            setRect(mTempRectF, mCurrentWidgetSize);
+            mDragLayerRelativeCoordinateHelper.viewToRect(this, mCurrentWidgetSize);
             updateColorExtraction(mCurrentWidgetSize,
                     mWorkspace.getPageIndexForScreenId(info.screenId));
         }
@@ -358,7 +351,6 @@
         mIsInDragMode = false;
         mDragListener = null;
         mWidgetSizeAtDrag.setEmpty();
-        requestLayout();
     }
 
     /**
diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java
index fcc0dde..5c8ea72 100644
--- a/src/com/android/launcher3/widget/util/WidgetSizes.java
+++ b/src/com/android/launcher3/widget/util/WidgetSizes.java
@@ -99,13 +99,11 @@
      */
     public static Bundle getWidgetSizeOptions(Context context, ComponentName provider, int spanX,
             int spanY) {
-        boolean shouldInsetWidgets =
-                LauncherAppState.getIDP(context).getDeviceProfile(context).shouldInsetWidgets();
         ArrayList<SizeF> sizes = getWidgetSizes(context, spanX, spanY);
         Rect padding = getDefaultPaddingForWidget(context, provider, null);
         float density = context.getResources().getDisplayMetrics().density;
-        float xPaddingDips = shouldInsetWidgets ? (padding.left + padding.right) / density : 0;
-        float yPaddingDips = shouldInsetWidgets ? (padding.top + padding.bottom) / density : 0;
+        float xPaddingDips = (padding.left + padding.right) / density;
+        float yPaddingDips = (padding.top + padding.bottom) / density;
 
         ArrayList<SizeF> paddedSizes = sizes.stream()
                 .map(size -> new SizeF(
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index f5c1efa..96e8222 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -39,6 +39,7 @@
 import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.DeadObjectException;
 import android.os.Parcelable;
 import android.os.RemoteException;
 import android.os.SystemClock;
@@ -269,6 +270,9 @@
         try (ContentProviderClient client = getContext().getContentResolver()
                 .acquireContentProviderClient(mTestProviderUri)) {
             return client.call(request, null, null);
+        } catch (DeadObjectException e) {
+            fail("Launcher crashed");
+            return null;
         } catch (RemoteException e) {
             throw new RuntimeException(e);
         }
diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java
index 51e331d..99d9889 100644
--- a/tests/tapl/com/android/launcher3/tapl/Widgets.java
+++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java
@@ -185,8 +185,12 @@
                     targetAppSelector);
             if (headerTitle != null) {
                 // If we find the header and it has not been expanded, let's click it to see the
-                // widgets list.
-                if (!hasHeaderExpanded) {
+                // widgets list. Note that we wait until the header is out of the gesture region at
+                // the bottom of the screen, because tapping there in Launcher3 causes NexusLauncher
+                // to briefly appear to handle the gesture, which can break our test.
+                boolean isHeaderOutOfGestureRegion = headerTitle.getVisibleCenter().y
+                        < mLauncher.getBottomGestureStartOnScreen();
+                if (!hasHeaderExpanded && isHeaderOutOfGestureRegion) {
                     log("Header has not been expanded. Click to expand.");
                     hasHeaderExpanded = true;
                     mLauncher.clickLauncherObject(headerTitle);