Snap for 7806961 from 4e9a3d5bdf09739bf78701dda347eb1daf614d36 to sc-v2-release

Change-Id: If6ac2d464732d2852bdccc57f20eb248484b9b15
diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
index 68dfac7..6bc49ed 100644
--- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
@@ -16,8 +16,6 @@
 package com.android.launcher3.taskbar;
 
 import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
-import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_HIDE;
-import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_SHOW;
 import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_APP;
 import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_STASHED_LAUNCHER_STATE;
 import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME;
@@ -52,7 +50,6 @@
 import com.android.quickstep.RecentsAnimationCallbacks;
 import com.android.quickstep.RecentsAnimationCallbacks.RecentsAnimationListener;
 import com.android.quickstep.RecentsAnimationController;
-import com.android.quickstep.SystemUiProxy;
 import com.android.quickstep.views.RecentsView;
 import com.android.systemui.shared.recents.model.ThumbnailData;
 
@@ -187,8 +184,6 @@
         TaskbarStashController stashController = mControllers.taskbarStashController;
         stashController.updateStateForFlag(FLAG_IN_APP, !isResumed);
         stashController.applyState(duration);
-        SystemUiProxy.INSTANCE.get(mContext).notifyTaskbarStatus(!isResumed,
-                mControllers.taskbarStashController.isStashedInApp());
     }
 
     /**
@@ -286,11 +281,6 @@
     @Override
     protected void onStashedInAppChanged() {
         onStashedInAppChanged(mLauncher.getDeviceProfile());
-        if (mControllers.taskbarStashController.isStashedInApp()) {
-            mContext.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_HIDE);
-        } else {
-            mContext.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_SHOW);
-        }
     }
 
     private void onStashedInAppChanged(DeviceProfile deviceProfile) {
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
index 0316333..ad0243c 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
@@ -321,6 +321,7 @@
         mControllers.taskbarViewController.setRecentsButtonDisabled(
                 mControllers.navbarButtonsViewController.isRecentsDisabled());
         mControllers.taskbarKeyguardController.updateStateForSysuiFlags(systemUiStateFlags);
+        mControllers.taskbarStashController.updateStateForSysuiFlags(systemUiStateFlags);
     }
 
     public void onRotationProposal(int rotation, boolean isValid) {
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java
index fc5abd0..5e76b96 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java
@@ -45,6 +45,9 @@
     private final TaskbarActivityContext mContext;
     private final TaskbarView mContainer;
 
+    // Initialized in init.
+    private TaskbarControllers mControllers;
+
     private boolean mBindInProgress = false;
 
     public TaskbarModelCallbacks(
@@ -53,6 +56,10 @@
         mContainer = container;
     }
 
+    public void init(TaskbarControllers controllers) {
+        mControllers = controllers;
+    }
+
     @Override
     public void startBinding() {
         mBindInProgress = true;
@@ -161,6 +168,7 @@
         int predictionSize = mPredictedItems.size();
         int predictionNextIndex = 0;
 
+        boolean isHotseatEmpty = true;
         for (int i = 0; i < hotseatItemInfos.length; i++) {
             hotseatItemInfos[i] = mHotseatItems.get(i);
             if (hotseatItemInfos[i] == null && predictionNextIndex < predictionSize) {
@@ -168,7 +176,14 @@
                 hotseatItemInfos[i].screenId = i;
                 predictionNextIndex++;
             }
+            if (hotseatItemInfos[i] != null) {
+                isHotseatEmpty = false;
+            }
         }
         mContainer.updateHotseatItems(hotseatItemInfos);
+
+        mControllers.taskbarStashController.updateStateForFlag(
+                TaskbarStashController.FLAG_STASHED_IN_APP_EMPTY, isHotseatEmpty);
+        mControllers.taskbarStashController.applyState();
     }
 }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
index 02170ab..6d6f0f2 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
@@ -17,6 +17,10 @@
 
 import static android.view.HapticFeedbackConstants.LONG_PRESS;
 
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_HIDE;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_SHOW;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
+
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
@@ -40,8 +44,14 @@
 public class TaskbarStashController {
 
     public static final int FLAG_IN_APP = 1 << 0;
-    public static final int FLAG_STASHED_IN_APP = 1 << 1;
-    public static final int FLAG_IN_STASHED_LAUNCHER_STATE = 1 << 2;
+    public static final int FLAG_STASHED_IN_APP_MANUAL = 1 << 1; // long press, persisted
+    public static final int FLAG_STASHED_IN_APP_PINNED = 1 << 2; // app pinning
+    public static final int FLAG_STASHED_IN_APP_EMPTY = 1 << 3; // no hotseat icons
+    public static final int FLAG_IN_STASHED_LAUNCHER_STATE = 1 << 4;
+
+    // If we're in an app and any of these flags are enabled, taskbar should be stashed.
+    public static final int FLAGS_STASHED_IN_APP = FLAG_STASHED_IN_APP_MANUAL
+            | FLAG_STASHED_IN_APP_PINNED | FLAG_STASHED_IN_APP_EMPTY;
 
     /**
      * How long to stash/unstash when manually invoked via long press.
@@ -96,8 +106,6 @@
     private AnimatedFloat mTaskbarStashedHandleAlpha;
     private AnimatedFloat mTaskbarStashedHandleHintScale;
 
-    /** Whether the user has manually invoked taskbar stashing, which we persist. */
-    private boolean mIsStashedInApp;
     /** Whether we are currently visually stashed (might change based on launcher state). */
     private boolean mIsStashed = false;
     private int mState;
@@ -107,12 +115,9 @@
     // Evaluate whether the handle should be stashed
     private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder(
             flags -> {
-                if (!supportsVisualStashing()) {
-                    return false;
-                }
-                boolean inApp = (flags & FLAG_IN_APP) != 0;
-                boolean stashedInApp = (flags & FLAG_STASHED_IN_APP) != 0;
-                boolean stashedLauncherState = (flags & FLAG_IN_STASHED_LAUNCHER_STATE) != 0;
+                boolean inApp = hasAnyFlag(flags, FLAG_IN_APP);
+                boolean stashedInApp = hasAnyFlag(flags, FLAGS_STASHED_IN_APP);
+                boolean stashedLauncherState = hasAnyFlag(flags, FLAG_IN_STASHED_LAUNCHER_STATE);
                 return (inApp && stashedInApp) || (!inApp && stashedLauncherState);
             });
 
@@ -141,12 +146,13 @@
         mTaskbarStashedHandleAlpha = stashedHandleController.getStashedHandleAlpha();
         mTaskbarStashedHandleHintScale = stashedHandleController.getStashedHandleHintScale();
 
-        mIsStashedInApp = supportsManualStashing()
+        boolean isManuallyStashedInApp = supportsManualStashing()
                 && mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
-        updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
+        updateStateForFlag(FLAG_STASHED_IN_APP_MANUAL, isManuallyStashedInApp);
+        applyState();
 
         SystemUiProxy.INSTANCE.get(mActivity)
-                .notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
+                .notifyTaskbarStatus(/* visible */ false, /* stashed */ isStashedInApp());
     }
 
     /**
@@ -178,10 +184,18 @@
     }
 
     /**
-     * Returns whether the user has manually stashed the taskbar in apps.
+     * Returns whether the taskbar should be stashed in apps (e.g. user long pressed to stash).
      */
     public boolean isStashedInApp() {
-        return mIsStashedInApp;
+        return hasAnyFlag(FLAGS_STASHED_IN_APP);
+    }
+
+    private boolean hasAnyFlag(int flagMask) {
+        return hasAnyFlag(mState, flagMask);
+    }
+
+    private boolean hasAnyFlag(int flags, int flagMask) {
+        return (flags & flagMask) != 0;
     }
 
     public int getContentHeight() {
@@ -202,7 +216,7 @@
             // taskbar, we use an OnLongClickListener on TaskbarView instead.
             return false;
         }
-        if (updateAndAnimateIsStashedInApp(false)) {
+        if (updateAndAnimateIsManuallyStashedInApp(false)) {
             mControllers.taskbarActivityContext.getDragLayer().performHapticFeedback(LONG_PRESS);
             return true;
         }
@@ -213,25 +227,32 @@
      * Updates whether we should stash the taskbar when in apps, and animates to the changed state.
      * @return Whether we started an animation to either be newly stashed or unstashed.
      */
-    public boolean updateAndAnimateIsStashedInApp(boolean isStashedInApp) {
+    public boolean updateAndAnimateIsManuallyStashedInApp(boolean isManuallyStashedInApp) {
         if (!supportsManualStashing()) {
             return false;
         }
-        if (mIsStashedInApp != isStashedInApp) {
-            mIsStashedInApp = isStashedInApp;
-            mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, mIsStashedInApp).apply();
-            updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
+        if (hasAnyFlag(FLAG_STASHED_IN_APP_MANUAL) != isManuallyStashedInApp) {
+            mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, isManuallyStashedInApp).apply();
+            updateStateForFlag(FLAG_STASHED_IN_APP_MANUAL, isManuallyStashedInApp);
             applyState();
-
-            SystemUiProxy.INSTANCE.get(mActivity)
-                    .notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
-            mControllers.uiController.onStashedInAppChanged();
             return true;
         }
         return false;
     }
 
     private Animator createAnimToIsStashed(boolean isStashed, long duration) {
+        if (mAnimator != null) {
+            mAnimator.cancel();
+        }
+        mAnimator = new AnimatorSet();
+
+        if (!supportsVisualStashing()) {
+            // Just hide/show the icons instead of stashing into a handle.
+            mAnimator.play(mIconAlphaForStash.animateToValue(isStashed ? 0 : 1)
+                    .setDuration(duration));
+            return mAnimator;
+        }
+
         AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
         // Not exactly half and may overlap. See [first|second]HalfDurationScale below.
         AnimatorSet firstHalfAnimatorSet = new AnimatorSet();
@@ -287,10 +308,6 @@
         secondHalfAnimatorSet.setDuration((long) (duration * secondHalfDurationScale));
         secondHalfAnimatorSet.setStartDelay((long) (duration * (1 - secondHalfDurationScale)));
 
-        if (mAnimator != null) {
-            mAnimator.cancel();
-        }
-        mAnimator = new AnimatorSet();
         mAnimator.playTogether(fullLengthAnimatorSet, firstHalfAnimatorSet,
                 secondHalfAnimatorSet);
         mAnimator.addListener(new AnimatorListenerAdapter() {
@@ -360,6 +377,13 @@
         return mStatePropertyHolder.setState(mState, duration, false);
     }
 
+    /** Called when some system ui state has changed. (See SYSUI_STATE_... in QuickstepContract) */
+    public void updateStateForSysuiFlags(int systemUiStateFlags) {
+        updateStateForFlag(FLAG_STASHED_IN_APP_PINNED,
+                hasAnyFlag(systemUiStateFlags, SYSUI_STATE_SCREEN_PINNING));
+        applyState();
+    }
+
     /**
      * Updates the proper flag to indicate whether the task bar should be stashed.
      *
@@ -377,16 +401,44 @@
         }
     }
 
+    /**
+     * Called after updateStateForFlag() and applyState() have been called.
+     * @param changedFlags The flags that have changed.
+     */
+    private void onStateChangeApplied(int changedFlags) {
+        if (hasAnyFlag(changedFlags, FLAGS_STASHED_IN_APP)) {
+            mControllers.uiController.onStashedInAppChanged();
+        }
+        if (hasAnyFlag(changedFlags, FLAGS_STASHED_IN_APP | FLAG_IN_APP)) {
+            SystemUiProxy.INSTANCE.get(mActivity)
+                    .notifyTaskbarStatus(/* visible */ hasAnyFlag(FLAG_IN_APP),
+                            /* stashed */ isStashedInApp());
+        }
+        if (hasAnyFlag(changedFlags, FLAG_STASHED_IN_APP_MANUAL)) {
+            if (hasAnyFlag(FLAG_STASHED_IN_APP_MANUAL)) {
+                mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_HIDE);
+            } else {
+                mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_SHOW);
+            }
+        }
+    }
+
     private class StatePropertyHolder {
         private final IntPredicate mStashCondition;
 
         private boolean mIsStashed;
+        private int mPrevFlags;
 
         StatePropertyHolder(IntPredicate stashCondition) {
             mStashCondition = stashCondition;
         }
 
         public Animator setState(int flags, long duration, boolean start) {
+            if (mPrevFlags != flags) {
+                int changedFlags = mPrevFlags ^ flags;
+                onStateChangeApplied(changedFlags);
+                mPrevFlags = flags;
+            }
             boolean isStashed = mStashCondition.test(flags);
             if (mIsStashed != isStashed) {
                 mIsStashed = isStashed;
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java
index 4cd6814..ed09fa5 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java
@@ -85,6 +85,8 @@
         mTaskbarView.getLayoutParams().height = mActivity.getDeviceProfile().taskbarSize;
 
         mTaskbarIconScaleForStash.updateValue(1f);
+
+        mModelCallbacks.init(controllers);
         LauncherAppState.getInstance(mActivity).getModel().addCallbacksAndLoad(mModelCallbacks);
     }
 
@@ -254,7 +256,8 @@
         }
 
         public View.OnLongClickListener getBackgroundOnLongClickListener() {
-            return view -> mControllers.taskbarStashController.updateAndAnimateIsStashedInApp(true);
+            return view -> mControllers.taskbarStashController
+                    .updateAndAnimateIsManuallyStashedInApp(true);
         }
 
         /**
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 319c87d..ef6291e 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -184,11 +184,9 @@
         <attr name="twoPanelPortraitMinCellHeightDps" format="float" />
         <!-- twoPanelPortraitMinCellHeightDps defaults to minCellWidthDps, if not specified -->
         <attr name="twoPanelPortraitMinCellWidthDps" format="float" />
-        <!-- twoPanelLandscapeMinCellHeightDps defaults to twoPanelPortraitMinCellHeightDps,
-        if not specified -->
+        <!-- twoPanelLandscapeMinCellHeightDps defaults to minCellHeightDps, if not specified -->
         <attr name="twoPanelLandscapeMinCellHeightDps" format="float" />
-        <!-- twoPanelLandscapeMinCellWidthDps defaults to twoPanelPortraitMinCellWidthDps,
-        if not specified -->
+        <!-- twoPanelLandscapeMinCellWidthDps defaults to minCellWidthDps, if not specified -->
         <attr name="twoPanelLandscapeMinCellWidthDps" format="float" />
 
         <!-- These border spaces are only used if GridDisplayOption#isScalable is true -->
@@ -217,15 +215,20 @@
         if not specified -->
         <attr name="twoPanelLandscapeBorderSpaceVerticalDps" format="float" />
 
-
+        <!-- allAppsCellSpacingDps defaults to borderSpaceDps, if not specified -->
         <attr name="allAppsCellSpacingDps" format="float" />
+        <!-- The following values are only enabled if grid is supported. -->
+        <!-- allAppsIconSize defaults to iconSize, if not specified -->
+        <attr name="allAppsIconSize" format="float" />
+        <!-- allAppsIconTextSize defaults to iconTextSize, if not specified -->
+        <attr name="allAppsIconTextSize" format="float" />
 
         <attr name="iconImageSize" format="float" />
         <!-- landscapeIconSize defaults to iconImageSize, if not specified -->
         <attr name="landscapeIconSize" format="float" />
         <!-- twoPanelPortraitIconSize defaults to iconImageSize, if not specified -->
         <attr name="twoPanelPortraitIconSize" format="float" />
-        <!-- twoPanelLandscapeIconSize defaults to landscapeIconSize, if not specified -->
+        <!-- twoPanelLandscapeIconSize defaults to iconImageSize, if not specified -->
         <attr name="twoPanelLandscapeIconSize" format="float" />
 
         <attr name="iconTextSize" format="float" />
@@ -233,7 +236,7 @@
         <attr name="landscapeIconTextSize" format="float" />
         <!-- twoPanelPortraitIconTextSize defaults to iconTextSize, if not specified -->
         <attr name="twoPanelPortraitIconTextSize" format="float" />
-        <!-- twoPanelLandscapeIconTextSize defaults to landscapeIconTextSize, if not specified -->
+        <!-- twoPanelLandscapeIconTextSize defaults to iconTextSize, if not specified -->
         <attr name="twoPanelLandscapeIconTextSize" format="float" />
 
         <!-- If set, this display option is used to determine the default grid -->
@@ -242,12 +245,6 @@
             <flag name="split_display" value="0x2" />
         </attr>
 
-        <!-- The following values are only enabled if grid is supported. -->
-        <!-- allAppsIconSize defaults to iconSize, if not specified -->
-        <attr name="allAppsIconSize" format="float" />
-        <!-- allAppsIconTextSize defaults to iconTextSize, if not specified -->
-        <attr name="allAppsIconTextSize" format="float" />
-
         <!-- Margin on left and right of the workspace when GridDisplayOption#isScalable is true -->
         <attr name="horizontalMargin" format="float"/>
         <!-- twoPanelLandscapeHorizontalMargin defaults to horizontalMargin if not specified -->
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 4e06ff9..0b60b32 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -80,6 +80,7 @@
     public final float aspectRatio;
 
     public final boolean isScalableGrid;
+    private final int mTypeIndex;
 
     /**
      * The maximum amount of left/right workspace padding as a percentage of the screen width.
@@ -169,7 +170,7 @@
     public int qsbBottomMarginPx;
 
     // All apps
-    public int allAppsCellSpacingPx;
+    public Point allAppsCellSpacePx;
     public int allAppsOpenVerticalTranslate;
     public int allAppsCellHeightPx;
     public int allAppsCellWidthPx;
@@ -262,6 +263,20 @@
         mMetrics = context.getResources().getDisplayMetrics();
         final Resources res = context.getResources();
 
+        if (isTwoPanels) {
+            if (isLandscape) {
+                mTypeIndex = InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
+            } else {
+                mTypeIndex = InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
+            }
+        } else {
+            if (isLandscape) {
+                mTypeIndex = InvariantDeviceProfile.INDEX_LANDSCAPE;
+            } else {
+                mTypeIndex = InvariantDeviceProfile.INDEX_DEFAULT;
+            }
+        }
+
         hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
         isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS
                 && FeatureFlags.ENABLE_TASKBAR.get();
@@ -283,7 +298,9 @@
         folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
 
         cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
-        allAppsCellSpacingPx = pxFromDp(inv.allAppsCellSpacing, mMetrics, 1f);
+        allAppsCellSpacePx = new Point(
+                pxFromDp(inv.borderSpaces[InvariantDeviceProfile.INDEX_ALL_APPS].x, mMetrics, 1f),
+                pxFromDp(inv.borderSpaces[InvariantDeviceProfile.INDEX_ALL_APPS].y, mMetrics, 1f));
         cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
         folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics, 1f);
         folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
@@ -339,7 +356,8 @@
         hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
         hotseatExtraVerticalSize =
                 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
-        updateHotseatIconSize(pxFromDp(inv.iconSize, mMetrics, 1f));
+        updateHotseatIconSize(
+                pxFromDp(inv.iconSize[InvariantDeviceProfile.INDEX_DEFAULT], mMetrics, 1f));
 
         qsbBottomMarginOriginalPx = isScalableGrid
                 ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin)
@@ -451,22 +469,9 @@
             return 0;
         }
 
-        int horizontalMarginPx;
-
-        if (isScalableGrid) {
-            if (isTwoPanels) {
-                if (isLandscape) {
-                    horizontalMarginPx = pxFromDp(idp.twoPanelLandscapeHorizontalMargin, mMetrics);
-                } else {
-                    horizontalMarginPx = pxFromDp(idp.twoPanelPortraitHorizontalMargin, mMetrics);
-                }
-            } else {
-                horizontalMarginPx = pxFromDp(idp.horizontalMargin, mMetrics);
-            }
-        } else {
-            horizontalMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
-        }
-        return horizontalMarginPx;
+        return isScalableGrid
+                ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
+                : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
     }
 
     private void updateHotseatIconSize(int hotseatIconSizePx) {
@@ -487,21 +492,8 @@
             return new Point(0, 0);
         }
 
-        int horizontalSpacePx;
-        int verticalSpacePx;
-
-        if (isTwoPanels) {
-            if (isLandscape) {
-                horizontalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.x, mMetrics);
-                verticalSpacePx = pxFromDp(idp.twoPanelLandscapeBorderSpace.y, mMetrics);
-            } else {
-                horizontalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.x, mMetrics);
-                verticalSpacePx = pxFromDp(idp.twoPanelPortraitBorderSpace.y, mMetrics);
-            }
-        } else {
-            horizontalSpacePx = pxFromDp(idp.borderSpace.x, mMetrics);
-            verticalSpacePx = pxFromDp(idp.borderSpace.y, mMetrics);
-        }
+        int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics);
+        int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics);
 
         return new Point(horizontalSpacePx, verticalSpacePx);
     }
@@ -598,7 +590,7 @@
     private void updateAllAppsWidth() {
         if (isTwoPanels) {
             int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
-                    + (allAppsCellSpacingPx * (numShownAllAppsColumns + 1));
+                    + (allAppsCellSpacePx.x * (numShownAllAppsColumns + 1));
             allAppsLeftRightPadding = Math.max(1, (availableWidthPx - usedWidth) / 2);
         } else {
             allAppsLeftRightPadding =
@@ -661,26 +653,8 @@
 
         // Workspace
         final boolean isVerticalLayout = isVerticalBarLayout();
-        float invIconSizeDp;
-        float invIconTextSizeSp;
-
-        if (isTwoPanels) {
-            if (isLandscape) {
-                invIconSizeDp = inv.twoPanelLandscapeIconSize;
-                invIconTextSizeSp = inv.twoPanelLandscapeIconTextSize;
-            } else {
-                invIconSizeDp = inv.twoPanelPortraitIconSize;
-                invIconTextSizeSp = inv.twoPanelPortraitIconTextSize;
-            }
-        } else {
-            if (isLandscape) {
-                invIconSizeDp = inv.landscapeIconSize;
-                invIconTextSizeSp = inv.landscapeIconTextSize;
-            } else {
-                invIconSizeDp = inv.iconSize;
-                invIconTextSizeSp = inv.iconTextSize;
-            }
-        }
+        float invIconSizeDp = inv.iconSize[mTypeIndex];
+        float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
 
         iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
         iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
@@ -689,9 +663,8 @@
         cellLayoutBorderSpacePx = getCellLayoutBorderSpaceScaled(inv, scale);
 
         if (isScalableGrid) {
-            PointF minCellHeightAndWidth = getMinCellHeightAndWidth();
-            cellWidthPx = pxFromDp(minCellHeightAndWidth.x, mMetrics, scale);
-            cellHeightPx = pxFromDp(minCellHeightAndWidth.y, mMetrics, scale);
+            cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
+            cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
             int cellContentHeight = iconSizePx + iconDrawablePaddingPx
                     + Utilities.calculateTextHeight(iconTextSizePx);
             cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
@@ -715,8 +688,10 @@
 
         // All apps
         if (numShownAllAppsColumns != inv.numColumns) {
-            allAppsIconSizePx = pxFromDp(inv.allAppsIconSize, mMetrics);
-            allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize, mMetrics);
+            allAppsIconSizePx =
+                    pxFromDp(inv.iconSize[InvariantDeviceProfile.INDEX_ALL_APPS], mMetrics);
+            allAppsIconTextSizePx =
+                    pxFromSp(inv.iconTextSize[InvariantDeviceProfile.INDEX_ALL_APPS], mMetrics);
             allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
             autoResizeAllAppsCells();
         } else {
@@ -752,28 +727,6 @@
         folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
     }
 
-    /**
-     * Returns the minimum cell height and width as a pair.
-     */
-    private PointF getMinCellHeightAndWidth() {
-        PointF result = new PointF();
-
-        if (isTwoPanels) {
-            if (isLandscape) {
-                result.x = inv.twoPanelLandscapeMinCellWidthDps;
-                result.y = inv.twoPanelLandscapeMinCellHeightDps;
-            } else {
-                result.x = inv.twoPanelPortraitMinCellWidthDps;
-                result.y = inv.twoPanelPortraitMinCellHeightDps;
-            }
-        } else {
-            result.x = inv.minCellWidth;
-            result.y = inv.minCellHeight;
-        }
-
-        return result;
-    }
-
     private void updateAvailableFolderCellDimensions(Resources res) {
         updateFolderCellSize(1f, res);
 
@@ -804,9 +757,12 @@
     }
 
     private void updateFolderCellSize(float scale, Resources res) {
-        float invIconSizeDp = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
+        float invIconSizeDp = isVerticalBarLayout()
+                ? inv.iconSize[InvariantDeviceProfile.INDEX_LANDSCAPE]
+                : inv.iconSize[InvariantDeviceProfile.INDEX_DEFAULT];
         folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
-        folderChildTextSizePx = pxFromSp(inv.iconTextSize, mMetrics, scale);
+        folderChildTextSizePx =
+                pxFromSp(inv.iconTextSize[InvariantDeviceProfile.INDEX_DEFAULT], mMetrics, scale);
         folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
 
         int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
@@ -901,7 +857,7 @@
                     + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
 
             padding.set(desiredWorkspaceHorizontalMarginPx,
-                    (isScalableGrid ? workspaceTopPadding : edgeMarginPx),
+                    workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
                     desiredWorkspaceHorizontalMarginPx,
                     paddingBottom);
         }
@@ -1094,19 +1050,10 @@
 
         writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
 
-        writer.println(prefix + "\tinv.minCellWidth:" + inv.minCellWidth + "dp");
-        writer.println(prefix + "\tinv.minCellHeight:" + inv.minCellHeight + "dp");
-        writer.println(prefix + "\tinv.twoPanelPortraitMinCellHeightDps:"
-                + inv.twoPanelPortraitMinCellHeightDps + "dp");
-        writer.println(prefix + "\tinv.twoPanelPortraitMinCellWidthDps:"
-                + inv.twoPanelPortraitMinCellWidthDps + "dp");
-        writer.println(prefix + "\tinv.twoPanelLandscapeMinCellHeightDps:"
-                + inv.twoPanelLandscapeMinCellHeightDps + "dp");
-        writer.println(prefix + "\tinv.twoPanelLandscapeMinCellWidthDps:"
-                + inv.twoPanelLandscapeMinCellWidthDps + "dp");
+        writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
+        writer.println(prefix + "\tinv.numRows: " + inv.numRows);
 
-        writer.println(prefix + "\tinv.numColumns:" + inv.numColumns);
-        writer.println(prefix + "\tinv.numRows:" + inv.numRows);
+        writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
 
         writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
         writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
@@ -1114,7 +1061,11 @@
         writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
         writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
 
-        writer.println(prefix + "\tinv.iconSize:" + inv.iconSize + "dp");
+        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
+                cellLayoutBorderSpacePx.x));
+        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
+                cellLayoutBorderSpacePx.y));
+
         writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
         writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
         writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
@@ -1132,14 +1083,6 @@
         writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
                 folderCellLayoutBorderSpacePx.y));
 
-        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
-                cellLayoutBorderSpacePx.x));
-        writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
-                cellLayoutBorderSpacePx.y));
-
-        writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
-                desiredWorkspaceHorizontalMarginPx));
-
         writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
         writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
         writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
@@ -1161,6 +1104,8 @@
         writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
         writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
 
+        writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
+                desiredWorkspaceHorizontalMarginPx));
         writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
         writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
         writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index cfc14b6..ca07249 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -86,6 +86,15 @@
     // used to offset float not being able to express extremely small weights in extreme cases.
     private static final float WEIGHT_EFFICIENT = 100000f;
 
+    // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
+    // constraints
+    static final int COUNT_SIZES = 5;
+    static final int INDEX_DEFAULT = 0;
+    static final int INDEX_LANDSCAPE = 1;
+    static final int INDEX_TWO_PANEL_PORTRAIT = 2;
+    static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
+    static final int INDEX_ALL_APPS = 4;
+
     /**
      * Number of icons per row and column in the workspace.
      */
@@ -97,36 +106,18 @@
      */
     public int numFolderRows;
     public int numFolderColumns;
-    public float iconSize;
-    public float landscapeIconSize;
-    public float twoPanelPortraitIconSize;
-    public float twoPanelLandscapeIconSize;
-    public float landscapeIconTextSize;
-    public float twoPanelPortraitIconTextSize;
-    public float twoPanelLandscapeIconTextSize;
+    public float[] iconSize;
+    public float[] iconTextSize;
     public int iconBitmapSize;
     public int fillResIconDpi;
-    public float iconTextSize;
-    public float allAppsIconSize;
-    public float allAppsIconTextSize;
-    public float allAppsCellSpacing;
     public boolean isSplitDisplay;
 
-    public float minCellHeight;
-    public float minCellWidth;
-    public float twoPanelPortraitMinCellHeightDps;
-    public float twoPanelPortraitMinCellWidthDps;
-    public float twoPanelLandscapeMinCellHeightDps;
-    public float twoPanelLandscapeMinCellWidthDps;
+    public PointF[] minCellSize;
 
-    public PointF borderSpace;
-    public PointF twoPanelPortraitBorderSpace;
-    public PointF twoPanelLandscapeBorderSpace;
+    public PointF[] borderSpaces;
     public float folderBorderSpace;
 
-    public float horizontalMargin;
-    public float twoPanelLandscapeHorizontalMargin;
-    public float twoPanelPortraitHorizontalMargin;
+    public float[] horizontalMargin;
 
     private SparseArray<TypedValue> mExtraAttrs;
 
@@ -221,17 +212,17 @@
 
         DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
                 .add(myDisplayOption);
-        result.iconSizes[DisplayOption.INDEX_DEFAULT] =
-                defaultDisplayOption.iconSizes[DisplayOption.INDEX_DEFAULT];
-        for (int i = 1; i < DisplayOption.COUNT_SIZES; i++) {
+        result.iconSizes[INDEX_DEFAULT] =
+                defaultDisplayOption.iconSizes[INDEX_DEFAULT];
+        for (int i = 1; i < COUNT_SIZES; i++) {
             result.iconSizes[i] = Math.min(
                     defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
         }
 
-        result.minCellHeight = defaultDisplayOption.minCellHeight;
-        result.minCellWidth = defaultDisplayOption.minCellWidth;
-        result.borderSpaces[DisplayOption.INDEX_ALL_APPS] =
-                defaultDisplayOption.borderSpaces[DisplayOption.INDEX_ALL_APPS];
+        System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
+                COUNT_SIZES);
+        System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
+                COUNT_SIZES);
 
         initGrid(context, myInfo, result, false);
     }
@@ -274,39 +265,18 @@
 
         mExtraAttrs = closestProfile.extraAttrs;
 
-        iconSize = displayOption.iconSizes[DisplayOption.INDEX_DEFAULT];
-        landscapeIconSize = displayOption.iconSizes[DisplayOption.INDEX_LANDSCAPE];
-        twoPanelPortraitIconSize = displayOption.iconSizes[DisplayOption.INDEX_TWO_PANEL_PORTRAIT];
-        twoPanelLandscapeIconSize =
-                displayOption.iconSizes[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE];
-        iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
+        iconSize = displayOption.iconSizes;
+        iconBitmapSize = ResourceUtils.pxFromDp(iconSize[INDEX_DEFAULT], metrics);
         fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
 
-        iconTextSize = displayOption.textSizes[DisplayOption.INDEX_DEFAULT];
-        landscapeIconTextSize = displayOption.textSizes[DisplayOption.INDEX_LANDSCAPE];
-        twoPanelPortraitIconTextSize =
-                displayOption.textSizes[DisplayOption.INDEX_TWO_PANEL_PORTRAIT];
-        twoPanelLandscapeIconTextSize =
-                displayOption.textSizes[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE];
+        iconTextSize = displayOption.textSizes;
 
-        minCellHeight = displayOption.minCellHeight;
-        minCellWidth = displayOption.minCellWidth;
-        twoPanelPortraitMinCellHeightDps = displayOption.twoPanelPortraitMinCellHeightDps;
-        twoPanelPortraitMinCellWidthDps = displayOption.twoPanelPortraitMinCellWidthDps;
-        twoPanelLandscapeMinCellHeightDps = displayOption.twoPanelLandscapeMinCellHeightDps;
-        twoPanelLandscapeMinCellWidthDps = displayOption.twoPanelLandscapeMinCellWidthDps;
+        minCellSize = displayOption.minCellSize;
 
-        borderSpace = displayOption.borderSpaces[DisplayOption.INDEX_DEFAULT];
-        twoPanelPortraitBorderSpace =
-                displayOption.borderSpaces[DisplayOption.INDEX_TWO_PANEL_PORTRAIT];
-        twoPanelLandscapeBorderSpace =
-                displayOption.borderSpaces[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE];
-        allAppsCellSpacing = displayOption.borderSpaces[DisplayOption.INDEX_ALL_APPS].x;
+        borderSpaces = displayOption.borderSpaces;
         folderBorderSpace = displayOption.folderBorderSpace;
 
         horizontalMargin = displayOption.horizontalMargin;
-        twoPanelLandscapeHorizontalMargin = displayOption.twoPanelLandscapeHorizontalMargin;
-        twoPanelPortraitHorizontalMargin = displayOption.twoPanelPortraitHorizontalMargin;
 
         numShownHotseatIcons = closestProfile.numHotseatIcons;
         numDatabaseHotseatIcons = isSplitDisplay
@@ -316,12 +286,9 @@
         numDatabaseAllAppsColumns = isSplitDisplay
                 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
 
-        if (Utilities.isGridOptionsEnabled(context)) {
-            allAppsIconSize = displayOption.iconSizes[DisplayOption.INDEX_ALL_APPS];
-            allAppsIconTextSize = displayOption.textSizes[DisplayOption.INDEX_ALL_APPS];
-        } else {
-            allAppsIconSize = iconSize;
-            allAppsIconTextSize = iconTextSize;
+        if (!Utilities.isGridOptionsEnabled(context)) {
+            iconSize[INDEX_ALL_APPS] = iconSize[INDEX_DEFAULT];
+            iconTextSize[INDEX_ALL_APPS] = iconTextSize[INDEX_DEFAULT];
         }
 
         if (devicePaddingId != 0) {
@@ -566,11 +533,11 @@
 
         // Since the bitmaps are persisted, ensure that the default bitmap size is same as
         // predefined size to avoid cache invalidation
-        out.iconSizes[DisplayOption.INDEX_DEFAULT] =
-                closestPoint.iconSizes[DisplayOption.INDEX_DEFAULT];
-        for (int i = DisplayOption.INDEX_DEFAULT + 1; i < DisplayOption.COUNT_SIZES; i++) {
+        out.iconSizes[INDEX_DEFAULT] =
+                closestPoint.iconSizes[INDEX_DEFAULT];
+        for (int i = INDEX_DEFAULT + 1; i < COUNT_SIZES; i++) {
             out.iconSizes[i] = Math.min(out.iconSizes[i],
-                    out.iconSizes[DisplayOption.INDEX_DEFAULT]);
+                    out.iconSizes[INDEX_DEFAULT]);
         }
 
         return out;
@@ -724,32 +691,17 @@
     @VisibleForTesting
     static final class DisplayOption {
 
-        static final int COUNT_SIZES = 5;
-        static final int INDEX_DEFAULT = 0;
-        static final int INDEX_LANDSCAPE = 1;
-        static final int INDEX_TWO_PANEL_PORTRAIT = 2;
-        static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
-        static final int INDEX_ALL_APPS = 4;
-
         public final GridOption grid;
 
         private final float minWidthDps;
         private final float minHeightDps;
         private final boolean canBeDefault;
 
-        private float minCellHeight;
-        private float minCellWidth;
-        private float twoPanelPortraitMinCellHeightDps;
-        private float twoPanelPortraitMinCellWidthDps;
-        private float twoPanelLandscapeMinCellHeightDps;
-        private float twoPanelLandscapeMinCellWidthDps;
+        private final PointF[] minCellSize = new PointF[COUNT_SIZES];
 
         private float folderBorderSpace;
         private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
-
-        private float horizontalMargin;
-        private float twoPanelLandscapeHorizontalMargin;
-        private float twoPanelPortraitHorizontalMargin;
+        private final float[] horizontalMargin = new float[COUNT_SIZES];
 
         private final float[] iconSizes = new float[COUNT_SIZES];
         private final float[] textSizes = new float[COUNT_SIZES];
@@ -766,27 +718,32 @@
             canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
                     == defaultFlagValue;
 
-            minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
-            minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
-            twoPanelPortraitMinCellHeightDps = a.getFloat(
-                    R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellHeightDps,
-                    minCellHeight);
-            twoPanelPortraitMinCellWidthDps = a.getFloat(
-                    R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellWidthDps, minCellWidth);
-            twoPanelLandscapeMinCellHeightDps = a.getFloat(
-                    R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellHeightDps,
-                    twoPanelPortraitMinCellHeightDps);
-            twoPanelLandscapeMinCellWidthDps = a.getFloat(
-                    R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps,
-                    twoPanelPortraitMinCellWidthDps);
+            float x;
+            float y;
+
+            x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
+            y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
+            minCellSize[INDEX_DEFAULT] = new PointF(x, y);
+            minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
+            minCellSize[INDEX_ALL_APPS] = new PointF(x, y);
+
+            x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellWidthDps,
+                    minCellSize[INDEX_DEFAULT].x);
+            y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellHeightDps,
+                    minCellSize[INDEX_DEFAULT].y);
+            minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
+
+            x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps,
+                    minCellSize[INDEX_DEFAULT].x);
+            y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellHeightDps,
+                    minCellSize[INDEX_DEFAULT].y);
+            minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
 
             float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceDps, 0);
             float twoPanelPortraitBorderSpaceDps = a.getFloat(
                     R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceDps, borderSpace);
             float twoPanelLandscapeBorderSpaceDps = a.getFloat(
                     R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceDps, borderSpace);
-            float x;
-            float y;
 
             x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontalDps, borderSpace);
             y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVerticalDps, borderSpace);
@@ -827,7 +784,7 @@
                             iconSizes[INDEX_DEFAULT]);
             iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
                     a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconSize,
-                            iconSizes[INDEX_LANDSCAPE]);
+                            iconSizes[INDEX_DEFAULT]);
 
             textSizes[INDEX_DEFAULT] =
                     a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
@@ -842,15 +799,18 @@
                             textSizes[INDEX_DEFAULT]);
             textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
                     a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize,
-                            textSizes[INDEX_LANDSCAPE]);
+                            textSizes[INDEX_DEFAULT]);
 
-            horizontalMargin = a.getFloat(R.styleable.ProfileDisplayOption_horizontalMargin, 0);
-            twoPanelLandscapeHorizontalMargin = a.getFloat(
+            horizontalMargin[INDEX_DEFAULT] = a.getFloat(
+                    R.styleable.ProfileDisplayOption_horizontalMargin, 0);
+            horizontalMargin[INDEX_LANDSCAPE] = horizontalMargin[INDEX_DEFAULT];
+            horizontalMargin[INDEX_ALL_APPS] = horizontalMargin[INDEX_DEFAULT];
+            horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
                     R.styleable.ProfileDisplayOption_twoPanelLandscapeHorizontalMargin,
-                    horizontalMargin);
-            twoPanelPortraitHorizontalMargin = a.getFloat(
+                    horizontalMargin[INDEX_DEFAULT]);
+            horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
                     R.styleable.ProfileDisplayOption_twoPanelPortraitHorizontalMargin,
-                    horizontalMargin);
+                    horizontalMargin[INDEX_DEFAULT]);
 
             a.recycle();
         }
@@ -864,12 +824,11 @@
             minWidthDps = 0;
             minHeightDps = 0;
             canBeDefault = false;
-            minCellHeight = 0;
-            minCellWidth = 0;
             for (int i = 0; i < COUNT_SIZES; i++) {
                 iconSizes[i] = 0;
                 textSizes[i] = 0;
                 borderSpaces[i] = new PointF();
+                minCellSize[i] = new PointF();
             }
         }
 
@@ -877,21 +836,15 @@
             for (int i = 0; i < COUNT_SIZES; i++) {
                 iconSizes[i] *= w;
                 textSizes[i] *= w;
-                borderSpaces[i].x *=  w;
-                borderSpaces[i].y *=  w;
+                borderSpaces[i].x *= w;
+                borderSpaces[i].y *= w;
+                minCellSize[i].x *= w;
+                minCellSize[i].y *= w;
+                horizontalMargin[i] *= w;
             }
-            minCellHeight *= w;
-            minCellWidth *= w;
-            twoPanelPortraitMinCellHeightDps *= w;
-            twoPanelPortraitMinCellWidthDps *= w;
-            twoPanelLandscapeMinCellHeightDps *= w;
-            twoPanelLandscapeMinCellWidthDps *= w;
 
             folderBorderSpace *= w;
 
-            horizontalMargin *= w;
-            twoPanelLandscapeHorizontalMargin *= w;
-            twoPanelPortraitHorizontalMargin *= w;
             return this;
         }
 
@@ -899,21 +852,15 @@
             for (int i = 0; i < COUNT_SIZES; i++) {
                 iconSizes[i] += p.iconSizes[i];
                 textSizes[i] += p.textSizes[i];
-                borderSpaces[i].x +=  p.borderSpaces[i].x;
-                borderSpaces[i].y +=  p.borderSpaces[i].y;
+                borderSpaces[i].x += p.borderSpaces[i].x;
+                borderSpaces[i].y += p.borderSpaces[i].y;
+                minCellSize[i].x += p.minCellSize[i].x;
+                minCellSize[i].y += p.minCellSize[i].y;
+                horizontalMargin[i] += p.horizontalMargin[i];
             }
-            minCellHeight += p.minCellHeight;
-            minCellWidth += p.minCellWidth;
-            twoPanelPortraitMinCellHeightDps += p.twoPanelPortraitMinCellHeightDps;
-            twoPanelPortraitMinCellWidthDps += p.twoPanelPortraitMinCellWidthDps;
-            twoPanelLandscapeMinCellHeightDps += p.twoPanelLandscapeMinCellHeightDps;
-            twoPanelLandscapeMinCellWidthDps += p.twoPanelLandscapeMinCellWidthDps;
 
             folderBorderSpace += p.folderBorderSpace;
 
-            horizontalMargin += p.horizontalMargin;
-            twoPanelLandscapeHorizontalMargin += p.twoPanelLandscapeHorizontalMargin;
-            twoPanelPortraitHorizontalMargin += p.twoPanelPortraitHorizontalMargin;
             return this;
         }
     }
diff --git a/src/com/android/launcher3/Partner.java b/src/com/android/launcher3/Partner.java
index 0bdb37c..2e27f32 100644
--- a/src/com/android/launcher3/Partner.java
+++ b/src/com/android/launcher3/Partner.java
@@ -142,7 +142,7 @@
         }
 
         if (iconSize > 0) {
-            inv.iconSize = iconSize;
+            inv.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] = iconSize;
         }
     }
 }
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 3f1f915..9bb4b25 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -491,6 +491,7 @@
             mViewPager.initParentViews(this);
             mViewPager.getPageIndicator().setOnActivePageChangedListener(this);
             mWorkManager.attachWorkModeSwitch();
+            mWorkManager.getWorkModeSwitch().post(() -> mAH[AdapterHolder.WORK].applyPadding());
         } else {
             mWorkManager.detachWorkModeSwitch();
             mViewPager = null;
diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java
index 5d64041..be01581 100644
--- a/src/com/android/launcher3/allapps/WorkModeSwitch.java
+++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java
@@ -113,10 +113,12 @@
     /**
      * Sets the enabled or disabled state of the button
      */
-    public void updateCurrentState(boolean active) {
+    public void updateCurrentState(boolean isEnabled) {
         removeFlag(FLAG_PROFILE_TOGGLE_ONGOING);
-        mWorkEnabled = active;
-        updateVisibility();
+        if (mWorkEnabled != isEnabled) {
+            mWorkEnabled = isEnabled;
+            updateVisibility();
+        }
     }
 
 
@@ -125,7 +127,6 @@
         if (mWorkEnabled && mOnWorkTab) {
             setFlag(FLAG_FADE_ONGOING);
             setVisibility(VISIBLE);
-            setAlpha(0);
             animate().alpha(1).withEndAction(() -> removeFlag(FLAG_FADE_ONGOING)).start();
         } else if (getVisibility() != GONE) {
             setFlag(FLAG_FADE_ONGOING);
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 0acafc0..61f314c 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -176,10 +176,6 @@
             "Replace Smartspace with the enhanced version. "
                     + "Ignored if ENABLE_SMARTSPACE_UNIVERSAL is enabled.");
 
-    public static final BooleanFlag ENABLE_SMARTSPACE_FEEDBACK = getDebugFlag(
-            "ENABLE_SMARTSPACE_FEEDBACK", false,
-            "Adds a menu option to send feedback for Enhanced Smartspace.");
-
     public static final BooleanFlag ENABLE_SMARTSPACE_DISMISS = getDebugFlag(
             "ENABLE_SMARTSPACE_DISMISS", true,
             "Adds a menu option to dismiss the current Enhanced Smartspace card.");
@@ -262,7 +258,7 @@
             "Enables widgets in Launcher preview for the Wallpaper app.");
 
     public static final BooleanFlag QUICK_WALLPAPER_PICKER = getDebugFlag(
-            "QUICK_WALLPAPER_PICKER", false,
+            "QUICK_WALLPAPER_PICKER", true,
             "Shows quick wallpaper picker in long-press menu");
 
     public static final BooleanFlag ENABLE_BACK_SWIPE_HOME_ANIMATION = getDebugFlag(
diff --git a/src/com/android/launcher3/model/UserManagerState.java b/src/com/android/launcher3/model/UserManagerState.java
index 3a4206c..97a5905 100644
--- a/src/com/android/launcher3/model/UserManagerState.java
+++ b/src/com/android/launcher3/model/UserManagerState.java
@@ -36,7 +36,7 @@
      * Initialises the state values for all users
      */
     public void init(UserCache userCache, UserManager userManager) {
-        for (UserHandle user : userCache.getUserProfiles()) {
+        for (UserHandle user : userManager.getUserProfiles()) {
             long serialNo = userCache.getSerialNumberForUser(user);
             boolean isUserQuiet = userManager.isQuietModeEnabled(user);
             allUsers.put(serialNo, user);
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index 65dd8ea..d6e927b 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -46,7 +46,6 @@
 import com.android.launcher3.DropTarget;
 import com.android.launcher3.DropTarget.DragObject;
 import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherState;
 import com.android.launcher3.R;
 import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
 import com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate;
@@ -64,7 +63,6 @@
 import com.android.launcher3.popup.PopupDataProvider.PopupDataChangeListener;
 import com.android.launcher3.shortcuts.DeepShortcutView;
 import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider;
-import com.android.launcher3.statemanager.StatefulActivity;
 import com.android.launcher3.touch.ItemLongClickListener;
 import com.android.launcher3.util.PackageUserKey;
 import com.android.launcher3.util.ShortcutUtil;
@@ -83,7 +81,7 @@
  *
  * @param <T> The activity on with the popup shows
  */
-public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
+public class PopupContainerWithArrow<T extends BaseDraggingActivity>
         extends ArrowPopup<T> implements DragSource, DragController.DragListener {
 
     private final List<DeepShortcutView> mShortcuts = new ArrayList<>();
diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java
index 931ecb8..2068c29 100644
--- a/src/com/android/launcher3/util/DisplayController.java
+++ b/src/com/android/launcher3/util/DisplayController.java
@@ -243,7 +243,7 @@
         }
 
         int change = 0;
-        if (!newInfo.mScreenSizeDp.equals(oldInfo.mScreenSizeDp)) {
+        if (!newInfo.displayId.equals(oldInfo.displayId)) {
             change |= CHANGE_ACTIVE_SCREEN;
         }
         if (newInfo.rotation != oldInfo.rotation) {
@@ -296,6 +296,7 @@
 
         public final Point currentSize;
 
+        public String displayId;
         public final Set<WindowBounds> supportedBounds = new ArraySet<>();
         private final Map<String, Set<WindowBounds>> mPerDisplayBounds = new ArrayMap<>();
         private final ArrayMap<String, PortraitSize> mInternalDisplays;
@@ -319,17 +320,17 @@
             currentSize = new Point();
             display.getRealSize(currentSize);
 
-            String myDisplayId = ApiWrapper.getUniqueId(display);
+            displayId = ApiWrapper.getUniqueId(display);
             Set<WindowBounds> currentSupportedBounds =
                     getSupportedBoundsForDisplay(display, currentSize);
-            mPerDisplayBounds.put(myDisplayId, currentSupportedBounds);
+            mPerDisplayBounds.put(displayId, currentSupportedBounds);
             supportedBounds.addAll(currentSupportedBounds);
 
             if (ApiWrapper.isInternalDisplay(display) && internalDisplays.size() > 1) {
                 int displayCount = internalDisplays.size();
                 for (int i = 0; i < displayCount; i++) {
                     String displayKey = internalDisplays.keyAt(i);
-                    if (TextUtils.equals(myDisplayId, displayKey)) {
+                    if (TextUtils.equals(displayId, displayKey)) {
                         continue;
                     }