Merge "Auto-stash taskbar when locking device" into tm-qpr-dev
diff --git a/quickstep/res/layout/taskbar_edu_tooltip.xml b/quickstep/res/layout/taskbar_edu_tooltip.xml
index 29f4956..3fcd713 100644
--- a/quickstep/res/layout/taskbar_edu_tooltip.xml
+++ b/quickstep/res/layout/taskbar_edu_tooltip.xml
@@ -21,6 +21,8 @@
     android:clipChildren="false"
     android:clipToPadding="false"
     android:fitsSystemWindows="true"
+    android:focusable="true"
+    android:importantForAccessibility="yes"
     android:gravity="center"
     android:orientation="vertical">
 
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
index 77a9d78..e27e979 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
@@ -30,8 +30,7 @@
 import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_FULLSCREEN;
 import static com.android.launcher3.taskbar.TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW;
 import static com.android.launcher3.testing.shared.ResourceUtils.getBoolByName;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING;
 
 import android.animation.AnimatorSet;
@@ -571,9 +570,8 @@
     public void updateSysuiStateFlags(int systemUiStateFlags, boolean fromInit) {
         mControllers.navbarButtonsViewController.updateStateForSysuiFlags(systemUiStateFlags,
                 fromInit);
-        int shadeExpandedFlags = SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED
-                | SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
-        onNotificationShadeExpandChanged((systemUiStateFlags & shadeExpandedFlags) != 0, fromInit);
+        boolean isShadeVisible = (systemUiStateFlags & SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE) != 0;
+        onNotificationShadeExpandChanged(isShadeVisible, fromInit);
         mControllers.taskbarViewController.setRecentsButtonDisabled(
                 mControllers.navbarButtonsViewController.isRecentsDisabled()
                         || isNavBarKidsModeActive());
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt
index bc582e2..e56e258 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarEduTooltipController.kt
@@ -17,10 +17,13 @@
 
 import android.graphics.PorterDuff.Mode.SRC_ATOP
 import android.graphics.PorterDuffColorFilter
+import android.os.Bundle
 import android.view.View
 import android.view.View.GONE
 import android.view.View.VISIBLE
 import android.view.ViewGroup
+import android.view.accessibility.AccessibilityEvent
+import android.view.accessibility.AccessibilityNodeInfo
 import androidx.annotation.IntDef
 import androidx.annotation.LayoutRes
 import com.airbnb.lottie.LottieAnimationView
@@ -153,6 +156,7 @@
             FLAG_AUTOHIDE_SUSPEND_EDU_OPEN,
             true
         )
+
         tooltip.onCloseCallback = {
             this.tooltip = null
             controllers.taskbarAutohideSuspendController.updateFlag(
@@ -161,11 +165,47 @@
             )
             controllers.taskbarStashController.updateAndAnimateTransientTaskbar(true)
         }
+        tooltip.accessibilityDelegate = createAccessibilityDelegate()
 
         overlayContext.layoutInflater.inflate(contentResId, tooltip.content, true)
         this.tooltip = tooltip
     }
 
+    private fun createAccessibilityDelegate() =
+        object : View.AccessibilityDelegate() {
+            override fun performAccessibilityAction(
+                host: View?,
+                action: Int,
+                args: Bundle?
+            ): Boolean {
+                if (action == R.id.close) {
+                    hide()
+                    return true
+                }
+                return super.performAccessibilityAction(host, action, args)
+            }
+
+            override fun onPopulateAccessibilityEvent(host: View?, event: AccessibilityEvent?) {
+                super.onPopulateAccessibilityEvent(host, event)
+                if (event?.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
+                    event.text?.add(host?.context?.getText(R.string.taskbar_edu_a11y_title))
+                }
+            }
+
+            override fun onInitializeAccessibilityNodeInfo(
+                host: View?,
+                info: AccessibilityNodeInfo?
+            ) {
+                super.onInitializeAccessibilityNodeInfo(host, info)
+                info?.addAction(
+                    AccessibilityNodeInfo.AccessibilityAction(
+                        R.id.close,
+                        host?.context?.getText(R.string.taskbar_edu_close)
+                    )
+                )
+            }
+        }
+
     override fun dumpLogs(prefix: String?, pw: PrintWriter?) {
         pw?.println(prefix + "TaskbarEduTooltipController:")
         pw?.println("$prefix\tisTooltipEnabled=$isTooltipEnabled")
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java
index 0ed4538..cfc7813 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarPopupController.java
@@ -201,14 +201,12 @@
 
     // Create a Stream of all applicable system shortcuts
     private Stream<SystemShortcut.Factory> getSystemShortcuts() {
-        // concat a Stream of split options with a Stream of APP_INFO
-        Stream<SystemShortcut.Factory> appInfo = Stream.of(APP_INFO);
-
+        // append split options to APP_INFO shortcut, the order here will reflect in the popup
         return Stream.concat(
+                Stream.of(APP_INFO),
                 Utilities.getSplitPositionOptions(mContext.getDeviceProfile())
                         .stream()
-                        .map(this::createSplitShortcutFactory),
-                appInfo
+                        .map(this::createSplitShortcutFactory)
         );
     }
 
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
index 123d7a1..1e1769c 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
@@ -32,8 +32,7 @@
 import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SHOWING;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_IME_SWITCHER_SHOWING;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
 
 import android.animation.Animator;
@@ -910,8 +909,7 @@
         long startDelay = 0;
 
         updateStateForFlag(FLAG_STASHED_IN_APP_SYSUI, hasAnyFlag(systemUiStateFlags,
-                SYSUI_STATE_QUICK_SETTINGS_EXPANDED
-                        | SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED));
+                SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE));
         updateStateForFlag(FLAG_STASHED_SYSUI,
                 hasAnyFlag(systemUiStateFlags, SYSUI_STATE_SCREEN_PINNING));
 
diff --git a/res/values/id.xml b/res/values/id.xml
index dc81944..7b812de 100644
--- a/res/values/id.xml
+++ b/res/values/id.xml
@@ -28,6 +28,7 @@
     <item type="id" name="home" />
     <item type="id" name="recent_apps" />
     <item type="id" name="back" />
+    <item type="id" name="close"/>
     <item type="id" name="ime_switcher" />
     <item type="id" name="accessibility_button" />
     <item type="id" name="rotate_suggestion" />
@@ -41,4 +42,5 @@
 
     <item type="id" name="saved_floating_widget_foreground" />
     <item type="id" name="saved_floating_widget_background" />
+
 </resources>
diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
index 2c8f1f3..ae5d8d4 100644
--- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
+++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java
@@ -66,6 +66,9 @@
 
     private static final String KEY_SURFACE_PACKAGE = "surface_package";
     private static final String KEY_CALLBACK = "callback";
+    public static final String KEY_HIDE_BOTTOM_ROW = "hide_bottom_row";
+
+    private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337;
 
     private final ArrayMap<IBinder, PreviewLifecycleObserver> mActivePreviews = new ArrayMap<>();
 
@@ -79,7 +82,7 @@
             String[] selectionArgs, String sortOrder) {
         switch (uri.getPath()) {
             case KEY_LIST_OPTIONS: {
-                MatrixCursor cursor = new MatrixCursor(new String[] {
+                MatrixCursor cursor = new MatrixCursor(new String[]{
                         KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT});
                 InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext());
                 for (GridOption gridOption : idp.parseAllGridOptions(getContext())) {
@@ -95,7 +98,7 @@
             }
             case GET_ICON_THEMED:
             case ICON_THEMED: {
-                MatrixCursor cursor = new MatrixCursor(new String[] {BOOLEAN_VALUE});
+                MatrixCursor cursor = new MatrixCursor(new String[]{BOOLEAN_VALUE});
                 cursor.newRow().add(BOOLEAN_VALUE, isThemedIconEnabled(getContext()) ? 1 : 0);
                 return cursor;
             }
@@ -224,7 +227,14 @@
 
         @Override
         public boolean handleMessage(Message message) {
-            destroyObserver(this);
+            if (destroyed) {
+                return true;
+            }
+            if (message.what == MESSAGE_ID_UPDATE_PREVIEW) {
+                renderer.hideBottomRow(message.getData().getBoolean(KEY_HIDE_BOTTOM_ROW));
+            } else {
+                destroyObserver(this);
+            }
             return true;
         }
 
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index b061f8f..7f49aa9 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -344,6 +344,25 @@
         return mHotseat;
     }
 
+    /**
+     * Hides the components in the bottom row.
+     *
+     * @param hide True to hide and false to show.
+     */
+    public void hideBottomRow(boolean hide) {
+        mUiHandler.post(() -> {
+            if (mDp.isTaskbarPresent) {
+                // hotseat icons on bottom
+                mHotseat.setIconsAlpha(hide ? 0 : 1);
+                if (mDp.isQsbInline) {
+                    mHotseat.setQsbAlpha(hide ? 0 : 1);
+                }
+            } else {
+                mHotseat.setQsbAlpha(hide ? 0 : 1);
+            }
+        });
+    }
+
     @Override
     public CellLayout getScreenWithId(int screenId) {
         return mWorkspaceScreens.get(screenId);
diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
index 85c0a7a..0767e69 100644
--- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
+++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
@@ -87,6 +87,8 @@
     private final SurfaceControlViewHost mSurfaceControlViewHost;
 
     private boolean mDestroyed = false;
+    private LauncherPreviewRenderer mRenderer;
+    private boolean mHideQsb;
 
     public PreviewSurfaceRenderer(Context context, Bundle bundle) throws Exception {
         mContext = context;
@@ -97,6 +99,7 @@
             gridName = InvariantDeviceProfile.getCurrentGridName(context);
         }
         mWallpaperColors = bundle.getParcelable(KEY_COLORS);
+        mHideQsb = bundle.getBoolean(GridCustomizationsProvider.KEY_HIDE_BOTTOM_ROW);
         mIdp = new InvariantDeviceProfile(context, gridName);
 
         mHostToken = bundle.getBinder(KEY_HOST_TOKEN);
@@ -174,6 +177,17 @@
         MODEL_EXECUTOR.execute(this::loadModelData);
     }
 
+    /**
+     * Hides the components in the bottom row.
+     *
+     * @param hide True to hide and false to show.
+     */
+    public void hideBottomRow(boolean hide) {
+        if (mRenderer != null) {
+            mRenderer.hideBottomRow(hide);
+        }
+    }
+
     @WorkerThread
     private void loadModelData() {
         final boolean migrated = doGridMigrationIfNecessary();
@@ -209,8 +223,8 @@
                     DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                     String query =
                             LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID
-                            + " or " + LauncherSettings.Favorites.CONTAINER + " = "
-                            + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
+                                    + " or " + LauncherSettings.Favorites.CONTAINER + " = "
+                                    + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                     if (deviceProfile.isTwoPanels) {
                         query += " or " + LauncherSettings.Favorites.SCREEN + " = "
                                 + Workspace.SECOND_SCREEN_ID;
@@ -254,8 +268,10 @@
         if (mDestroyed) {
             return;
         }
-        View view = new LauncherPreviewRenderer(inflationContext, mIdp, mWallpaperColors,
-                launcherWidgetSpanInfo).getRenderedView(dataModel, widgetProviderInfoMap);
+        mRenderer = new LauncherPreviewRenderer(inflationContext, mIdp,
+                mWallpaperColors, launcherWidgetSpanInfo);
+        mRenderer.hideBottomRow(mHideQsb);
+        View view = mRenderer.getRenderedView(dataModel, widgetProviderInfoMap);
         // This aspect scales the view to fit in the surface and centers it
         final float scale = Math.min(mWidth / (float) view.getMeasuredWidth(),
                 mHeight / (float) view.getMeasuredHeight());
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
index 2ffe34f..a917b68 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java
@@ -197,13 +197,13 @@
             return false;
         }
 
+        // order of this list will reflect in the popup
         List<SystemShortcut> systemShortcuts = new ArrayList<>();
-
+        systemShortcuts.add(APP_INFO.getShortcut(mActivity, item, v));
         // Hide redundant pin shortcut for app drawer icons if drag-n-drop is enabled.
         if (!FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN.get() || !mActivity.isAppDrawerShown()) {
             systemShortcuts.add(mPinnedAppsAdapter.getSystemShortcut(item, v));
         }
-        systemShortcuts.add(APP_INFO.getShortcut(mActivity, item, v));
         int deepShortcutCount = popupDataProvider.getShortcutCountForItem(item);
         final PopupContainerWithArrow<SecondaryDisplayLauncher> container;
         if (ENABLE_MATERIAL_U_POPUP.get()) {