Merge "Actually call LauncherTransitionable.onLauncherTransitionStep()." into ub-launcher3-burnaby-polish
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 99a6ad9..b0b1e95 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -92,39 +92,6 @@
             </intent-filter>
         </activity>
 
-        <!-- ENABLE_FOR_TESTING
-
-        <activity
-            android:name="com.android.launcher3.testing.LauncherExtension"
-            android:launchMode="singleTask"
-            android:clearTaskOnLaunch="true"
-            android:stateNotNeeded="true"
-            android:theme="@style/Theme"
-            android:windowSoftInputMode="adjustPan"
-            android:screenOrientation="nosensor"
-            android:enabled="false">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.HOME" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.MONKEY"/>
-            </intent-filter>
-        </activity>
-
-        -->
-
-        <activity
-            android:name="com.android.launcher3.ToggleWeightWatcher"
-            android:label="@string/toggle_weight_watcher"
-            android:enabled="@bool/debug_memory_enabled"
-            android:icon="@mipmap/ic_launcher_home">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-
         <activity
             android:name="com.android.launcher3.WallpaperPickerActivity"
             android:theme="@style/Theme.WallpaperPicker"
@@ -159,27 +126,6 @@
             android:process=":settings_process">
         </activity>
 
-        <!-- Debugging tools -->
-        <activity
-            android:name="com.android.launcher3.MemoryDumpActivity"
-            android:theme="@android:style/Theme.NoDisplay"
-            android:label="@string/debug_memory_activity"
-            android:enabled="@bool/debug_memory_enabled"
-            android:excludeFromRecents="true"
-            android:icon="@mipmap/ic_launcher_home"
-            >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-
-        <service android:name="com.android.launcher3.MemoryTracker"
-            android:enabled="@bool/debug_memory_enabled"
-            >
-        </service>
-
         <receiver
             android:name="com.android.launcher3.WallpaperChangedReceiver">
             <intent-filter>
@@ -219,5 +165,54 @@
 
         <meta-data android:name="android.nfc.disable_beam_default"
                        android:value="true" />
+
+        <!-- ENABLE_FOR_TESTING
+
+        <activity
+            android:name="com.android.launcher3.testing.LauncherExtension"
+            android:launchMode="singleTask"
+            android:clearTaskOnLaunch="true"
+            android:stateNotNeeded="true"
+            android:theme="@style/Theme"
+            android:windowSoftInputMode="adjustPan"
+            android:screenOrientation="nosensor"
+            >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.HOME" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.MONKEY"/>
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name="com.android.launcher3.testing.MemoryDumpActivity"
+            android:theme="@android:style/Theme.NoDisplay"
+            android:label="* HPROF"
+            android:excludeFromRecents="true"
+            android:icon="@mipmap/ic_launcher_home"
+            >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name="com.android.launcher3.testing.ToggleWeightWatcher"
+            android:label="Show Mem"
+            android:icon="@mipmap/ic_launcher_home">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <service android:name="com.android.launcher3.testing.MemoryTracker" />
+
+        -->
+
     </application>
 </manifest>
diff --git a/res/layout/dummy_widget.xml b/res/layout/zzz_dummy_widget.xml
similarity index 100%
rename from res/layout/dummy_widget.xml
rename to res/layout/zzz_dummy_widget.xml
diff --git a/res/layout/zzz_weight_watcher.xml b/res/layout/zzz_weight_watcher.xml
new file mode 100644
index 0000000..07fd39e
--- /dev/null
+++ b/res/layout/zzz_weight_watcher.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.android.launcher3.testing.WeightWatcher xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" />
diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml
index 807fab9..b9e28a9 100644
--- a/res/values-sw720dp/dimens.xml
+++ b/res/values-sw720dp/dimens.xml
@@ -16,6 +16,7 @@
 
 <resources>
 <!-- All Apps -->
+    <dimen name="all_apps_button_scale_down">8dp</dimen>
     <dimen name="all_apps_search_bar_height">54dp</dimen>
     <dimen name="all_apps_icon_top_bottom_padding">14dp</dimen>
     <dimen name="all_apps_empty_search_message_top_offset">64dp</dimen>
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 8f0d883..1f2a394 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -77,10 +77,8 @@
     <string name="abandoned_search" msgid="891119232568284442">"搜索"</string>
     <string name="abandoned_promises_title" msgid="7096178467971716750">"未安装此应用"</string>
     <string name="abandoned_promise_explanation" msgid="3990027586878167529">"未安装此图标对应的应用。您可以移除此图标,也可以尝试搜索相应的应用并手动安装。"</string>
-    <!-- no translation found for app_downloading_title (8336702962104482644) -->
-    <skip />
-    <!-- no translation found for app_waiting_download_title (7053938513995617849) -->
-    <skip />
+    <string name="app_downloading_title" msgid="8336702962104482644">"正在下载<xliff:g id="NAME">%1$s</xliff:g>,已完成 <xliff:g id="PROGRESS">%2$s</xliff:g>"</string>
+    <string name="app_waiting_download_title" msgid="7053938513995617849">"<xliff:g id="NAME">%1$s</xliff:g>正在等待安装"</string>
     <string name="action_add_to_workspace" msgid="8902165848117513641">"添加到主屏幕"</string>
     <string name="action_move_here" msgid="2170188780612570250">"将项目移至此处"</string>
     <string name="item_added_to_workspace" msgid="4211073925752213539">"已将项目添加到主屏幕"</string>
diff --git a/res/values/config.xml b/res/values/config.xml
index 5cde42e..8550088 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -67,9 +67,6 @@
 <!-- Hotseat -->
     <bool name="hotseat_transpose_layout_with_orientation">true</bool>
 
-    <!-- Memory debugging, including a memory dump icon -->
-    <bool name="debug_memory_enabled">false</bool>
-
     <!-- Name of a subclass of com.android.launcher3.AppFilter used to
          filter the activities shown in the launcher. Can be empty. -->
     <string name="app_filter_class" translatable="false"></string>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 3672179..5d69012 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -21,6 +21,9 @@
     <dimen name="dynamic_grid_edge_margin">6dp</dimen>
     <dimen name="dynamic_grid_search_bar_max_width">500dp</dimen>
     <dimen name="dynamic_grid_search_bar_height">56dp</dimen>
+    <!-- We want 32dp extra for the tall search bar, but 10dp comes from unwanted padding between
+         the search bar and workspace. -->
+    <dimen name="dynamic_grid_search_bar_height_tall">78dp</dimen>
     <dimen name="dynamic_grid_page_indicator_height">20dp</dimen>
     <dimen name="dynamic_grid_icon_drawable_padding">4dp</dimen>
     <dimen name="dynamic_grid_workspace_page_spacing">8dp</dimen>
@@ -63,6 +66,7 @@
     <dimen name="container_fastscroll_popup_text_size">48dp</dimen>
 
 <!-- All Apps -->
+    <dimen name="all_apps_button_scale_down">0dp</dimen>
     <dimen name="all_apps_grid_view_start_margin">0dp</dimen>
     <dimen name="all_apps_grid_section_y_offset">8dp</dimen>
     <dimen name="all_apps_grid_section_text_size">24sp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 91dfb19..ca92e11 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -45,8 +45,6 @@
     <!-- SafeMode widget error string -->
     <string name="safemode_widget_error">Widgets disabled in Safe mode</string>
 
-    <string name="toggle_weight_watcher">Show Mem</string>
-
     <!-- Widgets -->
     <!-- Message to tell the user to press and hold on a widget to add it [CHAR_LIMIT=50] -->
     <string name="long_press_widget_to_add">Touch &amp; hold to pick up a widget.</string>
@@ -162,9 +160,6 @@
     <!-- Folder name format -->
     <string name="folder_name_format">Folder: <xliff:g id="name" example="Games">%1$s</xliff:g></string>
 
-    <!-- Debug-only activity name. [DO NOT TRANSLATE] -->
-    <string name="debug_memory_activity">* HPROF</string>
-
     <!-- Strings for the customization mode -->
     <!-- Text for widget add button -->
     <string name="widget_button_text">Widgets</string>
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 774594f..947b164 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -49,6 +49,12 @@
     public final int heightPx;
     public final int availableWidthPx;
     public final int availableHeightPx;
+    /**
+     * The maximum amount of left/right workspace padding as a percentage of the screen width.
+     * To be clear, this means that up to 7% of the screen width can be used as left padding, and
+     * 7% of the screen width can be used as right padding.
+     */
+    private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
 
     // Overview mode
     private final int overviewModeMinIconZoneHeightPx;
@@ -84,7 +90,8 @@
     public int hotseatCellWidthPx;
     public int hotseatCellHeightPx;
     public int hotseatIconSizePx;
-    private int hotseatBarHeightPx;
+    private int hotseatBarHeightNormalPx, hotseatBarHeightShortPx;
+    private int hotseatBarHeightPx; // One of the above.
 
     // All apps
     public int allAppsNumCols;
@@ -95,7 +102,9 @@
 
     // QSB
     private int searchBarSpaceWidthPx;
-    private int searchBarSpaceHeightPx;
+    private int searchBarSpaceHeightNormalPx, searchBarSpaceHeightTallPx;
+    private int searchBarSpaceHeightPx; // One of the above.
+    private int searchBarHeight = LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
 
     public DeviceProfile(Context context, InvariantDeviceProfile inv,
             Point minSize, Point maxSize,
@@ -167,7 +176,8 @@
     private void computeAllAppsButtonSize(Context context) {
         Resources res = context.getResources();
         float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
-        allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding));
+        allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)) - context.getResources()
+                        .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
     }
 
     private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
@@ -198,8 +208,10 @@
         // Search Bar
         searchBarSpaceWidthPx = Math.min(widthPx,
                 res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
-        searchBarSpaceHeightPx = getSearchBarTopOffset()
+        searchBarSpaceHeightNormalPx = getSearchBarTopOffset()
                 + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);
+        searchBarSpaceHeightTallPx = getSearchBarTopOffset()
+                + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height_tall);
 
         // Calculate the actual text height
         Paint textPaint = new Paint();
@@ -211,7 +223,8 @@
         dragViewScale = (iconSizePx + scaleDps) / iconSizePx;
 
         // Hotseat
-        hotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx;
+        hotseatBarHeightNormalPx = iconSizePx + 4 * edgeMarginPx;
+        hotseatBarHeightShortPx = iconSizePx + 2 * edgeMarginPx;
         hotseatCellWidthPx = iconSizePx;
         hotseatCellHeightPx = iconSizePx;
 
@@ -250,12 +263,12 @@
     /** Returns the search bar bounds in the current orientation */
     public Rect getSearchBarBounds(boolean isLayoutRtl) {
         Rect bounds = new Rect();
-        if (isLandscape && transposeLayoutWithOrientation) {
+        if (isVerticalBarLayout()) {
             if (isLayoutRtl) {
-                bounds.set(availableWidthPx - searchBarSpaceHeightPx, edgeMarginPx,
+                bounds.set(availableWidthPx - searchBarSpaceHeightNormalPx, edgeMarginPx,
                         availableWidthPx, availableHeightPx - edgeMarginPx);
             } else {
-                bounds.set(0, edgeMarginPx, searchBarSpaceHeightPx,
+                bounds.set(0, edgeMarginPx, searchBarSpaceHeightNormalPx,
                         availableHeightPx - edgeMarginPx);
             }
         } else {
@@ -284,14 +297,14 @@
     Rect getWorkspacePadding(boolean isLayoutRtl) {
         Rect searchBarBounds = getSearchBarBounds(isLayoutRtl);
         Rect padding = new Rect();
-        if (isLandscape && transposeLayoutWithOrientation) {
+        if (isVerticalBarLayout()) {
             // Pad the left and right of the workspace with search/hotseat bar sizes
             if (isLayoutRtl) {
-                padding.set(hotseatBarHeightPx, edgeMarginPx,
+                padding.set(hotseatBarHeightNormalPx, edgeMarginPx,
                         searchBarBounds.width(), edgeMarginPx);
             } else {
                 padding.set(searchBarBounds.width(), edgeMarginPx,
-                        hotseatBarHeightPx, edgeMarginPx);
+                        hotseatBarHeightNormalPx, edgeMarginPx);
             }
         } else {
             if (isTablet) {
@@ -302,12 +315,15 @@
                 int height = getCurrentHeight();
                 int paddingTop = searchBarBounds.bottom;
                 int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx;
-                int availableWidth = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) +
-                        (inv.numColumns * gapScale * cellWidthPx)));
-                int availableHeight = Math.max(0, height - paddingTop - paddingBottom
+                // The amount of screen space available for left/right padding.
+                int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) +
+                        ((inv.numColumns - 1) * gapScale * cellWidthPx)));
+                availablePaddingX = (int) Math.min(availablePaddingX,
+                            width * MAX_HORIZONTAL_PADDING_PERCENT);
+                int availablePaddingY = Math.max(0, height - paddingTop - paddingBottom
                         - (int) (2 * inv.numRows * cellHeightPx));
-                padding.set(availableWidth / 2, paddingTop + availableHeight / 2,
-                        availableWidth / 2, paddingBottom + availableHeight / 2);
+                padding.set(availablePaddingX / 2, paddingTop + availablePaddingY / 2,
+                        availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
             } else {
                 // Pad the top and bottom of the workspace with search/hotseat bar sizes
                 padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
@@ -320,7 +336,7 @@
     }
 
     private int getWorkspacePageSpacing(boolean isLayoutRtl) {
-        if ((isLandscape && transposeLayoutWithOrientation) || isLargeTablet) {
+        if (isVerticalBarLayout() || isLargeTablet) {
             // In landscape mode the page spacing is set to the default.
             return defaultPageSpacingPx;
         } else {
@@ -341,7 +357,7 @@
     // The rect returned will be extended to below the system ui that covers the workspace
     Rect getHotseatRect() {
         if (isVerticalBarLayout()) {
-            return new Rect(availableWidthPx - hotseatBarHeightPx, 0,
+            return new Rect(availableWidthPx - hotseatBarHeightNormalPx, 0,
                     Integer.MAX_VALUE, availableHeightPx);
         } else {
             return new Rect(0, availableHeightPx - hotseatBarHeightPx,
@@ -357,8 +373,9 @@
     }
 
     /**
-     * When {@code true}, hotseat is on the bottom row when in landscape mode.
-     * If {@code false}, hotseat is on the right column when in landscape mode.
+     * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
+     * When {@code false}, either device is in portrait mode or the device is in landscape mode and
+     * the hotseat is on the bottom row.
      */
     boolean isVerticalBarLayout() {
         return isLandscape && transposeLayoutWithOrientation;
@@ -386,11 +403,19 @@
         // Layout the search bar space
         View searchBar = launcher.getSearchDropTargetBar();
         lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
+        searchBarHeight = launcher.getSearchBarHeight();
+        if (searchBarHeight == LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL) {
+            hotseatBarHeightPx = hotseatBarHeightShortPx;
+            searchBarSpaceHeightPx = searchBarSpaceHeightTallPx;
+        } else {
+            hotseatBarHeightPx = hotseatBarHeightNormalPx;
+            searchBarSpaceHeightPx = searchBarSpaceHeightNormalPx;
+        }
         if (hasVerticalBarLayout) {
             // Vertical search bar space -- The search bar is fixed in the layout to be on the left
             //                              of the screen regardless of RTL
             lp.gravity = Gravity.LEFT;
-            lp.width = searchBarSpaceHeightPx;
+            lp.width = searchBarSpaceHeightNormalPx;
 
             LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar);
             targets.setOrientation(LinearLayout.VERTICAL);
@@ -420,11 +445,18 @@
         // Layout the hotseat
         View hotseat = launcher.findViewById(R.id.hotseat);
         lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
+        // We want the edges of the hotseat to line up with the edges of the workspace, but the
+        // icons in the hotseat are a different size, and so don't line up perfectly. To account for
+        // this, we pad the left and right of the hotseat with half of the difference of a workspace
+        // cell vs a hotseat cell.
+        float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
+        float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
+        int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
         if (hasVerticalBarLayout) {
             // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
             //                     screen regardless of RTL
             lp.gravity = Gravity.RIGHT;
-            lp.width = hotseatBarHeightPx;
+            lp.width = hotseatBarHeightNormalPx;
             lp.height = LayoutParams.MATCH_PARENT;
             hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx);
         } else if (isTablet) {
@@ -432,17 +464,18 @@
             lp.gravity = Gravity.BOTTOM;
             lp.width = LayoutParams.MATCH_PARENT;
             lp.height = hotseatBarHeightPx;
-            hotseat.setPadding(edgeMarginPx + padding.left, 0,
-                    edgeMarginPx + padding.right,
-                    2 * edgeMarginPx);
+            hotseat.findViewById(R.id.layout).setPadding(
+                    hotseatAdjustment + padding.left, 0,
+                    hotseatAdjustment + padding.right, 2 * edgeMarginPx);
         } else {
             // For phones, layout the hotseat without any bottom margin
             // to ensure that we have space for the folders
             lp.gravity = Gravity.BOTTOM;
             lp.width = LayoutParams.MATCH_PARENT;
             lp.height = hotseatBarHeightPx;
-            hotseat.findViewById(R.id.layout).setPadding(2 * edgeMarginPx, 0,
-                    2 * edgeMarginPx, 0);
+            hotseat.findViewById(R.id.layout).setPadding(
+                    hotseatAdjustment + padding.left, 0,
+                    hotseatAdjustment + padding.right, 0);
         }
         hotseat.setLayoutParams(lp);
 
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 17fdeb1..98912f5 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -17,8 +17,7 @@
 package com.android.launcher3;
 
 import android.content.Context;
-import android.content.res.Configuration;
-import android.content.res.Resources;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.util.AttributeSet;
@@ -118,6 +117,10 @@
         Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
 
         mLauncher.resizeIconDrawable(d);
+        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
+        Rect bounds = d.getBounds();
+        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
+                bounds.bottom - scaleDownPx / 2);
         allAppsButton.setCompoundDrawables(null, d, null, null);
 
         allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 9e46a84..e983eb1 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -17,9 +17,9 @@
 package com.android.launcher3;
 
 import android.annotation.TargetApi;
+import android.app.ActivityManager;
 import android.content.Context;
 import android.graphics.Point;
-import android.os.Build;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.WindowManager;
@@ -74,7 +74,7 @@
     /**
      * Number of icons inside the hotseat area.
      */
-    float numHotseatIcons;
+    int numHotseatIcons;
     float hotseatIconSize;
     int defaultLayoutId;
 
@@ -84,6 +84,9 @@
     DeviceProfile landscapeProfile;
     DeviceProfile portraitProfile;
 
+    // On Marshmallow the status bar is no longer opaque, when drawn on the right.
+    public boolean isRightInsetOpaque;
+
     InvariantDeviceProfile() {
     }
 
@@ -95,7 +98,7 @@
     }
 
     InvariantDeviceProfile(String n, float w, float h, int r, int c, int fr, int fc, int maapc,
-            float is, float its, float hs, float his, int dlId) {
+            float is, float its, int hs, float his, int dlId) {
         // Ensure that we have an odd number of hotseat items (since we need to place all apps)
         if (hs % 2 == 0) {
             throw new RuntimeException("All Device Profiles must have an odd number of hotseat spaces");
@@ -116,7 +119,7 @@
         defaultLayoutId = dlId;
     }
 
-    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+    @TargetApi(23)
     InvariantDeviceProfile(Context context) {
         WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         Display display = wm.getDefaultDisplay();
@@ -167,6 +170,9 @@
                 largeSide, smallSide, true /* isLandscape */);
         portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize,
                 smallSide, largeSide, false /* isLandscape */);
+
+        isRightInsetOpaque = !Utilities.ATLEAST_MARSHMALLOW ||
+                context.getSystemService(ActivityManager.class).isLowRamDevice();
     }
 
     ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles() {
@@ -195,7 +201,7 @@
                 575, 904,     5, 6, 4, 5, 4, 72, 14.4f,  7, 60, R.xml.default_workspace_5x6));
         // Larger tablet profiles always have system bars on the top & bottom
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 10",
-                727, 1207,    5, 6, 4, 5, 4, 76, 14.4f,  7, 64, R.xml.default_workspace_5x6));
+                727, 1207,    5, 6, 4, 5, 4, 76, 14.4f,  7, 76, R.xml.default_workspace_5x6));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("20-inch Tablet",
                 1527, 2527,   7, 7, 6, 6, 4, 100, 20,  7, 72, R.xml.default_workspace_4x4));
         return predefinedDeviceProfiles;
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 59fcb44..8679ec7 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -72,7 +72,6 @@
 import android.text.method.TextKeyListener;
 import android.util.Log;
 import android.view.Display;
-import android.view.Gravity;
 import android.view.HapticFeedbackConstants;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -91,7 +90,6 @@
 import android.view.animation.OvershootInterpolator;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Advanceable;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -107,6 +105,7 @@
 import com.android.launcher3.model.WidgetsModel;
 import com.android.launcher3.util.ComponentKey;
 import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.TestingUtils;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.WidgetHostViewLoader;
@@ -200,9 +199,6 @@
     static final String ACTION_FIRST_LOAD_COMPLETE =
             "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
 
-    public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
-    public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
-
     private static final String QSB_WIDGET_ID = "qsb_widget_id";
     private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
 
@@ -240,7 +236,8 @@
     private View mPageIndicators;
     @Thunk DragLayer mDragLayer;
     private DragController mDragController;
-    private View mWeightWatcher;
+
+    public View mWeightWatcher;
 
     private AppWidgetManagerCompat mAppWidgetManager;
     private LauncherAppWidgetHost mAppWidgetHost;
@@ -350,10 +347,9 @@
     protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
             new HashMap<String, CustomAppWidget>();
 
-    private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
     static {
-        if (ENABLE_CUSTOM_WIDGET_TEST) {
-            sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
+        if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
+            TestingUtils.addDummyWidget(sCustomAppWidgets);
         }
     }
 
@@ -425,8 +421,8 @@
         // Load configuration-specific DeviceProfile
         mDeviceProfile = getResources().getConfiguration().orientation
                 == Configuration.ORIENTATION_LANDSCAPE ?
-                        app.getInvariantDeviceProfile().landscapeProfile
-                            : app.getInvariantDeviceProfile().portraitProfile;
+                app.getInvariantDeviceProfile().landscapeProfile
+                : app.getInvariantDeviceProfile().portraitProfile;
 
         mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
                 Context.MODE_PRIVATE);
@@ -1453,19 +1449,8 @@
             mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
         }
 
-        if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
-            Log.v(TAG, "adding WeightWatcher");
-            mWeightWatcher = new WeightWatcher(this);
-            mWeightWatcher.setAlpha(0.5f);
-            ((FrameLayout) mLauncherView).addView(mWeightWatcher,
-                    new FrameLayout.LayoutParams(
-                            FrameLayout.LayoutParams.MATCH_PARENT,
-                            FrameLayout.LayoutParams.WRAP_CONTENT,
-                            Gravity.BOTTOM)
-            );
-
-            boolean show = shouldShowWeightWatcher();
-            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
+        if (TestingUtils.MEMORY_DUMP_ENABLED) {
+            TestingUtils.addWeightWatcher(this);
         }
     }
 
@@ -2413,11 +2398,13 @@
             }
         } else if (itemInfo instanceof LauncherAppWidgetInfo) {
             final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
-            unbindAppWidget(widgetInfo, deleteFromDb);
             mWorkspace.removeWorkspaceItem(v);
+            removeWidgetToAutoAdvance(widgetInfo.hostView);
+            widgetInfo.hostView = null;
             if (deleteFromDb) {
-                LauncherModel.deleteItemFromDatabase(this, widgetInfo);
+                deleteWidgetInfo(widgetInfo);
             }
+
         } else {
             return false;
         }
@@ -2432,12 +2419,11 @@
     }
 
     /**
-     * Unbinds any launcher references to the widget and deletes the app widget id.
+     * Deletes the widget info and the widget id.
      */
-    private void unbindAppWidget(final LauncherAppWidgetInfo widgetInfo, boolean deleteAppWidgetId) {
+    private void deleteWidgetInfo(final LauncherAppWidgetInfo widgetInfo) {
         final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
-        if (deleteAppWidgetId && appWidgetHost != null &&
-                !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
+        if (appWidgetHost != null && !widgetInfo.isCustomWidget() && widgetInfo.isWidgetIdValid()) {
             // Deleting an app widget ID is a void call but writes to disk before returning
             // to the caller...
             new AsyncTask<Void, Void, Void>() {
@@ -2447,8 +2433,7 @@
                 }
             }.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
         }
-        removeWidgetToAutoAdvance(widgetInfo.hostView);
-        widgetInfo.hostView = null;
+        LauncherModel.deleteItemFromDatabase(this, widgetInfo);
     }
 
     @Override
@@ -2673,21 +2658,6 @@
             return;
         }
 
-        final Intent intent = shortcut.intent;
-
-        // Check for special shortcuts
-        if (intent.getComponent() != null) {
-            final String shortcutClass = intent.getComponent().getClassName();
-
-            if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
-                MemoryDumpActivity.startDump(this);
-                return;
-            } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
-                toggleShowWeightWatcher();
-                return;
-            }
-        }
-
         // Check for abandoned promise
         if ((v instanceof BubbleTextView)
                 && shortcut.isPromise()
@@ -3561,6 +3531,28 @@
             opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                     AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX);
 
+            // Determine the min and max dimensions of the widget.
+            LauncherAppState app = LauncherAppState.getInstance();
+            DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile;
+            DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile;
+            float density = getResources().getDisplayMetrics().density;
+            Rect searchBounds = portraitProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
+            int maxHeight = (int) (searchBounds.height() / density);
+            int minHeight = maxHeight;
+            int maxWidth = (int) (searchBounds.width() / density);
+            int minWidth = maxWidth;
+            if (!landscapeProfile.isVerticalBarLayout()) {
+                searchBounds = landscapeProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
+                maxHeight = (int) Math.max(maxHeight, searchBounds.height() / density);
+                minHeight = (int) Math.min(minHeight, searchBounds.height() / density);
+                maxWidth = (int) Math.max(maxWidth, searchBounds.width() / density);
+                minWidth = (int) Math.min(minWidth, searchBounds.width() / density);
+            }
+            opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight);
+            opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight);
+            opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth);
+            opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth);
+
             SharedPreferences sp = getSharedPreferences(
                     LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
             int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
@@ -3758,30 +3750,6 @@
         }
     }
 
-    private boolean shouldShowWeightWatcher() {
-        String spKey = LauncherAppState.getSharedPreferencesKey();
-        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
-        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
-
-        return show;
-    }
-
-    private void toggleShowWeightWatcher() {
-        String spKey = LauncherAppState.getSharedPreferencesKey();
-        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
-        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
-
-        show = !show;
-
-        SharedPreferences.Editor editor = sp.edit();
-        editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
-        editor.commit();
-
-        if (mWeightWatcher != null) {
-            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
-        }
-    }
-
     public void bindAppsAdded(final ArrayList<Long> newScreens,
                               final ArrayList<ItemInfo> addNotAnimated,
                               final ArrayList<ItemInfo> addAnimated,
@@ -4034,6 +4002,15 @@
                         + appWidgetInfo.provider);
             }
 
+            // Verify that we own the widget
+            AppWidgetProviderInfo info = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+            if (info == null || appWidgetInfo == null ||
+                    !info.provider.equals(appWidgetInfo.provider)) {
+                Log.e(TAG, "Removing invalid widget: id=" + item.appWidgetId);
+                deleteWidgetInfo(item);
+                return;
+            }
+
             item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
             item.minSpanX = appWidgetInfo.minSpanX;
             item.minSpanY = appWidgetInfo.minSpanY;
@@ -4178,10 +4155,18 @@
         return mDeviceProfile.isVerticalBarLayout();
     }
 
+    /** Returns the search bar bounds in pixels. */
     protected Rect getSearchBarBounds() {
         return mDeviceProfile.getSearchBarBounds(Utilities.isRtl(getResources()));
     }
 
+    public int getSearchBarHeight() {
+        if (mLauncherCallbacks != null) {
+            return mLauncherCallbacks.getSearchBarHeight();
+        }
+        return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
+    }
+
     public void bindSearchProviderChanged() {
         if (mSearchDropTargetBar == null) {
             return;
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index d87ad67..f75b33c 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -27,6 +27,7 @@
 import com.android.launcher3.compat.LauncherAppsCompat;
 import com.android.launcher3.compat.PackageInstallerCompat;
 import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.TestingUtils;
 import com.android.launcher3.util.Thunk;
 
 import java.lang.ref.WeakReference;
@@ -79,8 +80,8 @@
 
         Log.v(Launcher.TAG, "LauncherAppState inited");
 
-        if (sContext.getResources().getBoolean(R.bool.debug_memory_enabled)) {
-            MemoryTracker.startTrackingMe(sContext, "L");
+        if (TestingUtils.MEMORY_DUMP_ENABLED) {
+            TestingUtils.startTrackingMemory(sContext);
         }
 
         mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
diff --git a/src/com/android/launcher3/LauncherAppWidgetHost.java b/src/com/android/launcher3/LauncherAppWidgetHost.java
index 6c3a1e8..28c5eac 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHost.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHost.java
@@ -125,5 +125,8 @@
         LauncherAppWidgetProviderInfo info = LauncherAppWidgetProviderInfo.fromProviderInfo(
                 mLauncher, appWidget);
         super.onProviderChanged(appWidgetId, info);
+        // The super method updates the dimensions of the providerInfo. Update the
+        // launcher spans accordingly.
+        info.initSpans();
     }
 }
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index 71a08a8..28d8052 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -59,7 +59,7 @@
         initSpans();
     }
 
-    private void initSpans() {
+    public void initSpans() {
         LauncherAppState app = LauncherAppState.getInstance();
         InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
 
diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java
index e34bd57..927db22 100644
--- a/src/com/android/launcher3/LauncherCallbacks.java
+++ b/src/com/android/launcher3/LauncherCallbacks.java
@@ -99,6 +99,9 @@
     public boolean isLauncherPreinstalled();
     public AllAppsSearchBarController getAllAppsSearchBarController();
     public List<ComponentKey> getPredictedApps();
+    public static final int SEARCH_BAR_HEIGHT_NORMAL = 0, SEARCH_BAR_HEIGHT_TALL = 1;
+    /** Must return one of {@link #SEARCH_BAR_HEIGHT_NORMAL} or {@link #SEARCH_BAR_HEIGHT_TALL} */
+    public int getSearchBarHeight();
 
     /**
      * Returning true will immediately result in a call to {@link #setLauncherOverlayView(ViewGroup,
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 8791e9e..a6fd282 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -331,10 +331,6 @@
         return mOpenHelper.generateNewItemId();
     }
 
-    public void updateMaxItemId(long id) {
-        mOpenHelper.updateMaxItemId(id);
-    }
-
     public long generateNewScreenId() {
         return mOpenHelper.generateNewScreenId();
     }
@@ -488,6 +484,16 @@
             mContext = context;
             mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
 
+            // Table creation sometimes fails silently, which leads to a crash loop.
+            // This way, we will try to create a table every time after crash, so the device
+            // would eventually be able to recover.
+            if (!tableExists(TABLE_FAVORITES) || !tableExists(TABLE_WORKSPACE_SCREENS)) {
+                Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
+                // This operation is a no-op if the table already exists.
+                addFavoritesTable(getWritableDatabase(), true);
+                addWorkspacesTable(getWritableDatabase(), true);
+            }
+
             // In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
             // the DB here
             if (mMaxItemId == -1) {
@@ -498,6 +504,18 @@
             }
         }
 
+        private boolean tableExists(String tableName) {
+            Cursor c = getReadableDatabase().query(
+                    true, "sqlite_master", new String[] {"tbl_name"},
+                    "tbl_name = ?", new String[] {tableName},
+                    null, null, null, null, null);
+            try {
+                return c.getCount() > 0;
+            } finally {
+                c.close();
+            }
+        }
+
         public boolean wasNewDbCreated() {
             return mNewDbCreated;
         }
@@ -510,37 +528,8 @@
             mMaxScreenId = 0;
             mNewDbCreated = true;
 
-            UserManagerCompat userManager = UserManagerCompat.getInstance(mContext);
-            long userSerialNumber = userManager.getSerialNumberForUser(
-                    UserHandleCompat.myUserHandle());
-
-            db.execSQL("CREATE TABLE favorites (" +
-                    "_id INTEGER PRIMARY KEY," +
-                    "title TEXT," +
-                    "intent TEXT," +
-                    "container INTEGER," +
-                    "screen INTEGER," +
-                    "cellX INTEGER," +
-                    "cellY INTEGER," +
-                    "spanX INTEGER," +
-                    "spanY INTEGER," +
-                    "itemType INTEGER," +
-                    "appWidgetId INTEGER NOT NULL DEFAULT -1," +
-                    "isShortcut INTEGER," +
-                    "iconType INTEGER," +
-                    "iconPackage TEXT," +
-                    "iconResource TEXT," +
-                    "icon BLOB," +
-                    "uri TEXT," +
-                    "displayMode INTEGER," +
-                    "appWidgetProvider TEXT," +
-                    "modified INTEGER NOT NULL DEFAULT 0," +
-                    "restored INTEGER NOT NULL DEFAULT 0," +
-                    "profileId INTEGER DEFAULT " + userSerialNumber + "," +
-                    "rank INTEGER NOT NULL DEFAULT 0," +
-                    "options INTEGER NOT NULL DEFAULT 0" +
-                    ");");
-            addWorkspacesTable(db);
+            addFavoritesTable(db, false);
+            addWorkspacesTable(db, false);
 
             // Database was just created, so wipe any previous widgets
             if (mAppWidgetHost != null) {
@@ -571,8 +560,43 @@
             ManagedProfileHeuristic.processAllUsers(Collections.<UserHandleCompat>emptyList(), mContext);
         }
 
-        private void addWorkspacesTable(SQLiteDatabase db) {
-            db.execSQL("CREATE TABLE " + TABLE_WORKSPACE_SCREENS + " (" +
+        private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
+            UserManagerCompat userManager = UserManagerCompat.getInstance(mContext);
+            long userSerialNumber = userManager.getSerialNumberForUser(
+                    UserHandleCompat.myUserHandle());
+            String ifNotExists = optional ? " IF NOT EXISTS " : "";
+
+            db.execSQL("CREATE TABLE " + ifNotExists + TABLE_FAVORITES + " (" +
+                    "_id INTEGER PRIMARY KEY," +
+                    "title TEXT," +
+                    "intent TEXT," +
+                    "container INTEGER," +
+                    "screen INTEGER," +
+                    "cellX INTEGER," +
+                    "cellY INTEGER," +
+                    "spanX INTEGER," +
+                    "spanY INTEGER," +
+                    "itemType INTEGER," +
+                    "appWidgetId INTEGER NOT NULL DEFAULT -1," +
+                    "isShortcut INTEGER," +
+                    "iconType INTEGER," +
+                    "iconPackage TEXT," +
+                    "iconResource TEXT," +
+                    "icon BLOB," +
+                    "uri TEXT," +
+                    "displayMode INTEGER," +
+                    "appWidgetProvider TEXT," +
+                    "modified INTEGER NOT NULL DEFAULT 0," +
+                    "restored INTEGER NOT NULL DEFAULT 0," +
+                    "profileId INTEGER DEFAULT " + userSerialNumber + "," +
+                    "rank INTEGER NOT NULL DEFAULT 0," +
+                    "options INTEGER NOT NULL DEFAULT 0" +
+                    ");");
+        }
+
+        private void addWorkspacesTable(SQLiteDatabase db, boolean optional) {
+            String ifNotExists = optional ? " IF NOT EXISTS " : "";
+            db.execSQL("CREATE TABLE " + ifNotExists + TABLE_WORKSPACE_SCREENS + " (" +
                     LauncherSettings.WorkspaceScreens._ID + " INTEGER PRIMARY KEY," +
                     LauncherSettings.WorkspaceScreens.SCREEN_RANK + " INTEGER," +
                     LauncherSettings.ChangeLogColumns.MODIFIED + " INTEGER NOT NULL DEFAULT 0" +
@@ -632,7 +656,7 @@
                     // With the new shrink-wrapped and re-orderable workspaces, it makes sense
                     // to persist workspace screens and their relative order.
                     mMaxScreenId = 0;
-                    addWorkspacesTable(db);
+                    addWorkspacesTable(db, false);
                 }
                 case 13: {
                     db.beginTransaction();
@@ -828,7 +852,7 @@
                 }
 
                 db.execSQL("DROP TABLE IF EXISTS " + TABLE_WORKSPACE_SCREENS);
-                addWorkspacesTable(db);
+                addWorkspacesTable(db, false);
 
                 // Add all screen ids back
                 int total = sortedIDs.size();
@@ -926,10 +950,6 @@
             return dbInsertAndCheck(this, db, TABLE_FAVORITES, null, values);
         }
 
-        public void updateMaxItemId(long id) {
-            mMaxItemId = id + 1;
-        }
-
         public void checkId(String table, ContentValues values) {
             long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID);
             if (table == LauncherProvider.TABLE_WORKSPACE_SCREENS) {
diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java
index e8c11c4..1c6ca87 100644
--- a/src/com/android/launcher3/LauncherRootView.java
+++ b/src/com/android/launcher3/LauncherRootView.java
@@ -1,17 +1,42 @@
 package com.android.launcher3;
 
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
 import android.graphics.Rect;
 import android.util.AttributeSet;
 
 public class LauncherRootView extends InsettableFrameLayout {
+
+    private final Paint mOpaquePaint;
+    private boolean mDrawRightInsetBar;
+
     public LauncherRootView(Context context, AttributeSet attrs) {
         super(context, attrs);
+
+        mOpaquePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+        mOpaquePaint.setColor(Color.BLACK);
+        mOpaquePaint.setStyle(Paint.Style.FILL);
     }
 
     @Override
     protected boolean fitSystemWindows(Rect insets) {
         setInsets(insets);
+        mDrawRightInsetBar = mInsets.right > 0 && LauncherAppState
+                .getInstance().getInvariantDeviceProfile().isRightInsetOpaque;
+
         return true; // I'll take it from here
     }
+
+    @Override
+    protected void dispatchDraw(Canvas canvas) {
+        super.dispatchDraw(canvas);
+
+        // If the right inset is opaque, draw a black rectangle to ensure that is stays opaque.
+        if (mDrawRightInsetBar) {
+            int width = getWidth();
+            canvas.drawRect(width - mInsets.right, 0, width, getHeight(), mOpaquePaint);
+        }
+    }
 }
\ No newline at end of file
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 05f0a05..2579ea3 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -202,6 +202,9 @@
     protected final Rect mInsets = new Rect();
     protected final boolean mIsRtl;
 
+    // When set to true, full screen content and overscroll effect is shited inside by right inset.
+    protected boolean mIgnoreRightInset;
+
     // Edge effect
     private final LauncherEdgeEffect mEdgeGlowLeft = new LauncherEdgeEffect();
     private final LauncherEdgeEffect mEdgeGlowRight = new LauncherEdgeEffect();
@@ -819,7 +822,8 @@
                     childWidthMode = MeasureSpec.EXACTLY;
                     childHeightMode = MeasureSpec.EXACTLY;
 
-                    childWidth = getViewportWidth() - mInsets.left - mInsets.right;
+                    childWidth = getViewportWidth() - mInsets.left
+                            - (mIgnoreRightInset ? mInsets.right : 0);
                     childHeight = getViewportHeight();
                 }
                 if (referenceChildWidth == 0) {
@@ -1177,8 +1181,10 @@
                 canvas.rotate(90);
 
                 getEdgeVerticalPostion(sTmpIntPoint);
-                canvas.translate(sTmpIntPoint[0] - display.top, -display.width());
-                mEdgeGlowRight.setSize(sTmpIntPoint[1] - sTmpIntPoint[0], display.width());
+
+                int width = mIgnoreRightInset ? (display.width() - mInsets.right) : display.width();
+                canvas.translate(sTmpIntPoint[0] - display.top, -width);
+                mEdgeGlowRight.setSize(sTmpIntPoint[1] - sTmpIntPoint[0], width);
                 if (mEdgeGlowRight.draw(canvas)) {
                     postInvalidateOnAnimation();
                 }
diff --git a/src/com/android/launcher3/ToggleWeightWatcher.java b/src/com/android/launcher3/ToggleWeightWatcher.java
deleted file mode 100644
index 33701a2..0000000
--- a/src/com/android/launcher3/ToggleWeightWatcher.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.android.launcher3;
-
-import android.app.Activity;
-
-public class ToggleWeightWatcher extends Activity {
-
-}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 8d70c0b..89d1ab4 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -455,6 +455,7 @@
         setWallpaperDimension();
 
         setEdgeGlowColor(getResources().getColor(R.color.workspace_edge_effect_color));
+        mIgnoreRightInset = app.getInvariantDeviceProfile().isRightInsetOpaque;
     }
 
     private void setupLayoutTransition() {
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 3ad5101..6424e03 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -107,7 +107,7 @@
         @Override
         public void onProgressChanged(int sessionId, float progress) {
             SessionInfo session = mInstaller.getSessionInfo(sessionId);
-            if (session != null) {
+            if (session != null && session.getAppPackageName() != null) {
                 sendUpdate(new PackageInstallInfo(session.getAppPackageName(),
                         STATUS_INSTALLING,
                         (int) (session.getProgress() * 100)));
@@ -124,7 +124,7 @@
 
         private void pushSessionDisplayToLauncher(int sessionId) {
             SessionInfo session = mInstaller.getSessionInfo(sessionId);
-            if (session != null) {
+            if (session != null && session.getAppPackageName() != null) {
                 addSessionInfoToCahce(session, UserHandleCompat.myUserHandle());
                 LauncherAppState app = LauncherAppState.getInstanceNoCreate();
 
diff --git a/src/com/android/launcher3/DummyWidget.java b/src/com/android/launcher3/testing/DummyWidget.java
similarity index 82%
rename from src/com/android/launcher3/DummyWidget.java
rename to src/com/android/launcher3/testing/DummyWidget.java
index 59cd805..df887ac 100644
--- a/src/com/android/launcher3/DummyWidget.java
+++ b/src/com/android/launcher3/testing/DummyWidget.java
@@ -1,7 +1,10 @@
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.appwidget.AppWidgetProviderInfo;
 
+import com.android.launcher3.CustomAppWidget;
+import com.android.launcher3.R;
+
 public class DummyWidget implements CustomAppWidget {
     @Override
     public String getLabel() {
@@ -20,7 +23,7 @@
 
     @Override
     public int getWidgetLayout() {
-        return R.layout.dummy_widget;
+        return R.layout.zzz_dummy_widget;
     }
 
     @Override
diff --git a/src/com/android/launcher3/testing/LauncherExtension.java b/src/com/android/launcher3/testing/LauncherExtension.java
index dac279a..3364fcc 100644
--- a/src/com/android/launcher3/testing/LauncherExtension.java
+++ b/src/com/android/launcher3/testing/LauncherExtension.java
@@ -303,6 +303,11 @@
         }
 
         @Override
+        public int getSearchBarHeight() {
+            return SEARCH_BAR_HEIGHT_NORMAL;
+        }
+
+        @Override
         public boolean isLauncherPreinstalled() {
             return false;
         }
diff --git a/src/com/android/launcher3/MemoryDumpActivity.java b/src/com/android/launcher3/testing/MemoryDumpActivity.java
similarity index 93%
rename from src/com/android/launcher3/MemoryDumpActivity.java
rename to src/com/android/launcher3/testing/MemoryDumpActivity.java
index d79be80..9bcf92b 100644
--- a/src/com/android/launcher3/MemoryDumpActivity.java
+++ b/src/com/android/launcher3/testing/MemoryDumpActivity.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.app.Activity;
 import android.content.ComponentName;
@@ -23,10 +23,20 @@
 import android.content.ServiceConnection;
 import android.content.pm.PackageManager;
 import android.net.Uri;
-import android.os.*;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.IBinder;
 import android.util.Log;
 
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.zip.ZipEntry;
diff --git a/src/com/android/launcher3/MemoryTracker.java b/src/com/android/launcher3/testing/MemoryTracker.java
similarity index 92%
rename from src/com/android/launcher3/MemoryTracker.java
rename to src/com/android/launcher3/testing/MemoryTracker.java
index 067a50f..ed2a312 100644
--- a/src/com/android/launcher3/MemoryTracker.java
+++ b/src/com/android/launcher3/testing/MemoryTracker.java
@@ -14,22 +14,28 @@
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.app.ActivityManager;
 import android.app.Service;
 import android.content.Context;
 import android.content.Intent;
-import android.os.*;
+import android.os.Binder;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.SystemClock;
 import android.util.Log;
 import android.util.LongSparseArray;
 
+import com.android.launcher3.util.TestingUtils;
+
 import java.util.ArrayList;
 import java.util.List;
 
 public class MemoryTracker extends Service {
     public static final String TAG = MemoryTracker.class.getSimpleName();
-    public static final String ACTION_START_TRACKING = "com.android.launcher3.action.START_TRACKING";
 
     private static final long UPDATE_RATE = 5000;
 
@@ -83,14 +89,6 @@
 
     ActivityManager mAm;
 
-    public static void startTrackingMe(Context context, String name) {
-        context.startService(new Intent(context, MemoryTracker.class)
-                .setAction(MemoryTracker.ACTION_START_TRACKING)
-                .putExtra("pid", android.os.Process.myPid())
-                .putExtra("name", name)
-        );
-    }
-
     public ProcessMemInfo getMemInfo(int pid) {
         return mData.get(pid);
     }
@@ -190,7 +188,7 @@
         Log.v(TAG, "Received start id " + startId + ": " + intent);
 
         if (intent != null) {
-            if (ACTION_START_TRACKING.equals(intent.getAction())) {
+            if (TestingUtils.ACTION_START_TRACKING.equals(intent.getAction())) {
                 final int pid = intent.getIntExtra("pid", -1);
                 final String name = intent.getStringExtra("name");
                 final long start = intent.getLongExtra("start", System.currentTimeMillis());
diff --git a/src/com/android/launcher3/testing/ToggleWeightWatcher.java b/src/com/android/launcher3/testing/ToggleWeightWatcher.java
new file mode 100644
index 0000000..15e55ee
--- /dev/null
+++ b/src/com/android/launcher3/testing/ToggleWeightWatcher.java
@@ -0,0 +1,32 @@
+package com.android.launcher3.testing;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.View;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.util.TestingUtils;
+
+public class ToggleWeightWatcher extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        String spKey = LauncherAppState.getSharedPreferencesKey();
+        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
+        boolean show = sp.getBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, true);
+
+        show = !show;
+        sp.edit().putBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, show).apply();
+
+        Launcher launcher = (Launcher) LauncherAppState.getInstance().getModel().getCallback();
+        if (launcher != null && launcher.mWeightWatcher != null) {
+            launcher.mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
+        }
+        finish();
+    }
+}
diff --git a/src/com/android/launcher3/WeightWatcher.java b/src/com/android/launcher3/testing/WeightWatcher.java
similarity index 98%
rename from src/com/android/launcher3/WeightWatcher.java
rename to src/com/android/launcher3/testing/WeightWatcher.java
index 7568479..a26a2b6 100644
--- a/src/com/android/launcher3/WeightWatcher.java
+++ b/src/com/android/launcher3/testing/WeightWatcher.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.content.ComponentName;
 import android.content.Context;
@@ -116,10 +116,6 @@
         }
     }
 
-    public WeightWatcher(Context context) {
-        this(context, null);
-    }
-
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
diff --git a/src/com/android/launcher3/util/TestingUtils.java b/src/com/android/launcher3/util/TestingUtils.java
new file mode 100644
index 0000000..39b8046
--- /dev/null
+++ b/src/com/android/launcher3/util/TestingUtils.java
@@ -0,0 +1,73 @@
+package com.android.launcher3.util;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import com.android.launcher3.CustomAppWidget;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.R;
+
+import java.util.HashMap;
+
+public class TestingUtils {
+
+    public static final String MEMORY_TRACKER = "com.android.launcher3.testing.MemoryTracker";
+    public static final String ACTION_START_TRACKING = "com.android.launcher3.action.START_TRACKING";
+
+    public static final boolean MEMORY_DUMP_ENABLED = false;
+    public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
+
+    public static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
+    public static final String DUMMY_WIDGET = "com.android.launcher3.testing.DummyWidget";
+
+    public static void startTrackingMemory(Context context) {
+        if (MEMORY_DUMP_ENABLED) {
+            context.startService(new Intent()
+                .setComponent(new ComponentName(context.getPackageName(), MEMORY_TRACKER))
+                .setAction(ACTION_START_TRACKING)
+                .putExtra("pid", android.os.Process.myPid())
+                .putExtra("name", "L"));
+        }
+    }
+
+    public static void addWeightWatcher(Launcher launcher) {
+        if (MEMORY_DUMP_ENABLED) {
+            String spKey = LauncherAppState.getSharedPreferencesKey();
+            SharedPreferences sp = launcher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+            boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
+
+            int id = launcher.getResources().getIdentifier("zzz_weight_watcher", "layout",
+                    launcher.getPackageName());
+            View watcher = launcher.getLayoutInflater().inflate(id, null);
+            watcher.setAlpha(0.5f);
+            ((FrameLayout) launcher.findViewById(R.id.launcher)).addView(watcher,
+                    new FrameLayout.LayoutParams(
+                            FrameLayout.LayoutParams.MATCH_PARENT,
+                            FrameLayout.LayoutParams.WRAP_CONTENT,
+                            Gravity.BOTTOM)
+            );
+
+            watcher.setVisibility(show ? View.VISIBLE : View.GONE);
+            launcher.mWeightWatcher = watcher;
+        }
+    }
+
+    public static void addDummyWidget(HashMap<String, CustomAppWidget> set) {
+        if (ENABLE_CUSTOM_WIDGET_TEST) {
+            try {
+                Class<?> clazz = Class.forName(DUMMY_WIDGET);
+                CustomAppWidget widget = (CustomAppWidget) clazz.newInstance();
+                set.put(widget.getClass().getName(), widget);
+            } catch (Exception e) {
+                Log.e("TestingUtils", "Error adding dummy widget", e);
+            }
+        }
+    }
+}