Merge "Ensure TestLauncher is actaully shown in goToOverviewFromHome" into tm-dev
diff --git a/protos/launcher_atom.proto b/protos/launcher_atom.proto
index a61e430..4127650 100644
--- a/protos/launcher_atom.proto
+++ b/protos/launcher_atom.proto
@@ -121,6 +121,7 @@
   optional int32 cardinality = 2;
 }
 
+// Next value 39
 enum Attribute {
   UNKNOWN = 0;
   DEFAULT_LAYOUT = 1;       // icon automatically placed in workspace, folder, hotseat
@@ -166,11 +167,13 @@
   ALL_APPS_SEARCH_RESULT_ASSISTANT_MEMORY = 31;
 
   // Suggestion Type provided by AGA
-  ONE_SEARCH_WEB_QUERY = 32;
-  ONE_SEARCH_WEB_TRENDING = 33;
-  ONE_SEARCH_WEB_ENTITY = 34;
-  ONE_SEARCH_WEB_ANSWER = 35;
-  ONE_SEARCH_WEB_PERSONAL = 36;
+  WEB_SEARCH_RESULT_QUERY = 32;
+  WEB_SEARCH_RESULT_TRENDING = 33;
+  WEB_SEARCH_RESULT_ENTITY = 34;
+  WEB_SEARCH_RESULT_ANSWER = 35;
+  WEB_SEARCH_RESULT_PERSONAL = 36;
+  WEB_SEARCH_RESULT_CALCULATOR = 37;
+  WEB_SEARCH_RESULT_URL = 38;
 
   WIDGETS_BOTTOM_TRAY = 28;
   WIDGETS_TRAY_PREDICTION = 29;
diff --git a/quickstep/src/com/android/launcher3/search/SearchSessionManager.java b/quickstep/src/com/android/launcher3/search/SearchSessionManager.java
new file mode 100644
index 0000000..da85793
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/search/SearchSessionManager.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.search;
+
+import android.app.search.SearchSession;
+import android.content.Context;
+
+import androidx.annotation.IntDef;
+import androidx.annotation.UiThread;
+
+import com.android.launcher3.R;
+import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.util.ResourceBasedOverride;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.List;
+
+/** Manages an all apps search session. */
+public class SearchSessionManager implements ResourceBasedOverride {
+
+    /** Entry state for the search session (e.g. from all apps). */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(value = {ZERO_ALLAPPS, ZERO_QSB})
+    public @interface ZeroEntryState {}
+    public static final int ZERO_ALLAPPS = 1;
+    public static final int ZERO_QSB = 2;
+
+    /** Creates a {@link SearchSessionManager} instance. */
+    public static SearchSessionManager newInstance(Context context) {
+        return Overrides.getObject(
+                SearchSessionManager.class, context, R.string.search_session_manager_class);
+    }
+
+    /** The current {@link SearchSession}. */
+    @UiThread
+    public void setSearchSession(SearchSession session) {}
+
+    /** {@code true} if IME is shown. */
+    public void setIsImeShown(boolean value) {}
+
+    /** Returns {@code true} if IME is enabled. */
+    public boolean getIsImeEnabled() {
+        return false;
+    }
+
+    /** The current entry state for search. */
+    public @ZeroEntryState int getEntryState() {
+        return ZERO_ALLAPPS;
+    }
+
+    /**
+     * When user enters all apps surface via tap on home widget, set the state to
+     * {@code #ZERO_QSB}. When user exits, reset to {@code #ZERO_ALLAPPS}
+     */
+    public void setEntryState(@ZeroEntryState int state) {}
+
+    /** This will be called before opening all apps, to prepare zero state suggestions. */
+    public void prepareZeroState() {}
+
+    /** Apply predicted items for the search zero state. */
+    public void setZeroStatePredictedItems(List<ItemInfo> items) {}
+
+    /** Returns {@code true} if the session is valid and should be enabled. */
+    public boolean isValidSession() {
+        return false;
+    }
+
+    /** Called when the search session is destroyed. */
+    public void onDestroy() {}
+}
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
index 06107b8..7abe6d4 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarStashController.java
@@ -65,6 +65,9 @@
             | FLAG_STASHED_IN_APP_PINNED | FLAG_STASHED_IN_APP_EMPTY | FLAG_STASHED_IN_APP_SETUP
             | FLAG_STASHED_IN_APP_IME | FLAG_STASHED_IN_APP_ALL_APPS;
 
+    private static final int FLAGS_STASHED_IN_APP_IGNORING_IME =
+            FLAGS_STASHED_IN_APP & ~FLAG_STASHED_IN_APP_IME;
+
     // If any of these flags are enabled, inset apps by our stashed height instead of our unstashed
     // height. This way the reported insets are consistent even during transitions out of the app.
     // Currently any flag that causes us to stash in an app is included, except for IME or All Apps
@@ -239,6 +242,13 @@
     }
 
     /**
+     * Returns whether the taskbar should be stashed in apps regardless of the IME visibility.
+     */
+    public boolean isStashedInAppIgnoringIme() {
+        return hasAnyFlag(FLAGS_STASHED_IN_APP_IGNORING_IME);
+    }
+
+    /**
      * Returns whether the taskbar should be stashed in the current LauncherState.
      */
     public boolean isInStashedLauncherState() {
@@ -586,7 +596,11 @@
 
     private void notifyStashChange(boolean visible, boolean stashed) {
         mSystemUiProxy.notifyTaskbarStatus(visible, stashed);
-        mControllers.taskbarActivityContext.updateInsetRoundedCornerFrame(visible && !stashed);
+        // If stashing taskbar is caused by IME visibility, we could just skip updating rounded
+        // corner insets since the rounded corners will be covered by IME during IME is showing and
+        // taskbar will be restored back to unstashed when IME is hidden.
+        mControllers.taskbarActivityContext.updateInsetRoundedCornerFrame(
+                    visible && !isStashedInAppIgnoringIme());
         mControllers.rotationButtonController.onTaskbarStateChange(visible, stashed);
     }
 
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index a38728a..53296b5 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -71,6 +71,7 @@
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.provider.RestoreDbTask;
 import com.android.launcher3.statemanager.StatefulActivity;
+import com.android.launcher3.taskbar.TaskbarActivityContext;
 import com.android.launcher3.taskbar.TaskbarManager;
 import com.android.launcher3.testing.TestLogging;
 import com.android.launcher3.testing.TestProtocol;
@@ -688,11 +689,9 @@
             }
 
             // If Taskbar is present, we listen for long press to unstash it.
-            BaseActivityInterface activityInterface = newGestureState.getActivityInterface();
-            StatefulActivity activity = activityInterface.getCreatedActivity();
-            if (activity != null && activity.getDeviceProfile().isTaskbarPresent) {
-                base = new TaskbarStashInputConsumer(this, base, mInputMonitorCompat,
-                        mTaskbarManager.getCurrentActivityContext());
+            TaskbarActivityContext tac = mTaskbarManager.getCurrentActivityContext();
+            if (tac != null) {
+                base = new TaskbarStashInputConsumer(this, base, mInputMonitorCompat, tac);
             }
 
             // If Bubbles is expanded, use the overlay input consumer, which will close Bubbles
diff --git a/quickstep/src/com/android/quickstep/interaction/EdgeBackGestureHandler.java b/quickstep/src/com/android/quickstep/interaction/EdgeBackGestureHandler.java
index c532f8e..d059d82 100644
--- a/quickstep/src/com/android/quickstep/interaction/EdgeBackGestureHandler.java
+++ b/quickstep/src/com/android/quickstep/interaction/EdgeBackGestureHandler.java
@@ -31,6 +31,7 @@
 
 import com.android.launcher3.ResourceUtils;
 import com.android.launcher3.Utilities;
+import com.android.launcher3.util.DisplayController;
 
 /**
  * Utility class to handle edge swipes for back gestures.
@@ -115,10 +116,9 @@
             // Add a nav bar panel window.
             mEdgeBackPanel = new EdgeBackGesturePanel(mContext, parent, createLayoutParams());
             mEdgeBackPanel.setBackCallback(mBackCallback);
-            if (mContext.getDisplay() != null) {
-                mContext.getDisplay().getRealSize(mDisplaySize);
-                mEdgeBackPanel.setDisplaySize(mDisplaySize);
-            }
+            Point currentSize = DisplayController.INSTANCE.get(mContext).getInfo().currentSize;
+            mDisplaySize.set(currentSize.x, currentSize.y);
+            mEdgeBackPanel.setDisplaySize(mDisplaySize);
         }
     }
 
diff --git a/quickstep/src/com/android/quickstep/interaction/NavBarGestureHandler.java b/quickstep/src/com/android/quickstep/interaction/NavBarGestureHandler.java
index a8163af..f981860 100644
--- a/quickstep/src/com/android/quickstep/interaction/NavBarGestureHandler.java
+++ b/quickstep/src/com/android/quickstep/interaction/NavBarGestureHandler.java
@@ -37,7 +37,6 @@
 import android.view.Display;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
-import android.view.Surface;
 import android.view.View;
 import android.view.View.OnTouchListener;
 import android.view.ViewConfiguration;
@@ -47,6 +46,7 @@
 import com.android.launcher3.R;
 import com.android.launcher3.ResourceUtils;
 import com.android.launcher3.anim.Interpolators;
+import com.android.launcher3.util.DisplayController;
 import com.android.launcher3.util.DisplayController.NavigationMode;
 import com.android.quickstep.util.MotionPauseDetector;
 import com.android.quickstep.util.NavBarPosition;
@@ -92,13 +92,10 @@
     NavBarGestureHandler(Context context) {
         mContext = context;
         final Display display = mContext.getDisplay();
-        final int displayRotation;
-        if (display == null) {
-            displayRotation = Surface.ROTATION_0;
-        } else {
-            displayRotation = display.getRotation();
-            display.getRealSize(mDisplaySize);
-        }
+        DisplayController.Info displayInfo = DisplayController.INSTANCE.get(mContext).getInfo();
+        final int displayRotation = displayInfo.rotation;
+        Point currentSize = displayInfo.currentSize;
+        mDisplaySize.set(currentSize.x, currentSize.y);
         mSwipeUpTouchTracker =
                 new TriggerSwipeUpTouchTracker(context, true /*disableHorizontalSwipe*/,
                         new NavBarPosition(NavigationMode.NO_BUTTON, displayRotation),
diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
index f6002ec..13007ea 100644
--- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
+++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java
@@ -403,7 +403,7 @@
                             String.format("(State:%s->%s)", getStateString(srcState),
                                     getStateString(dstState)));
                 }
-                if (mItemInfo != DEFAULT_ITEM_INFO) {
+                if (atomInfo.hasContainerInfo()) {
                     logStringBuilder.append("\n").append(atomInfo);
                 }
                 Log.d(TAG, logStringBuilder.toString());
@@ -492,9 +492,7 @@
                 String name = (event instanceof Enum) ? ((Enum) event).name() :
                         event.getId() + "";
                 StringBuilder logStringBuilder = new StringBuilder("\n");
-                if (mInstanceId != DEFAULT_INSTANCE_ID) {
-                    logStringBuilder.append(String.format("InstanceId:%s ", mInstanceId));
-                }
+                logStringBuilder.append(String.format("InstanceId:%s ", mInstanceId));
                 logStringBuilder.append(String.format("%s=%sms", name, mLatencyInMillis));
                 Log.d(LATENCY_TAG, logStringBuilder.toString());
             }
diff --git a/res/values/config.xml b/res/values/config.xml
index e2fd0e3..76d1161 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -91,6 +91,7 @@
     <string name="custom_activity_picker" translatable="false">
         com.android.customization.picker.CustomizationPickerActivity</string>
     <string name="local_colors_extraction_class" translatable="false"></string>
+    <string name="search_session_manager_class" translatable="false"></string>
 
     <!-- Accessibility actions -->
     <item type="id" name="action_remove" />