Always insetting the widget by a minimum of 6dp

Removing default widget padding logic. Also widget padding it applied
at ShortcutAndWidgetContainer so that the widgetView always has the
correct size.

Bug: 274826296
Bug: 257589413
Test: Verified using screenshots
Flags: N/A
Change-Id: Id4b5e94db6ec7b2aa3dca87b1e9ccc831b608cac
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index bc4a5c3..7131452 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -1,7 +1,5 @@
 package com.android.launcher3;
 
-import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;
-
 import static com.android.launcher3.CellLayout.SPRING_LOADED_PROGRESS;
 import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
 import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
@@ -77,8 +75,6 @@
     private DragLayer mDragLayer;
     private ImageButton mReconfigureButton;
 
-    private Rect mWidgetPadding;
-
     private final int mBackgroundPadding;
     private final int mTouchTargetWidth;
 
@@ -218,9 +214,6 @@
         mMaxHSpan = info.maxSpanX;
         mMaxVSpan = info.maxSpanY;
 
-        mWidgetPadding = getDefaultPaddingForWidget(getContext(),
-                widgetView.getAppWidgetInfo().provider, null);
-
         // Only show resize handles for the directions in which resizing is possible.
         InvariantDeviceProfile idp = LauncherAppState.getIDP(cellLayout.getContext());
         mVerticalResizeActive = (info.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0
@@ -517,16 +510,12 @@
      */
     private void getSnappedRectRelativeToDragLayer(Rect out) {
         float scale = mWidgetView.getScaleToFit();
-
         mDragLayer.getViewRectRelativeToSelf(mWidgetView, out);
 
-        int width = 2 * mBackgroundPadding
-                + (int) (scale * (out.width() - mWidgetPadding.left - mWidgetPadding.right));
-        int height = 2 * mBackgroundPadding
-                + (int) (scale * (out.height() - mWidgetPadding.top - mWidgetPadding.bottom));
-
-        int x = (int) (out.left - mBackgroundPadding + scale * mWidgetPadding.left);
-        int y = (int) (out.top - mBackgroundPadding + scale * mWidgetPadding.top);
+        int width = 2 * mBackgroundPadding + Math.round(scale * out.width());
+        int height = 2 * mBackgroundPadding + Math.round(scale * out.height());
+        int x = out.left - mBackgroundPadding;
+        int y = out.top - mBackgroundPadding;
 
         out.left = x;
         out.top = y;
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 86c9f16..8675226 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -67,14 +67,12 @@
     private static final int DEFAULT_DOT_SIZE = 100;
     private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
     private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
+    private static final float MIN_WIDGET_PADDING_DP = 6f;
 
     public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
     public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
     public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
 
-    // Ratio of empty space, qsb should take up to appear visually centered.
-    private final float mQsbCenterFactor;
-
     public final InvariantDeviceProfile inv;
     private final Info mInfo;
     private final DisplayMetrics mMetrics;
@@ -252,6 +250,10 @@
     // Insets
     private final Rect mInsets = new Rect();
     public final Rect workspacePadding = new Rect();
+    // Additional padding added to the widget inside its cellSpace. It is applied outside
+    // the widgetView, such that the actual view size is same as the widget size.
+    public final Rect widgetPadding = new Rect();
+
     // When true, nav bar is on the left side of the screen.
     private boolean mIsSeascape;
 
@@ -314,9 +316,6 @@
         availableHeightPx = windowBounds.availableSize.y;
 
         aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
-        boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
-        mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
-
         if (isTwoPanels) {
             if (isLandscape) {
                 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
@@ -730,22 +729,6 @@
         return mInfo;
     }
 
-    /**
-     * We inset the widget padding added by the system and instead rely on the border spacing
-     * between cells to create reliable consistency between widgets
-     */
-    public boolean shouldInsetWidgets() {
-        Rect widgetPadding = inv.defaultWidgetPadding;
-
-        // Check all sides to ensure that the widget won't overlap into another cell, or into
-        // status bar.
-        return workspaceTopPadding > widgetPadding.top
-                && cellLayoutBorderSpacePx.x > widgetPadding.left
-                && cellLayoutBorderSpacePx.y > widgetPadding.top
-                && cellLayoutBorderSpacePx.x > widgetPadding.right
-                && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
-    }
-
     public Builder toBuilder(Context context) {
         WindowBounds bounds = new WindowBounds(
                 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
@@ -999,6 +982,18 @@
         // Folder icon
         folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
         folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
+
+        // Update widget padding:
+        float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
+        if (cellLayoutBorderSpacePx.x < minSpacing
+                || cellLayoutBorderSpacePx.y < minSpacing) {
+            widgetPadding.left = widgetPadding.right =
+                    Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
+            widgetPadding.top = widgetPadding.bottom =
+                    Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
+        } else {
+            widgetPadding.setEmpty();
+        }
     }
 
     /**
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 5e07a3c..3aa582d 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -26,8 +26,6 @@
 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
 
 import android.annotation.TargetApi;
-import android.appwidget.AppWidgetHostView;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
@@ -35,7 +33,6 @@
 import android.content.res.XmlResourceParser;
 import android.graphics.Point;
 import android.graphics.PointF;
-import android.graphics.Rect;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
@@ -192,7 +189,6 @@
     public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
 
     public Point defaultWallpaperSize;
-    public Rect defaultWidgetPadding;
 
     private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
 
@@ -443,9 +439,6 @@
                     deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
                     deviceProfile.recalculateHotseatWidthAndBorderSpace();
                 });
-
-        ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
-        defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
     }
 
     public void addOnChangeListener(OnIDPChangeListener listener) {
diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
index b00199f..a0ceefb 100644
--- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java
+++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
@@ -46,8 +46,6 @@
     // return an (x, y) value from helper functions. Do NOT use them to maintain other state.
     private final int[] mTmpCellXY = new int[2];
 
-    private final Rect mTempRect = new Rect();
-
     @ContainerType
     private final int mContainerType;
     private final WallpaperManager mWallpaperManager;
@@ -124,13 +122,12 @@
         CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
         if (child instanceof NavigableAppWidgetHostView) {
             DeviceProfile profile = mActivity.getDeviceProfile();
-            ((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
             final PointF appWidgetScale = profile.getAppWidgetScale((ItemInfo) child.getTag());
             lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
-                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect);
+                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, profile.widgetPadding);
         } else {
             lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
-                    mBorderSpace, null);
+                    mBorderSpace);
         }
     }
 
@@ -149,13 +146,12 @@
         final DeviceProfile dp = mActivity.getDeviceProfile();
 
         if (child instanceof NavigableAppWidgetHostView) {
-            ((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
             final PointF appWidgetScale = dp.getAppWidgetScale((ItemInfo) child.getTag());
             lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
-                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect);
+                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, dp.widgetPadding);
         } else {
             lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
-                    mBorderSpace, null);
+                    mBorderSpace);
             // Center the icon/folder
             int cHeight = getCellContentHeight();
             int cellPaddingY = dp.isScalableGrid && mContainerType == WORKSPACE
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 6e6f1ac..98016f6 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2912,9 +2912,8 @@
         Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY);
         if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
             DeviceProfile profile = mLauncher.getDeviceProfile();
-            if (profile.shouldInsetWidgets() && finalView instanceof NavigableAppWidgetHostView) {
-                Rect widgetPadding = new Rect();
-                ((NavigableAppWidgetHostView) finalView).getWidgetInset(profile, widgetPadding);
+            if (finalView instanceof NavigableAppWidgetHostView) {
+                Rect widgetPadding = profile.widgetPadding;
                 r.left -= widgetPadding.left;
                 r.right += widgetPadding.right;
                 r.top -= widgetPadding.top;
diff --git a/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java b/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
index 4b6a062..bdf7643 100644
--- a/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
+++ b/src/com/android/launcher3/celllayout/CellLayoutLayoutParams.java
@@ -113,13 +113,13 @@
      * full/invariant device profile sizes.
      */
     public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
-            int rowCount, Point borderSpace, @Nullable Rect inset) {
+            int rowCount, Point borderSpace) {
         setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f,
-                borderSpace, inset);
+                borderSpace, null);
     }
 
     /**
-     * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point, Rect)},
+     * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, Point)},
      * if the view needs to be scaled.
      *
      * ie. In multi-window mode, we setup widgets so that they are measured and laid out
@@ -150,10 +150,10 @@
             y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpace.y);
 
             if (inset != null) {
-                x -= inset.left;
-                y -= inset.top;
-                width += inset.left + inset.right;
-                height += inset.top + inset.bottom;
+                x += inset.left;
+                y += inset.top;
+                width -= inset.left + inset.right;
+                height -= inset.top + inset.bottom;
             }
         }
     }
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index 7f49aa9..b438e86 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -451,26 +451,8 @@
         final Size origSize = WidgetSizes.getWidgetSizePx(mDpOrig,
                 launcherWidgetSize.getWidth(), launcherWidgetSize.getHeight());
         final Size newSize = WidgetSizes.getWidgetSizePx(mDp, info.spanX, info.spanY);
-        final Rect previewInset = new Rect();
-        final Rect origInset = new Rect();
-        // When the setup() is called for the LayoutParams, insets are added to the width
-        // and height of the view. This is not accounted for in WidgetSizes and is handled
-        // here.
-        if (mDp.shouldInsetWidgets()) {
-            previewInset.set(mDp.inv.defaultWidgetPadding);
-        } else {
-            previewInset.setEmpty();
-        }
-        if (mDpOrig.shouldInsetWidgets()) {
-            origInset.set(mDpOrig.inv.defaultWidgetPadding);
-        } else {
-            origInset.setEmpty();
-        }
-
-        return new PointF((float) newSize.getWidth() / (origSize.getWidth()
-                + origInset.left + origInset.right),
-                (float) newSize.getHeight() / (origSize.getHeight()
-                + origInset.top + origInset.bottom));
+        return new PointF((float) newSize.getWidth() / origSize.getWidth(),
+                (float) newSize.getHeight() / origSize.getHeight());
     }
 
     private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) {
diff --git a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
index 7030f6d..6f74fd9 100644
--- a/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
+++ b/src/com/android/launcher3/widget/DatabaseWidgetPreviewLoader.java
@@ -146,8 +146,7 @@
             previewWidth = drawable.getIntrinsicWidth();
             previewHeight = drawable.getIntrinsicHeight();
         } else {
-            Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX,
-                    spanY);
+            Size widgetSize = WidgetSizes.getWidgetSizePx(dp, spanX, spanY);
             previewWidth = widgetSize.getWidth();
             previewHeight = widgetSize.getHeight();
         }
diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
index bba1016..10aef9a 100644
--- a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java
@@ -2,7 +2,6 @@
 
 import static com.android.launcher3.Utilities.ATLEAST_S;
 
-import android.appwidget.AppWidgetHostView;
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.ComponentName;
 import android.content.Context;
@@ -105,44 +104,35 @@
         int spanX = 0;
         int spanY = 0;
 
-        Rect widgetPadding = new Rect();
-        Rect localPadding = new Rect();
-        AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding);
 
         Point cellSize = new Point();
         for (DeviceProfile dp : idp.supportedProfiles) {
             dp.getCellSize(cellSize);
-            // We want to account for the extra amount of padding that we are adding to the widget
-            // to ensure that it gets the full amount of space that it has requested.
-            // If grids supports insetting widgets, we do not account for widget padding.
-            if (dp.shouldInsetWidgets()) {
-                localPadding.setEmpty();
-            } else {
-                localPadding.set(widgetPadding);
-            }
+            Rect widgetPadding = dp.widgetPadding;
+
             minSpanX = Math.max(minSpanX,
-                    getSpanX(localPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x,
+                    getSpanX(widgetPadding, minResizeWidth, dp.cellLayoutBorderSpacePx.x,
                             cellSize.x));
             minSpanY = Math.max(minSpanY,
-                    getSpanY(localPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y,
+                    getSpanY(widgetPadding, minResizeHeight, dp.cellLayoutBorderSpacePx.y,
                             cellSize.y));
 
             if (ATLEAST_S) {
                 if (maxResizeWidth > 0) {
-                    maxSpanX = Math.min(maxSpanX, getSpanX(localPadding, maxResizeWidth,
+                    maxSpanX = Math.min(maxSpanX, getSpanX(widgetPadding, maxResizeWidth,
                             dp.cellLayoutBorderSpacePx.x, cellSize.x));
                 }
                 if (maxResizeHeight > 0) {
-                    maxSpanY = Math.min(maxSpanY, getSpanY(localPadding, maxResizeHeight,
+                    maxSpanY = Math.min(maxSpanY, getSpanY(widgetPadding, maxResizeHeight,
                             dp.cellLayoutBorderSpacePx.y, cellSize.y));
                 }
             }
 
             spanX = Math.max(spanX,
-                    getSpanX(localPadding, minWidth, dp.cellLayoutBorderSpacePx.x,
+                    getSpanX(widgetPadding, minWidth, dp.cellLayoutBorderSpacePx.x,
                             cellSize.x));
             spanY = Math.max(spanY,
-                    getSpanY(localPadding, minHeight, dp.cellLayoutBorderSpacePx.y,
+                    getSpanY(widgetPadding, minHeight, dp.cellLayoutBorderSpacePx.y,
                             cellSize.y));
         }
 
@@ -184,15 +174,22 @@
     }
 
     private int getSpanX(Rect widgetPadding, int widgetWidth, int cellSpacing, float cellWidth) {
-        return Math.max(1, (int) Math.ceil(
-                (widgetWidth + widgetPadding.left + widgetPadding.right + cellSpacing) / (cellWidth
-                        + cellSpacing)));
+        return getSpan(widgetPadding.left + widgetPadding.right,
+                widgetWidth, cellSpacing, cellWidth);
     }
 
     private int getSpanY(Rect widgetPadding, int widgetHeight, int cellSpacing, float cellHeight) {
+        return getSpan(widgetPadding.top + widgetPadding.bottom, widgetHeight,
+                cellSpacing, cellHeight);
+    }
+
+    /**
+     * Solving the equation:
+     *   n * cellSize + (n - 1) * cellSpacing - widgetPadding = widgetSize
+     */
+    private int getSpan(int widgetPadding, int widgetSize, int cellSpacing, float cellSize) {
         return Math.max(1, (int) Math.ceil(
-                (widgetHeight + widgetPadding.top + widgetPadding.bottom + cellSpacing) / (
-                        cellHeight + cellSpacing)));
+                (widgetSize + widgetPadding + cellSpacing) / (cellSize + cellSpacing)));
     }
 
     public String getLabel(PackageManager packageManager) {
diff --git a/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java b/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
index 3389fb1..f46b214 100644
--- a/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
+++ b/src/com/android/launcher3/widget/NavigableAppWidgetHostView.java
@@ -25,7 +25,6 @@
 import android.view.ViewDebug;
 import android.view.ViewGroup;
 
-import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Reorderable;
 import com.android.launcher3.dragndrop.DraggableView;
 import com.android.launcher3.util.MultiTranslateDelegate;
@@ -48,13 +47,13 @@
 
     private float mScaleForReorderBounce = 1f;
 
-    private final Rect mTempRect = new Rect();
-
     @ViewDebug.ExportedProperty(category = "launcher")
     private boolean mChildrenFocused;
 
     protected final ActivityContext mActivity;
 
+    private boolean mDisableSetPadding = false;
+
     public NavigableAppWidgetHostView(Context context) {
         super(context);
         mActivity = ActivityContext.lookupContext(context);
@@ -147,6 +146,22 @@
     }
 
     @Override
+    public void setAppWidget(int appWidgetId, AppWidgetProviderInfo info) {
+        // Prevent default padding being set on the view based on provider info. Launcher manages
+        // its own widget spacing
+        mDisableSetPadding = true;
+        super.setAppWidget(appWidgetId, info);
+        mDisableSetPadding = false;
+    }
+
+    @Override
+    public void setPadding(int left, int top, int right, int bottom) {
+        if (!mDisableSetPadding) {
+            super.setPadding(left, top, right, bottom);
+        }
+    }
+
+    @Override
     public boolean dispatchUnhandledMove(View focused, int direction) {
         return mChildrenFocused;
     }
@@ -195,26 +210,6 @@
     public void getWorkspaceVisualDragBounds(Rect bounds) {
         int width = (int) (getMeasuredWidth() * mScaleToFit);
         int height = (int) (getMeasuredHeight() * mScaleToFit);
-
-        getWidgetInset(mActivity.getDeviceProfile(), mTempRect);
-        bounds.set(mTempRect.left, mTempRect.top, width - mTempRect.right,
-                height - mTempRect.bottom);
-    }
-
-    /**
-     * Widgets have padding added by the system. We may choose to inset this padding if the grid
-     * supports it.
-     */
-    public void getWidgetInset(DeviceProfile grid, Rect out) {
-        if (!grid.shouldInsetWidgets()) {
-            out.setEmpty();
-            return;
-        }
-        AppWidgetProviderInfo info = getAppWidgetInfo();
-        if (info == null) {
-            out.set(grid.inv.defaultWidgetPadding);
-        } else {
-            AppWidgetHostView.getDefaultPaddingForWidget(getContext(), info.provider, out);
-        }
+        bounds.set(0, 0, width, height);
     }
 }
diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java
index 410a555..67d21f7 100644
--- a/src/com/android/launcher3/widget/PendingItemDragHelper.java
+++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java
@@ -16,6 +16,8 @@
 
 package com.android.launcher3.widget;
 
+import static com.android.launcher3.widget.util.WidgetSizes.getWidgetSizePx;
+
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
@@ -43,7 +45,6 @@
 import com.android.launcher3.icons.LauncherIcons;
 import com.android.launcher3.icons.RoundDrawableWrapper;
 import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener;
-import com.android.launcher3.widget.util.WidgetSizes;
 
 /**
  * Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts
@@ -121,13 +122,8 @@
                 mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */ -1,
                         ((PendingAddWidgetInfo) mAddInfo).info);
                 DeviceProfile deviceProfile = launcher.getDeviceProfile();
-                Rect padding = new Rect();
-                mAppWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
-                mAppWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right,
-                        padding.bottom);
                 mAppWidgetHostViewPreview.updateAppWidget(/* remoteViews= */ mRemoteViewsPreview);
-                Size widgetSizes = WidgetSizes.getWidgetPaddedSizePx(launcher,
-                        mAddInfo.componentName, deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
+                Size widgetSizes = getWidgetSizePx(deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
                 mAppWidgetHostViewPreview.measure(
                         MeasureSpec.makeMeasureSpec(widgetSizes.getWidth(), MeasureSpec.EXACTLY),
                         MeasureSpec.makeMeasureSpec(widgetSizes.getHeight(), MeasureSpec.EXACTLY));
diff --git a/src/com/android/launcher3/widget/util/WidgetSizes.java b/src/com/android/launcher3/widget/util/WidgetSizes.java
index 601c1b5..7049509 100644
--- a/src/com/android/launcher3/widget/util/WidgetSizes.java
+++ b/src/com/android/launcher3/widget/util/WidgetSizes.java
@@ -15,8 +15,6 @@
  */
 package com.android.launcher3.widget.util;
 
-import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;
-
 import android.appwidget.AppWidgetHostView;
 import android.appwidget.AppWidgetManager;
 import android.content.ComponentName;
@@ -28,8 +26,6 @@
 import android.util.Size;
 import android.util.SizeF;
 
-import androidx.annotation.Nullable;
-
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.R;
@@ -43,24 +39,13 @@
 
     /**
      * Returns the list of all possible sizes, in dp, for a widget of given spans on this device.
-     *
-     * <p>The returned sizes already take into account the system padding, and whether it is applied
-     * or not in that specific configuration.
      */
-    public static ArrayList<SizeF> getWidgetPaddedSizes(Context context, ComponentName provider,
-            int spanX, int spanY) {
-        Rect padding = getDefaultPaddingForWidget(context, provider, /* padding= */ null);
-
+    public static ArrayList<SizeF> getWidgetSizesDp(Context context, int spanX, int spanY) {
         ArrayList<SizeF> sizes = new ArrayList<>(2);
         final float density = context.getResources().getDisplayMetrics().density;
-        final Point cellSize = new Point();
 
         for (DeviceProfile profile : LauncherAppState.getIDP(context).supportedProfiles) {
-            Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY, cellSize);
-            if (!profile.shouldInsetWidgets()) {
-                widgetSizePx = new Size(widgetSizePx.getWidth() - padding.left - padding.right,
-                        widgetSizePx.getHeight() - padding.top - padding.bottom);
-            }
+            Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY);
             sizes.add(new SizeF(widgetSizePx.getWidth() / density,
                     widgetSizePx.getHeight() / density));
         }
@@ -69,21 +54,15 @@
 
     /** Returns the size, in pixels, a widget of given spans & {@code profile}. */
     public static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY) {
-        return getWidgetSizePx(profile, spanX, spanY, /* recycledCellSize= */ null);
-    }
+        final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacePx.x;
+        final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacePx.y;
 
-    /**
-     * Returns the size, in pixels and removing padding, a widget of given spans & {@code profile}.
-     */
-    public static Size getWidgetPaddedSizePx(Context context, ComponentName component,
-            DeviceProfile profile, int spanX, int spanY) {
-        Size size = getWidgetSizePx(profile, spanX, spanY);
-        if (profile.shouldInsetWidgets()) {
-            return size;
-        }
-        Rect padding = getDefaultPaddingForWidget(context, component, /* padding= */ null);
-        return new Size(size.getWidth() - padding.left - padding.right,
-                size.getHeight() - padding.top - padding.bottom);
+        Point cellSize = profile.getCellSize();
+        Rect padding = profile.widgetPadding;
+
+        return new Size(
+                (spanX * cellSize.x) + hBorderSpacing - padding.left - padding.right,
+                (spanY * cellSize.y) + vBorderSpacing - padding.top - padding.bottom);
     }
 
     /**
@@ -92,8 +71,7 @@
      * <p>This size is used by the widget picker. It should NEVER be shared with app widgets.
      *
      * <p>For sizes shared with app widgets, please refer to
-     * {@link #getWidgetPaddedSizes(Context, ComponentName, int, int)} &
-     * {@link #getWidgetPaddedSizePx(Context, ComponentName, DeviceProfile, int, int)}.
+     * {@link #getWidgetSizesDp(Context, int, int)} &
      */
     public static Size getWidgetItemSizePx(Context context, DeviceProfile profile,
             WidgetItem widgetItem) {
@@ -102,27 +80,7 @@
                     .getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
             return new Size(dimension, dimension);
         }
-        Size widgetItemSize = getWidgetSizePx(profile, widgetItem.spanX,
-                widgetItem.spanY, /* recycledCellSize= */ null);
-        if (profile.shouldInsetWidgets()) {
-            Rect inset = new Rect();
-            AppWidgetHostView.getDefaultPaddingForWidget(context, widgetItem.componentName, inset);
-            return new Size(widgetItemSize.getWidth() + inset.left + inset.right,
-                    widgetItemSize.getHeight() + inset.top + inset.bottom);
-        }
-        return widgetItemSize;
-    }
-
-    private static Size getWidgetSizePx(DeviceProfile profile, int spanX, int spanY,
-            @Nullable Point recycledCellSize) {
-        final int hBorderSpacing = (spanX - 1) * profile.cellLayoutBorderSpacePx.x;
-        final int vBorderSpacing = (spanY - 1) * profile.cellLayoutBorderSpacePx.y;
-        if (recycledCellSize == null) {
-            recycledCellSize = new Point();
-        }
-        profile.getCellSize(recycledCellSize);
-        return new Size(((spanX * recycledCellSize.x) + hBorderSpacing),
-                ((spanY * recycledCellSize.y) + vBorderSpacing));
+        return getWidgetSizePx(profile, widgetItem.spanX, widgetItem.spanY);
     }
 
     /**
@@ -154,7 +112,7 @@
      */
     public static Bundle getWidgetSizeOptions(Context context, ComponentName provider, int spanX,
             int spanY) {
-        ArrayList<SizeF> paddedSizes = getWidgetPaddedSizes(context, provider, spanX, spanY);
+        ArrayList<SizeF> paddedSizes = getWidgetSizesDp(context, spanX, spanY);
 
         Rect rect = getMinMaxSizes(paddedSizes);
         Bundle options = new Bundle();