Snap for 7704922 from 28325b078277cd02ceb1d3d064727d50f25f7923 to sc-v2-release

Change-Id: I5226ad6e9cdd1cb2a9e7bd7b0220cfe50b4d3306
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index 1ec5bb8..e7de0ac 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -157,7 +157,7 @@
     <dimen name="accessibility_gesture_min_swipe_distance">80dp</dimen>
 
     <!-- Taskbar -->
-    <dimen name="taskbar_size">60dp</dimen>
+    <dimen name="taskbar_size">@*android:dimen/taskbar_frame_height</dimen>
     <dimen name="taskbar_icon_touch_size">48dp</dimen>
     <dimen name="taskbar_icon_drag_icon_size">54dp</dimen>
     <dimen name="taskbar_folder_margin">16dp</dimen>
diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
index acabb0d..b172095 100644
--- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
@@ -16,6 +16,7 @@
 package com.android.launcher3.taskbar;
 
 import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
+import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_APP;
 import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME;
 
 import android.animation.Animator;
@@ -162,10 +163,9 @@
         anim.start();
         mIsAnimatingToLauncherViaResume = isResumed;
 
-        if (!isResumed) {
-            TaskbarStashController stashController = mControllers.taskbarStashController;
-            stashController.animateToIsStashed(stashController.isStashedInApp(), duration);
-        }
+        TaskbarStashController stashController = mControllers.taskbarStashController;
+        stashController.updateStateForFlag(FLAG_IN_APP, !isResumed);
+        stashController.applyState(duration);
         SystemUiProxy.INSTANCE.get(mContext).notifyTaskbarStatus(!isResumed,
                 mControllers.taskbarStashController.isStashedInApp());
     }
@@ -193,8 +193,11 @@
             public void onAnimationStart(Animator animation) {
                 mTargetStateOverride = toState;
                 mIsAnimatingToLauncherViaGesture = true;
-                // TODO: base this on launcher state
-                stashController.animateToIsStashed(false, duration);
+                // TODO: FLAG_IN_APP might be sufficient for now, but in the future we do want to
+                // add another flag for LauncherState as well. We will need to decide whether to
+                // show hotseat or the task bar.
+                stashController.updateStateForFlag(FLAG_IN_APP, false);
+                stashController.applyState(duration);
             }
         });
 
@@ -327,9 +330,8 @@
                     .start();
 
             TaskbarStashController controller = mControllers.taskbarStashController;
-            if (finishedToApp) {
-                controller.animateToIsStashed(controller.isStashedInApp());
-            }
+            controller.updateStateForFlag(FLAG_IN_APP, finishedToApp);
+            controller.applyState();
         }
     }
 }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
index 51d031b..0d684a0 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
@@ -27,6 +27,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.LauncherApps;
+import android.graphics.Insets;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.os.Process;
@@ -167,6 +168,10 @@
                 mWindowLayoutParams,
                 new int[] { ITYPE_EXTRA_NAVIGATION_BAR, ITYPE_BOTTOM_TAPPABLE_ELEMENT }
         );
+        // Adjust the frame by the rounded corners (ie. leaving just the bar as the inset) when
+        // the IME is showing
+        mWindowLayoutParams.providedInternalImeInsets = Insets.of(0,
+                getDefaultTaskbarWindowHeight() - mDeviceProfile.taskbarSize, 0, 0);
 
         // Initialize controllers after all are constructed.
         mControllers.init();
@@ -216,6 +221,14 @@
         return mViewCache;
     }
 
+    @Override
+    public boolean supportsIme() {
+        // Currently we don't support IME because we have FLAG_NOT_FOCUSABLE. We can remove that
+        // flag when opening a floating view that needs IME (such as Folder), but then that means
+        // Taskbar will be below IME and thus users can't click the back button.
+        return false;
+    }
+
     /**
      * Sets a new data-source for this taskbar instance
      */
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
index 1f5ff02..fc277cc 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
@@ -31,12 +31,17 @@
 import com.android.quickstep.AnimatedFloat;
 import com.android.quickstep.SystemUiProxy;
 
+import java.util.function.IntPredicate;
+
 /**
  * Coordinates between controllers such as TaskbarViewController and StashedHandleViewController to
  * create a cohesive animation between stashed/unstashed states.
  */
 public class TaskbarStashController {
 
+    public static final int FLAG_IN_APP = 1 << 0;
+    public static final int FLAG_STASHED_IN_APP = 1 << 1;
+
     /**
      * How long to stash/unstash when manually invoked via long press.
      */
@@ -78,6 +83,9 @@
     private final int mStashedHeight;
     private final int mUnstashedHeight;
 
+    private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder(
+            flags -> (((flags & FLAG_IN_APP) != 0) && (flags & FLAG_STASHED_IN_APP) != 0));
+
     // Initialized in init.
     private TaskbarControllers mControllers;
     // Taskbar background properties.
@@ -94,6 +102,7 @@
     private boolean mIsStashedInApp;
     /** Whether we are currently visually stashed (might change based on launcher state). */
     private boolean mIsStashed = false;
+    private int mState;
 
     private @Nullable AnimatorSet mAnimator;
 
@@ -124,6 +133,7 @@
 
         mIsStashedInApp = supportsStashing()
                 && mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
+        updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
 
         SystemUiProxy.INSTANCE.get(mActivity)
                 .notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
@@ -190,35 +200,19 @@
             return false;
         }
         if (mIsStashedInApp != isStashedInApp) {
-            boolean wasStashed = mIsStashedInApp;
             mIsStashedInApp = isStashedInApp;
             mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, mIsStashedInApp).apply();
-            boolean isStashed = mIsStashedInApp;
-            if (wasStashed != isStashed) {
-                SystemUiProxy.INSTANCE.get(mActivity)
-                        .notifyTaskbarStatus(/* visible */ true, /* stashed */ isStashed);
-                mControllers.uiController.onStashedInAppChanged();
-                createAnimToIsStashed(isStashed, TASKBAR_STASH_DURATION).start();
-                return true;
-            }
+            updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
+            applyState();
+
+            SystemUiProxy.INSTANCE.get(mActivity)
+                    .notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
+            mControllers.uiController.onStashedInAppChanged();
+            return true;
         }
         return false;
     }
 
-    /**
-     * Starts an animation to the new stashed state with a default duration.
-     */
-    public void animateToIsStashed(boolean isStashed) {
-        animateToIsStashed(isStashed, TASKBAR_STASH_DURATION);
-    }
-
-    /**
-     * Starts an animation to the new stashed state with the specified duration.
-     */
-    public void animateToIsStashed(boolean isStashed, long duration) {
-        createAnimToIsStashed(isStashed, duration).start();
-    }
-
     private Animator createAnimToIsStashed(boolean isStashed, long duration) {
         AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
         // Not exactly half and may overlap. See [first|second]HalfDurationScale below.
@@ -331,4 +325,47 @@
     private void onIsStashed(boolean isStashed) {
         mControllers.stashedHandleViewController.onIsStashed(isStashed);
     }
+
+    public void applyState() {
+        applyState(TASKBAR_STASH_DURATION);
+    }
+
+    public void applyState(long duration) {
+        mStatePropertyHolder.setState(mState, duration);
+    }
+
+    /**
+     * Updates the proper flag to indicate whether the task bar should be stashed.
+     *
+     * Note that this only updates the flag. {@link #applyState()} needs to be called separately.
+     *
+     * @param flag The flag to update.
+     * @param enabled Whether to enable the flag: True will cause the task bar to be stashed /
+     *                unstashed.
+     */
+    public void updateStateForFlag(int flag, boolean enabled) {
+        if (enabled) {
+            mState |= flag;
+        } else {
+            mState &= ~flag;
+        }
+    }
+
+    private class StatePropertyHolder {
+        private final IntPredicate mStashCondition;
+
+        private boolean mIsStashed;
+
+        StatePropertyHolder(IntPredicate stashCondition) {
+            mStashCondition = stashCondition;
+        }
+
+        public void setState(int flags, long duration) {
+            boolean isStashed = mStashCondition.test(flags);
+            if (mIsStashed != isStashed) {
+                mIsStashed = isStashed;
+                createAnimToIsStashed(mIsStashed, duration).start();
+            }
+        }
+    }
 }
diff --git a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
index e14dbb1..78de300 100644
--- a/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
+++ b/quickstep/src/com/android/quickstep/SwipeUpAnimationLogic.java
@@ -289,9 +289,11 @@
                 mRemoteTargetHandles[0].mTaskViewSimulator.setPreview(primaryTaskTarget);
             }
         } else {
+            int[] taskIds = LauncherSplitScreenListener.INSTANCE.getNoCreate()
+                    .getRunningSplitTaskIds();
             // We're in staged split
-            primaryTaskTarget = targets.apps[0];
-            secondaryTaskTarget = targets.apps[1];
+            primaryTaskTarget = targets.findTask(taskIds[0]);
+            secondaryTaskTarget = targets.findTask(taskIds[1]);
             mStagedSplitBounds = new SplitConfigurationOptions.StagedSplitBounds(
                     primaryTaskTarget.screenSpaceBounds,
                     secondaryTaskTarget.screenSpaceBounds, dividerTarget.screenSpaceBounds);
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 20eff34..3ce12c5 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -358,12 +358,14 @@
         mDeviceState = new RecentsAnimationDeviceState(this, true);
         mDisplayManager = getSystemService(DisplayManager.class);
         mTaskbarManager = new TaskbarManager(this);
-
         mRotationTouchHelper = mDeviceState.getRotationTouchHelper();
-        mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
-        mDeviceState.addOneHandedModeChangedCallback(this::onOneHandedModeOverlayChanged);
+
+        // Call runOnUserUnlocked() before any other callbacks to ensure everything is initialized.
         mDeviceState.runOnUserUnlocked(this::onUserUnlocked);
         mDeviceState.runOnUserUnlocked(mTaskbarManager::onUserUnlocked);
+        mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
+        mDeviceState.addOneHandedModeChangedCallback(this::onOneHandedModeOverlayChanged);
+
         ProtoTracer.INSTANCE.get(this).add(this);
         LauncherSplitScreenListener.INSTANCE.get(this).init();
         sConnected = true;
diff --git a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
index 9960fd3..a089e73 100644
--- a/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
+++ b/quickstep/src/com/android/quickstep/util/TaskViewSimulator.java
@@ -51,8 +51,8 @@
  */
 public class TaskViewSimulator implements TransformParams.BuilderProxy {
 
-    private final String TAG = "TaskViewSimulator";
-    private final boolean DEBUG = false;
+    private static final String TAG = "TaskViewSimulator";
+    private static final boolean DEBUG = false;
 
     private final Rect mTmpCropRect = new Rect();
     private final RectF mTempRectF = new RectF();
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 7187188..879739f 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -276,15 +276,19 @@
         mPageIndicator = findViewById(R.id.folder_page_indicator);
         mFolderName = findViewById(R.id.folder_name);
         mFolderName.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.folderLabelTextSizePx);
-        mFolderName.setOnBackKeyListener(this);
-        mFolderName.setOnFocusChangeListener(this);
-        mFolderName.setOnEditorActionListener(this);
-        mFolderName.setSelectAllOnFocus(true);
-        mFolderName.setInputType(mFolderName.getInputType()
-                & ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
-                | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
-                | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
-        mFolderName.forceDisableSuggestions(true);
+        if (mActivityContext.supportsIme()) {
+            mFolderName.setOnBackKeyListener(this);
+            mFolderName.setOnFocusChangeListener(this);
+            mFolderName.setOnEditorActionListener(this);
+            mFolderName.setSelectAllOnFocus(true);
+            mFolderName.setInputType(mFolderName.getInputType()
+                    & ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
+                    | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
+                    | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
+            mFolderName.forceDisableSuggestions(true);
+        } else {
+            mFolderName.setEnabled(false);
+        }
 
         mFooter = findViewById(R.id.folder_footer);
         mFooterHeight = getResources().getDimensionPixelSize(R.dimen.folder_label_height);
diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java
index c822213..dc5fe06 100644
--- a/src/com/android/launcher3/views/ActivityContext.java
+++ b/src/com/android/launcher3/views/ActivityContext.java
@@ -115,6 +115,13 @@
     }
 
     /**
+     * Returns whether we can show the IME for elements hosted by this ActivityContext.
+     */
+    default boolean supportsIme() {
+        return true;
+    }
+
+    /**
      * Returns the ActivityContext associated with the given Context.
      */
     static <T extends Context & ActivityContext> T lookupContext(Context context) {
diff --git a/src_plugins/com/android/systemui/plugins/OneSearch.java b/src_plugins/com/android/systemui/plugins/OneSearch.java
index 59ee4f4..6d57c19 100644
--- a/src_plugins/com/android/systemui/plugins/OneSearch.java
+++ b/src_plugins/com/android/systemui/plugins/OneSearch.java
@@ -29,7 +29,7 @@
 @ProvidesInterface(action = OneSearch.ACTION, version = OneSearch.VERSION)
 public interface OneSearch extends Plugin {
     String ACTION = "com.android.systemui.action.PLUGIN_ONE_SEARCH";
-    int VERSION = 1;
+    int VERSION = 2;
 
     /**
      * Get the content provider warmed up.
@@ -53,4 +53,7 @@
      * @param suggest The suggest to get the subtitle for.
      */
     String getSubtitle(Spanned suggest);
+
+    /** Clear any cached data or storage used in search. */
+    void clear();
 }