Merge "Fix several issues with hub scrolling during widget drag-and-drop." into main
diff --git a/core/java/android/hardware/camera2/params/StreamConfigurationMap.java b/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
index 978a8f9..e3dbb2b 100644
--- a/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
+++ b/core/java/android/hardware/camera2/params/StreamConfigurationMap.java
@@ -747,6 +747,10 @@
      * {@link android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession#createHighSpeedRequestList}.
      * </p>
      *
+     * <p>This function returns an empty array if
+     * {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO}
+     * is not supported.</p>
+     *
      * @return an array of supported high speed video recording sizes
      * @see #getHighSpeedVideoFpsRangesFor(Size)
      * @see CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO
@@ -836,6 +840,10 @@
      * supported for the same recording rate.</li>
      * </p>
      *
+     * <p>This function returns an empty array if
+     * {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO}
+     * is not supported.</p>
+     *
      * @return an array of supported high speed video recording FPS ranges The upper bound of
      *         returned ranges is guaranteed to be larger or equal to 120.
      * @see #getHighSpeedVideoSizesFor
diff --git a/core/java/android/inputmethodservice/AbstractInputMethodService.java b/core/java/android/inputmethodservice/AbstractInputMethodService.java
index e2d215e..4bc5bd2 100644
--- a/core/java/android/inputmethodservice/AbstractInputMethodService.java
+++ b/core/java/android/inputmethodservice/AbstractInputMethodService.java
@@ -29,6 +29,7 @@
 import android.view.MotionEvent;
 import android.view.WindowManager;
 import android.view.WindowManagerGlobal;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethod;
 import android.view.inputmethod.InputMethodSession;
 import android.window.WindowProviderService;
@@ -186,6 +187,10 @@
             if (callback != null) {
                 callback.finishedEvent(seq, handled);
             }
+            if (Flags.imeSwitcherRevamp() && !handled && event.getAction() == KeyEvent.ACTION_DOWN
+                    && event.getUnicodeChar() > 0 && mInputMethodServiceInternal != null) {
+                mInputMethodServiceInternal.notifyUserActionIfNecessary();
+            }
         }
 
         /**
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 943b04f..d560399 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -101,6 +101,7 @@
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.Trace;
+import android.os.UserHandle;
 import android.provider.Settings;
 import android.text.InputType;
 import android.text.Layout;
@@ -4341,6 +4342,16 @@
     }
 
     /**
+     * Called when the IME switch button was clicked from the client. This will show the input
+     * method picker dialog.
+     *
+     * @hide
+     */
+    final void onImeSwitchButtonClickFromClient() {
+        mPrivOps.onImeSwitchButtonClickFromClient(getDisplayId(), UserHandle.myUserId());
+    }
+
+    /**
      * Used to inject custom {@link InputMethodServiceInternal}.
      *
      * @return the {@link InputMethodServiceInternal} to be used.
diff --git a/core/java/android/inputmethodservice/NavigationBarController.java b/core/java/android/inputmethodservice/NavigationBarController.java
index de67e06..3ce67b0 100644
--- a/core/java/android/inputmethodservice/NavigationBarController.java
+++ b/core/java/android/inputmethodservice/NavigationBarController.java
@@ -42,6 +42,7 @@
 import android.view.WindowInsetsController.Appearance;
 import android.view.animation.Interpolator;
 import android.view.animation.PathInterpolator;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.FrameLayout;
 
 import com.android.internal.inputmethod.InputMethodNavButtonFlags;
@@ -145,7 +146,8 @@
         return mImpl.toDebugString();
     }
 
-    private static final class Impl implements Callback, Window.DecorCallback {
+    private static final class Impl implements Callback, Window.DecorCallback,
+            NavigationBarView.ButtonClickListener {
         private static final int DEFAULT_COLOR_ADAPT_TRANSITION_TIME = 1700;
 
         // Copied from com.android.systemui.animation.Interpolators#LEGACY_DECELERATE
@@ -241,6 +243,7 @@
                                     ? StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_SHOWN
                                     : 0);
                     navigationBarView.setNavigationIconHints(hints);
+                    navigationBarView.prepareNavButtons(this);
                 }
             } else {
                 mNavigationBarFrame.setLayoutParams(new FrameLayout.LayoutParams(
@@ -592,6 +595,17 @@
             return drawLegacyNavigationBarBackground;
         }
 
+        @Override
+        public void onImeSwitchButtonClick(View v) {
+            mService.onImeSwitchButtonClickFromClient();
+        }
+
+        @Override
+        public boolean onImeSwitchButtonLongClick(View v) {
+            v.getContext().getSystemService(InputMethodManager.class).showInputMethodPicker();
+            return true;
+        }
+
         /**
          * Returns the height of the IME caption bar if this should be shown, or {@code 0} instead.
          */
diff --git a/core/java/android/inputmethodservice/navigationbar/KeyButtonView.java b/core/java/android/inputmethodservice/navigationbar/KeyButtonView.java
index f423672..540243c 100644
--- a/core/java/android/inputmethodservice/navigationbar/KeyButtonView.java
+++ b/core/java/android/inputmethodservice/navigationbar/KeyButtonView.java
@@ -41,6 +41,7 @@
 import android.view.ViewConfiguration;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputConnection;
 import android.widget.ImageView;
 
@@ -58,12 +59,30 @@
     private int mTouchDownY;
     private AudioManager mAudioManager;
     private boolean mGestureAborted;
+    /**
+     * Whether the long click action has been invoked. The short click action is invoked on the up
+     * event while a long click is invoked as soon as the long press duration is reached, so a long
+     * click could be performed before the short click is checked, in which case the short click's
+     * action should not be invoked.
+     *
+     * @see View#mHasPerformedLongPress
+     */
+    private boolean mLongClicked;
     private OnClickListener mOnClickListener;
     private final KeyButtonRipple mRipple;
     private final Paint mOvalBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
     private float mDarkIntensity;
     private boolean mHasOvalBg = false;
 
+    /** Runnable for checking whether the long click action should be performed. */
+    private final Runnable mCheckLongPress = new Runnable() {
+        public void run() {
+            if (isPressed() && performLongClick()) {
+                mLongClicked = true;
+            }
+        }
+    };
+
     public KeyButtonView(Context context, AttributeSet attrs) {
         super(context, attrs);
 
@@ -159,6 +178,7 @@
         switch (action) {
             case MotionEvent.ACTION_DOWN:
                 mDownTime = SystemClock.uptimeMillis();
+                mLongClicked = false;
                 setPressed(true);
 
                 // Use raw X and Y to detect gestures in case a parent changes the x and y values
@@ -173,6 +193,10 @@
                 if (!showSwipeUI) {
                     playSoundEffect(SoundEffectConstants.CLICK);
                 }
+                if (Flags.imeSwitcherRevamp() && isLongClickable()) {
+                    removeCallbacks(mCheckLongPress);
+                    postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
+                }
                 break;
             case MotionEvent.ACTION_MOVE:
                 x = (int) ev.getRawX();
@@ -183,6 +207,9 @@
                     // When quick step is enabled, prevent animating the ripple triggered by
                     // setPressed and decide to run it on touch up
                     setPressed(false);
+                    if (isLongClickable()) {
+                        removeCallbacks(mCheckLongPress);
+                    }
                 }
                 break;
             case MotionEvent.ACTION_CANCEL:
@@ -190,9 +217,12 @@
                 if (mCode != KEYCODE_UNKNOWN) {
                     sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
                 }
+                if (isLongClickable()) {
+                    removeCallbacks(mCheckLongPress);
+                }
                 break;
             case MotionEvent.ACTION_UP:
-                final boolean doIt = isPressed();
+                final boolean doIt = isPressed() && !mLongClicked;
                 setPressed(false);
                 final boolean doHapticFeedback = (SystemClock.uptimeMillis() - mDownTime) > 150;
                 if (showSwipeUI) {
@@ -201,7 +231,7 @@
                         performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                         playSoundEffect(SoundEffectConstants.CLICK);
                     }
-                } else if (doHapticFeedback) {
+                } else if (doHapticFeedback && !mLongClicked) {
                     // Always send a release ourselves because it doesn't seem to be sent elsewhere
                     // and it feels weird to sometimes get a release haptic and other times not.
                     performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE);
@@ -221,6 +251,9 @@
                         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
                     }
                 }
+                if (isLongClickable()) {
+                    removeCallbacks(mCheckLongPress);
+                }
                 break;
         }
 
diff --git a/core/java/android/inputmethodservice/navigationbar/NavigationBarView.java b/core/java/android/inputmethodservice/navigationbar/NavigationBarView.java
index e28f345..a3beaf4 100644
--- a/core/java/android/inputmethodservice/navigationbar/NavigationBarView.java
+++ b/core/java/android/inputmethodservice/navigationbar/NavigationBarView.java
@@ -26,6 +26,7 @@
 import android.animation.PropertyValuesHolder;
 import android.annotation.DrawableRes;
 import android.annotation.FloatRange;
+import android.annotation.NonNull;
 import android.app.StatusBarManager;
 import android.content.Context;
 import android.content.res.Configuration;
@@ -39,6 +40,7 @@
 import android.view.View;
 import android.view.animation.Interpolator;
 import android.view.animation.PathInterpolator;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.FrameLayout;
 
@@ -79,6 +81,28 @@
 
     private NavigationBarInflaterView mNavigationInflaterView;
 
+    /**
+     * Interface definition for callbacks to be invoked when navigation bar buttons are clicked.
+     */
+    public interface ButtonClickListener {
+
+        /**
+         * Called when the IME switch button is clicked.
+         *
+         * @param v The view that was clicked.
+         */
+        void onImeSwitchButtonClick(View v);
+
+        /**
+         * Called when the IME switch button has been clicked and held.
+         *
+         * @param v The view that was clicked and held.
+         *
+         * @return true if the callback consumed the long click, false otherwise.
+         */
+        boolean onImeSwitchButtonLongClick(View v);
+    }
+
     public NavigationBarView(Context context, AttributeSet attrs) {
         super(context, attrs);
 
@@ -98,13 +122,27 @@
                 new ButtonDispatcher(com.android.internal.R.id.input_method_nav_home_handle));
 
         mDeadZone = new android.inputmethodservice.navigationbar.DeadZone(this);
+    }
 
+    /**
+     * Prepares the navigation bar buttons to be used and sets the on click listeners.
+     *
+     * @param listener The listener used to handle the clicks on the navigation bar buttons.
+     */
+    public void prepareNavButtons(@NonNull ButtonClickListener listener) {
         getBackButton().setLongClickable(false);
 
-        final ButtonDispatcher imeSwitchButton = getImeSwitchButton();
-        imeSwitchButton.setLongClickable(false);
-        imeSwitchButton.setOnClickListener(view -> view.getContext()
-                .getSystemService(InputMethodManager.class).showInputMethodPicker());
+        if (Flags.imeSwitcherRevamp()) {
+            final var imeSwitchButton = getImeSwitchButton();
+            imeSwitchButton.setLongClickable(true);
+            imeSwitchButton.setOnClickListener(listener::onImeSwitchButtonClick);
+            imeSwitchButton.setOnLongClickListener(listener::onImeSwitchButtonLongClick);
+        } else {
+            final ButtonDispatcher imeSwitchButton = getImeSwitchButton();
+            imeSwitchButton.setLongClickable(false);
+            imeSwitchButton.setOnClickListener(view -> view.getContext()
+                    .getSystemService(InputMethodManager.class).showInputMethodPicker());
+        }
     }
 
     @Override
diff --git a/core/java/android/view/accessibility/a11ychecker/Android.bp b/core/java/android/view/accessibility/a11ychecker/Android.bp
deleted file mode 100644
index e5a577c..0000000
--- a/core/java/android/view/accessibility/a11ychecker/Android.bp
+++ /dev/null
@@ -1,7 +0,0 @@
-java_library_static {
-    name: "A11yChecker",
-    srcs: [
-        "*.java",
-    ],
-    visibility: ["//visibility:public"],
-}
diff --git a/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java b/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
index e7a2fb9..07a9794 100644
--- a/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
+++ b/core/java/android/view/inputmethod/IInputMethodManagerGlobalInvoker.java
@@ -465,6 +465,20 @@
     }
 
     @AnyThread
+    @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
+    static void onImeSwitchButtonClickFromSystem(int displayId) {
+        final IInputMethodManager service = getService();
+        if (service == null) {
+            return;
+        }
+        try {
+            service.onImeSwitchButtonClickFromSystem(displayId);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    @AnyThread
     @Nullable
     @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
     static InputMethodSubtype getCurrentInputMethodSubtype(@UserIdInt int userId) {
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 0c63e58..dbbfff0 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -4354,6 +4354,19 @@
     }
 
     /**
+     * Called when the IME switch button was clicked from the system. This will show the input
+     * method picker dialog.
+     *
+     * @param displayId The ID of the display where the input method picker dialog should be shown.
+     *
+     * @hide
+     */
+    @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
+    public void onImeSwitchButtonClickFromSystem(int displayId) {
+        IInputMethodManagerGlobalInvoker.onImeSwitchButtonClickFromSystem(displayId);
+    }
+
+    /**
      * A test API for CTS to check whether there are any pending IME visibility requests.
      *
      * @return {@code true} iff there are pending IME visibility requests.
diff --git a/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl b/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl
index 63623c7..82ae76a 100644
--- a/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl
+++ b/core/java/com/android/internal/inputmethod/IInputMethodPrivilegedOperations.aidl
@@ -43,6 +43,7 @@
     void switchToPreviousInputMethod(in AndroidFuture future /* T=Boolean */);
     void switchToNextInputMethod(boolean onlyCurrentIme, in AndroidFuture future /* T=Boolean */);
     void shouldOfferSwitchingToNextInputMethod(in AndroidFuture future /* T=Boolean */);
+    void onImeSwitchButtonClickFromClient(int displayId, int userId);
     void notifyUserActionAsync();
     void applyImeVisibilityAsync(IBinder showOrHideInputToken, boolean setVisible,
             in ImeTracker.Token statsToken);
diff --git a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java
index 72c41be..f50f02e 100644
--- a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java
+++ b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperations.java
@@ -378,6 +378,22 @@
     }
 
     /**
+     * Calls {@link IInputMethodPrivilegedOperations#onImeSwitchButtonClickFromClient(int, int)}
+     */
+    @AnyThread
+    public void onImeSwitchButtonClickFromClient(int displayId, int userId) {
+        final IInputMethodPrivilegedOperations ops = mOps.getAndWarnIfNull();
+        if (ops == null) {
+            return;
+        }
+        try {
+            ops.onImeSwitchButtonClickFromClient(displayId, userId);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Calls {@link IInputMethodPrivilegedOperations#notifyUserActionAsync()}
      */
     @AnyThread
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index 2b3ffeb2..cba27ce 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -135,6 +135,19 @@
             + "android.Manifest.permission.TEST_INPUT_METHOD)")
     boolean isInputMethodPickerShownForTest();
 
+    /**
+     * Called when the IME switch button was clicked from the system. Depending on the number of
+     * enabled IME subtypes, this will either switch to the next IME/subtype, or show the input
+     * method picker dialog.
+     *
+     * @param displayId The ID of the display where the input method picker dialog should be shown.
+     * @param userId    The ID of the user that triggered the click.
+     */
+    @EnforcePermission("WRITE_SECURE_SETTINGS")
+    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
+            + "android.Manifest.permission.WRITE_SECURE_SETTINGS)")
+    oneway void onImeSwitchButtonClickFromSystem(int displayId);
+
     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
             + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
     @nullable InputMethodSubtype getCurrentInputMethodSubtype(int userId);
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 7c62615..c07fd38 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -27,7 +27,6 @@
 #include <android_media_audiopolicy.h>
 #include <android_os_Parcel.h>
 #include <audiomanager/AudioManager.h>
-#include <android-base/properties.h>
 #include <binder/IBinder.h>
 #include <jni.h>
 #include <media/AidlConversion.h>
@@ -42,10 +41,8 @@
 #include <system/audio_policy.h>
 #include <utils/Log.h>
 
-#include <thread>
 #include <optional>
 #include <sstream>
-#include <memory>
 #include <vector>
 
 #include "android_media_AudioAttributes.h"
@@ -264,13 +261,6 @@
     jfieldID mMixerBehavior;
 } gAudioMixerAttributesField;
 
-static struct {
-    jclass clazz;
-    jmethodID run;
-} gRunnableClassInfo;
-
-static JavaVM* gVm;
-
 static Mutex gLock;
 
 enum AudioError {
@@ -3372,55 +3362,6 @@
     return enabled;
 }
 
-class JavaSystemPropertyListener {
-  public:
-    JavaSystemPropertyListener(JNIEnv* env, jobject javaCallback, std::string sysPropName) :
-            mCallback(env->NewGlobalRef(javaCallback)),
-            mCachedProperty(android::base::CachedProperty{std::move(sysPropName)}) {
-        mListenerThread = std::thread([this]() mutable {
-            JNIEnv* threadEnv = GetOrAttachJNIEnvironment(gVm);
-            while (!mCleanupSignal.load()) {
-                using namespace std::chrono_literals;
-                // 1s timeout so this thread can read the cleanup signal to (slowly) be able to
-                // be destroyed.
-                std::string newVal = mCachedProperty.WaitForChange(1000ms) ?: "";
-                if (newVal != "" && mLastVal != newVal) {
-                    threadEnv->CallVoidMethod(mCallback, gRunnableClassInfo.run);
-                    mLastVal = std::move(newVal);
-                }
-            }
-            });
-    }
-
-    ~JavaSystemPropertyListener() {
-        mCleanupSignal.store(true);
-        mListenerThread.join();
-        JNIEnv* env = GetOrAttachJNIEnvironment(gVm);
-        env->DeleteGlobalRef(mCallback);
-    }
-
-  private:
-    jobject mCallback;
-    android::base::CachedProperty mCachedProperty;
-    std::thread mListenerThread;
-    std::atomic<bool> mCleanupSignal{false};
-    std::string mLastVal = "";
-};
-
-std::vector<std::unique_ptr<JavaSystemPropertyListener>> gSystemPropertyListeners;
-std::mutex gSysPropLock{};
-
-static void android_media_AudioSystem_listenForSystemPropertyChange(JNIEnv *env,  jobject thiz,
-        jstring sysProp,
-        jobject javaCallback) {
-    ScopedUtfChars sysPropChars{env, sysProp};
-    auto listener = std::make_unique<JavaSystemPropertyListener>(env, javaCallback,
-            std::string{sysPropChars.c_str()});
-    std::unique_lock _l{gSysPropLock};
-    gSystemPropertyListeners.push_back(std::move(listener));
-}
-
-
 // ----------------------------------------------------------------------------
 
 #define MAKE_AUDIO_SYSTEM_METHOD(x) \
@@ -3593,12 +3534,7 @@
                                 android_media_AudioSystem_clearPreferredMixerAttributes),
          MAKE_AUDIO_SYSTEM_METHOD(supportsBluetoothVariableLatency),
          MAKE_AUDIO_SYSTEM_METHOD(setBluetoothVariableLatencyEnabled),
-         MAKE_AUDIO_SYSTEM_METHOD(isBluetoothVariableLatencyEnabled),
-         MAKE_JNI_NATIVE_METHOD("listenForSystemPropertyChange",
-                                "(Ljava/lang/String;Ljava/lang/Runnable;)V",
-                                android_media_AudioSystem_listenForSystemPropertyChange),
-
-        };
+         MAKE_AUDIO_SYSTEM_METHOD(isBluetoothVariableLatencyEnabled)};
 
 static const JNINativeMethod gEventHandlerMethods[] =
         {MAKE_JNI_NATIVE_METHOD("native_setup", "(Ljava/lang/Object;)V",
@@ -3880,12 +3816,6 @@
     gAudioMixerAttributesField.mMixerBehavior =
             GetFieldIDOrDie(env, audioMixerAttributesClass, "mMixerBehavior", "I");
 
-    jclass runnableClazz = FindClassOrDie(env, "java/lang/Runnable");
-    gRunnableClassInfo.clazz = MakeGlobalRefOrDie(env, runnableClazz);
-    gRunnableClassInfo.run = GetMethodIDOrDie(env, runnableClazz, "run", "()V");
-
-    LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&gVm) != 0);
-
     AudioSystem::addErrorCallback(android_media_AudioSystem_error_callback);
 
     RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
diff --git a/core/jni/android_view_InputChannel.cpp b/core/jni/android_view_InputChannel.cpp
index d11166f..e874163 100644
--- a/core/jni/android_view_InputChannel.cpp
+++ b/core/jni/android_view_InputChannel.cpp
@@ -16,18 +16,22 @@
 
 #define LOG_TAG "InputChannel-JNI"
 
-#include "android-base/stringprintf.h"
-#include <nativehelper/JNIHelp.h>
-#include "nativehelper/scoped_utf_chars.h"
+#include "android_view_InputChannel.h"
+
 #include <android_runtime/AndroidRuntime.h>
 #include <binder/Parcel.h>
-#include <utils/Log.h>
+#include <com_android_input_flags.h>
 #include <input/InputTransport.h>
-#include "android_view_InputChannel.h"
+#include <nativehelper/JNIHelp.h>
+#include <utils/Log.h>
+
+#include "android-base/stringprintf.h"
 #include "android_os_Parcel.h"
 #include "android_util_Binder.h"
-
 #include "core_jni_helpers.h"
+#include "nativehelper/scoped_utf_chars.h"
+
+namespace input_flags = com::android::input::flags;
 
 namespace android {
 
@@ -69,6 +73,9 @@
 }
 
 void NativeInputChannel::setDisposeCallback(InputChannelObjDisposeCallback callback, void* data) {
+    if (input_flags::remove_input_channel_from_windowstate()) {
+        return;
+    }
     mDisposeCallback = callback;
     mDisposeData = data;
 }
diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp
index d277169..41696df 100644
--- a/core/tests/coretests/Android.bp
+++ b/core/tests/coretests/Android.bp
@@ -63,7 +63,6 @@
         "-c fa",
     ],
     static_libs: [
-        "A11yChecker",
         "collector-device-lib-platform",
         "frameworks-base-testutils",
         "core-test-rules", // for libcore.dalvik.system.CloseGuardSupport
diff --git a/core/tests/coretests/src/android/view/accessibility/a11ychecker/OWNERS b/core/tests/coretests/src/android/view/accessibility/a11ychecker/OWNERS
deleted file mode 100644
index 872a180..0000000
--- a/core/tests/coretests/src/android/view/accessibility/a11ychecker/OWNERS
+++ /dev/null
@@ -1,5 +0,0 @@
-# Android Accessibility Framework owners
-include /core/java/android/view/accessibility/a11ychecker/OWNERS
-include /services/accessibility/OWNERS
-
-yaraabdullatif@google.com
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
index ca05864..247cc42 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt
@@ -88,14 +88,17 @@
     /** Add a [VisibleTasksListener] to be notified when freeform tasks are visible or not. */
     fun addVisibleTasksListener(visibleTasksListener: VisibleTasksListener, executor: Executor) {
         visibleTasksListeners[visibleTasksListener] = executor
-        displayData.keyIterator().forEach { displayId ->
-            val visibleTasksCount = getVisibleTaskCount(displayId)
+        displayData.keyIterator().forEach {
             executor.execute {
-                visibleTasksListener.onTasksVisibilityChanged(displayId, visibleTasksCount)
+                visibleTasksListener.onTasksVisibilityChanged(it, visibleTaskCount(it))
             }
         }
     }
 
+    /** Returns a list of all [DisplayData]. */
+    private fun displayDataList(): Sequence<DisplayData> =
+        displayData.valueIterator().asSequence()
+
     /**
      * Add a Consumer which will inform other classes of changes to exclusion regions for all
      * Desktop tasks.
@@ -208,37 +211,17 @@
         return removed
     }
 
-    /** Check if a task with the given [taskId] was marked as an active task */
-    fun isActiveTask(taskId: Int): Boolean {
-        return displayData.valueIterator().asSequence().any { data ->
-            data.activeTasks.contains(taskId)
-        }
-    }
-
-    /** Check if a task with the given [taskId] was marked as a closing task */
-    fun isClosingTask(taskId: Int): Boolean =
-        displayData.valueIterator().asSequence().any { data -> taskId in data.closingTasks }
-
-    /** Whether a task is visible. */
-    fun isVisibleTask(taskId: Int): Boolean {
-        return displayData.valueIterator().asSequence().any { data ->
-            data.visibleTasks.contains(taskId)
-        }
-    }
-
-    /** Return whether the given Task is minimized. */
-    fun isMinimizedTask(taskId: Int): Boolean {
-        return displayData.valueIterator().asSequence().any { data ->
-            data.minimizedTasks.contains(taskId)
-        }
-    }
+    fun isActiveTask(taskId: Int) = displayDataList().any { taskId in it.activeTasks }
+    fun isClosingTask(taskId: Int) = displayDataList().any { taskId in it.closingTasks }
+    fun isVisibleTask(taskId: Int) = displayDataList().any { taskId in it.visibleTasks }
+    fun isMinimizedTask(taskId: Int) = displayDataList().any { taskId in it.minimizedTasks }
 
     /**
      * Check if a task with the given [taskId] is the only visible, non-closing, not-minimized task
      * on its display
      */
     fun isOnlyVisibleNonClosingTask(taskId: Int): Boolean =
-        displayData.valueIterator().asSequence().any { data ->
+        displayDataList().any { data ->
             data.visibleTasks
                 .subtract(data.closingTasks)
                 .subtract(data.minimizedTasks)
@@ -255,12 +238,6 @@
         ArraySet(displayData[displayId]?.minimizedTasks)
 
     /**
-     * Returns whether Desktop Mode is currently showing any tasks, i.e. whether any Desktop Tasks
-     * are visible.
-     */
-    fun isDesktopModeShowing(displayId: Int): Boolean = getVisibleTaskCount(displayId) > 0
-
-    /**
      * Returns a list of Tasks IDs representing all active non-minimized Tasks on the given display,
      * ordered from front to back.
      */
@@ -305,14 +282,14 @@
             return
         }
 
-        val prevCount = getVisibleTaskCount(displayId)
+        val prevCount = visibleTaskCount(displayId)
         if (visible) {
             displayData.getOrCreate(displayId).visibleTasks.add(taskId)
             unminimizeTask(displayId, taskId)
         } else {
             displayData[displayId]?.visibleTasks?.remove(taskId)
         }
-        val newCount = getVisibleTaskCount(displayId)
+        val newCount = visibleTaskCount(displayId)
 
         // Check if count changed
         if (prevCount != newCount) {
@@ -340,7 +317,7 @@
     }
 
     /** Get number of tasks that are marked as visible on given [displayId] */
-    fun getVisibleTaskCount(displayId: Int): Int {
+    fun visibleTaskCount(displayId: Int): Int {
         ProtoLog.d(
             WM_SHELL_DESKTOP_MODE,
             "DesktopTaskRepo: visibleTaskCount= %d",
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index d46b2d6..9a1a8a2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -246,10 +246,12 @@
         }
     }
 
-    /** Get number of tasks that are marked as visible */
-    fun getVisibleTaskCount(displayId: Int): Int {
-        return desktopModeTaskRepository.getVisibleTaskCount(displayId)
-    }
+    /** Gets number of visible tasks in [displayId]. */
+    fun visibleTaskCount(displayId: Int): Int =
+        desktopModeTaskRepository.visibleTaskCount(displayId)
+
+    /** Returns true if any tasks are visible in Desktop Mode. */
+    fun isDesktopModeShowing(displayId: Int): Boolean = visibleTaskCount(displayId) > 0
 
     /** Enter desktop by using the focused task in given `displayId` */
     fun moveFocusedTaskToDesktop(displayId: Int, transitionSource: DesktopModeTransitionSource) {
@@ -981,7 +983,7 @@
             ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: skip keyguard is locked")
             return null
         }
-        if (!desktopModeTaskRepository.isDesktopModeShowing(task.displayId)) {
+        if (!isDesktopModeShowing(task.displayId)) {
             ProtoLog.d(
                 WM_SHELL_DESKTOP_MODE,
                 "DesktopTasksController: bring desktop tasks to front on transition" +
@@ -1012,7 +1014,7 @@
         transition: IBinder
     ): WindowContainerTransaction? {
         ProtoLog.v(WM_SHELL_DESKTOP_MODE, "DesktopTasksController: handleFullscreenTaskLaunch")
-        if (desktopModeTaskRepository.isDesktopModeShowing(task.displayId)) {
+        if (isDesktopModeShowing(task.displayId)) {
             ProtoLog.d(
                 WM_SHELL_DESKTOP_MODE,
                 "DesktopTasksController: switch fullscreen task to freeform on transition" +
@@ -1396,8 +1398,7 @@
         onFinishCallback: Consumer<Boolean>
     ): Boolean {
         // TODO(b/320797628): Pass through which display we are dropping onto
-        val activeTasks = desktopModeTaskRepository.getActiveTasks(DEFAULT_DISPLAY)
-        if (!activeTasks.any { desktopModeTaskRepository.isVisibleTask(it) }) {
+        if (!isDesktopModeShowing(DEFAULT_DISPLAY)) {
             // Not currently in desktop mode, ignore the drop
             return false
         }
@@ -1556,8 +1557,8 @@
             val result = IntArray(1)
             executeRemoteCallWithTaskPermission(
                 controller,
-                "getVisibleTaskCount",
-                { controller -> result[0] = controller.getVisibleTaskCount(displayId) },
+                "visibleTaskCount",
+                { controller -> result[0] = controller.visibleTaskCount(displayId) },
                 true /* blocking */
             )
             return result[0]
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
index ff40d4c..8d63ff2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java
@@ -1980,12 +1980,6 @@
             }
             clearContentOverlay();
         }
-        if (mPipTransitionState.getTransitionState() == PipTransitionState.UNDEFINED) {
-            // Avoid double removal, which is fatal.
-            ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
-                    "%s: trying to remove overlay (%s) while in UNDEFINED state", TAG, surface);
-            return;
-        }
         if (surface == null || !surface.isValid()) {
             ProtoLog.w(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                     "%s: trying to remove invalid content overlay (%s)", TAG, surface);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
index 4f4b809..766a6b3 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java
@@ -353,7 +353,7 @@
                 return this::setRecentsTransitionDuringKeyguard;
             } else if (mDesktopTasksController != null
                     // Check on the default display. Recents/gesture nav is only available there
-                    && mDesktopTasksController.getVisibleTaskCount(DEFAULT_DISPLAY) > 0) {
+                    && mDesktopTasksController.visibleTaskCount(DEFAULT_DISPLAY) > 0) {
                 return this::setRecentsTransitionDuringDesktop;
             }
         }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
index 1532211..b5b476d 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
@@ -18,6 +18,7 @@
 
 import static android.view.WindowManager.TRANSIT_CHANGE;
 
+import static com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_DRAG_WINDOW;
 import static com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_RESIZE_WINDOW;
 
 import android.graphics.Point;
@@ -103,6 +104,9 @@
                 wct.reorder(mDesktopWindowDecoration.mTaskInfo.token, true);
                 mTaskOrganizer.applyTransaction(wct);
             }
+        } else {
+            mInteractionJankMonitor.begin(mDesktopWindowDecoration.mTaskSurface,
+                    mDesktopWindowDecoration.mContext, CUJ_DESKTOP_MODE_DRAG_WINDOW);
         }
         mDragStartListener.onDragStart(mDesktopWindowDecoration.mTaskInfo.taskId);
         mRepositionTaskBounds.set(mTaskBoundsAtDragStart);
@@ -157,11 +161,16 @@
             }
             mInteractionJankMonitor.end(CUJ_DESKTOP_MODE_RESIZE_WINDOW);
         } else {
-            final WindowContainerTransaction wct = new WindowContainerTransaction();
             DragPositioningCallbackUtility.updateTaskBounds(mRepositionTaskBounds,
                     mTaskBoundsAtDragStart, mRepositionStartPoint, x, y);
-            wct.setBounds(mDesktopWindowDecoration.mTaskInfo.token, mRepositionTaskBounds);
-            mTransitions.startTransition(TRANSIT_CHANGE, wct, this);
+            if (!mTaskBoundsAtDragStart.equals(mRepositionTaskBounds)) {
+                final WindowContainerTransaction wct = new WindowContainerTransaction();
+                wct.setBounds(mDesktopWindowDecoration.mTaskInfo.token, mRepositionTaskBounds);
+                mTransitions.startTransition(TRANSIT_CHANGE, wct, this);
+            } else {
+                // Drag-move ended where it originally started, no need to update WM.
+                mInteractionJankMonitor.end(CUJ_DESKTOP_MODE_DRAG_WINDOW);
+            }
         }
 
         mCtrlType = CTRL_TYPE_UNDEFINED;
@@ -202,6 +211,7 @@
         mCtrlType = CTRL_TYPE_UNDEFINED;
         finishCallback.onTransitionFinished(null);
         mIsResizingOrAnimatingResize = false;
+        mInteractionJankMonitor.end(CUJ_DESKTOP_MODE_DRAG_WINDOW);
         return true;
     }
 
diff --git a/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowMultiWindow.kt b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowMultiWindow.kt
new file mode 100644
index 0000000..bbf0ce5
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowMultiWindow.kt
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2024 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.wm.shell.flicker.service.desktopmode.scenarios
+
+import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
+import com.android.server.wm.flicker.helpers.ImeAppHelper
+import com.android.server.wm.flicker.helpers.MailAppHelper
+import com.android.server.wm.flicker.helpers.NewTasksAppHelper
+import com.android.server.wm.flicker.helpers.SimpleAppHelper
+import com.android.window.flags.Flags
+import org.junit.After
+import org.junit.Assume
+import org.junit.Before
+import org.junit.Ignore
+import org.junit.Test
+
+/** Base scenario test for window drag CUJ with multiple windows. */
+@Ignore("Base Test Class")
+abstract class DragAppWindowMultiWindow : DragAppWindowScenarioTestBase()
+{
+    private val imeAppHelper = ImeAppHelper(instrumentation)
+    private val testApp = DesktopModeAppHelper(SimpleAppHelper(instrumentation))
+    private val mailApp = DesktopModeAppHelper(MailAppHelper(instrumentation))
+    private val newTasksApp = DesktopModeAppHelper(NewTasksAppHelper(instrumentation))
+    private val imeApp = DesktopModeAppHelper(ImeAppHelper(instrumentation))
+
+    @Before
+    fun setup() {
+        Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet)
+        testApp.enterDesktopWithDrag(wmHelper, device)
+        mailApp.launchViaIntent(wmHelper)
+        newTasksApp.launchViaIntent(wmHelper)
+        imeApp.launchViaIntent(wmHelper)
+    }
+
+    @Test
+    override fun dragAppWindow() {
+        val (startXIme, startYIme) = getWindowDragStartCoordinate(imeAppHelper)
+
+        imeApp.dragWindow(startXIme, startYIme,
+            endX = startXIme + 150, endY = startYIme + 150,
+            wmHelper, device)
+    }
+
+    @After
+    fun teardown() {
+        testApp.exit(wmHelper)
+        mailApp.exit(wmHelper)
+        newTasksApp.exit(wmHelper)
+        imeApp.exit(wmHelper)
+    }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowScenarioTestBase.kt b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowScenarioTestBase.kt
new file mode 100644
index 0000000..a613ca1
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowScenarioTestBase.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2024 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.wm.shell.flicker.service.desktopmode.scenarios
+
+import android.app.Instrumentation
+import android.tools.NavBar
+import android.tools.Rotation
+import android.tools.device.apphelpers.StandardAppHelper
+import android.tools.traces.parsers.WindowManagerStateHelper
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.UiDevice
+import com.android.launcher3.tapl.LauncherInstrumentation
+import com.android.wm.shell.flicker.service.common.Utils
+import org.junit.Ignore
+import org.junit.Rule
+import org.junit.Test
+
+/** Base test class for window drag CUJ. */
+@Ignore("Base Test Class")
+abstract class DragAppWindowScenarioTestBase {
+
+    val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
+    val tapl = LauncherInstrumentation()
+    val wmHelper = WindowManagerStateHelper(instrumentation)
+    val device = UiDevice.getInstance(instrumentation)
+
+    @Rule
+    @JvmField
+    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0)
+
+    @Test abstract fun dragAppWindow()
+
+    /** Return the top-center coordinate of the app header as the start coordinate. */
+    fun getWindowDragStartCoordinate(appHelper: StandardAppHelper): Pair<Int, Int> {
+        val windowRect = wmHelper.getWindowRegion(appHelper).bounds
+        // Set start x-coordinate as center of app header.
+        val startX = windowRect.centerX()
+        val startY = windowRect.top
+        return Pair(startX, startY)
+    }
+}
diff --git a/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowSingleWindow.kt b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowSingleWindow.kt
new file mode 100644
index 0000000..0655620
--- /dev/null
+++ b/libs/WindowManager/Shell/tests/flicker/service/src/com/android/wm/shell/flicker/service/desktopmode/scenarios/DragAppWindowSingleWindow.kt
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2024 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.wm.shell.flicker.service.desktopmode.scenarios
+
+import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
+import com.android.server.wm.flicker.helpers.SimpleAppHelper
+import com.android.window.flags.Flags
+import org.junit.After
+import org.junit.Assume
+import org.junit.Before
+import org.junit.Ignore
+import org.junit.Test
+
+/** Base scenario test for window drag CUJ with single window. */
+@Ignore("Base Test Class")
+abstract class DragAppWindowSingleWindow : DragAppWindowScenarioTestBase()
+{
+    private val simpleAppHelper = SimpleAppHelper(instrumentation)
+    private val testApp = DesktopModeAppHelper(simpleAppHelper)
+
+    @Before
+    fun setup() {
+        Assume.assumeTrue(Flags.enableDesktopWindowingMode() && tapl.isTablet)
+        testApp.enterDesktopWithDrag(wmHelper, device)
+    }
+
+    @Test
+    override fun dragAppWindow() {
+        val (startXTest, startYTest) = getWindowDragStartCoordinate(simpleAppHelper)
+        testApp.dragWindow(startXTest, startYTest,
+            endX = startXTest + 150, endY = startYTest + 150,
+            wmHelper, device)
+    }
+
+    @After
+    fun teardown() {
+        testApp.exit(wmHelper)
+    }
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepositoryTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepositoryTest.kt
index 6612aee..18b08bf 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepositoryTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepositoryTest.kt
@@ -337,65 +337,65 @@
     }
 
     @Test
-    fun getVisibleTaskCount() {
+    fun visibleTaskCount_defaultDisplay_returnsCorrectCount() {
         // No tasks, count is 0
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
 
         // New task increments count to 1
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
 
         // Visibility update to same task does not increase count
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
 
         // Second task visible increments count
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 2, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(2)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(2)
 
         // Hiding a task decrements count
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = false)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
 
         // Hiding all tasks leaves count at 0
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 2, visible = false)
-        assertThat(repo.getVisibleTaskCount(displayId = 9)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(displayId = 9)).isEqualTo(0)
 
         // Hiding a not existing task, count remains at 0
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 999, visible = false)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
     }
 
     @Test
-    fun getVisibleTaskCount_multipleDisplays() {
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(0)
+    fun visibleTaskCount_multipleDisplays_returnsCorrectCount() {
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(0)
 
         // New task on default display increments count for that display only
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(0)
 
         // New task on secondary display, increments count for that display only
         repo.updateVisibleFreeformTasks(SECOND_DISPLAY, taskId = 2, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
 
         // Marking task visible on another display, updates counts for both displays
         repo.updateVisibleFreeformTasks(SECOND_DISPLAY, taskId = 1, visible = true)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(2)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(2)
 
         // Marking task that is on secondary display, hidden on default display, does not affect
         // secondary display
         repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = false)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(2)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(2)
 
         // Hiding a task on that display, decrements count
         repo.updateVisibleFreeformTasks(SECOND_DISPLAY, taskId = 1, visible = false)
-        assertThat(repo.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
-        assertThat(repo.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
+        assertThat(repo.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+        assertThat(repo.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
     }
 
     @Test
@@ -494,28 +494,6 @@
     }
 
     @Test
-    fun isDesktopModeShowing_noActiveTasks_returnsFalse() {
-        assertThat(repo.isDesktopModeShowing(displayId = 0)).isFalse()
-    }
-
-    @Test
-    fun isDesktopModeShowing_noTasksVisible_returnsFalse() {
-        repo.addActiveTask(displayId = 0, taskId = 1)
-        repo.addActiveTask(displayId = 0, taskId = 2)
-
-        assertThat(repo.isDesktopModeShowing(displayId = 0)).isFalse()
-    }
-
-    @Test
-    fun isDesktopModeShowing_tasksActiveAndVisible_returnsTrue() {
-        repo.addActiveTask(displayId = 0, taskId = 1)
-        repo.addActiveTask(displayId = 0, taskId = 2)
-        repo.updateVisibleFreeformTasks(displayId = 0, taskId = 1, visible = true)
-
-        assertThat(repo.isDesktopModeShowing(displayId = 0)).isTrue()
-    }
-
-    @Test
     fun getActiveNonMinimizedTasksOrderedFrontToBack_returnsFreeformTasksInCorrectOrder() {
         repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 1)
         repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 2)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
index c56671a..da88686 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt
@@ -311,6 +311,31 @@
   }
 
   @Test
+  fun isDesktopModeShowing_noTasks_returnsFalse() {
+    assertThat(controller.isDesktopModeShowing(displayId = 0)).isFalse()
+  }
+
+  @Test
+  fun isDesktopModeShowing_noTasksVisible_returnsFalse() {
+    val task1 = setUpFreeformTask()
+    val task2 = setUpFreeformTask()
+    markTaskHidden(task1)
+    markTaskHidden(task2)
+
+    assertThat(controller.isDesktopModeShowing(displayId = 0)).isFalse()
+  }
+
+  @Test
+  fun isDesktopModeShowing_tasksActiveAndVisible_returnsTrue() {
+    val task1 = setUpFreeformTask()
+    val task2 = setUpFreeformTask()
+    markTaskVisible(task1)
+    markTaskHidden(task2)
+
+    assertThat(controller.isDesktopModeShowing(displayId = 0)).isTrue()
+  }
+
+  @Test
   @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
   fun showDesktopApps_onSecondaryDisplay_desktopWallpaperEnabled_shouldNotShowWallpaper() {
     val homeTask = setUpHomeTask(SECOND_DISPLAY)
@@ -526,32 +551,32 @@
   }
 
   @Test
-  fun getVisibleTaskCount_noTasks_returnsZero() {
-    assertThat(controller.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
+  fun visibleTaskCount_noTasks_returnsZero() {
+    assertThat(controller.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(0)
   }
 
   @Test
-  fun getVisibleTaskCount_twoTasks_bothVisible_returnsTwo() {
+  fun visibleTaskCount_twoTasks_bothVisible_returnsTwo() {
     setUpHomeTask()
     setUpFreeformTask().also(::markTaskVisible)
     setUpFreeformTask().also(::markTaskVisible)
-    assertThat(controller.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(2)
+    assertThat(controller.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(2)
   }
 
   @Test
-  fun getVisibleTaskCount_twoTasks_oneVisible_returnsOne() {
+  fun visibleTaskCount_twoTasks_oneVisible_returnsOne() {
     setUpHomeTask()
     setUpFreeformTask().also(::markTaskVisible)
     setUpFreeformTask().also(::markTaskHidden)
-    assertThat(controller.getVisibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
+    assertThat(controller.visibleTaskCount(DEFAULT_DISPLAY)).isEqualTo(1)
   }
 
   @Test
-  fun getVisibleTaskCount_twoTasksVisibleOnDifferentDisplays_returnsOne() {
+  fun visibleTaskCount_twoTasksVisibleOnDifferentDisplays_returnsOne() {
     setUpHomeTask()
     setUpFreeformTask(DEFAULT_DISPLAY).also(::markTaskVisible)
     setUpFreeformTask(SECOND_DISPLAY).also(::markTaskVisible)
-    assertThat(controller.getVisibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
+    assertThat(controller.visibleTaskCount(SECOND_DISPLAY)).isEqualTo(1)
   }
 
   @Test
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index 52b5ff7..d148afd 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -2649,11 +2649,4 @@
      * @hide
      */
     public static native boolean isBluetoothVariableLatencyEnabled();
-
-    /**
-     * Register a native listener for system property sysprop
-     * @param callback the listener which fires when the property changes
-     * @hide
-     */
-    public static native void listenForSystemPropertyChange(String sysprop, Runnable callback);
 }
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index d42b256..d20b7f0 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -762,14 +762,14 @@
 
     void unregisterLoudnessCodecUpdatesDispatcher(in ILoudnessCodecUpdatesDispatcher dispatcher);
 
-    oneway void startLoudnessCodecUpdates(int sessionId);
+    void startLoudnessCodecUpdates(int sessionId);
 
-    oneway void stopLoudnessCodecUpdates(int sessionId);
+    void stopLoudnessCodecUpdates(int sessionId);
 
-    oneway void addLoudnessCodecInfo(int sessionId, int mediaCodecHash,
+    void addLoudnessCodecInfo(int sessionId, int mediaCodecHash,
             in LoudnessCodecInfo codecInfo);
 
-    oneway void removeLoudnessCodecInfo(int sessionId, in LoudnessCodecInfo codecInfo);
+    void removeLoudnessCodecInfo(int sessionId, in LoudnessCodecInfo codecInfo);
 
     PersistableBundle getLoudnessParams(in LoudnessCodecInfo codecInfo);
 
diff --git a/nfc/java/android/nfc/AvailableNfcAntenna.java b/nfc/java/android/nfc/AvailableNfcAntenna.java
index 6e6512a..e76aeb0 100644
--- a/nfc/java/android/nfc/AvailableNfcAntenna.java
+++ b/nfc/java/android/nfc/AvailableNfcAntenna.java
@@ -28,13 +28,13 @@
 public final class AvailableNfcAntenna implements Parcelable {
     /**
      * Location of the antenna on the Y axis in millimeters.
-     * 0 is the bottom-left when the user is facing the screen
+     * 0 is the top-left when the user is facing the screen
      * and the device orientation is Portrait.
      */
     private final int mLocationX;
     /**
      * Location of the antenna on the Y axis in millimeters.
-     * 0 is the bottom-left when the user is facing the screen
+     * 0 is the top-left when the user is facing the screen
      * and the device orientation is Portrait.
      */
     private final int mLocationY;
@@ -46,7 +46,7 @@
 
     /**
      * Location of the antenna on the X axis in millimeters.
-     * 0 is the bottom-left when the user is facing the screen
+     * 0 is the top-left when the user is facing the screen
      * and the device orientation is Portrait.
      */
     public int getLocationX() {
@@ -55,7 +55,7 @@
 
     /**
      * Location of the antenna on the Y axis in millimeters.
-     * 0 is the bottom-left when the user is facing the screen
+     * 0 is the top-left when the user is facing the screen
      * and the device orientation is Portrait.
      */
     public int getLocationY() {
diff --git a/nfc/java/android/nfc/NfcAntennaInfo.java b/nfc/java/android/nfc/NfcAntennaInfo.java
index b002ca2..c57b2e0 100644
--- a/nfc/java/android/nfc/NfcAntennaInfo.java
+++ b/nfc/java/android/nfc/NfcAntennaInfo.java
@@ -64,9 +64,9 @@
 
     /**
      * Whether the device is foldable. When the device is foldable,
-     * the 0, 0 is considered to be bottom-left when the device is unfolded and
+     * the 0, 0 is considered to be top-left when the device is unfolded and
      * the screens are facing the user. For non-foldable devices 0, 0
-     * is bottom-left when the user is facing the screen.
+     * is top-left when the user is facing the screen.
      */
     public boolean isDeviceFoldable() {
         return mDeviceFoldable;
diff --git a/packages/SettingsProvider/test/src/com/android/providers/settings/DeviceConfigServiceTest.java b/packages/SettingsProvider/test/src/com/android/providers/settings/DeviceConfigServiceTest.java
index 8dd51b2..8de0c35 100644
--- a/packages/SettingsProvider/test/src/com/android/providers/settings/DeviceConfigServiceTest.java
+++ b/packages/SettingsProvider/test/src/com/android/providers/settings/DeviceConfigServiceTest.java
@@ -22,8 +22,6 @@
 
 import android.content.ContentResolver;
 import android.os.Bundle;
-import android.platform.test.annotations.RequiresFlagsDisabled;
-import android.platform.test.annotations.RequiresFlagsEnabled;
 import android.platform.test.flag.junit.CheckFlagsRule;
 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
 import android.provider.Settings;
@@ -73,24 +71,9 @@
     }
 
     /**
-     * Test that setting overrides are properly disabled when the flag is off.
-     */
-    @Test
-    @RequiresFlagsDisabled("com.android.providers.settings.support_overrides")
-    public void testOverrideDisabled() throws IOException {
-        final String newValue = "value2";
-
-        executeShellCommand("device_config put " + sNamespace + " " + sKey + " " + sValue);
-        executeShellCommand("device_config override " + sNamespace + " " + sKey + " " + newValue);
-        String result = readShellCommandOutput("device_config get " + sNamespace + " " + sKey);
-        assertEquals(sValue + "\n", result);
-    }
-
-    /**
      * Test that overrides are readable and can be cleared.
      */
     @Test
-    @RequiresFlagsEnabled("com.android.providers.settings.support_overrides")
     public void testOverride() throws IOException {
         final String newValue = "value2";
 
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
index 43d51c3..92f03d7 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
@@ -45,7 +45,7 @@
 import com.android.systemui.communal.shared.model.CommunalBackgroundType
 import com.android.systemui.communal.shared.model.CommunalScenes
 import com.android.systemui.communal.shared.model.CommunalTransitionKeys
-import com.android.systemui.communal.ui.compose.Dimensions.SlideOffsetY
+import com.android.systemui.communal.ui.compose.Dimensions.Companion.SlideOffsetY
 import com.android.systemui.communal.ui.compose.extensions.allowGestures
 import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
 import com.android.systemui.communal.util.CommunalColors
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
index 9f35fcc..ef6eec8 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt
@@ -16,6 +16,8 @@
 
 package com.android.systemui.communal.ui.compose
 
+import android.content.Context
+import android.content.res.Configuration
 import android.graphics.drawable.Icon
 import android.os.Bundle
 import android.util.SizeF
@@ -116,6 +118,7 @@
 import androidx.compose.ui.layout.onGloballyPositioned
 import androidx.compose.ui.layout.onSizeChanged
 import androidx.compose.ui.layout.positionInWindow
+import androidx.compose.ui.platform.LocalConfiguration
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.platform.LocalDensity
 import androidx.compose.ui.platform.testTag
@@ -129,6 +132,7 @@
 import androidx.compose.ui.semantics.semantics
 import androidx.compose.ui.semantics.testTagsAsResourceId
 import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.Density
 import androidx.compose.ui.unit.Dp
 import androidx.compose.ui.unit.IntSize
 import androidx.compose.ui.unit.LayoutDirection
@@ -388,6 +392,10 @@
     }
 }
 
+val hubDimensions: Dimensions
+    @Composable
+    get() = Dimensions(LocalContext.current, LocalConfiguration.current, LocalDensity.current)
+
 @Composable
 private fun DisclaimerBottomSheetContent(onButtonClicked: () -> Unit) {
     val colors = LocalAndroidColorScheme.current
@@ -516,7 +524,7 @@
         // for android drag events.
         Box(Modifier.fillMaxSize().dragAndDropTarget(dragAndDropTargetState)) {}
     } else {
-        gridModifier = gridModifier.height(Dimensions.GridHeight)
+        gridModifier = gridModifier.height(hubDimensions.GridHeight)
     }
 
     LazyHorizontalGrid(
@@ -594,7 +602,7 @@
 ) {
     val colors = LocalAndroidColorScheme.current
     Card(
-        modifier = Modifier.height(Dimensions.GridHeight).padding(contentPadding),
+        modifier = Modifier.height(hubDimensions.GridHeight).padding(contentPadding),
         colors = CardDefaults.cardColors(containerColor = Color.Transparent),
         border = BorderStroke(3.dp, colors.secondary),
         shape = RoundedCornerShape(size = 80.dp)
@@ -1279,7 +1287,7 @@
         return PaddingValues(
             start = Dimensions.ItemSpacing,
             end = Dimensions.ItemSpacing,
-            top = Dimensions.GridTopSpacing,
+            top = hubDimensions.GridTopSpacing,
         )
     }
     val context = LocalContext.current
@@ -1288,7 +1296,8 @@
     val screenHeight = with(density) { windowMetrics.bounds.height().toDp() }
     val toolbarHeight = with(density) { Dimensions.ToolbarPaddingTop + toolbarSize.height.toDp() }
     val verticalPadding =
-        ((screenHeight - toolbarHeight - Dimensions.GridHeight + Dimensions.GridTopSpacing) / 2)
+        ((screenHeight - toolbarHeight - hubDimensions.GridHeight + hubDimensions.GridTopSpacing) /
+                2)
             .coerceAtLeast(Dimensions.Spacing)
     return PaddingValues(
         start = Dimensions.ToolbarPaddingHorizontal,
@@ -1344,29 +1353,44 @@
     fun toOffset(): Offset = Offset(start, top)
 }
 
-object Dimensions {
-    val CardHeightFull = 530.dp
-    val GridTopSpacing = 114.dp
-    val GridHeight = CardHeightFull + GridTopSpacing
-    val ItemSpacing = 50.dp
-    val CardHeightHalf = (CardHeightFull - ItemSpacing) / 2
-    val CardHeightThird = (CardHeightFull - (2 * ItemSpacing)) / 3
-    val CardWidth = 360.dp
-    val CardOutlineWidth = 3.dp
-    val Spacing = ItemSpacing / 2
+class Dimensions(val context: Context, val config: Configuration, val density: Density) {
+    val GridTopSpacing: Dp
+        get() {
+            if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+                return 114.dp
+            } else {
+                val windowMetrics =
+                    WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(context)
+                val screenHeight = with(density) { windowMetrics.bounds.height().toDp() }
 
-    // The sizing/padding of the toolbar in glanceable hub edit mode
-    val ToolbarPaddingTop = 27.dp
-    val ToolbarPaddingHorizontal = ItemSpacing
-    val ToolbarButtonPaddingHorizontal = 24.dp
-    val ToolbarButtonPaddingVertical = 16.dp
-    val ButtonPadding =
-        PaddingValues(
-            vertical = ToolbarButtonPaddingVertical,
-            horizontal = ToolbarButtonPaddingHorizontal,
-        )
-    val IconSize = 40.dp
-    val SlideOffsetY = 30.dp
+                return (screenHeight - CardHeightFull) / 2
+            }
+        }
+
+    val GridHeight = CardHeightFull + GridTopSpacing
+
+    companion object {
+        val CardHeightFull = 530.dp
+        val ItemSpacing = 50.dp
+        val CardHeightHalf = (CardHeightFull - ItemSpacing) / 2
+        val CardHeightThird = (CardHeightFull - (2 * ItemSpacing)) / 3
+        val CardWidth = 360.dp
+        val CardOutlineWidth = 3.dp
+        val Spacing = ItemSpacing / 2
+
+        // The sizing/padding of the toolbar in glanceable hub edit mode
+        val ToolbarPaddingTop = 27.dp
+        val ToolbarPaddingHorizontal = ItemSpacing
+        val ToolbarButtonPaddingHorizontal = 24.dp
+        val ToolbarButtonPaddingVertical = 16.dp
+        val ButtonPadding =
+            PaddingValues(
+                vertical = ToolbarButtonPaddingVertical,
+                horizontal = ToolbarButtonPaddingHorizontal,
+            )
+        val IconSize = 40.dp
+        val SlideOffsetY = 30.dp
+    }
 }
 
 private object Colors {
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
index a184cf3..776e166 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/notifications/ui/composable/Notifications.kt
@@ -198,6 +198,7 @@
 
     LaunchedEffect(scrollableState.isScrollInProgress) {
         if (!scrollableState.isScrollInProgress && scrollOffset <= minScrollOffset) {
+            viewModel.setHeadsUpAnimatingAway(false)
             viewModel.snoozeHun()
         }
     }
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelTest.kt
index f9f7df8..4f5d0e5 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelTest.kt
@@ -29,6 +29,7 @@
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pattern
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin
+import com.android.systemui.biometrics.FaceHelpMessageDebouncer
 import com.android.systemui.biometrics.data.repository.FaceSensorInfo
 import com.android.systemui.biometrics.data.repository.fakeFacePropertyRepository
 import com.android.systemui.biometrics.data.repository.fakeFingerprintPropertyRepository
@@ -36,7 +37,7 @@
 import com.android.systemui.bouncer.domain.interactor.bouncerInteractor
 import com.android.systemui.bouncer.shared.flag.fakeComposeBouncerFlags
 import com.android.systemui.coroutines.collectLastValue
-import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
+import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor
 import com.android.systemui.deviceentry.shared.model.ErrorFaceAuthenticationStatus
 import com.android.systemui.deviceentry.shared.model.FailedFaceAuthenticationStatus
 import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
@@ -75,15 +76,20 @@
     private val authenticationInteractor by lazy { kosmos.authenticationInteractor }
     private val bouncerInteractor by lazy { kosmos.bouncerInteractor }
     private lateinit var underTest: BouncerMessageViewModel
+    private val ignoreHelpMessageId = 1
 
     @Before
     fun setUp() {
         kosmos.fakeUserRepository.setUserInfos(listOf(PRIMARY_USER))
         kosmos.fakeComposeBouncerFlags.composeBouncerEnabled = true
+        overrideResource(
+            R.array.config_face_acquire_device_entry_ignorelist,
+            intArrayOf(ignoreHelpMessageId)
+        )
         underTest = kosmos.bouncerMessageViewModel
         overrideResource(R.string.kg_trust_agent_disabled, "Trust agent is unavailable")
         kosmos.fakeSystemPropertiesHelper.set(
-            DeviceEntryInteractor.SYS_BOOT_REASON_PROP,
+            DeviceUnlockedInteractor.SYS_BOOT_REASON_PROP,
             "not mainline reboot"
         )
     }
@@ -379,7 +385,15 @@
             runCurrent()
 
             kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
-                HelpFaceAuthenticationStatus(1, "some helpful message")
+                HelpFaceAuthenticationStatus(0, "some helpful message", 0)
+            )
+            runCurrent()
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(
+                    0,
+                    "some helpful message",
+                    FaceHelpMessageDebouncer.DEFAULT_WINDOW_MS
+                )
             )
             runCurrent()
             assertThat(bouncerMessage?.text).isEqualTo("Enter PIN")
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt
index cee8ae9..2cbfa7d 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/CommunalSceneStartableTest.kt
@@ -16,9 +16,11 @@
 
 package com.android.systemui.communal
 
+import android.platform.test.annotations.EnableFlags
 import android.provider.Settings
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
+import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.communal.domain.interactor.communalInteractor
 import com.android.systemui.communal.domain.interactor.communalSceneInteractor
@@ -60,6 +62,7 @@
 @OptIn(ExperimentalCoroutinesApi::class)
 @SmallTest
 @RunWith(AndroidJUnit4::class)
+@EnableFlags(FLAG_COMMUNAL_HUB)
 class CommunalSceneStartableTest : SysuiTestCase() {
     private val kosmos = testKosmos()
 
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
index 2546f27..2bf50b3 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepositoryTest.kt
@@ -52,7 +52,6 @@
 import com.android.systemui.deviceentry.shared.model.ErrorFaceAuthenticationStatus
 import com.android.systemui.deviceentry.shared.model.FaceAuthenticationStatus
 import com.android.systemui.deviceentry.shared.model.FaceDetectionStatus
-import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
 import com.android.systemui.deviceentry.shared.model.SuccessFaceAuthenticationStatus
 import com.android.systemui.display.data.repository.displayRepository
 import com.android.systemui.dump.DumpManager
@@ -79,7 +78,6 @@
 import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
 import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
 import com.android.systemui.power.domain.interactor.powerInteractor
-import com.android.systemui.res.R
 import com.android.systemui.statusbar.commandQueue
 import com.android.systemui.statusbar.phone.KeyguardBypassController
 import com.android.systemui.testKosmos
@@ -478,29 +476,6 @@
         }
 
     @Test
-    fun faceHelpMessagesAreIgnoredBasedOnConfig() =
-        testScope.runTest {
-            overrideResource(
-                R.array.config_face_acquire_device_entry_ignorelist,
-                intArrayOf(10, 11)
-            )
-            underTest = createDeviceEntryFaceAuthRepositoryImpl()
-            initCollectors()
-            allPreconditionsToRunFaceAuthAreTrue()
-
-            underTest.requestAuthenticate(FACE_AUTH_TRIGGERED_SWIPE_UP_ON_BOUNCER)
-            faceAuthenticateIsCalled()
-
-            authenticationCallback.value.onAuthenticationHelp(9, "help msg")
-            authenticationCallback.value.onAuthenticationHelp(10, "Ignored help msg")
-            authenticationCallback.value.onAuthenticationHelp(11, "Ignored help msg")
-
-            val response = authStatus() as HelpFaceAuthenticationStatus
-            assertThat(response.msg).isEqualTo("help msg")
-            assertThat(response.msgId).isEqualTo(response.msgId)
-        }
-
-    @Test
     fun dumpDoesNotErrorOutWhenFaceManagerOrBypassControllerIsNull() =
         testScope.runTest {
             fakeUserRepository.setSelectedUserInfo(primaryUser)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt
index 546510b..3253edf 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt
@@ -20,7 +20,6 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
 import com.android.compose.animation.scene.SceneKey
-import com.android.internal.widget.LockPatternUtils
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository
 import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository
@@ -32,27 +31,14 @@
 import com.android.systemui.coroutines.collectLastValue
 import com.android.systemui.coroutines.collectValues
 import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.AdaptiveAuthRequest
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.BouncerLockedOut
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.PolicyLockdown
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.SecurityTimeout
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.TrustAgentDisabled
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.UnattendedUpdate
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason.UserLockdown
 import com.android.systemui.flags.EnableSceneContainer
-import com.android.systemui.flags.fakeSystemPropertiesHelper
 import com.android.systemui.keyguard.data.repository.biometricSettingsRepository
 import com.android.systemui.keyguard.data.repository.deviceEntryFingerprintAuthRepository
-import com.android.systemui.keyguard.data.repository.fakeBiometricSettingsRepository
 import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFaceAuthRepository
 import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
 import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
 import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
 import com.android.systemui.keyguard.data.repository.fakeTrustRepository
-import com.android.systemui.keyguard.shared.model.AuthenticationFlags
 import com.android.systemui.keyguard.shared.model.KeyguardState
 import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
 import com.android.systemui.kosmos.testScope
@@ -61,7 +47,6 @@
 import com.android.systemui.testKosmos
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.test.TestScope
 import kotlinx.coroutines.test.runCurrent
 import kotlinx.coroutines.test.runTest
 import org.junit.Before
@@ -438,231 +423,6 @@
             assertThat(isUnlocked).isTrue()
         }
 
-    @Test
-    fun deviceEntryRestrictionReason_whenFaceOrFingerprintOrTrust_alwaysNull() =
-        testScope.runTest {
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
-            runCurrent()
-
-            verifyRestrictionReasonsForAuthFlags(
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to null,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to null,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to null,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to null,
-                LockPatternUtils.StrongAuthTracker
-                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to null,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
-                    null,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
-                    null,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to null
-            )
-        }
-
-    @Test
-    fun deviceEntryRestrictionReason_whenFaceIsEnrolledAndEnabled_mapsToAuthFlagsState() =
-        testScope.runTest {
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
-            kosmos.fakeSystemPropertiesHelper.set(
-                DeviceEntryInteractor.SYS_BOOT_REASON_PROP,
-                "not mainline reboot"
-            )
-            runCurrent()
-
-            verifyRestrictionReasonsForAuthFlags(
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
-                    DeviceNotUnlockedSinceReboot,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
-                    AdaptiveAuthRequest,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
-                    BouncerLockedOut,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
-                    SecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
-                    UserLockdown,
-                LockPatternUtils.StrongAuthTracker
-                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
-                    NonStrongBiometricsSecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
-                    UnattendedUpdate,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
-                    PolicyLockdown,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
-                    null,
-            )
-        }
-
-    @Test
-    fun deviceEntryRestrictionReason_whenFingerprintIsEnrolledAndEnabled_mapsToAuthFlagsState() =
-        testScope.runTest {
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
-            kosmos.fakeSystemPropertiesHelper.set(
-                DeviceEntryInteractor.SYS_BOOT_REASON_PROP,
-                "not mainline reboot"
-            )
-            runCurrent()
-
-            verifyRestrictionReasonsForAuthFlags(
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
-                    DeviceNotUnlockedSinceReboot,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
-                    AdaptiveAuthRequest,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
-                    BouncerLockedOut,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
-                    SecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
-                    UserLockdown,
-                LockPatternUtils.StrongAuthTracker
-                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
-                    NonStrongBiometricsSecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
-                    UnattendedUpdate,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
-                    PolicyLockdown,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
-                    null,
-            )
-        }
-
-    @Test
-    fun deviceEntryRestrictionReason_whenTrustAgentIsEnabled_mapsToAuthFlagsState() =
-        testScope.runTest {
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(true)
-            kosmos.fakeTrustRepository.setCurrentUserTrustManaged(false)
-            kosmos.fakeSystemPropertiesHelper.set(
-                DeviceEntryInteractor.SYS_BOOT_REASON_PROP,
-                "not mainline reboot"
-            )
-            runCurrent()
-
-            verifyRestrictionReasonsForAuthFlags(
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
-                    DeviceNotUnlockedSinceReboot,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
-                    AdaptiveAuthRequest,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
-                    BouncerLockedOut,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
-                    SecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
-                    UserLockdown,
-                LockPatternUtils.StrongAuthTracker
-                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
-                    NonStrongBiometricsSecurityTimeout,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
-                    UnattendedUpdate,
-                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
-                    PolicyLockdown,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to
-                    TrustAgentDisabled,
-                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
-                    TrustAgentDisabled,
-            )
-        }
-
-    @Test
-    fun deviceEntryRestrictionReason_whenDeviceRebootedForMainlineUpdate_mapsToTheCorrectReason() =
-        testScope.runTest {
-            val deviceEntryRestrictionReason by
-                collectLastValue(underTest.deviceEntryRestrictionReason)
-            kosmos.fakeSystemPropertiesHelper.set(
-                DeviceEntryInteractor.SYS_BOOT_REASON_PROP,
-                DeviceEntryInteractor.REBOOT_MAINLINE_UPDATE
-            )
-            kosmos.fakeBiometricSettingsRepository.setAuthenticationFlags(
-                AuthenticationFlags(
-                    userId = 1,
-                    flag = LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
-                )
-            )
-            runCurrent()
-
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
-            runCurrent()
-
-            assertThat(deviceEntryRestrictionReason).isNull()
-
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
-            runCurrent()
-
-            assertThat(deviceEntryRestrictionReason)
-                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
-
-            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
-            runCurrent()
-
-            assertThat(deviceEntryRestrictionReason)
-                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
-
-            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
-            kosmos.fakeTrustRepository.setTrustUsuallyManaged(true)
-            runCurrent()
-
-            assertThat(deviceEntryRestrictionReason)
-                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
-        }
-
-    @Test
-    fun reportUserPresent_whenDeviceEntered() =
-        testScope.runTest {
-            val isDeviceEntered by collectLastValue(underTest.isDeviceEntered)
-            assertThat(isDeviceEntered).isFalse()
-            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(0)
-
-            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
-                SuccessFingerprintAuthenticationStatus(0, true)
-            )
-            runCurrent()
-            switchToScene(Scenes.Gone)
-            assertThat(isDeviceEntered).isTrue()
-            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(1)
-
-            switchToScene(Scenes.Lockscreen)
-            assertThat(isDeviceEntered).isFalse()
-            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(1)
-
-            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
-                SuccessFingerprintAuthenticationStatus(0, true)
-            )
-            switchToScene(Scenes.Gone)
-            assertThat(isDeviceEntered).isTrue()
-            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(2)
-        }
-
-    private fun TestScope.verifyRestrictionReasonsForAuthFlags(
-        vararg authFlagToDeviceEntryRestriction: Pair<Int, DeviceEntryRestrictionReason?>
-    ) {
-        val deviceEntryRestrictionReason by collectLastValue(underTest.deviceEntryRestrictionReason)
-
-        authFlagToDeviceEntryRestriction.forEach { (flag, expectedReason) ->
-            kosmos.fakeBiometricSettingsRepository.setAuthenticationFlags(
-                AuthenticationFlags(userId = 1, flag = flag)
-            )
-            runCurrent()
-
-            if (expectedReason == null) {
-                assertThat(deviceEntryRestrictionReason).isNull()
-            } else {
-                assertThat(deviceEntryRestrictionReason).isEqualTo(expectedReason)
-            }
-        }
-    }
-
     private fun switchToScene(sceneKey: SceneKey) {
         sceneInteractor.changeScene(sceneKey, "reason")
     }
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt
index a7a7bea3..c2acc5f 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt
@@ -19,17 +19,20 @@
 import android.content.pm.UserInfo
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
+import com.android.internal.widget.LockPatternUtils
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository
-import com.android.systemui.authentication.domain.interactor.authenticationInteractor
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
 import com.android.systemui.coroutines.collectLastValue
 import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository
+import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
 import com.android.systemui.deviceentry.shared.model.DeviceUnlockSource
+import com.android.systemui.flags.fakeSystemPropertiesHelper
+import com.android.systemui.keyguard.data.repository.fakeBiometricSettingsRepository
 import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFaceAuthRepository
 import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
 import com.android.systemui.keyguard.data.repository.fakeTrustRepository
-import com.android.systemui.keyguard.domain.interactor.trustInteractor
+import com.android.systemui.keyguard.shared.model.AuthenticationFlags
 import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
 import com.android.systemui.kosmos.testScope
 import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
@@ -40,6 +43,7 @@
 import com.android.systemui.user.data.repository.fakeUserRepository
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.TestScope
 import kotlinx.coroutines.test.runCurrent
 import kotlinx.coroutines.test.runTest
 import org.junit.Before
@@ -54,18 +58,8 @@
     private val kosmos = testKosmos()
     private val testScope = kosmos.testScope
     private val authenticationRepository = kosmos.fakeAuthenticationRepository
-    private val deviceEntryRepository = kosmos.fakeDeviceEntryRepository
 
-    val underTest =
-        DeviceUnlockedInteractor(
-            applicationScope = testScope.backgroundScope,
-            authenticationInteractor = kosmos.authenticationInteractor,
-            deviceEntryRepository = deviceEntryRepository,
-            trustInteractor = kosmos.trustInteractor,
-            faceAuthInteractor = kosmos.deviceEntryFaceAuthInteractor,
-            fingerprintAuthInteractor = kosmos.deviceEntryFingerprintAuthInteractor,
-            powerInteractor = kosmos.powerInteractor,
-        )
+    val underTest = kosmos.deviceUnlockedInteractor
 
     @Before
     fun setup() {
@@ -100,6 +94,30 @@
         }
 
     @Test
+    fun deviceUnlockStatus_whenUnlockedAndAuthMethodIsPinAndInLockdown_isFalse() =
+        testScope.runTest {
+            val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus)
+            val isInLockdown by collectLastValue(underTest.isInLockdown)
+
+            authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin)
+            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
+                SuccessFingerprintAuthenticationStatus(0, true)
+            )
+            kosmos.fakeBiometricSettingsRepository.setAuthenticationFlags(
+                AuthenticationFlags(
+                    userId = 1,
+                    flag =
+                        LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
+                )
+            )
+            runCurrent()
+            assertThat(isInLockdown).isTrue()
+
+            assertThat(deviceUnlockStatus?.isUnlocked).isFalse()
+            assertThat(deviceUnlockStatus?.deviceUnlockSource).isNull()
+        }
+
+    @Test
     fun deviceUnlockStatus_whenUnlockedAndAuthMethodIsSim_isFalse() =
         testScope.runTest {
             val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus)
@@ -221,6 +239,218 @@
             assertThat(deviceUnlockStatus?.isUnlocked).isFalse()
         }
 
+    @Test
+    fun deviceEntryRestrictionReason_whenFaceOrFingerprintOrTrust_alwaysNull() =
+        testScope.runTest {
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
+            runCurrent()
+
+            verifyRestrictionReasonsForAuthFlags(
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to null,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to null,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to null,
+                LockPatternUtils.StrongAuthTracker
+                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to null,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
+                    null,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
+                    null,
+            )
+        }
+
+    @Test
+    fun deviceEntryRestrictionReason_whenFaceOrFingerprintOrTrust_whenLockdown() =
+        testScope.runTest {
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
+            runCurrent()
+
+            verifyRestrictionReasonsForAuthFlags(
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
+                    DeviceEntryRestrictionReason.UserLockdown,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
+                    DeviceEntryRestrictionReason.PolicyLockdown
+            )
+        }
+
+    @Test
+    fun deviceEntryRestrictionReason_whenFaceIsEnrolledAndEnabled_mapsToAuthFlagsState() =
+        testScope.runTest {
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
+            kosmos.fakeSystemPropertiesHelper.set(
+                DeviceUnlockedInteractor.SYS_BOOT_REASON_PROP,
+                "not mainline reboot"
+            )
+            runCurrent()
+
+            verifyRestrictionReasonsForAuthFlags(
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
+                    DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
+                    DeviceEntryRestrictionReason.AdaptiveAuthRequest,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
+                    DeviceEntryRestrictionReason.BouncerLockedOut,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
+                    DeviceEntryRestrictionReason.SecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
+                    DeviceEntryRestrictionReason.UserLockdown,
+                LockPatternUtils.StrongAuthTracker
+                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
+                    DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
+                    DeviceEntryRestrictionReason.UnattendedUpdate,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
+                    DeviceEntryRestrictionReason.PolicyLockdown,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
+                    null,
+            )
+        }
+
+    @Test
+    fun deviceEntryRestrictionReason_whenFingerprintIsEnrolledAndEnabled_mapsToAuthFlagsState() =
+        testScope.runTest {
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
+            kosmos.fakeSystemPropertiesHelper.set(
+                DeviceUnlockedInteractor.SYS_BOOT_REASON_PROP,
+                "not mainline reboot"
+            )
+            runCurrent()
+
+            verifyRestrictionReasonsForAuthFlags(
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
+                    DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
+                    DeviceEntryRestrictionReason.AdaptiveAuthRequest,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
+                    DeviceEntryRestrictionReason.BouncerLockedOut,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
+                    DeviceEntryRestrictionReason.SecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
+                    DeviceEntryRestrictionReason.UserLockdown,
+                LockPatternUtils.StrongAuthTracker
+                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
+                    DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
+                    DeviceEntryRestrictionReason.UnattendedUpdate,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
+                    DeviceEntryRestrictionReason.PolicyLockdown,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to null,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
+                    null,
+            )
+        }
+
+    @Test
+    fun deviceEntryRestrictionReason_whenTrustAgentIsEnabled_mapsToAuthFlagsState() =
+        testScope.runTest {
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(true)
+            kosmos.fakeTrustRepository.setCurrentUserTrustManaged(false)
+            kosmos.fakeSystemPropertiesHelper.set(
+                DeviceUnlockedInteractor.SYS_BOOT_REASON_PROP,
+                "not mainline reboot"
+            )
+            runCurrent()
+
+            verifyRestrictionReasonsForAuthFlags(
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT to
+                    DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_ADAPTIVE_AUTH_REQUEST to
+                    DeviceEntryRestrictionReason.AdaptiveAuthRequest,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT to
+                    DeviceEntryRestrictionReason.BouncerLockedOut,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT to
+                    DeviceEntryRestrictionReason.SecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN to
+                    DeviceEntryRestrictionReason.UserLockdown,
+                LockPatternUtils.StrongAuthTracker
+                    .STRONG_AUTH_REQUIRED_AFTER_NON_STRONG_BIOMETRICS_TIMEOUT to
+                    DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_FOR_UNATTENDED_UPDATE to
+                    DeviceEntryRestrictionReason.UnattendedUpdate,
+                LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW to
+                    DeviceEntryRestrictionReason.PolicyLockdown,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST to
+                    DeviceEntryRestrictionReason.TrustAgentDisabled,
+                LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED to
+                    DeviceEntryRestrictionReason.TrustAgentDisabled,
+            )
+        }
+
+    @Test
+    fun deviceEntryRestrictionReason_whenDeviceRebootedForMainlineUpdate_mapsToTheCorrectReason() =
+        testScope.runTest {
+            val deviceEntryRestrictionReason by
+                collectLastValue(underTest.deviceEntryRestrictionReason)
+            kosmos.fakeSystemPropertiesHelper.set(
+                DeviceUnlockedInteractor.SYS_BOOT_REASON_PROP,
+                DeviceUnlockedInteractor.REBOOT_MAINLINE_UPDATE
+            )
+            kosmos.fakeBiometricSettingsRepository.setAuthenticationFlags(
+                AuthenticationFlags(
+                    userId = 1,
+                    flag = LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT
+                )
+            )
+            runCurrent()
+
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(false)
+            runCurrent()
+
+            assertThat(deviceEntryRestrictionReason).isNull()
+
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
+            runCurrent()
+
+            assertThat(deviceEntryRestrictionReason)
+                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
+
+            kosmos.fakeBiometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
+            runCurrent()
+
+            assertThat(deviceEntryRestrictionReason)
+                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
+
+            kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
+            kosmos.fakeTrustRepository.setTrustUsuallyManaged(true)
+            runCurrent()
+
+            assertThat(deviceEntryRestrictionReason)
+                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
+        }
+
+    private fun TestScope.verifyRestrictionReasonsForAuthFlags(
+        vararg authFlagToDeviceEntryRestriction: Pair<Int, DeviceEntryRestrictionReason?>
+    ) {
+        val deviceEntryRestrictionReason by collectLastValue(underTest.deviceEntryRestrictionReason)
+
+        authFlagToDeviceEntryRestriction.forEach { (flag, expectedReason) ->
+            kosmos.fakeBiometricSettingsRepository.setAuthenticationFlags(
+                AuthenticationFlags(userId = 1, flag = flag)
+            )
+            runCurrent()
+
+            if (expectedReason == null) {
+                assertThat(deviceEntryRestrictionReason).isNull()
+            } else {
+                assertThat(deviceEntryRestrictionReason).isEqualTo(expectedReason)
+            }
+        }
+    }
+
     companion object {
         private const val primaryUserId = 1
         private val primaryUser = UserInfo(primaryUserId, "test user", UserInfo.FLAG_PRIMARY)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt
index 444f63a..60c9bb0 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/dreams/DreamOverlayServiceTest.kt
@@ -41,6 +41,7 @@
 import com.android.internal.logging.UiEventLogger
 import com.android.keyguard.KeyguardUpdateMonitor
 import com.android.keyguard.KeyguardUpdateMonitorCallback
+import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.ambient.touch.TouchMonitor
 import com.android.systemui.ambient.touch.dagger.AmbientTouchComponent
@@ -118,11 +119,11 @@
 
     @Mock
     lateinit var mDreamComplicationComponentFactory:
-            com.android.systemui.dreams.complication.dagger.ComplicationComponent.Factory
+        com.android.systemui.dreams.complication.dagger.ComplicationComponent.Factory
 
     @Mock
     lateinit var mDreamComplicationComponent:
-            com.android.systemui.dreams.complication.dagger.ComplicationComponent
+        com.android.systemui.dreams.complication.dagger.ComplicationComponent
 
     @Mock lateinit var mHideComplicationTouchHandler: HideComplicationTouchHandler
 
@@ -202,8 +203,12 @@
         whenever(mScrimManager.getCurrentController()).thenReturn(mScrimController)
         whenever(mLazyViewCapture.value).thenReturn(viewCaptureSpy)
         mWindowParams = WindowManager.LayoutParams()
-        mViewCaptureAwareWindowManager = ViewCaptureAwareWindowManager(mWindowManager,
-                mLazyViewCapture, isViewCaptureEnabled = false)
+        mViewCaptureAwareWindowManager =
+            ViewCaptureAwareWindowManager(
+                mWindowManager,
+                mLazyViewCapture,
+                isViewCaptureEnabled = false
+            )
         mService =
             DreamOverlayService(
                 mContext,
@@ -257,7 +262,7 @@
         mMainExecutor.runAllReady()
         verify(mUiEventLogger).log(DreamOverlayService.DreamOverlayEvent.DREAM_OVERLAY_ENTER_START)
         verify(mUiEventLogger)
-                .log(DreamOverlayService.DreamOverlayEvent.DREAM_OVERLAY_COMPLETE_START)
+            .log(DreamOverlayService.DreamOverlayEvent.DREAM_OVERLAY_COMPLETE_START)
     }
 
     @Test
@@ -634,7 +639,7 @@
     }
 
     @Test
-    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT)
+    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_COMMUNAL_HUB)
     @kotlin.Throws(RemoteException::class)
     fun testTransitionToGlanceableHub() =
         testScope.runTest {
@@ -658,7 +663,7 @@
         }
 
     @Test
-    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT)
+    @EnableFlags(Flags.FLAG_DREAM_WAKE_REDIRECT, FLAG_COMMUNAL_HUB)
     @Throws(RemoteException::class)
     fun testRedirectExit() =
         testScope.runTest {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
index ec4fd79..b885800 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/domain/interactor/FromDozingTransitionInteractorTest.kt
@@ -123,7 +123,7 @@
         }
 
     @Test
-    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
+    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR, Flags.FLAG_COMMUNAL_HUB)
     fun testTransitionToLockscreen_onPowerButtonPress_canDream_glanceableHubAvailable() =
         testScope.runTest {
             whenever(kosmos.dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropStateTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropStateTest.kt
index 1c3021e..73a0039 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropStateTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/compose/DragAndDropStateTest.kt
@@ -82,6 +82,20 @@
         TestEditTiles.forEach { assertThat(underTest.isMoving(it.tileSpec)).isFalse() }
     }
 
+    @Test
+    fun onMoveOutOfBounds_removeMovingTileFromCurrentList() {
+        val movingTileSpec = TestEditTiles[0].tileSpec
+
+        // Start the drag movement
+        underTest.onStarted(movingTileSpec)
+
+        // Move the tile outside of the list
+        underTest.movedOutOfBounds()
+
+        // Asserts the moving tile is not current
+        assertThat(listState.tiles.first { it.tileSpec == movingTileSpec }.isCurrent).isFalse()
+    }
+
     companion object {
         private fun createEditTile(tileSpec: String): EditTileViewModel {
             return EditTileViewModel(
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
index 090033d..5d804cc 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
@@ -120,7 +120,7 @@
     oneway void notifyTaskbarAutohideSuspend(boolean suspend) = 48;
 
     /**
-     * Notifies SystemUI to invoke IME Switcher.
+     * Notifies that the IME switcher button has been pressed.
      */
     oneway void onImeSwitcherPressed() = 49;
 
@@ -167,5 +167,10 @@
      */
     oneway void toggleQuickSettingsPanel() = 56;
 
-    // Next id = 57
+    /**
+     * Notifies that the IME Switcher button has been long pressed.
+     */
+    oneway void onImeSwitcherLongPress() = 57;
+
+    // Next id = 58
 }
diff --git a/packages/SystemUI/src/com/android/systemui/assist/ui/DefaultUiController.java b/packages/SystemUI/src/com/android/systemui/assist/ui/DefaultUiController.java
index 56273eb..6e25744 100644
--- a/packages/SystemUI/src/com/android/systemui/assist/ui/DefaultUiController.java
+++ b/packages/SystemUI/src/com/android/systemui/assist/ui/DefaultUiController.java
@@ -33,6 +33,7 @@
 import android.view.animation.PathInterpolator;
 import android.widget.FrameLayout;
 
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.systemui.assist.AssistLogger;
@@ -66,7 +67,7 @@
     protected InvocationLightsView mInvocationLightsView;
     protected final AssistLogger mAssistLogger;
 
-    private final WindowManager mWindowManager;
+    private final ViewCaptureAwareWindowManager mWindowManager;
     private final MetricsLogger mMetricsLogger;
     private final Lazy<AssistManager> mAssistManagerLazy;
     private final WindowManager.LayoutParams mLayoutParams;
@@ -80,12 +81,12 @@
 
     @Inject
     public DefaultUiController(Context context, AssistLogger assistLogger,
-            WindowManager windowManager, MetricsLogger metricsLogger,
-            Lazy<AssistManager> assistManagerLazy,
+            ViewCaptureAwareWindowManager viewCaptureAwareWindowManager,
+            MetricsLogger metricsLogger, Lazy<AssistManager> assistManagerLazy,
             NavigationBarController navigationBarController) {
         mAssistLogger = assistLogger;
         mRoot = new FrameLayout(context);
-        mWindowManager = windowManager;
+        mWindowManager = viewCaptureAwareWindowManager;
         mMetricsLogger = metricsLogger;
         mAssistManagerLazy = assistManagerLazy;
 
diff --git a/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt b/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt
index a9f985f..468737d 100644
--- a/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/authentication/data/repository/AuthenticationRepository.kt
@@ -288,6 +288,7 @@
     override suspend fun reportAuthenticationAttempt(isSuccessful: Boolean) {
         withContext(backgroundDispatcher) {
             if (isSuccessful) {
+                lockPatternUtils.userPresent(selectedUserId)
                 lockPatternUtils.reportSuccessfulPasswordAttempt(selectedUserId)
                 _hasLockoutOccurred.value = false
             } else {
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/FaceHelpMessageDebouncer.kt b/packages/SystemUI/src/com/android/systemui/biometrics/FaceHelpMessageDebouncer.kt
new file mode 100644
index 0000000..1685f49
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/FaceHelpMessageDebouncer.kt
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2024 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.systemui.biometrics
+
+import android.util.Log
+import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
+
+/**
+ * Debounces face help messages with parameters:
+ * - window: Window of time (in milliseconds) to analyze face acquired messages)
+ * - startWindow: Window of time on start required before showing the first help message
+ * - shownFaceMessageFrequencyBoost: Frequency boost given to messages that are currently shown to
+ *   the user
+ */
+class FaceHelpMessageDebouncer(
+    private val window: Long = DEFAULT_WINDOW_MS,
+    private val startWindow: Long = window,
+    private val shownFaceMessageFrequencyBoost: Int = 4,
+) {
+    private val TAG = "FaceHelpMessageDebouncer"
+    private var startTime = 0L
+    private var helpFaceAuthStatuses: MutableList<HelpFaceAuthenticationStatus> = mutableListOf()
+    private var lastMessageIdShown: Int? = null
+
+    /** Remove messages that are outside of the time [window]. */
+    private fun removeOldMessages(currTimestamp: Long) {
+        var numToRemove = 0
+        // This works under the assumption that timestamps are ordered from first to last
+        // in chronological order
+        for (index in helpFaceAuthStatuses.indices) {
+            if ((helpFaceAuthStatuses[index].createdAt + window) >= currTimestamp) {
+                break // all timestamps from here and on are within the window
+            }
+            numToRemove += 1
+        }
+
+        // Remove all outside time window
+        repeat(numToRemove) { helpFaceAuthStatuses.removeFirst() }
+
+        if (numToRemove > 0) {
+            Log.v(TAG, "removedFirst=$numToRemove")
+        }
+    }
+
+    private fun getMostFrequentHelpMessage(): HelpFaceAuthenticationStatus? {
+        // freqMap: msgId => frequency
+        val freqMap = helpFaceAuthStatuses.groupingBy { it.msgId }.eachCount().toMutableMap()
+
+        // Give shownFaceMessageFrequencyBoost to lastMessageIdShown
+        if (lastMessageIdShown != null) {
+            freqMap.computeIfPresent(lastMessageIdShown!!) { _, value ->
+                value + shownFaceMessageFrequencyBoost
+            }
+        }
+        // Go through all msgId keys & find the highest frequency msgId
+        val msgIdWithHighestFrequency =
+            freqMap.entries
+                .maxWithOrNull { (msgId1, freq1), (msgId2, freq2) ->
+                    // ties are broken by more recent message
+                    if (freq1 == freq2) {
+                        helpFaceAuthStatuses
+                            .findLast { it.msgId == msgId1 }!!
+                            .createdAt
+                            .compareTo(
+                                helpFaceAuthStatuses.findLast { it.msgId == msgId2 }!!.createdAt
+                            )
+                    } else {
+                        freq1.compareTo(freq2)
+                    }
+                }
+                ?.key
+        return helpFaceAuthStatuses.findLast { it.msgId == msgIdWithHighestFrequency }
+    }
+
+    fun addMessage(helpFaceAuthStatus: HelpFaceAuthenticationStatus) {
+        helpFaceAuthStatuses.add(helpFaceAuthStatus)
+        Log.v(TAG, "added message=$helpFaceAuthStatus")
+    }
+
+    fun getMessageToShow(atTimestamp: Long): HelpFaceAuthenticationStatus? {
+        if (helpFaceAuthStatuses.isEmpty() || (atTimestamp - startTime) < startWindow) {
+            // there's not enough time that has passed to determine whether to show anything yet
+            Log.v(TAG, "No message; haven't made initial threshold window OR no messages")
+            return null
+        }
+        removeOldMessages(atTimestamp)
+        val messageToShow = getMostFrequentHelpMessage()
+        if (lastMessageIdShown != messageToShow?.msgId) {
+            Log.v(
+                TAG,
+                "showMessage previousLastMessageId=$lastMessageIdShown" +
+                    "\n\tmessageToShow=$messageToShow " +
+                    "\n\thelpFaceAuthStatusesSize=${helpFaceAuthStatuses.size}" +
+                    "\n\thelpFaceAuthStatuses=$helpFaceAuthStatuses"
+            )
+            lastMessageIdShown = messageToShow?.msgId
+        }
+        return messageToShow
+    }
+
+    fun startNewFaceAuthSession(faceAuthStartedTime: Long) {
+        Log.d(TAG, "startNewFaceAuthSession at startTime=$startTime")
+        startTime = faceAuthStartedTime
+        helpFaceAuthStatuses.clear()
+        lastMessageIdShown = null
+    }
+
+    companion object {
+        const val DEFAULT_WINDOW_MS = 200L
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt
index c868d01..430887d 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt
@@ -94,8 +94,16 @@
 
         val textColorError =
             view.resources.getColor(R.color.biometric_dialog_error, view.context.theme)
+
+        val attributes =
+            view.context.obtainStyledAttributes(
+                R.style.TextAppearance_AuthCredential_Indicator,
+                intArrayOf(android.R.attr.textColor)
+            )
         val textColorHint =
-            view.resources.getColor(R.color.biometric_dialog_gray, view.context.theme)
+            if (constraintBp()) attributes.getColor(0, 0)
+            else view.resources.getColor(R.color.biometric_dialog_gray, view.context.theme)
+        attributes.recycle()
 
         val logoView = view.requireViewById<ImageView>(R.id.logo)
         val logoDescriptionView = view.requireViewById<TextView>(R.id.logo_description)
diff --git a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModel.kt b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModel.kt
index 6cb9b16..810b6d1 100644
--- a/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModel.kt
@@ -32,7 +32,7 @@
 import com.android.systemui.deviceentry.domain.interactor.BiometricMessageInteractor
 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryFaceAuthInteractor
 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryFingerprintAuthInteractor
-import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
+import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor
 import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
 import com.android.systemui.deviceentry.shared.model.FaceFailureMessage
 import com.android.systemui.deviceentry.shared.model.FaceLockoutMessage
@@ -75,7 +75,7 @@
     private val clock: SystemClock,
     private val biometricMessageInteractor: BiometricMessageInteractor,
     private val faceAuthInteractor: DeviceEntryFaceAuthInteractor,
-    private val deviceEntryInteractor: DeviceEntryInteractor,
+    private val deviceUnlockedInteractor: DeviceUnlockedInteractor,
     private val fingerprintInteractor: DeviceEntryFingerprintAuthInteractor,
     flags: ComposeBouncerFlags,
 ) {
@@ -119,7 +119,7 @@
                         }
                     } else if (authMethod.isSecure) {
                         combine(
-                            deviceEntryInteractor.deviceEntryRestrictionReason,
+                            deviceUnlockedInteractor.deviceEntryRestrictionReason,
                             lockoutMessage,
                             fingerprintInteractor.isFingerprintCurrentlyAllowedOnBouncer,
                             resetToDefault,
@@ -413,7 +413,7 @@
         clock: SystemClock,
         biometricMessageInteractor: BiometricMessageInteractor,
         faceAuthInteractor: DeviceEntryFaceAuthInteractor,
-        deviceEntryInteractor: DeviceEntryInteractor,
+        deviceUnlockedInteractor: DeviceUnlockedInteractor,
         fingerprintInteractor: DeviceEntryFingerprintAuthInteractor,
         flags: ComposeBouncerFlags,
         userSwitcherViewModel: UserSwitcherViewModel,
@@ -427,7 +427,7 @@
             clock = clock,
             biometricMessageInteractor = biometricMessageInteractor,
             faceAuthInteractor = faceAuthInteractor,
-            deviceEntryInteractor = deviceEntryInteractor,
+            deviceUnlockedInteractor = deviceUnlockedInteractor,
             fingerprintInteractor = fingerprintInteractor,
             flags = flags,
             selectedUser = userSwitcherViewModel.selectedUser,
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
index fa52dad..9460eaf 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryFaceAuthRepository.kt
@@ -57,16 +57,13 @@
 import com.android.systemui.log.SessionTracker
 import com.android.systemui.log.table.TableLogBuffer
 import com.android.systemui.power.domain.interactor.PowerInteractor
-import com.android.systemui.res.R
 import com.android.systemui.scene.shared.model.Scenes
 import com.android.systemui.statusbar.phone.KeyguardBypassController
 import com.android.systemui.user.data.model.SelectionStatus
 import com.android.systemui.user.data.repository.UserRepository
 import com.google.errorprone.annotations.CompileTimeConstant
 import java.io.PrintWriter
-import java.util.Arrays
 import java.util.concurrent.Executor
-import java.util.stream.Collectors
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.CoroutineScope
@@ -170,7 +167,6 @@
 ) : DeviceEntryFaceAuthRepository, Dumpable {
     private var authCancellationSignal: CancellationSignal? = null
     private var detectCancellationSignal: CancellationSignal? = null
-    private var faceAcquiredInfoIgnoreList: Set<Int>
     private var retryCount = 0
 
     private var pendingAuthenticateRequest = MutableStateFlow<AuthenticationRequest?>(null)
@@ -240,14 +236,6 @@
             faceManager?.addLockoutResetCallback(faceLockoutResetCallback)
             faceAuthLogger.addLockoutResetCallbackDone()
         }
-        faceAcquiredInfoIgnoreList =
-            Arrays.stream(
-                    context.resources.getIntArray(
-                        R.array.config_face_acquire_device_entry_ignorelist
-                    )
-                )
-                .boxed()
-                .collect(Collectors.toSet())
         dumpManager.registerCriticalDumpable("DeviceEntryFaceAuthRepositoryImpl", this)
 
         canRunFaceAuth =
@@ -485,10 +473,8 @@
             }
 
             override fun onAuthenticationHelp(code: Int, helpStr: CharSequence?) {
-                if (faceAcquiredInfoIgnoreList.contains(code)) {
-                    return
-                }
-                _authenticationStatus.value = HelpFaceAuthenticationStatus(code, helpStr.toString())
+                _authenticationStatus.value =
+                    HelpFaceAuthenticationStatus(code, helpStr?.toString())
             }
 
             override fun onAuthenticationSucceeded(result: FaceManager.AuthenticationResult) {
@@ -731,7 +717,6 @@
         pw.println("  _pendingAuthenticateRequest: ${pendingAuthenticateRequest.value}")
         pw.println("  authCancellationSignal: $authCancellationSignal")
         pw.println("  detectCancellationSignal: $detectCancellationSignal")
-        pw.println("  faceAcquiredInfoIgnoreList: $faceAcquiredInfoIgnoreList")
         pw.println("  _authenticationStatus: ${_authenticationStatus.value}")
         pw.println("  _detectionStatus: ${_detectionStatus.value}")
         pw.println("  currentUserId: $currentUserId")
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepository.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepository.kt
index 0f18978..e2ad774 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepository.kt
@@ -39,12 +39,6 @@
      * the lockscreen.
      */
     val isBypassEnabled: StateFlow<Boolean>
-
-    /**
-     * Reports, to system server, that the user is "present" now. This is a signal that system
-     * server uses to know that the device has been entered.
-     */
-    suspend fun reportUserPresent()
 }
 
 /** Encapsulates application state for device entry. */
@@ -84,17 +78,6 @@
                 SharingStarted.Eagerly,
                 initialValue = keyguardBypassController.bypassEnabled,
             )
-
-    override suspend fun reportUserPresent() {
-        withContext(backgroundDispatcher) {
-            val selectedUserId = userRepository.selectedUser.value.userInfo.id
-            lockPatternUtils.userPresent(selectedUserId)
-        }
-    }
-
-    companion object {
-        private const val TAG = "DeviceEntryRepositoryImpl"
-    }
 }
 
 @Module
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractor.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractor.kt
new file mode 100644
index 0000000..34b1544
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractor.kt
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2024 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.systemui.deviceentry.domain.interactor
+
+import android.content.res.Resources
+import android.hardware.biometrics.BiometricFaceConstants
+import com.android.systemui.biometrics.FaceHelpMessageDebouncer
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepository
+import com.android.systemui.deviceentry.shared.model.AcquiredFaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.FaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
+import com.android.systemui.res.R
+import java.util.Arrays
+import java.util.stream.Collectors
+import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.flow.transform
+
+/**
+ * Process face authentication statuses.
+ * - Ignores face help messages based on R.array.config_face_acquire_device_entry_ignorelist.
+ * - Uses FaceHelpMessageDebouncer to debounce flickery help messages.
+ */
+@SysUISingleton
+class DeviceEntryFaceAuthStatusInteractor
+@Inject
+constructor(
+    repository: DeviceEntryFaceAuthRepository,
+    @Main private val resources: Resources,
+    @Application private val applicationScope: CoroutineScope,
+) {
+    private val faceHelpMessageDebouncer = FaceHelpMessageDebouncer()
+    private var faceAcquiredInfoIgnoreList: Set<Int> =
+        Arrays.stream(resources.getIntArray(R.array.config_face_acquire_device_entry_ignorelist))
+            .boxed()
+            .collect(Collectors.toSet())
+
+    val authenticationStatus: StateFlow<FaceAuthenticationStatus?> =
+        repository.authenticationStatus
+            .transform { authenticationStatus ->
+                if (authenticationStatus is AcquiredFaceAuthenticationStatus) {
+                    if (
+                        authenticationStatus.acquiredInfo ==
+                            BiometricFaceConstants.FACE_ACQUIRED_START
+                    ) {
+                        faceHelpMessageDebouncer.startNewFaceAuthSession(
+                            authenticationStatus.createdAt
+                        )
+                    }
+                }
+
+                if (authenticationStatus is HelpFaceAuthenticationStatus) {
+                    if (!faceAcquiredInfoIgnoreList.contains(authenticationStatus.msgId)) {
+                        faceHelpMessageDebouncer.addMessage(authenticationStatus)
+                    }
+
+                    val messageToShow =
+                        faceHelpMessageDebouncer.getMessageToShow(
+                            atTimestamp = authenticationStatus.createdAt,
+                        )
+                    if (messageToShow != null) {
+                        emit(messageToShow)
+                    }
+
+                    return@transform
+                }
+
+                emit(authenticationStatus)
+            }
+            .stateIn(
+                scope = applicationScope,
+                started = SharingStarted.WhileSubscribed(),
+                initialValue = null,
+            )
+}
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractor.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractor.kt
index 425bb96..ea0e59b 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractor.kt
@@ -16,33 +16,24 @@
 
 package com.android.systemui.deviceentry.domain.interactor
 
-import androidx.annotation.VisibleForTesting
 import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
 import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
-import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
-import com.android.systemui.flags.SystemPropertiesHelper
-import com.android.systemui.keyguard.domain.interactor.TrustInteractor
 import com.android.systemui.scene.domain.interactor.SceneInteractor
 import com.android.systemui.scene.shared.model.Scenes
-import com.android.systemui.util.kotlin.Quad
 import com.android.systemui.utils.coroutines.flow.mapLatestConflated
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.filter
 import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.flow.flatMapLatest
-import kotlinx.coroutines.flow.flowOf
 import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.flow.stateIn
 import kotlinx.coroutines.launch
 
@@ -61,12 +52,7 @@
     private val repository: DeviceEntryRepository,
     private val authenticationInteractor: AuthenticationInteractor,
     private val sceneInteractor: SceneInteractor,
-    faceAuthInteractor: DeviceEntryFaceAuthInteractor,
-    private val fingerprintAuthInteractor: DeviceEntryFingerprintAuthInteractor,
-    private val biometricSettingsInteractor: DeviceEntryBiometricSettingsInteractor,
-    private val trustInteractor: TrustInteractor,
     private val deviceUnlockedInteractor: DeviceUnlockedInteractor,
-    private val systemPropertiesHelper: SystemPropertiesHelper,
     private val alternateBouncerInteractor: AlternateBouncerInteractor,
 ) {
     /**
@@ -109,11 +95,6 @@
                     false
                 }
             }
-            .onEach { isDeviceEntered ->
-                if (isDeviceEntered) {
-                    repository.reportUserPresent()
-                }
-            }
             .stateIn(
                 scope = applicationScope,
                 started = SharingStarted.Eagerly,
@@ -156,70 +137,6 @@
                 initialValue = null,
             )
 
-    private val faceEnrolledAndEnabled = biometricSettingsInteractor.isFaceAuthEnrolledAndEnabled
-    private val fingerprintEnrolledAndEnabled =
-        biometricSettingsInteractor.isFingerprintAuthEnrolledAndEnabled
-    private val trustAgentEnabled = trustInteractor.isEnrolledAndEnabled
-
-    private val faceOrFingerprintOrTrustEnabled: Flow<Triple<Boolean, Boolean, Boolean>> =
-        combine(faceEnrolledAndEnabled, fingerprintEnrolledAndEnabled, trustAgentEnabled, ::Triple)
-
-    /**
-     * Reason why device entry is restricted to certain authentication methods for the current user.
-     *
-     * Emits null when there are no device entry restrictions active.
-     */
-    val deviceEntryRestrictionReason: Flow<DeviceEntryRestrictionReason?> =
-        faceOrFingerprintOrTrustEnabled.flatMapLatest {
-            (faceEnabled, fingerprintEnabled, trustEnabled) ->
-            if (faceEnabled || fingerprintEnabled || trustEnabled) {
-                combine(
-                        biometricSettingsInteractor.authenticationFlags,
-                        faceAuthInteractor.isLockedOut,
-                        fingerprintAuthInteractor.isLockedOut,
-                        trustInteractor.isTrustAgentCurrentlyAllowed,
-                        ::Quad
-                    )
-                    .map { (authFlags, isFaceLockedOut, isFingerprintLockedOut, trustManaged) ->
-                        when {
-                            authFlags.isPrimaryAuthRequiredAfterReboot &&
-                                wasRebootedForMainlineUpdate ->
-                                DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate
-                            authFlags.isPrimaryAuthRequiredAfterReboot ->
-                                DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot
-                            authFlags.isPrimaryAuthRequiredAfterDpmLockdown ->
-                                DeviceEntryRestrictionReason.PolicyLockdown
-                            authFlags.isInUserLockdown -> DeviceEntryRestrictionReason.UserLockdown
-                            authFlags.isPrimaryAuthRequiredForUnattendedUpdate ->
-                                DeviceEntryRestrictionReason.UnattendedUpdate
-                            authFlags.isPrimaryAuthRequiredAfterTimeout ->
-                                DeviceEntryRestrictionReason.SecurityTimeout
-                            authFlags.isPrimaryAuthRequiredAfterLockout ->
-                                DeviceEntryRestrictionReason.BouncerLockedOut
-                            isFingerprintLockedOut ->
-                                DeviceEntryRestrictionReason.StrongBiometricsLockedOut
-                            isFaceLockedOut && faceAuthInteractor.isFaceAuthStrong() ->
-                                DeviceEntryRestrictionReason.StrongBiometricsLockedOut
-                            isFaceLockedOut -> DeviceEntryRestrictionReason.NonStrongFaceLockedOut
-                            authFlags.isSomeAuthRequiredAfterAdaptiveAuthRequest ->
-                                DeviceEntryRestrictionReason.AdaptiveAuthRequest
-                            (trustEnabled && !trustManaged) &&
-                                (authFlags.someAuthRequiredAfterTrustAgentExpired ||
-                                    authFlags.someAuthRequiredAfterUserRequest) ->
-                                DeviceEntryRestrictionReason.TrustAgentDisabled
-                            authFlags.strongerAuthRequiredAfterNonStrongBiometricsTimeout ->
-                                DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout
-                            else -> null
-                        }
-                    }
-            } else {
-                flowOf(null)
-            }
-        }
-
-    /** Whether the device is in lockdown mode, where bouncer input is required to unlock. */
-    val isInLockdown: Flow<Boolean> = deviceEntryRestrictionReason.map { it.isInLockdown() }
-
     /**
      * Attempt to enter the device and dismiss the lockscreen. If authentication is required to
      * unlock the device it will transition to bouncer.
@@ -268,27 +185,6 @@
         return repository.isLockscreenEnabled()
     }
 
-    fun DeviceEntryRestrictionReason?.isInLockdown(): Boolean {
-        return when (this) {
-            DeviceEntryRestrictionReason.UserLockdown -> true
-            DeviceEntryRestrictionReason.PolicyLockdown -> true
-
-            // Add individual enum value instead of using "else" so new reasons are guaranteed
-            // to be added here at compile-time.
-            null -> false
-            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot -> false
-            DeviceEntryRestrictionReason.BouncerLockedOut -> false
-            DeviceEntryRestrictionReason.AdaptiveAuthRequest -> false
-            DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout -> false
-            DeviceEntryRestrictionReason.TrustAgentDisabled -> false
-            DeviceEntryRestrictionReason.StrongBiometricsLockedOut -> false
-            DeviceEntryRestrictionReason.SecurityTimeout -> false
-            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate -> false
-            DeviceEntryRestrictionReason.UnattendedUpdate -> false
-            DeviceEntryRestrictionReason.NonStrongFaceLockedOut -> false
-        }
-    }
-
     /**
      * Whether lockscreen bypass is enabled. When enabled, the lockscreen will be automatically
      * dismissed once the authentication challenge is completed. For example, completing a biometric
@@ -296,12 +192,4 @@
      * lockscreen.
      */
     val isBypassEnabled: StateFlow<Boolean> = repository.isBypassEnabled
-
-    private val wasRebootedForMainlineUpdate
-        get() = systemPropertiesHelper.get(SYS_BOOT_REASON_PROP) == REBOOT_MAINLINE_UPDATE
-
-    companion object {
-        @VisibleForTesting const val SYS_BOOT_REASON_PROP = "sys.boot.reason.last"
-        @VisibleForTesting const val REBOOT_MAINLINE_UPDATE = "reboot,mainline_update"
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractor.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractor.kt
index 5141690..e17e530 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractor.kt
@@ -16,20 +16,26 @@
 
 package com.android.systemui.deviceentry.domain.interactor
 
+import androidx.annotation.VisibleForTesting
 import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor
 import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
+import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
 import com.android.systemui.deviceentry.shared.model.DeviceUnlockSource
 import com.android.systemui.deviceentry.shared.model.DeviceUnlockStatus
+import com.android.systemui.flags.SystemPropertiesHelper
 import com.android.systemui.keyguard.domain.interactor.TrustInteractor
 import com.android.systemui.power.domain.interactor.PowerInteractor
+import com.android.systemui.utils.coroutines.flow.flatMapLatestConflated
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.filter
 import kotlinx.coroutines.flow.flatMapLatest
 import kotlinx.coroutines.flow.flowOf
@@ -49,6 +55,8 @@
     faceAuthInteractor: DeviceEntryFaceAuthInteractor,
     fingerprintAuthInteractor: DeviceEntryFingerprintAuthInteractor,
     private val powerInteractor: PowerInteractor,
+    private val biometricSettingsInteractor: DeviceEntryBiometricSettingsInteractor,
+    private val systemPropertiesHelper: SystemPropertiesHelper,
 ) {
 
     private val deviceUnlockSource =
@@ -69,6 +77,75 @@
                 .map { DeviceUnlockSource.BouncerInput }
         )
 
+    private val faceEnrolledAndEnabled = biometricSettingsInteractor.isFaceAuthEnrolledAndEnabled
+    private val fingerprintEnrolledAndEnabled =
+        biometricSettingsInteractor.isFingerprintAuthEnrolledAndEnabled
+    private val trustAgentEnabled = trustInteractor.isEnrolledAndEnabled
+
+    private val faceOrFingerprintOrTrustEnabled: Flow<Triple<Boolean, Boolean, Boolean>> =
+        combine(faceEnrolledAndEnabled, fingerprintEnrolledAndEnabled, trustAgentEnabled, ::Triple)
+
+    /**
+     * Reason why device entry is restricted to certain authentication methods for the current user.
+     *
+     * Emits null when there are no device entry restrictions active.
+     */
+    val deviceEntryRestrictionReason: Flow<DeviceEntryRestrictionReason?> =
+        faceOrFingerprintOrTrustEnabled.flatMapLatest {
+            (faceEnabled, fingerprintEnabled, trustEnabled) ->
+            if (faceEnabled || fingerprintEnabled || trustEnabled) {
+                combine(
+                    biometricSettingsInteractor.authenticationFlags,
+                    faceAuthInteractor.isLockedOut,
+                    fingerprintAuthInteractor.isLockedOut,
+                    trustInteractor.isTrustAgentCurrentlyAllowed,
+                ) { authFlags, isFaceLockedOut, isFingerprintLockedOut, trustManaged ->
+                    when {
+                        authFlags.isPrimaryAuthRequiredAfterReboot &&
+                            wasRebootedForMainlineUpdate() ->
+                            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate
+                        authFlags.isPrimaryAuthRequiredAfterReboot ->
+                            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot
+                        authFlags.isPrimaryAuthRequiredAfterDpmLockdown ->
+                            DeviceEntryRestrictionReason.PolicyLockdown
+                        authFlags.isInUserLockdown -> DeviceEntryRestrictionReason.UserLockdown
+                        authFlags.isPrimaryAuthRequiredForUnattendedUpdate ->
+                            DeviceEntryRestrictionReason.UnattendedUpdate
+                        authFlags.isPrimaryAuthRequiredAfterTimeout ->
+                            DeviceEntryRestrictionReason.SecurityTimeout
+                        authFlags.isPrimaryAuthRequiredAfterLockout ->
+                            DeviceEntryRestrictionReason.BouncerLockedOut
+                        isFingerprintLockedOut ->
+                            DeviceEntryRestrictionReason.StrongBiometricsLockedOut
+                        isFaceLockedOut && faceAuthInteractor.isFaceAuthStrong() ->
+                            DeviceEntryRestrictionReason.StrongBiometricsLockedOut
+                        isFaceLockedOut -> DeviceEntryRestrictionReason.NonStrongFaceLockedOut
+                        authFlags.isSomeAuthRequiredAfterAdaptiveAuthRequest ->
+                            DeviceEntryRestrictionReason.AdaptiveAuthRequest
+                        (trustEnabled && !trustManaged) &&
+                            (authFlags.someAuthRequiredAfterTrustAgentExpired ||
+                                authFlags.someAuthRequiredAfterUserRequest) ->
+                            DeviceEntryRestrictionReason.TrustAgentDisabled
+                        authFlags.strongerAuthRequiredAfterNonStrongBiometricsTimeout ->
+                            DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout
+                        else -> null
+                    }
+                }
+            } else {
+                biometricSettingsInteractor.authenticationFlags.map { authFlags ->
+                    when {
+                        authFlags.isInUserLockdown -> DeviceEntryRestrictionReason.UserLockdown
+                        authFlags.isPrimaryAuthRequiredAfterDpmLockdown ->
+                            DeviceEntryRestrictionReason.PolicyLockdown
+                        else -> null
+                    }
+                }
+            }
+        }
+
+    /** Whether the device is in lockdown mode, where bouncer input is required to unlock. */
+    val isInLockdown: Flow<Boolean> = deviceEntryRestrictionReason.map { it.isInLockdown() }
+
     /**
      * Whether the device is unlocked or not, along with the information about the authentication
      * method that was used to unlock the device.
@@ -90,13 +167,18 @@
                     // Device is locked if SIM is locked.
                     flowOf(DeviceUnlockStatus(false, null))
                 } else {
-                    powerInteractor.isAsleep.flatMapLatest { isAsleep ->
-                        if (isAsleep) {
-                            flowOf(DeviceUnlockStatus(false, null))
-                        } else {
-                            deviceUnlockSource.map { DeviceUnlockStatus(true, it) }
+                    combine(
+                            powerInteractor.isAsleep,
+                            isInLockdown,
+                            ::Pair,
+                        )
+                        .flatMapLatestConflated { (isAsleep, isInLockdown) ->
+                            if (isAsleep || isInLockdown) {
+                                flowOf(DeviceUnlockStatus(false, null))
+                            } else {
+                                deviceUnlockSource.map { DeviceUnlockStatus(true, it) }
+                            }
                         }
-                    }
                 }
             }
             .stateIn(
@@ -104,4 +186,34 @@
                 started = SharingStarted.Eagerly,
                 initialValue = DeviceUnlockStatus(false, null),
             )
+
+    private fun DeviceEntryRestrictionReason?.isInLockdown(): Boolean {
+        return when (this) {
+            DeviceEntryRestrictionReason.UserLockdown -> true
+            DeviceEntryRestrictionReason.PolicyLockdown -> true
+
+            // Add individual enum value instead of using "else" so new reasons are guaranteed
+            // to be added here at compile-time.
+            null -> false
+            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceReboot -> false
+            DeviceEntryRestrictionReason.BouncerLockedOut -> false
+            DeviceEntryRestrictionReason.AdaptiveAuthRequest -> false
+            DeviceEntryRestrictionReason.NonStrongBiometricsSecurityTimeout -> false
+            DeviceEntryRestrictionReason.TrustAgentDisabled -> false
+            DeviceEntryRestrictionReason.StrongBiometricsLockedOut -> false
+            DeviceEntryRestrictionReason.SecurityTimeout -> false
+            DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate -> false
+            DeviceEntryRestrictionReason.UnattendedUpdate -> false
+            DeviceEntryRestrictionReason.NonStrongFaceLockedOut -> false
+        }
+    }
+
+    private fun wasRebootedForMainlineUpdate(): Boolean {
+        return systemPropertiesHelper.get(SYS_BOOT_REASON_PROP) == REBOOT_MAINLINE_UPDATE
+    }
+
+    companion object {
+        @VisibleForTesting const val SYS_BOOT_REASON_PROP = "sys.boot.reason.last"
+        @VisibleForTesting const val REBOOT_MAINLINE_UPDATE = "reboot,mainline_update"
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/SystemUIDeviceEntryFaceAuthInteractor.kt b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/SystemUIDeviceEntryFaceAuthInteractor.kt
index d12ea45..c536d6b 100644
--- a/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/SystemUIDeviceEntryFaceAuthInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/deviceentry/domain/interactor/SystemUIDeviceEntryFaceAuthInteractor.kt
@@ -90,6 +90,7 @@
     private val powerInteractor: PowerInteractor,
     private val biometricSettingsRepository: BiometricSettingsRepository,
     private val trustManager: TrustManager,
+    deviceEntryFaceAuthStatusInteractor: DeviceEntryFaceAuthStatusInteractor,
 ) : DeviceEntryFaceAuthInteractor {
 
     private val listeners: MutableList<FaceAuthenticationListener> = mutableListOf()
@@ -276,9 +277,13 @@
     }
 
     private val faceAuthenticationStatusOverride = MutableStateFlow<FaceAuthenticationStatus?>(null)
+
     /** Provide the status of face authentication */
     override val authenticationStatus =
-        merge(faceAuthenticationStatusOverride.filterNotNull(), repository.authenticationStatus)
+        merge(
+            faceAuthenticationStatusOverride.filterNotNull(),
+            deviceEntryFaceAuthStatusInteractor.authenticationStatus.filterNotNull(),
+        )
 
     /** Provide the status of face detection */
     override val detectionStatus = repository.detectionStatus
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
index 1e4fb4f..493afde 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
@@ -64,7 +64,6 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.Settings;
-import android.service.dreams.IDreamManager;
 import android.sysprop.TelephonyProperties;
 import android.telecom.TelecomManager;
 import android.telephony.ServiceState;
@@ -197,7 +196,6 @@
     private final Context mContext;
     private final GlobalActionsManager mWindowManagerFuncs;
     private final AudioManager mAudioManager;
-    private final IDreamManager mDreamManager;
     private final DevicePolicyManager mDevicePolicyManager;
     private final LockPatternUtils mLockPatternUtils;
     private final SelectedUserInteractor mSelectedUserInteractor;
@@ -345,7 +343,6 @@
             Context context,
             GlobalActionsManager windowManagerFuncs,
             AudioManager audioManager,
-            IDreamManager iDreamManager,
             DevicePolicyManager devicePolicyManager,
             LockPatternUtils lockPatternUtils,
             BroadcastDispatcher broadcastDispatcher,
@@ -382,7 +379,6 @@
         mContext = context;
         mWindowManagerFuncs = windowManagerFuncs;
         mAudioManager = audioManager;
-        mDreamManager = iDreamManager;
         mDevicePolicyManager = devicePolicyManager;
         mLockPatternUtils = lockPatternUtils;
         mTelephonyListenerManager = telephonyListenerManager;
@@ -510,20 +506,7 @@
         mHandler.sendEmptyMessage(MESSAGE_DISMISS);
     }
 
-    protected void awakenIfNecessary() {
-        if (mDreamManager != null) {
-            try {
-                if (mDreamManager.isDreaming()) {
-                    mDreamManager.awaken();
-                }
-            } catch (RemoteException e) {
-                // we tried
-            }
-        }
-    }
-
     protected void handleShow(@Nullable Expandable expandable) {
-        awakenIfNecessary();
         mDialog = createDialog();
         prepareDialog();
 
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
index 853f176..1fd609d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/SideFpsProgressBar.kt
@@ -26,6 +26,7 @@
 import android.view.WindowManager
 import android.widget.ProgressBar
 import androidx.core.view.isGone
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.res.R
 import javax.inject.Inject
@@ -37,7 +38,7 @@
 @Inject
 constructor(
     private val layoutInflater: LayoutInflater,
-    private val windowManager: WindowManager,
+    private val windowManager: ViewCaptureAwareWindowManager,
 ) {
     private var overlayView: View? = null
 
@@ -90,7 +91,7 @@
     ) {
         if (overlayView == null) {
             overlayView = layoutInflater.inflate(R.layout.sidefps_progress_bar, null, false)
-            windowManager.addView(overlayView, overlayViewParams)
+            windowManager.addView(requireNotNull(overlayView), overlayViewParams)
             progressBar?.pivotX = 0.0f
             progressBar?.pivotY = 0.0f
         }
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionLog.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionLog.kt
new file mode 100644
index 0000000..a80bc09
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionLog.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2024 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.systemui.mediaprojection
+
+import javax.inject.Qualifier
+
+/** Logs for media projection related events. */
+@Qualifier
+@MustBeDocumented
+@Retention(AnnotationRetention.RUNTIME)
+annotation class MediaProjectionLog
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionModule.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionModule.kt
index 3489459..7fd77a9 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/MediaProjectionModule.kt
@@ -16,12 +16,25 @@
 
 package com.android.systemui.mediaprojection
 
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.LogBufferFactory
 import com.android.systemui.mediaprojection.data.repository.MediaProjectionManagerRepository
 import com.android.systemui.mediaprojection.data.repository.MediaProjectionRepository
 import dagger.Binds
 import dagger.Module
+import dagger.Provides
 
 @Module
 interface MediaProjectionModule {
     @Binds fun mediaRepository(impl: MediaProjectionManagerRepository): MediaProjectionRepository
+
+    companion object {
+        @Provides
+        @SysUISingleton
+        @MediaProjectionLog
+        fun provideMediaProjectionLogBuffer(factory: LogBufferFactory): LogBuffer {
+            return factory.create("MediaProjection", 50)
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepository.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepository.kt
index c90f197..5704e80 100644
--- a/packages/SystemUI/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepository.kt
@@ -21,7 +21,6 @@
 import android.media.projection.MediaProjectionInfo
 import android.media.projection.MediaProjectionManager
 import android.os.Handler
-import android.util.Log
 import android.view.ContentRecordingSession
 import android.view.ContentRecordingSession.RECORD_CONTENT_DISPLAY
 import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
@@ -29,6 +28,9 @@
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.core.LogLevel
+import com.android.systemui.mediaprojection.MediaProjectionLog
 import com.android.systemui.mediaprojection.MediaProjectionServiceHelper
 import com.android.systemui.mediaprojection.data.model.MediaProjectionState
 import com.android.systemui.mediaprojection.taskswitcher.data.repository.TasksRepository
@@ -56,22 +58,27 @@
     @Background private val backgroundDispatcher: CoroutineDispatcher,
     private val tasksRepository: TasksRepository,
     private val mediaProjectionServiceHelper: MediaProjectionServiceHelper,
+    @MediaProjectionLog private val logger: LogBuffer,
 ) : MediaProjectionRepository {
 
     override suspend fun switchProjectedTask(task: RunningTaskInfo) {
         withContext(backgroundDispatcher) {
             if (mediaProjectionServiceHelper.updateTaskRecordingSession(task.token)) {
-                Log.d(TAG, "Successfully switched projected task")
+                logger.log(TAG, LogLevel.DEBUG, {}, { "Successfully switched projected task" })
             } else {
-                Log.d(TAG, "Failed to switch projected task")
+                logger.log(TAG, LogLevel.WARNING, {}, { "Failed to switch projected task" })
             }
         }
     }
 
     override suspend fun stopProjecting() {
         withContext(backgroundDispatcher) {
-            // TODO(b/332662551): Convert Logcat to LogBuffer.
-            Log.d(TAG, "Requesting MediaProjectionManager#stopActiveProjection")
+            logger.log(
+                TAG,
+                LogLevel.DEBUG,
+                {},
+                { "Requesting MediaProjectionManager#stopActiveProjection" },
+            )
             mediaProjectionManager.stopActiveProjection()
         }
     }
@@ -81,12 +88,22 @@
                 val callback =
                     object : MediaProjectionManager.Callback() {
                         override fun onStart(info: MediaProjectionInfo?) {
-                            Log.d(TAG, "MediaProjectionManager.Callback#onStart")
+                            logger.log(
+                                TAG,
+                                LogLevel.DEBUG,
+                                {},
+                                { "MediaProjectionManager.Callback#onStart" },
+                            )
                             trySendWithFailureLogging(CallbackEvent.OnStart, TAG)
                         }
 
                         override fun onStop(info: MediaProjectionInfo?) {
-                            Log.d(TAG, "MediaProjectionManager.Callback#onStop")
+                            logger.log(
+                                TAG,
+                                LogLevel.DEBUG,
+                                {},
+                                { "MediaProjectionManager.Callback#onStop" },
+                            )
                             trySendWithFailureLogging(CallbackEvent.OnStop, TAG)
                         }
 
@@ -94,7 +111,12 @@
                             info: MediaProjectionInfo,
                             session: ContentRecordingSession?
                         ) {
-                            Log.d(TAG, "MediaProjectionManager.Callback#onSessionStarted: $session")
+                            logger.log(
+                                TAG,
+                                LogLevel.DEBUG,
+                                { str1 = session.toString() },
+                                { "MediaProjectionManager.Callback#onSessionStarted: $str1" },
+                            )
                             trySendWithFailureLogging(
                                 CallbackEvent.OnRecordingSessionSet(info, session),
                                 TAG,
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
index 18358a7..d8c13b6 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
@@ -33,6 +33,7 @@
 import androidx.core.os.postDelayed
 import androidx.core.view.isVisible
 import androidx.dynamicanimation.animation.DynamicAnimation
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager
 import com.android.internal.jank.Cuj
 import com.android.internal.jank.InteractionJankMonitor
 import com.android.internal.util.LatencyTracker
@@ -83,7 +84,7 @@
 class BackPanelController
 internal constructor(
     context: Context,
-    private val windowManager: WindowManager,
+    private val windowManager: ViewCaptureAwareWindowManager,
     private val viewConfiguration: ViewConfiguration,
     private val mainHandler: Handler,
     private val systemClock: SystemClock,
@@ -102,7 +103,7 @@
     class Factory
     @Inject
     constructor(
-        private val windowManager: WindowManager,
+        private val windowManager: ViewCaptureAwareWindowManager,
         private val viewConfiguration: ViewConfiguration,
         @BackPanelUiThread private val uiThreadContext: UiThreadContext,
         private val systemClock: SystemClock,
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
index e832abb..afdfa59 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
@@ -40,6 +40,8 @@
 import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
 import static com.android.systemui.shared.recents.utilities.Utilities.isLargeScreen;
 import static com.android.systemui.shared.rotation.RotationButtonController.DEBUG_ROTATION;
+import static com.android.systemui.shared.statusbar.phone.BarTransitions.MODE_OPAQUE;
+import static com.android.systemui.shared.statusbar.phone.BarTransitions.TransitionMode;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ALLOW_GESTURE_IGNORING_BAR_VISIBILITY;
@@ -48,8 +50,6 @@
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NAV_BAR_HIDDEN;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
 import static com.android.systemui.shared.system.QuickStepContract.isGesturalMode;
-import static com.android.systemui.shared.statusbar.phone.BarTransitions.MODE_OPAQUE;
-import static com.android.systemui.shared.statusbar.phone.BarTransitions.TransitionMode;
 import static com.android.systemui.statusbar.phone.CentralSurfaces.DEBUG_WINDOW_STATE;
 import static com.android.systemui.statusbar.phone.CentralSurfaces.dumpBarTransitions;
 import static com.android.systemui.util.Utils.isGesturalModeOnDefaultDisplay;
@@ -97,6 +97,7 @@
 import android.view.WindowManager;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodManager;
 
 import androidx.annotation.Nullable;
@@ -117,17 +118,17 @@
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.keyguard.WakefulnessLifecycle;
 import com.android.systemui.model.SysUiState;
-import com.android.systemui.navigationbar.views.buttons.NavBarButtonClickLogger;
 import com.android.systemui.navigationbar.NavBarHelper;
 import com.android.systemui.navigationbar.NavigationBarComponent.NavigationBarScope;
 import com.android.systemui.navigationbar.NavigationModeController;
 import com.android.systemui.navigationbar.NavigationModeController.ModeChangedListener;
+import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
+import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
 import com.android.systemui.navigationbar.views.buttons.ButtonDispatcher;
 import com.android.systemui.navigationbar.views.buttons.DeadZone;
 import com.android.systemui.navigationbar.views.buttons.KeyButtonView;
+import com.android.systemui.navigationbar.views.buttons.NavBarButtonClickLogger;
 import com.android.systemui.navigationbar.views.buttons.NavbarOrientationTrackingLogger;
-import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
-import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
 import com.android.systemui.plugins.statusbar.StatusBarStateController;
 import com.android.systemui.recents.OverviewProxyService;
 import com.android.systemui.recents.Recents;
@@ -1348,6 +1349,9 @@
 
         ButtonDispatcher imeSwitcherButton = mView.getImeSwitchButton();
         imeSwitcherButton.setOnClickListener(this::onImeSwitcherClick);
+        if (Flags.imeSwitcherRevamp()) {
+            imeSwitcherButton.setOnLongClickListener(this::onImeSwitcherLongClick);
+        }
 
         updateScreenPinningGestures();
     }
@@ -1501,12 +1505,29 @@
         mCommandQueue.toggleRecentApps();
     }
 
-    private void onImeSwitcherClick(View v) {
+    @VisibleForTesting
+    void onImeSwitcherClick(View v) {
+        mNavBarButtonClickLogger.logImeSwitcherClick();
+        if (Flags.imeSwitcherRevamp()) {
+            mInputMethodManager.onImeSwitchButtonClickFromSystem(mDisplayId);
+        } else {
+            mInputMethodManager.showInputMethodPickerFromSystem(
+                    true /* showAuxiliarySubtypes */, mDisplayId);
+        }
+        mUiEventLogger.log(KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP);
+    }
+
+    @VisibleForTesting
+    boolean onImeSwitcherLongClick(View v) {
+        if (!Flags.imeSwitcherRevamp()) {
+            return false;
+        }
         mNavBarButtonClickLogger.logImeSwitcherClick();
         mInputMethodManager.showInputMethodPickerFromSystem(
                 true /* showAuxiliarySubtypes */, mDisplayId);
-        mUiEventLogger.log(KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP);
-    };
+        mUiEventLogger.log(KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS);
+        return true;
+    }
 
     private boolean onLongPressBackHome(View v) {
         return onLongPressNavigationButtons(v, R.id.back, R.id.home);
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
index 0f36097..1dbd500 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
@@ -19,7 +19,6 @@
 import static android.inputmethodservice.InputMethodService.canImeRenderGesturalNavButtons;
 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
 
-import static com.android.systemui.Flags.enableViewCaptureTracing;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SEARCH_DISABLED;
@@ -38,7 +37,6 @@
 import android.graphics.Canvas;
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.media.permission.SafeCloseable;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.util.AttributeSet;
@@ -61,19 +59,18 @@
 import androidx.annotation.Nullable;
 
 import com.android.app.animation.Interpolators;
-import com.android.app.viewcapture.ViewCaptureFactory;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.settingslib.Utils;
 import com.android.systemui.Gefingerpoken;
 import com.android.systemui.model.SysUiState;
 import com.android.systemui.navigationbar.ScreenPinningNotify;
+import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
 import com.android.systemui.navigationbar.views.buttons.ButtonDispatcher;
 import com.android.systemui.navigationbar.views.buttons.ContextualButton;
 import com.android.systemui.navigationbar.views.buttons.ContextualButtonGroup;
 import com.android.systemui.navigationbar.views.buttons.DeadZone;
 import com.android.systemui.navigationbar.views.buttons.KeyButtonDrawable;
 import com.android.systemui.navigationbar.views.buttons.NearestTouchFrame;
-import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.res.R;
 import com.android.systemui.settings.DisplayTracker;
@@ -181,7 +178,6 @@
     private boolean mOverviewProxyEnabled;
     private boolean mShowSwipeUpUi;
     private UpdateActiveTouchRegionsCallback mUpdateActiveTouchRegionsCallback;
-    private SafeCloseable mViewCaptureCloseable;
 
     private class NavTransitionListener implements TransitionListener {
         private boolean mBackTransitioning;
@@ -1082,10 +1078,6 @@
         }
 
         updateNavButtonIcons();
-        if (enableViewCaptureTracing()) {
-            mViewCaptureCloseable = ViewCaptureFactory.getInstance(getContext())
-                    .startCapture(getRootView(), ".NavigationBarView");
-        }
     }
 
     @Override
@@ -1098,9 +1090,6 @@
             mFloatingRotationButton.hide();
             mRotationButtonController.unregisterListeners();
         }
-        if (mViewCaptureCloseable != null) {
-            mViewCaptureCloseable.close();
-        }
     }
 
     void dump(PrintWriter pw) {
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
index 1e85d6c..133d14d 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
@@ -112,6 +112,9 @@
         @UiEvent(doc = "The overview button was long-pressed in the navigation bar.")
         NAVBAR_OVERVIEW_BUTTON_LONGPRESS(538),
 
+        @UiEvent(doc = "The ime switcher button was long-pressed in the navigation bar.")
+        NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS(1799),
+
         NONE(0);  // an event we should not log
 
         private final int mId;
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
index 295a998..782fb2a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/DragAndDropState.kt
@@ -48,6 +48,9 @@
     val sourceSpec: MutableState<TileSpec?>,
     private val listState: EditTileListState
 ) {
+    val dragInProgress: Boolean
+        get() = sourceSpec.value != null
+
     /** Returns index of the dragged tile if it's present in the list. Returns -1 if not. */
     fun currentPosition(): Int {
         return sourceSpec.value?.let { listState.indexOf(it) } ?: -1
@@ -65,6 +68,12 @@
         sourceSpec.value?.let { listState.move(it, targetSpec) }
     }
 
+    fun movedOutOfBounds() {
+        // Removing the tiles from the current tile grid if it moves out of bounds. This clears
+        // the spacer and makes it apparent that dropping the tile at that point would remove it.
+        sourceSpec.value?.let { listState.removeFromCurrent(it) }
+    }
+
     fun onDrop() {
         sourceSpec.value = null
     }
@@ -112,6 +121,42 @@
 }
 
 /**
+ * Registers a composable as a [DragAndDropTarget] to receive drop events. Use this outside the tile
+ * grid to catch out of bounds drops.
+ *
+ * @param dragAndDropState The [DragAndDropState] using the tiles list
+ * @param onDrop Action to be executed when a [TileSpec] is dropped on the composable
+ */
+@Composable
+fun Modifier.dragAndDropRemoveZone(
+    dragAndDropState: DragAndDropState,
+    onDrop: (TileSpec) -> Unit,
+): Modifier {
+    val target =
+        remember(dragAndDropState) {
+            object : DragAndDropTarget {
+                override fun onDrop(event: DragAndDropEvent): Boolean {
+                    return dragAndDropState.sourceSpec.value?.let {
+                        onDrop(it)
+                        dragAndDropState.onDrop()
+                        true
+                    } ?: false
+                }
+
+                override fun onEntered(event: DragAndDropEvent) {
+                    dragAndDropState.movedOutOfBounds()
+                }
+            }
+        }
+    return dragAndDropTarget(
+        shouldStartDragAndDrop = { event ->
+            event.mimeTypes().contains(QsDragAndDrop.TILESPEC_MIME_TYPE)
+        },
+        target = target,
+    )
+}
+
+/**
  * Registers a tile list as a [DragAndDropTarget] to receive drop events. Use this on list
  * containers to catch drops outside of tiles.
  *
@@ -128,6 +173,10 @@
     val target =
         remember(dragAndDropState) {
             object : DragAndDropTarget {
+                override fun onEnded(event: DragAndDropEvent) {
+                    dragAndDropState.onDrop()
+                }
+
                 override fun onDrop(event: DragAndDropEvent): Boolean {
                     return dragAndDropState.sourceSpec.value?.let {
                         onDrop(it, dragAndDropState.currentPosition())
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
index 482c498..34876c4 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditTileListState.kt
@@ -46,6 +46,18 @@
         tiles.apply { add(toIndex, removeAt(fromIndex).copy(isCurrent = isMovingToCurrent)) }
     }
 
+    /**
+     * Sets the [TileSpec] as a non-current tile. Use this when a tile is dragged out of the current
+     * tile grid.
+     */
+    fun removeFromCurrent(tileSpec: TileSpec) {
+        val fromIndex = indexOf(tileSpec)
+        if (fromIndex >= 0 && fromIndex < tiles.size) {
+            // Mark the moving tile as non-current
+            tiles[fromIndex] = tiles[fromIndex].copy(isCurrent = false)
+        }
+    }
+
     fun indexOf(tileSpec: TileSpec): Int {
         return tiles.indexOfFirst { it.tileSpec == tileSpec }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/InfiniteGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/InfiniteGridLayout.kt
index ada774d..add830e 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/InfiniteGridLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/InfiniteGridLayout.kt
@@ -84,7 +84,7 @@
         DefaultEditTileGrid(
             tiles = tiles,
             isIconOnly = isIcon,
-            columns = GridCells.Fixed(columns),
+            columns = columns,
             modifier = modifier,
             onAddTile = onAddTile,
             onRemoveTile = onRemoveTile,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PartitionedGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PartitionedGridLayout.kt
index 8ca91d8..6c84edd 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PartitionedGridLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PartitionedGridLayout.kt
@@ -305,9 +305,9 @@
                     largeTiles,
                     ClickAction.ADD,
                     addTileToEnd,
-                    onDoubleTap,
                     isIconOnly,
                     dragAndDropState,
+                    onDoubleTap = onDoubleTap,
                     acceptDrops = { true },
                     onDrop = onDrop,
                 )
@@ -318,10 +318,10 @@
                     smallTiles,
                     ClickAction.ADD,
                     addTileToEnd,
-                    onDoubleTap,
                     isIconOnly,
+                    dragAndDropState,
+                    onDoubleTap = onDoubleTap,
                     showLabels = showLabels,
-                    dragAndDropState = dragAndDropState,
                     acceptDrops = { true },
                     onDrop = onDrop,
                 )
@@ -332,10 +332,10 @@
                     tilesCustom,
                     ClickAction.ADD,
                     addTileToEnd,
-                    onDoubleTap,
                     isIconOnly,
+                    dragAndDropState,
+                    onDoubleTap = onDoubleTap,
                     showLabels = showLabels,
-                    dragAndDropState = dragAndDropState,
                     acceptDrops = { true },
                     onDrop = onDrop,
                 )
@@ -372,11 +372,6 @@
         }
     }
 
-    private fun gridHeight(nTiles: Int, tileHeight: Dp, columns: Int, padding: Dp): Dp {
-        val rows = (nTiles + columns - 1) / columns
-        return ((tileHeight + padding) * rows) - padding
-    }
-
     /** Fill up the rest of the row if it's not complete. */
     private fun LazyGridScope.fillUpRow(nTiles: Int, columns: Int) {
         if (nTiles % columns != 0) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/StretchedGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/StretchedGridLayout.kt
index 770d4412..3e48245 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/StretchedGridLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/StretchedGridLayout.kt
@@ -100,7 +100,7 @@
         DefaultEditTileGrid(
             tiles = tiles,
             isIconOnly = iconTilesViewModel::isIconTile,
-            columns = GridCells.Fixed(columns),
+            columns = columns,
             modifier = modifier,
             onAddTile = onAddTile,
             onRemoveTile = onRemoveTile,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/Tile.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/Tile.kt
index 3fdd7f7..bd7956d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/Tile.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/Tile.kt
@@ -23,13 +23,19 @@
 import android.service.quicksettings.Tile.STATE_INACTIVE
 import android.text.TextUtils
 import androidx.appcompat.content.res.AppCompatResources
+import androidx.compose.animation.AnimatedContent
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
 import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
 import androidx.compose.animation.graphics.res.animatedVectorResource
 import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
 import androidx.compose.animation.graphics.vector.AnimatedImageVector
 import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.Image
+import androidx.compose.foundation.LocalOverscrollConfiguration
 import androidx.compose.foundation.basicMarquee
+import androidx.compose.foundation.border
 import androidx.compose.foundation.combinedClickable
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Arrangement.spacedBy
@@ -37,20 +43,31 @@
 import androidx.compose.foundation.layout.BoxScope
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
 import androidx.compose.foundation.layout.aspectRatio
 import androidx.compose.foundation.layout.fillMaxHeight
 import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.wrapContentSize
 import androidx.compose.foundation.lazy.grid.GridCells
 import androidx.compose.foundation.lazy.grid.GridItemSpan
 import androidx.compose.foundation.lazy.grid.LazyGridScope
 import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
+import androidx.compose.foundation.rememberScrollState
 import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Clear
+import androidx.compose.material3.Icon
+import androidx.compose.material3.LocalContentColor
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
 import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
@@ -80,6 +97,8 @@
 import com.android.systemui.common.ui.compose.Icon
 import com.android.systemui.common.ui.compose.load
 import com.android.systemui.plugins.qs.QSTile
+import com.android.systemui.qs.panels.shared.model.SizedTile
+import com.android.systemui.qs.panels.shared.model.TileRow
 import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
 import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
 import com.android.systemui.qs.panels.ui.viewmodel.toUiState
@@ -269,7 +288,7 @@
 fun DefaultEditTileGrid(
     tiles: List<EditTileViewModel>,
     isIconOnly: (TileSpec) -> Boolean,
-    columns: GridCells,
+    columns: Int,
     modifier: Modifier,
     onAddTile: (TileSpec, Int) -> Unit,
     onRemoveTile: (TileSpec) -> Unit,
@@ -277,84 +296,264 @@
 ) {
     val currentListState = rememberEditListState(tiles)
     val dragAndDropState = rememberDragAndDropState(currentListState)
-
     val (currentTiles, otherTiles) = currentListState.tiles.partition { it.isCurrent }
-    val (otherTilesStock, otherTilesCustom) =
-        otherTiles
-            .filter { !dragAndDropState.isMoving(it.tileSpec) }
-            .partition { it.appName == null }
+
     val addTileToEnd: (TileSpec) -> Unit by rememberUpdatedState {
         onAddTile(it, CurrentTilesInteractor.POSITION_AT_END)
     }
-
     val onDropAdd: (TileSpec, Int) -> Unit by rememberUpdatedState { tileSpec, position ->
         onAddTile(tileSpec, position)
     }
-    val onDropRemove: (TileSpec, Int) -> Unit by rememberUpdatedState { tileSpec, _ ->
-        onRemoveTile(tileSpec)
-    }
     val onDoubleTap: (TileSpec) -> Unit by rememberUpdatedState { tileSpec ->
         onResize(tileSpec, !isIconOnly(tileSpec))
     }
+    val tilePadding = dimensionResource(R.dimen.qs_tile_margin_vertical)
 
-    TileLazyGrid(
-        modifier = modifier.dragAndDropTileList(dragAndDropState, { true }, onDropAdd),
-        columns = columns
+    CompositionLocalProvider(LocalOverscrollConfiguration provides null) {
+        Column(
+            verticalArrangement =
+                spacedBy(dimensionResource(id = R.dimen.qs_label_container_margin)),
+            modifier = modifier.fillMaxSize().verticalScroll(rememberScrollState())
+        ) {
+            AnimatedContent(
+                targetState = dragAndDropState.dragInProgress,
+                modifier = Modifier.wrapContentSize()
+            ) { dragIsInProgress ->
+                EditGridHeader(Modifier.dragAndDropRemoveZone(dragAndDropState, onRemoveTile)) {
+                    if (dragIsInProgress) {
+                        RemoveTileTarget()
+                    } else {
+                        Text(text = "Hold and drag to rearrange tiles.")
+                    }
+                }
+            }
+
+            CurrentTilesGrid(
+                currentTiles,
+                columns,
+                tilePadding,
+                isIconOnly,
+                onRemoveTile,
+                onDoubleTap,
+                dragAndDropState,
+                onDropAdd,
+            )
+
+            // Hide available tiles when dragging
+            AnimatedVisibility(
+                visible = !dragAndDropState.dragInProgress,
+                enter = fadeIn(),
+                exit = fadeOut()
+            ) {
+                Column(
+                    verticalArrangement =
+                        spacedBy(dimensionResource(id = R.dimen.qs_label_container_margin)),
+                    modifier = modifier.fillMaxSize()
+                ) {
+                    EditGridHeader { Text(text = "Hold and drag to add tiles.") }
+
+                    AvailableTileGrid(
+                        otherTiles,
+                        columns,
+                        tilePadding,
+                        addTileToEnd,
+                        dragAndDropState,
+                    )
+                }
+            }
+
+            // Drop zone to remove tiles dragged out of the tile grid
+            Spacer(
+                modifier =
+                    Modifier.fillMaxWidth()
+                        .weight(1f)
+                        .dragAndDropRemoveZone(dragAndDropState, onRemoveTile)
+            )
+        }
+    }
+}
+
+@Composable
+private fun EditGridHeader(
+    modifier: Modifier = Modifier,
+    content: @Composable BoxScope.() -> Unit
+) {
+    CompositionLocalProvider(
+        LocalContentColor provides MaterialTheme.colorScheme.onBackground.copy(alpha = .5f)
     ) {
-        // These Text are just placeholders to see the different sections. Not final UI.
-        item(span = { GridItemSpan(maxLineSpan) }) { Text("Current tiles", color = Color.White) }
+        Box(
+            contentAlignment = Alignment.Center,
+            modifier = modifier.fillMaxWidth().height(TileDefaults.EditGridHeaderHeight)
+        ) {
+            content()
+        }
+    }
+}
 
-        editTiles(
-            currentTiles,
-            ClickAction.REMOVE,
-            onRemoveTile,
-            onDoubleTap,
-            isIconOnly,
-            indicatePosition = true,
-            dragAndDropState = dragAndDropState,
-            acceptDrops = { true },
-            onDrop = onDropAdd,
-        )
+@Composable
+private fun RemoveTileTarget() {
+    Row(
+        verticalAlignment = Alignment.CenterVertically,
+        horizontalArrangement = tileHorizontalArrangement(),
+        modifier =
+            Modifier.fillMaxHeight()
+                .border(1.dp, LocalContentColor.current, shape = TileDefaults.TileShape)
+                .padding(10.dp)
+    ) {
+        Icon(imageVector = Icons.Default.Clear, contentDescription = null)
+        Text(text = "Remove")
+    }
+}
 
-        item(span = { GridItemSpan(maxLineSpan) }) { Text("Tiles to add", color = Color.White) }
+@Composable
+private fun CurrentTilesContainer(content: @Composable () -> Unit) {
+    Box(
+        Modifier.fillMaxWidth()
+            .border(
+                width = 1.dp,
+                color = MaterialTheme.colorScheme.onBackground.copy(alpha = .5f),
+                shape = RoundedCornerShape(48.dp),
+            )
+            .padding(dimensionResource(R.dimen.qs_tile_margin_vertical))
+    ) {
+        content()
+    }
+}
 
+@Composable
+private fun CurrentTilesGrid(
+    tiles: List<EditTileViewModel>,
+    columns: Int,
+    tilePadding: Dp,
+    isIconOnly: (TileSpec) -> Boolean,
+    onClick: (TileSpec) -> Unit,
+    onDoubleTap: (TileSpec) -> Unit,
+    dragAndDropState: DragAndDropState,
+    onDrop: (TileSpec, Int) -> Unit
+) {
+    val tileHeight = tileHeight()
+    val currentRows =
+        remember(tiles) {
+            calculateRows(
+                tiles.map {
+                    SizedTile(
+                        it,
+                        if (isIconOnly(it.tileSpec)) {
+                            1
+                        } else {
+                            2
+                        }
+                    )
+                },
+                columns
+            )
+        }
+    val currentGridHeight = gridHeight(currentRows, tileHeight, tilePadding)
+    // Current tiles
+    CurrentTilesContainer {
+        TileLazyGrid(
+            modifier =
+                Modifier.height(currentGridHeight)
+                    .dragAndDropTileList(dragAndDropState, { true }, onDrop),
+            columns = GridCells.Fixed(columns)
+        ) {
+            editTiles(
+                tiles,
+                ClickAction.REMOVE,
+                onClick,
+                isIconOnly,
+                dragAndDropState,
+                onDoubleTap = onDoubleTap,
+                indicatePosition = true,
+                acceptDrops = { true },
+                onDrop = onDrop,
+            )
+        }
+    }
+}
+
+@Composable
+private fun AvailableTileGrid(
+    tiles: List<EditTileViewModel>,
+    columns: Int,
+    tilePadding: Dp,
+    onClick: (TileSpec) -> Unit,
+    dragAndDropState: DragAndDropState,
+) {
+    val (otherTilesStock, otherTilesCustom) =
+        tiles.filter { !dragAndDropState.isMoving(it.tileSpec) }.partition { it.appName == null }
+    val availableTileHeight = tileHeight(true)
+    val availableGridHeight = gridHeight(tiles.size, availableTileHeight, columns, tilePadding)
+
+    // Available tiles
+    TileLazyGrid(
+        modifier =
+            Modifier.height(availableGridHeight)
+                .dragAndDropTileList(dragAndDropState, { false }, { _, _ -> }),
+        columns = GridCells.Fixed(columns)
+    ) {
         editTiles(
             otherTilesStock,
             ClickAction.ADD,
-            addTileToEnd,
-            onDoubleTap,
-            isIconOnly,
+            onClick,
+            isIconOnly = { true },
             dragAndDropState = dragAndDropState,
-            acceptDrops = { true },
-            onDrop = onDropRemove,
+            acceptDrops = { false },
+            showLabels = true,
         )
-
-        item(span = { GridItemSpan(maxLineSpan) }) {
-            Text("Custom tiles to add", color = Color.White)
-        }
-
         editTiles(
             otherTilesCustom,
             ClickAction.ADD,
-            addTileToEnd,
-            onDoubleTap,
-            isIconOnly,
+            onClick,
+            isIconOnly = { true },
             dragAndDropState = dragAndDropState,
-            acceptDrops = { true },
-            onDrop = onDropRemove,
+            acceptDrops = { false },
+            showLabels = true,
         )
     }
 }
 
+fun gridHeight(nTiles: Int, tileHeight: Dp, columns: Int, padding: Dp): Dp {
+    val rows = (nTiles + columns - 1) / columns
+    return gridHeight(rows, tileHeight, padding)
+}
+
+fun gridHeight(rows: Int, tileHeight: Dp, padding: Dp): Dp {
+    return ((tileHeight + padding) * rows) - padding
+}
+
+private fun calculateRows(tiles: List<SizedTile<EditTileViewModel>>, columns: Int): Int {
+    val row = TileRow<EditTileViewModel>(columns)
+    var count = 0
+
+    for (tile in tiles) {
+        if (row.maybeAddTile(tile)) {
+            if (row.isFull()) {
+                // Row is full, no need to stretch tiles
+                count += 1
+                row.clear()
+            }
+        } else {
+            count += 1
+            row.clear()
+            row.maybeAddTile(tile)
+        }
+    }
+    if (row.tiles.isNotEmpty()) {
+        count += 1
+    }
+    return count
+}
+
 fun LazyGridScope.editTiles(
     tiles: List<EditTileViewModel>,
     clickAction: ClickAction,
     onClick: (TileSpec) -> Unit,
-    onDoubleTap: (TileSpec) -> Unit,
     isIconOnly: (TileSpec) -> Boolean,
     dragAndDropState: DragAndDropState,
     acceptDrops: (TileSpec) -> Boolean,
-    onDrop: (TileSpec, Int) -> Unit,
+    onDoubleTap: (TileSpec) -> Unit = {},
+    onDrop: (TileSpec, Int) -> Unit = { _, _ -> },
     showLabels: Boolean = false,
     indicatePosition: Boolean = false,
 ) {
@@ -534,6 +733,7 @@
 private object TileDefaults {
     val TileShape = CircleShape
     val IconTileWithLabelHeight = 140.dp
+    val EditGridHeaderHeight = 60.dp
 
     @Composable
     fun activeTileColors(): TileColors =
diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt
index 62bfc72..ef2c8bf 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt
@@ -151,12 +151,27 @@
      * present, it will be moved to the new position.
      */
     fun addTile(tileSpec: TileSpec, position: Int = POSITION_AT_END) {
-        // Removing tile if it's already present to insert it at the new index.
-        if (currentTilesInteractor.currentTilesSpecs.contains(tileSpec)) {
-            removeTile(tileSpec)
+        val specs = currentTilesInteractor.currentTilesSpecs.toMutableList()
+        val currentPosition = specs.indexOf(tileSpec)
+
+        if (currentPosition != -1) {
+            // No operation needed if the element is already in the list at the right position
+            if (currentPosition == position) {
+                return
+            }
+            // Removing tile if it's present at a different position to insert it at the new index.
+            specs.removeAt(currentPosition)
         }
 
-        currentTilesInteractor.addTile(tileSpec, position)
+        if (position >= 0 && position < specs.size) {
+            specs.add(position, tileSpec)
+        } else {
+            specs.add(tileSpec)
+        }
+
+        // Setting the new tiles as one operation to avoid UI jank with tiles disappearing and
+        // reappearing
+        currentTilesInteractor.setTiles(specs)
     }
 
     /** Immediately removes [tileSpec] from the current tiles. */
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
index df7430a..158eb6e 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java
@@ -65,6 +65,7 @@
 import androidx.annotation.VisibleForTesting;
 import androidx.annotation.WorkerThread;
 
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
 import com.android.internal.logging.UiEventLogger;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.keyguard.KeyguardUpdateMonitorCallback;
@@ -184,7 +185,7 @@
     private GlobalSettings mGlobalSettings;
     private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
     private ConnectivityManager.NetworkCallback mConnectivityManagerNetworkCallback;
-    private WindowManager mWindowManager;
+    private ViewCaptureAwareWindowManager mWindowManager;
     private ToastFactory mToastFactory;
     private SignalDrawable mSignalDrawable;
     private SignalDrawable mSecondarySignalDrawable; // For the secondary mobile data sub in DSDS
@@ -246,7 +247,7 @@
             @Main Handler handler, @Main Executor mainExecutor,
             BroadcastDispatcher broadcastDispatcher, KeyguardUpdateMonitor keyguardUpdateMonitor,
             GlobalSettings globalSettings, KeyguardStateController keyguardStateController,
-            WindowManager windowManager, ToastFactory toastFactory,
+            ViewCaptureAwareWindowManager viewCaptureAwareWindowManager, ToastFactory toastFactory,
             @Background Handler workerHandler,
             CarrierConfigTracker carrierConfigTracker,
             LocationController locationController,
@@ -278,7 +279,7 @@
         mAccessPointController = accessPointController;
         mWifiIconInjector = new WifiUtils.InternetIconInjector(mContext);
         mConnectivityManagerNetworkCallback = new DataConnectivityListener();
-        mWindowManager = windowManager;
+        mWindowManager = viewCaptureAwareWindowManager;
         mToastFactory = toastFactory;
         mSignalDrawable = new SignalDrawable(mContext);
         mSecondarySignalDrawable = new SignalDrawable(mContext);
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index b3624ad..371707d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -72,6 +72,7 @@
 import android.view.MotionEvent;
 import android.view.Surface;
 import android.view.accessibility.AccessibilityManager;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodManager;
 
 import androidx.annotation.NonNull;
@@ -302,10 +303,29 @@
         public void onImeSwitcherPressed() {
             // TODO(b/204901476) We're intentionally using the default display for now since
             // Launcher/Taskbar isn't display aware.
+            if (Flags.imeSwitcherRevamp()) {
+                mContext.getSystemService(InputMethodManager.class)
+                        .onImeSwitchButtonClickFromSystem(mDisplayTracker.getDefaultDisplayId());
+            } else {
+                mContext.getSystemService(InputMethodManager.class)
+                        .showInputMethodPickerFromSystem(true /* showAuxiliarySubtypes */,
+                                mDisplayTracker.getDefaultDisplayId());
+            }
+            mUiEventLogger.log(KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP);
+        }
+
+        @Override
+        public void onImeSwitcherLongPress() {
+            if (!Flags.imeSwitcherRevamp()) {
+                return;
+            }
+            // TODO(b/204901476) We're intentionally using the default display for now since
+            // Launcher/Taskbar isn't display aware.
             mContext.getSystemService(InputMethodManager.class)
                     .showInputMethodPickerFromSystem(true /* showAuxiliarySubtypes */,
                             mDisplayTracker.getDefaultDisplayId());
-            mUiEventLogger.log(KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP);
+            mUiEventLogger.log(
+                    KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS);
         }
 
         @Override
diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
index 1f4820a..8711e88 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt
@@ -665,7 +665,7 @@
             keyguardEnabledInteractor.isKeyguardEnabled
                 .sample(
                     combine(
-                        deviceEntryInteractor.isInLockdown,
+                        deviceUnlockedInteractor.isInLockdown,
                         deviceEntryInteractor.isDeviceEntered,
                         ::Pair,
                     )
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingController.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingController.java
index af1b6e1..46c5861 100644
--- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingController.java
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingController.java
@@ -27,7 +27,6 @@
 import android.os.CountDownTimer;
 import android.os.Process;
 import android.os.UserHandle;
-import android.util.Log;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
@@ -60,8 +59,6 @@
 @SysUISingleton
 public class RecordingController
         implements CallbackController<RecordingController.RecordingStateChangeCallback> {
-    private static final String TAG = "RecordingController";
-
     private boolean mIsStarting;
     private boolean mIsRecording;
     private PendingIntent mStopIntent;
@@ -71,6 +68,7 @@
     private final BroadcastDispatcher mBroadcastDispatcher;
     private final FeatureFlags mFlags;
     private final UserTracker mUserTracker;
+    private final RecordingControllerLogger mRecordingControllerLogger;
     private final MediaProjectionMetricsLogger mMediaProjectionMetricsLogger;
     private final ScreenCaptureDisabledDialogDelegate mScreenCaptureDisabledDialogDelegate;
     private final ScreenRecordDialogDelegate.Factory mScreenRecordDialogFactory;
@@ -102,9 +100,10 @@
             if (intent != null && INTENT_UPDATE_STATE.equals(intent.getAction())) {
                 if (intent.hasExtra(EXTRA_STATE)) {
                     boolean state = intent.getBooleanExtra(EXTRA_STATE, false);
+                    mRecordingControllerLogger.logIntentStateUpdated(state);
                     updateState(state);
                 } else {
-                    Log.e(TAG, "Received update intent with no state");
+                    mRecordingControllerLogger.logIntentMissingState();
                 }
             }
         }
@@ -120,6 +119,7 @@
             FeatureFlags flags,
             Lazy<ScreenCaptureDevicePolicyResolver> devicePolicyResolver,
             UserTracker userTracker,
+            RecordingControllerLogger recordingControllerLogger,
             MediaProjectionMetricsLogger mediaProjectionMetricsLogger,
             ScreenCaptureDisabledDialogDelegate screenCaptureDisabledDialogDelegate,
             ScreenRecordDialogDelegate.Factory screenRecordDialogFactory,
@@ -130,6 +130,7 @@
         mDevicePolicyResolver = devicePolicyResolver;
         mBroadcastDispatcher = broadcastDispatcher;
         mUserTracker = userTracker;
+        mRecordingControllerLogger = recordingControllerLogger;
         mMediaProjectionMetricsLogger = mediaProjectionMetricsLogger;
         mScreenCaptureDisabledDialogDelegate = screenCaptureDisabledDialogDelegate;
         mScreenRecordDialogFactory = screenRecordDialogFactory;
@@ -212,9 +213,9 @@
                     IntentFilter stateFilter = new IntentFilter(INTENT_UPDATE_STATE);
                     mBroadcastDispatcher.registerReceiver(mStateChangeReceiver, stateFilter, null,
                             UserHandle.ALL);
-                    Log.d(TAG, "sent start intent");
+                    mRecordingControllerLogger.logSentStartIntent();
                 } catch (PendingIntent.CanceledException e) {
-                    Log.e(TAG, "Pending intent was cancelled: " + e.getMessage());
+                    mRecordingControllerLogger.logPendingIntentCancelled(e);
                 }
             }
         };
@@ -227,9 +228,10 @@
      */
     public void cancelCountdown() {
         if (mCountDownTimer != null) {
+            mRecordingControllerLogger.logCountdownCancelled();
             mCountDownTimer.cancel();
         } else {
-            Log.e(TAG, "Timer was null");
+            mRecordingControllerLogger.logCountdownCancelErrorNoTimer();
         }
         mIsStarting = false;
 
@@ -258,16 +260,16 @@
      * Stop the recording
      */
     public void stopRecording() {
-        // TODO(b/332662551): Convert Logcat to LogBuffer.
         try {
             if (mStopIntent != null) {
+                mRecordingControllerLogger.logRecordingStopped();
                 mStopIntent.send(mInteractiveBroadcastOption);
             } else {
-                Log.e(TAG, "Stop intent was null");
+                mRecordingControllerLogger.logRecordingStopErrorNoStopIntent();
             }
             updateState(false);
         } catch (PendingIntent.CanceledException e) {
-            Log.e(TAG, "Error stopping: " + e.getMessage());
+            mRecordingControllerLogger.logRecordingStopError(e);
         }
     }
 
@@ -276,6 +278,7 @@
      * @param isRecording
      */
     public synchronized void updateState(boolean isRecording) {
+        mRecordingControllerLogger.logStateUpdated(isRecording);
         if (!isRecording && mIsRecording) {
             // Unregister receivers if we have stopped recording
             mUserTracker.removeCallback(mUserChangedCallback);
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLog.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLog.kt
new file mode 100644
index 0000000..dd2baef
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLog.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2024 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.systemui.screenrecord
+
+import javax.inject.Qualifier
+
+/**
+ * Logs for screen record events. See [com.android.systemui.screenrecord.RecordingController] and
+ * [com.android.systemui.screenrecord.RecordingControllerLogger].
+ */
+@Qualifier
+@MustBeDocumented
+@Retention(AnnotationRetention.RUNTIME)
+annotation class RecordingControllerLog
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLogger.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLogger.kt
new file mode 100644
index 0000000..e16c010
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingControllerLogger.kt
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2024 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.systemui.screenrecord
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.core.LogLevel
+import javax.inject.Inject
+
+/** Helper class for logging events to [RecordingControllerLog] from Java. */
+@SysUISingleton
+class RecordingControllerLogger
+@Inject
+constructor(
+    @RecordingControllerLog private val logger: LogBuffer,
+) {
+    fun logStateUpdated(isRecording: Boolean) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            { bool1 = isRecording },
+            { "Updating state. isRecording=$bool1" },
+        )
+
+    fun logIntentStateUpdated(isRecording: Boolean) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            { bool1 = isRecording },
+            { "Update intent has state. isRecording=$bool1" },
+        )
+
+    fun logIntentMissingState() =
+        logger.log(TAG, LogLevel.ERROR, {}, { "Received update intent with no state" })
+
+    fun logSentStartIntent() = logger.log(TAG, LogLevel.DEBUG, {}, { "Sent start intent" })
+
+    fun logPendingIntentCancelled(e: Exception) =
+        logger.log(TAG, LogLevel.ERROR, {}, { "Pending intent was cancelled" }, e)
+
+    fun logCountdownCancelled() =
+        logger.log(TAG, LogLevel.DEBUG, {}, { "Record countdown cancelled" })
+
+    fun logCountdownCancelErrorNoTimer() =
+        logger.log(TAG, LogLevel.ERROR, {}, { "Couldn't cancel countdown because timer was null" })
+
+    fun logRecordingStopped() = logger.log(TAG, LogLevel.DEBUG, {}, { "Stopping recording" })
+
+    fun logRecordingStopErrorNoStopIntent() =
+        logger.log(
+            TAG,
+            LogLevel.ERROR,
+            {},
+            { "Couldn't stop recording because stop intent was null" },
+        )
+
+    fun logRecordingStopError(e: Exception) =
+        logger.log(TAG, LogLevel.DEBUG, {}, { "Couldn't stop recording" }, e)
+
+    companion object {
+        private const val TAG = "RecordingController"
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordModule.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordModule.kt
index d7ddc50..a830e1b 100644
--- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordModule.kt
@@ -16,6 +16,9 @@
 
 package com.android.systemui.screenrecord
 
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.LogBufferFactory
 import com.android.systemui.qs.QsEventLogger
 import com.android.systemui.qs.pipeline.shared.TileSpec
 import com.android.systemui.qs.tileimpl.QSTileImpl
@@ -53,7 +56,7 @@
     @IntoMap
     @StringKey(SCREEN_RECORD_TILE_SPEC)
     fun provideScreenRecordAvailabilityInteractor(
-            impl: ScreenRecordTileDataInteractor
+        impl: ScreenRecordTileDataInteractor
     ): QSTileAvailabilityInteractor
 
     companion object {
@@ -89,5 +92,12 @@
                 stateInteractor,
                 mapper,
             )
+
+        @Provides
+        @SysUISingleton
+        @RecordingControllerLog
+        fun provideRecordingControllerLogBuffer(factory: LogBufferFactory): LogBuffer {
+            return factory.create("RecordingControllerLog", 50)
+        }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index 1789ad6..2081adc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -3519,7 +3519,7 @@
     // Only when scene container is enabled, mark that we are being dragged so that we start
     // dispatching the rest of the gesture to scene container.
     void startOverscrollAfterExpanding() {
-        SceneContainerFlag.isUnexpectedlyInLegacyMode();
+        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
         getExpandHelper().finishExpanding();
         setIsBeingDragged(true);
     }
@@ -3527,7 +3527,7 @@
     // Only when scene container is enabled, mark that we are being dragged so that we start
     // dispatching the rest of the gesture to scene container.
     void startDraggingOnHun() {
-        SceneContainerFlag.isUnexpectedlyInLegacyMode();
+        if (SceneContainerFlag.isUnexpectedlyInLegacyMode()) return;
         setIsBeingDragged(true);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
index 726fdee..a072ea6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java
@@ -2034,6 +2034,7 @@
                 hunWantsIt = mHeadsUpTouchHelper.onInterceptTouchEvent(ev);
                 if (hunWantsIt) {
                     mView.startDraggingOnHun();
+                    mHeadsUpManager.unpinAll(true);
                 }
             }
             boolean swipeWantsIt = false;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationsPlaceholderViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationsPlaceholderViewModel.kt
index eb1f778..1a7bc16 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationsPlaceholderViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationsPlaceholderViewModel.kt
@@ -110,6 +110,11 @@
         interactor.setScrolledToTop(scrolledToTop)
     }
 
+    /** Sets whether the heads up notification is animating away. */
+    fun setHeadsUpAnimatingAway(animatingAway: Boolean) {
+        headsUpNotificationInteractor.setHeadsUpAnimatingAway(animatingAway)
+    }
+
     /** Snooze the currently pinned HUN. */
     fun snoozeHun() {
         headsUpNotificationInteractor.snooze()
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpTouchHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpTouchHelper.java
index 7f16e18..26bd7ac 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpTouchHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpTouchHelper.java
@@ -124,7 +124,6 @@
                     mPanel.setHeadsUpDraggingStartingHeight(startHeight);
                     mPanel.startExpand(x, y, true /* startTracking */, startHeight);
 
-                    // TODO(b/340514839): Figure out where to move this side effect in flexiglass
                     if (!SceneContainerFlag.isEnabled()) {
                         // This call needs to be after the expansion start otherwise we will get a
                         // flicker of one frame as it's not expanded yet.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/AvalancheController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AvalancheController.kt
index 43ab337..40799583 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/AvalancheController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AvalancheController.kt
@@ -91,7 +91,11 @@
     }
 
     /** Run or delay Runnable for given HeadsUpEntry */
-    fun update(entry: HeadsUpEntry?, runnable: Runnable, label: String) {
+    fun update(entry: HeadsUpEntry?, runnable: Runnable?, label: String) {
+        if (runnable == null) {
+            log { "Runnable is NULL, stop update." }
+            return
+        }
         if (!NotificationThrottleHun.isEnabled) {
             runnable.run()
             return
@@ -147,7 +151,11 @@
      * Run or ignore Runnable for given HeadsUpEntry. If entry was never shown, ignore and delete
      * all Runnables associated with that entry.
      */
-    fun delete(entry: HeadsUpEntry?, runnable: Runnable, label: String) {
+    fun delete(entry: HeadsUpEntry?, runnable: Runnable?, label: String) {
+        if (runnable == null) {
+            log { "Runnable is NULL, stop delete." }
+            return
+        }
         if (!NotificationThrottleHun.isEnabled) {
             runnable.run()
             return
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java
index 994a0d0..7b82b56 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerImpl.java
@@ -26,7 +26,6 @@
 import android.media.projection.MediaProjectionManager;
 import android.os.Handler;
 import android.util.ArrayMap;
-import android.util.Log;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
@@ -46,11 +45,11 @@
 /** Platform implementation of the cast controller. **/
 @SysUISingleton
 public class CastControllerImpl implements CastController {
-    public static final String TAG = "CastController";
-    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+    private static final String TAG = "CastController";
 
     private final Context mContext;
     private final PackageManager mPackageManager;
+    private final CastControllerLogger mLogger;
     @GuardedBy("mCallbacks")
     private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
     private final MediaRouter mMediaRouter;
@@ -67,20 +66,22 @@
     public CastControllerImpl(
             Context context,
             PackageManager packageManager,
-            DumpManager dumpManager) {
+            DumpManager dumpManager,
+            CastControllerLogger logger) {
         mContext = context;
         mPackageManager = packageManager;
+        mLogger = logger;
         mMediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
         mMediaRouter.setRouterGroupId(MediaRouter.MIRRORING_GROUP_ID);
         mProjectionManager = (MediaProjectionManager)
                 context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
         mProjection = mProjectionManager.getActiveProjectionInfo();
         mProjectionManager.addCallback(mProjectionCallback, new Handler());
-        dumpManager.registerDumpable(TAG, this);
-        if (DEBUG) Log.d(TAG, "new CastController()");
+        dumpManager.registerNormalDumpable(TAG, this);
     }
 
-    public void dump(PrintWriter pw, String[] args) {
+    @Override
+    public void dump(PrintWriter pw, @NonNull String[] args) {
         pw.println("CastController state:");
         pw.print("  mDiscovering="); pw.println(mDiscovering);
         pw.print("  mCallbackRegistered="); pw.println(mCallbackRegistered);
@@ -88,7 +89,7 @@
         pw.print("  mRoutes.size="); pw.println(mRoutes.size());
         for (int i = 0; i < mRoutes.size(); i++) {
             final RouteInfo route = mRoutes.valueAt(i);
-            pw.print("    "); pw.println(routeToString(route));
+            pw.print("    "); pw.println(CastControllerLogger.Companion.toLogString(route));
         }
         pw.print("  mProjection="); pw.println(mProjection);
     }
@@ -119,7 +120,7 @@
         synchronized (mDiscoveringLock) {
             if (mDiscovering == request) return;
             mDiscovering = request;
-            if (DEBUG) Log.d(TAG, "setDiscovering: " + request);
+            mLogger.logDiscovering(request);
             handleDiscoveryChangeLocked();
         }
     }
@@ -166,7 +167,8 @@
                         CastDevice.Companion.toCastDevice(
                                 mProjection,
                                 mContext,
-                                mPackageManager));
+                                mPackageManager,
+                                mLogger));
             }
         }
 
@@ -177,7 +179,7 @@
     public void startCasting(CastDevice device) {
         if (device == null || device.getTag() == null) return;
         final RouteInfo route = (RouteInfo) device.getTag();
-        if (DEBUG) Log.d(TAG, "startCasting: " + routeToString(route));
+        mLogger.logStartCasting(route);
         mMediaRouter.selectRoute(ROUTE_TYPE_REMOTE_DISPLAY, route);
     }
 
@@ -185,15 +187,16 @@
     public void stopCasting(CastDevice device) {
         // TODO(b/332662551): Convert Logcat to LogBuffer.
         final boolean isProjection = device.getTag() instanceof MediaProjectionInfo;
-        if (DEBUG) Log.d(TAG, "stopCasting isProjection=" + isProjection);
+        mLogger.logStopCasting(isProjection);
         if (isProjection) {
             final MediaProjectionInfo projection = (MediaProjectionInfo) device.getTag();
             if (Objects.equals(mProjectionManager.getActiveProjectionInfo(), projection)) {
                 mProjectionManager.stopActiveProjection();
             } else {
-                Log.w(TAG, "Projection is no longer active: " + projection);
+                mLogger.logStopCastingNoProjection(projection);
             }
         } else {
+            mLogger.logStopCastingMediaRouter();
             mMediaRouter.getFallbackRoute().select();
         }
     }
@@ -218,7 +221,7 @@
             }
         }
         if (changed) {
-            if (DEBUG) Log.d(TAG, "setProjection: " + oldProjection + " -> " + mProjection);
+            mLogger.logSetProjection(oldProjection, mProjection);
             fireOnCastDevicesChanged();
         }
     }
@@ -265,42 +268,30 @@
         callback.onCastDevicesChanged();
     }
 
-    private static String routeToString(RouteInfo route) {
-        if (route == null) return null;
-        final StringBuilder sb = new StringBuilder().append(route.getName()).append('/')
-                .append(route.getDescription()).append('@').append(route.getDeviceAddress())
-                .append(",status=").append(route.getStatus());
-        if (route.isDefault()) sb.append(",default");
-        if (route.isEnabled()) sb.append(",enabled");
-        if (route.isConnecting()) sb.append(",connecting");
-        if (route.isSelected()) sb.append(",selected");
-        return sb.append(",id=").append(route.getTag()).toString();
-    }
-
     private final MediaRouter.SimpleCallback mMediaCallback = new MediaRouter.SimpleCallback() {
         @Override
         public void onRouteAdded(MediaRouter router, RouteInfo route) {
-            if (DEBUG) Log.d(TAG, "onRouteAdded: " + routeToString(route));
+            mLogger.logRouteAdded(route);
             updateRemoteDisplays();
         }
         @Override
         public void onRouteChanged(MediaRouter router, RouteInfo route) {
-            if (DEBUG) Log.d(TAG, "onRouteChanged: " + routeToString(route));
+            mLogger.logRouteChanged(route);
             updateRemoteDisplays();
         }
         @Override
         public void onRouteRemoved(MediaRouter router, RouteInfo route) {
-            if (DEBUG) Log.d(TAG, "onRouteRemoved: " + routeToString(route));
+            mLogger.logRouteRemoved(route);
             updateRemoteDisplays();
         }
         @Override
         public void onRouteSelected(MediaRouter router, int type, RouteInfo route) {
-            if (DEBUG) Log.d(TAG, "onRouteSelected(" + type + "): " + routeToString(route));
+            mLogger.logRouteSelected(route, type);
             updateRemoteDisplays();
         }
         @Override
         public void onRouteUnselected(MediaRouter router, int type, RouteInfo route) {
-            if (DEBUG) Log.d(TAG, "onRouteUnselected(" + type + "): " + routeToString(route));
+            mLogger.logRouteUnselected(route, type);
             updateRemoteDisplays();
         }
     };
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerLogger.kt
new file mode 100644
index 0000000..9a3a244
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastControllerLogger.kt
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2024 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.systemui.statusbar.policy
+
+import android.media.MediaRouter.RouteInfo
+import android.media.projection.MediaProjectionInfo
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.log.LogBuffer
+import com.android.systemui.log.core.LogLevel
+import com.android.systemui.log.core.MessageInitializer
+import com.android.systemui.log.core.MessagePrinter
+import com.android.systemui.statusbar.policy.dagger.CastControllerLog
+import javax.inject.Inject
+
+/** Helper class for logging events to [CastControllerLog] from Java. */
+@SysUISingleton
+class CastControllerLogger
+@Inject
+constructor(
+    @CastControllerLog val logger: LogBuffer,
+) {
+    /** Passthrough to [logger]. */
+    inline fun log(
+        tag: String,
+        level: LogLevel,
+        messageInitializer: MessageInitializer,
+        noinline messagePrinter: MessagePrinter,
+        exception: Throwable? = null,
+    ) {
+        logger.log(tag, level, messageInitializer, messagePrinter, exception)
+    }
+
+    fun logDiscovering(isDiscovering: Boolean) =
+        logger.log(TAG, LogLevel.DEBUG, { bool1 = isDiscovering }, { "setDiscovering: $bool1" })
+
+    fun logStartCasting(route: RouteInfo) =
+        logger.log(TAG, LogLevel.DEBUG, { str1 = route.toLogString() }, { "startCasting: $str1" })
+
+    fun logStopCasting(isProjection: Boolean) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            { bool1 = isProjection },
+            { "stopCasting. isProjection=$bool1" },
+        )
+
+    fun logStopCastingNoProjection(projection: MediaProjectionInfo) =
+        logger.log(
+            TAG,
+            LogLevel.WARNING,
+            { str1 = projection.toString() },
+            { "stopCasting failed because projection is no longer active: $str1" },
+        )
+
+    fun logStopCastingMediaRouter() =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            {},
+            { "stopCasting is selecting fallback route in MediaRouter" },
+        )
+
+    fun logSetProjection(oldInfo: MediaProjectionInfo?, newInfo: MediaProjectionInfo?) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            {
+                str1 = oldInfo.toString()
+                str2 = newInfo.toString()
+            },
+            { "setProjection: $str1 -> $str2" },
+        )
+
+    fun logRouteAdded(route: RouteInfo) =
+        logger.log(TAG, LogLevel.DEBUG, { str1 = route.toLogString() }, { "onRouteAdded: $str1" })
+
+    fun logRouteChanged(route: RouteInfo) =
+        logger.log(TAG, LogLevel.DEBUG, { str1 = route.toLogString() }, { "onRouteChanged: $str1" })
+
+    fun logRouteRemoved(route: RouteInfo) =
+        logger.log(TAG, LogLevel.DEBUG, { str1 = route.toLogString() }, { "onRouteRemoved: $str1" })
+
+    fun logRouteSelected(route: RouteInfo, type: Int) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            {
+                str1 = route.toLogString()
+                int1 = type
+            },
+            { "onRouteSelected($int1): $str1" },
+        )
+
+    fun logRouteUnselected(route: RouteInfo, type: Int) =
+        logger.log(
+            TAG,
+            LogLevel.DEBUG,
+            {
+                str1 = route.toLogString()
+                int1 = type
+            },
+            { "onRouteUnselected($int1): $str1" },
+        )
+
+    companion object {
+        @JvmStatic
+        fun RouteInfo?.toLogString(): String? {
+            if (this == null) return null
+            val sb =
+                StringBuilder()
+                    .append(name)
+                    .append('/')
+                    .append(description)
+                    .append('@')
+                    .append(deviceAddress)
+                    .append(",status=")
+                    .append(status)
+            if (isDefault) sb.append(",default")
+            if (isEnabled) sb.append(",enabled")
+            if (isConnecting) sb.append(",connecting")
+            if (isSelected) sb.append(",selected")
+            return sb.append(",id=").append(this.tag).toString()
+        }
+
+        private const val TAG = "CastController"
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastDevice.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastDevice.kt
index 68edd75..a787f7e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastDevice.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/CastDevice.kt
@@ -20,7 +20,7 @@
 import android.media.MediaRouter
 import android.media.projection.MediaProjectionInfo
 import android.text.TextUtils
-import android.util.Log
+import com.android.systemui.log.core.LogLevel
 import com.android.systemui.res.R
 import com.android.systemui.util.Utils
 
@@ -64,11 +64,12 @@
         /** Creates a [CastDevice] based on the provided information from MediaProjection. */
         fun MediaProjectionInfo.toCastDevice(
             context: Context,
-            packageManager: PackageManager
+            packageManager: PackageManager,
+            logger: CastControllerLogger,
         ): CastDevice {
             return CastDevice(
                 id = this.packageName,
-                name = getAppName(this.packageName, packageManager),
+                name = getAppName(this.packageName, packageManager, logger),
                 description = context.getString(R.string.quick_settings_casting),
                 state = CastState.Connected,
                 tag = this,
@@ -76,7 +77,11 @@
             )
         }
 
-        private fun getAppName(packageName: String, packageManager: PackageManager): String {
+        private fun getAppName(
+            packageName: String,
+            packageManager: PackageManager,
+            logger: CastControllerLogger,
+        ): String {
             if (Utils.isHeadlessRemoteDisplayProvider(packageManager, packageName)) {
                 return ""
             }
@@ -86,9 +91,20 @@
                 if (!TextUtils.isEmpty(label)) {
                     return label.toString()
                 }
-                Log.w(CastControllerImpl.TAG, "No label found for package: $packageName")
+                logger.log(
+                    "#getAppName",
+                    LogLevel.WARNING,
+                    { str1 = packageName },
+                    { "No label found for package: $str1" },
+                )
             } catch (e: PackageManager.NameNotFoundException) {
-                Log.w(CastControllerImpl.TAG, "Error getting appName for package: $packageName", e)
+                logger.log(
+                    "#getAppName",
+                    LogLevel.WARNING,
+                    { str1 = packageName },
+                    { "Error getting appName for package=$str1" },
+                    e,
+                )
             }
             return packageName
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/CastControllerLog.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/CastControllerLog.kt
new file mode 100644
index 0000000..23aade6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/CastControllerLog.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023 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.systemui.statusbar.policy.dagger
+
+import javax.inject.Qualifier
+
+/**
+ * Logs for cast events. See [com.android.systemui.statusbar.policy.CastControllerImpl] and
+ * [com.android.systemui.statusbar.policy.CastControllerLogger].
+ */
+@Qualifier
+@MustBeDocumented
+@Retention(AnnotationRetention.RUNTIME)
+annotation class CastControllerLog
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
index e08e4d7..71bcdfcb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
@@ -228,4 +228,12 @@
     static LogBuffer provideBatteryControllerLog(LogBufferFactory factory) {
         return factory.create(BatteryControllerLogger.TAG, 30);
     }
+
+    /** Provides a log buffer for CastControllerImpl */
+    @Provides
+    @SysUISingleton
+    @CastControllerLog
+    static LogBuffer provideCastControllerLog(LogBufferFactory factory) {
+        return factory.create("CastControllerLog", 50);
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/FaceHelpMessageDebouncerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/FaceHelpMessageDebouncerTest.kt
new file mode 100644
index 0000000..baef620
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/FaceHelpMessageDebouncerTest.kt
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2024 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.systemui.biometrics
+
+import android.hardware.biometrics.BiometricFaceConstants
+import android.testing.TestableLooper
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+@TestableLooper.RunWithLooper
+class FaceHelpMessageDebouncerTest : SysuiTestCase() {
+    private lateinit var underTest: FaceHelpMessageDebouncer
+    private val window = 9L
+    private val startWindow = 4L
+    private val shownFaceMessageFrequencyBoost = 2
+
+    @Before
+    fun setUp() {
+        underTest =
+            FaceHelpMessageDebouncer(
+                window = window,
+                startWindow = startWindow,
+                shownFaceMessageFrequencyBoost = shownFaceMessageFrequencyBoost,
+            )
+    }
+
+    @Test
+    fun getMessageBeforeStartWindow_null() {
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "testTooClose",
+                0
+            )
+        )
+        assertThat(underTest.getMessageToShow(0)).isNull()
+    }
+
+    @Test
+    fun getMessageAfterStartWindow() {
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                0
+            )
+        )
+
+        assertThat(underTest.getMessageToShow(startWindow)?.msgId)
+            .isEqualTo(BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE)
+        assertThat(underTest.getMessageToShow(startWindow)?.msg).isEqualTo("tooClose")
+    }
+
+    @Test
+    fun getMessageAfterMessagesCleared_null() {
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                0
+            )
+        )
+        underTest.startNewFaceAuthSession(0)
+
+        assertThat(underTest.getMessageToShow(startWindow)).isNull()
+    }
+
+    @Test
+    fun messagesBeforeWindowRemoved() {
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                0
+            )
+        )
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                0
+            )
+        )
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                window - 1
+            )
+        )
+        val lastMessage =
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT,
+                "tooBright",
+                window
+            )
+        underTest.addMessage(lastMessage)
+
+        assertThat(underTest.getMessageToShow(window + 1)).isEqualTo(lastMessage)
+    }
+
+    @Test
+    fun getMessageTieGoesToMostRecent() {
+        for (i in 1..window step 2) {
+            underTest.addMessage(
+                HelpFaceAuthenticationStatus(
+                    BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                    "tooClose",
+                    i
+                )
+            )
+            underTest.addMessage(
+                HelpFaceAuthenticationStatus(
+                    BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT,
+                    "tooBright",
+                    i + 1
+                )
+            )
+        }
+
+        assertThat(underTest.getMessageToShow(window)?.msgId)
+            .isEqualTo(BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT)
+        assertThat(underTest.getMessageToShow(window)?.msg).isEqualTo("tooBright")
+    }
+
+    @Test
+    fun boostCurrentlyShowingMessage() {
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT,
+                "tooBright",
+                0
+            )
+        )
+
+        val lastMessageShown = underTest.getMessageToShow(startWindow)
+        assertThat(lastMessageShown?.msgId)
+            .isEqualTo(BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT)
+
+        for (i in 1..<shownFaceMessageFrequencyBoost) {
+            underTest.addMessage(
+                HelpFaceAuthenticationStatus(
+                    BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                    "tooClose",
+                    startWindow
+                )
+            )
+        }
+
+        // although technically there's a different msgId with a higher frequency count now, the
+        // shownFaceMessageFrequencyBoost causes the last message shown to get a "boost"
+        // to keep showing
+        assertThat(underTest.getMessageToShow(startWindow)).isEqualTo(lastMessageShown)
+    }
+
+    @Test
+    fun overcomeBoostedCurrentlyShowingMessage() {
+        // Comments are assuming shownFaceMessageFrequencyBoost = 2
+        // [B], weights: B=1
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_BRIGHT,
+                "tooBright",
+                0
+            )
+        )
+
+        // [B], showing messageB, weights: B=3
+        val messageB = underTest.getMessageToShow(startWindow)
+
+        // [B, C, C], showing messageB, weights: B=3, C=2
+        for (i in 1..shownFaceMessageFrequencyBoost) {
+            underTest.addMessage(
+                HelpFaceAuthenticationStatus(
+                    BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                    "tooClose",
+                    startWindow
+                )
+            )
+        }
+        // messageB is getting boosted to continue to show
+        assertThat(underTest.getMessageToShow(startWindow)).isEqualTo(messageB)
+
+        // receive one more FACE_ACQUIRED_TOO_CLOSE acquired info to pass the boost
+        // [C, C, C], showing messageB, weights: B=2, C=3
+        underTest.addMessage(
+            HelpFaceAuthenticationStatus(
+                BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE,
+                "tooClose",
+                startWindow
+            )
+        )
+
+        // Now FACE_ACQUIRED_TOO_CLOSE has surpassed the boosted messageB frequency
+        // [C, C, C], showing messageC, weights: C=5
+        assertThat(underTest.getMessageToShow(startWindow)?.msgId)
+            .isEqualTo(BiometricFaceConstants.FACE_ACQUIRED_TOO_CLOSE)
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/BiometricMessageInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/BiometricMessageInteractorTest.kt
index 431fef6..6fd8660 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/BiometricMessageInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/BiometricMessageInteractorTest.kt
@@ -24,6 +24,7 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
+import com.android.systemui.biometrics.FaceHelpMessageDebouncer
 import com.android.systemui.biometrics.data.repository.fingerprintPropertyRepository
 import com.android.systemui.biometrics.domain.faceHelpMessageDeferral
 import com.android.systemui.biometrics.shared.model.FingerprintSensorType
@@ -45,6 +46,7 @@
 import com.android.systemui.util.mockito.whenever
 import com.google.common.truth.Truth.assertThat
 import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
 import kotlinx.coroutines.test.runTest
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -264,11 +266,20 @@
             biometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
             biometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(false)
 
-            // WHEN authentication status help
+            // WHEN authentication status help past debouncer
             faceAuthRepository.setAuthenticationStatus(
                 HelpFaceAuthenticationStatus(
                     msg = "Move left",
                     msgId = FACE_ACQUIRED_TOO_RIGHT,
+                    createdAt = 0L,
+                )
+            )
+            runCurrent()
+            faceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(
+                    msg = "Move left",
+                    msgId = FACE_ACQUIRED_TOO_RIGHT,
+                    createdAt = FaceHelpMessageDebouncer.DEFAULT_WINDOW_MS,
                 )
             )
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorTest.kt
index 529cd6e..0b7a3ed 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorTest.kt
@@ -90,6 +90,7 @@
     private val keyguardUpdateMonitor = kosmos.keyguardUpdateMonitor
     private val faceWakeUpTriggersConfig = kosmos.fakeFaceWakeUpTriggersConfig
     private val trustManager = kosmos.trustManager
+    private val deviceEntryFaceAuthStatusInteractor = kosmos.deviceEntryFaceAuthStatusInteractor
 
     @Before
     fun setup() {
@@ -112,6 +113,7 @@
                 powerInteractor,
                 fakeBiometricSettingsRepository,
                 trustManager,
+                deviceEntryFaceAuthStatusInteractor,
             )
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorTest.kt
new file mode 100644
index 0000000..6022d9c
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorTest.kt
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2024 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.systemui.deviceentry.domain.interactor
+
+import android.hardware.biometrics.BiometricFaceConstants
+import android.hardware.face.FaceManager
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.biometrics.FaceHelpMessageDebouncer.Companion.DEFAULT_WINDOW_MS
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.deviceentry.shared.model.AcquiredFaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.ErrorFaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.FailedFaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.HelpFaceAuthenticationStatus
+import com.android.systemui.deviceentry.shared.model.SuccessFaceAuthenticationStatus
+import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFaceAuthRepository
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.res.R
+import com.android.systemui.testKosmos
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.TestScope
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mockito.mock
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class DeviceEntryFaceAuthStatusInteractorTest : SysuiTestCase() {
+    private val kosmos = testKosmos()
+    private val testScope: TestScope = kosmos.testScope
+    private lateinit var underTest: DeviceEntryFaceAuthStatusInteractor
+    private val ignoreHelpMessageId = 1
+
+    @Before
+    fun setup() {
+        overrideResource(
+            R.array.config_face_acquire_device_entry_ignorelist,
+            intArrayOf(ignoreHelpMessageId)
+        )
+        underTest = kosmos.deviceEntryFaceAuthStatusInteractor
+    }
+
+    @Test
+    fun successAuthenticationStatus() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            val successStatus =
+                SuccessFaceAuthenticationStatus(
+                    successResult = mock(FaceManager.AuthenticationResult::class.java)
+                )
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(successStatus)
+            assertThat(authenticationStatus).isEqualTo(successStatus)
+        }
+
+    @Test
+    fun acquiredFaceAuthenticationStatus() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            val acquiredStatus = AcquiredFaceAuthenticationStatus(acquiredInfo = 0)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(acquiredStatus)
+            assertThat(authenticationStatus).isEqualTo(acquiredStatus)
+        }
+
+    @Test
+    fun failedFaceAuthenticationStatus() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            val failedStatus = FailedFaceAuthenticationStatus()
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(failedStatus)
+            assertThat(authenticationStatus).isEqualTo(failedStatus)
+        }
+
+    @Test
+    fun errorFaceAuthenticationStatus() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            val errorStatus = ErrorFaceAuthenticationStatus(0, "test")
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(errorStatus)
+            assertThat(authenticationStatus).isEqualTo(errorStatus)
+        }
+
+    @Test
+    fun firstHelpFaceAuthenticationStatus_noUpdate() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                AcquiredFaceAuthenticationStatus(
+                    BiometricFaceConstants.FACE_ACQUIRED_START,
+                    createdAt = 0
+                )
+            )
+            val helpMessage = HelpFaceAuthenticationStatus(0, "test", 1)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(helpMessage)
+            assertThat(authenticationStatus).isNull()
+        }
+
+    @Test
+    fun helpFaceAuthenticationStatus_afterWindow() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(0, "test1", 0)
+            )
+            runCurrent()
+            val helpMessage = HelpFaceAuthenticationStatus(0, "test2", DEFAULT_WINDOW_MS)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(helpMessage)
+            runCurrent()
+            assertThat(authenticationStatus).isEqualTo(helpMessage)
+        }
+
+    @Test
+    fun helpFaceAuthenticationStatus_onlyIgnoredHelpMessages_afterWindow() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(ignoreHelpMessageId, "ignoredMsg", 0)
+            )
+            runCurrent()
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(ignoreHelpMessageId, "ignoredMsg", DEFAULT_WINDOW_MS)
+            )
+            runCurrent()
+            assertThat(authenticationStatus).isNull()
+        }
+
+    @Test
+    fun helpFaceAuthenticationStatus_afterWindow_onIgnoredMessage_showsOtherMessageInstead() =
+        testScope.runTest {
+            val authenticationStatus by collectLastValue(underTest.authenticationStatus)
+            val validHelpMessage = HelpFaceAuthenticationStatus(0, "validHelpMsg", 0)
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(validHelpMessage)
+            runCurrent()
+            // help message that should be ignored
+            kosmos.fakeDeviceEntryFaceAuthRepository.setAuthenticationStatus(
+                HelpFaceAuthenticationStatus(ignoreHelpMessageId, "ignoredMsg", DEFAULT_WINDOW_MS)
+            )
+            runCurrent()
+            assertThat(authenticationStatus).isEqualTo(validHelpMessage)
+        }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
index e2cca38..ae635b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/globalactions/GlobalActionsDialogLiteTest.java
@@ -41,7 +41,6 @@
 import android.os.Handler;
 import android.os.UserManager;
 import android.provider.Settings;
-import android.service.dreams.IDreamManager;
 import android.testing.TestableLooper;
 import android.view.GestureDetector;
 import android.view.IWindowManager;
@@ -106,7 +105,6 @@
 
     @Mock private GlobalActions.GlobalActionsManager mWindowManagerFuncs;
     @Mock private AudioManager mAudioManager;
-    @Mock private IDreamManager mDreamManager;
     @Mock private DevicePolicyManager mDevicePolicyManager;
     @Mock private LockPatternUtils mLockPatternUtils;
     @Mock private BroadcastDispatcher mBroadcastDispatcher;
@@ -165,7 +163,6 @@
         mGlobalActionsDialogLite = new GlobalActionsDialogLite(mContext,
                 mWindowManagerFuncs,
                 mAudioManager,
-                mDreamManager,
                 mDevicePolicyManager,
                 mLockPatternUtils,
                 mBroadcastDispatcher,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepositoryTest.kt
index 5db8981..785d5a8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionManagerRepositoryTest.kt
@@ -30,6 +30,7 @@
 import com.android.systemui.kosmos.applicationCoroutineScope
 import com.android.systemui.kosmos.testDispatcher
 import com.android.systemui.kosmos.testScope
+import com.android.systemui.log.logcatLogBuffer
 import com.android.systemui.mediaprojection.data.model.MediaProjectionState
 import com.android.systemui.mediaprojection.taskswitcher.FakeActivityTaskManager.Companion.createTask
 import com.android.systemui.mediaprojection.taskswitcher.FakeActivityTaskManager.Companion.createToken
@@ -273,6 +274,7 @@
                     applicationScope = kosmos.applicationCoroutineScope,
                     backgroundDispatcher = kosmos.testDispatcher,
                     mediaProjectionServiceHelper = fakeMediaProjectionManager.helper,
+                    logger = logcatLogBuffer("TestMediaProjection"),
                 )
 
             val state by collectLastValue(repoWithTimingControl.mediaProjectionState)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt
index b169cc1..b4db6da 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt
@@ -27,6 +27,7 @@
 import android.view.WindowManager
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.filters.SmallTest
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager
 import com.android.internal.jank.Cuj
 import com.android.internal.util.LatencyTracker
 import com.android.systemui.SysuiTestCase
@@ -63,7 +64,7 @@
     private var triggerThreshold: Float = 0.0f
     private val touchSlop = ViewConfiguration.get(context).scaledEdgeSlop
     @Mock private lateinit var vibratorHelper: VibratorHelper
-    @Mock private lateinit var windowManager: WindowManager
+    @Mock private lateinit var viewCaptureAwareWindowManager: ViewCaptureAwareWindowManager
     @Mock private lateinit var configurationController: ConfigurationController
     @Mock private lateinit var latencyTracker: LatencyTracker
     private val interactionJankMonitor by lazy { kosmos.interactionJankMonitor }
@@ -78,7 +79,7 @@
         mBackPanelController =
             BackPanelController(
                 context,
-                windowManager,
+                viewCaptureAwareWindowManager,
                 ViewConfiguration.get(context),
                 Handler.createAsync(testableLooper.looper),
                 systemClock,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/views/NavigationBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/views/NavigationBarTest.java
index 98ff6c9..45d77f6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/views/NavigationBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/views/NavigationBarTest.java
@@ -29,6 +29,8 @@
 import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.HOME_BUTTON_LONG_PRESS_DURATION_MS;
 import static com.android.systemui.assist.AssistManager.INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS;
 import static com.android.systemui.navigationbar.views.NavigationBar.NavBarActionEvent.NAVBAR_ASSIST_LONGPRESS;
+import static com.android.systemui.navigationbar.views.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS;
+import static com.android.systemui.navigationbar.views.buttons.KeyButtonView.NavBarButtonEvent.NAVBAR_IME_SWITCHER_BUTTON_TAP;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -38,6 +40,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
@@ -70,6 +73,7 @@
 import android.view.WindowManager;
 import android.view.WindowMetrics;
 import android.view.accessibility.AccessibilityManager;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodManager;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -162,6 +166,8 @@
     @Mock
     ButtonDispatcher mImeSwitchButton;
     @Mock
+    KeyButtonView mImeSwitchButtonView;
+    @Mock
     ButtonDispatcher mBackButton;
     @Mock
     NavigationBarTransitions mNavigationBarTransitions;
@@ -433,6 +439,45 @@
     }
 
     @Test
+    public void testImeSwitcherClick() {
+        mNavigationBar.init();
+        mNavigationBar.onViewAttached();
+        mNavigationBar.onImeSwitcherClick(mImeSwitchButtonView);
+
+        verify(mUiEventLogger).log(NAVBAR_IME_SWITCHER_BUTTON_TAP);
+        verify(mUiEventLogger, never()).log(NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS);
+        if (Flags.imeSwitcherRevamp()) {
+            verify(mInputMethodManager)
+                    .onImeSwitchButtonClickFromSystem(mNavigationBar.mDisplayId);
+            verify(mInputMethodManager, never()).showInputMethodPickerFromSystem(
+                    anyBoolean() /* showAuxiliarySubtypes */, anyInt() /* displayId */);
+        } else {
+            verify(mInputMethodManager, never())
+                    .onImeSwitchButtonClickFromSystem(anyInt() /* displayId */);
+            verify(mInputMethodManager).showInputMethodPickerFromSystem(
+                    true /* showAuxiliarySubtypes */, mNavigationBar.mDisplayId);
+        }
+    }
+
+    @Test
+    public void testImeSwitcherLongClick() {
+        mNavigationBar.init();
+        mNavigationBar.onViewAttached();
+        mNavigationBar.onImeSwitcherLongClick(mImeSwitchButtonView);
+
+        verify(mUiEventLogger, never()).log(NAVBAR_IME_SWITCHER_BUTTON_TAP);
+        if (Flags.imeSwitcherRevamp()) {
+            verify(mUiEventLogger).log(NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS);
+            verify(mInputMethodManager).showInputMethodPickerFromSystem(
+                    true /* showAuxiliarySubtypes */, mNavigationBar.mDisplayId);
+        } else {
+            verify(mUiEventLogger, never()).log(NAVBAR_IME_SWITCHER_BUTTON_LONGPRESS);
+            verify(mInputMethodManager, never()).showInputMethodPickerFromSystem(
+                    anyBoolean() /* showAuxiliarySubtypes */, anyInt() /* displayId */);
+        }
+    }
+
+    @Test
     public void testRegisteredWithUserTracker() {
         mNavigationBar.init();
         mNavigationBar.onViewAttached();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
index 5273495..eea02ee 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogDelegateControllerTest.java
@@ -61,6 +61,7 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 
+import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
 import com.android.internal.logging.UiEventLogger;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.settingslib.wifi.WifiUtils;
@@ -160,7 +161,7 @@
     @Mock
     InternetDialogController.InternetDialogCallback mInternetDialogCallback;
     @Mock
-    private WindowManager mWindowManager;
+    private ViewCaptureAwareWindowManager mWindowManager;
     @Mock
     private ToastFactory mToastFactory;
     @Mock
@@ -232,8 +233,9 @@
                 mSubscriptionManager, mTelephonyManager, mWifiManager,
                 mConnectivityManager, mHandler, mExecutor, mBroadcastDispatcher,
                 mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController,
-                mWindowManager, mToastFactory, mWorkerHandler, mCarrierConfigTracker,
-                mLocationController, mDialogTransitionAnimator, mWifiStateWorker, mFlags);
+                mWindowManager, mToastFactory, mWorkerHandler,
+                mCarrierConfigTracker, mLocationController, mDialogTransitionAnimator,
+                mWifiStateWorker, mFlags);
         mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
                 mInternetDialogController.mOnSubscriptionsChangedListener);
         mInternetDialogController.onStart(mInternetDialogCallback, true);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingControllerTest.java
index 2444af7..477c50b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/RecordingControllerTest.java
@@ -18,6 +18,8 @@
 
 import static android.os.Process.myUid;
 
+import static com.android.systemui.log.LogBufferHelperKt.logcatLogBuffer;
+
 import static com.google.common.truth.Truth.assertThat;
 
 import static junit.framework.Assert.assertFalse;
@@ -69,10 +71,6 @@
 @SmallTest
 @RunWith(AndroidTestingRunner.class)
 @TestableLooper.RunWithLooper(setAsMainLooper = true)
-/**
- * Tests for exception handling and  bitmap configuration in adding smart actions to Screenshot
- * Notification.
- */
 public class RecordingControllerTest extends SysuiTestCase {
 
     private static final int TEST_USER_ID = 12345;
@@ -146,6 +144,7 @@
                 mFeatureFlags,
                 () -> mDevicePolicyResolver,
                 mUserTracker,
+                new RecordingControllerLogger(logcatLogBuffer("RecordingControllerTest")),
                 mMediaProjectionMetricsLogger,
                 mScreenCaptureDisabledDialogDelegate,
                 mScreenRecordDialogFactory,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java
index 59b20c8..627463b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastControllerImplTest.java
@@ -1,6 +1,8 @@
 package com.android.systemui.statusbar.policy;
 
 
+import static com.android.systemui.log.LogBufferHelperKt.logcatLogBuffer;
+
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -58,7 +60,8 @@
         mController = new CastControllerImpl(
                 mContext,
                 mock(PackageManager.class),
-                mock(DumpManager.class));
+                mock(DumpManager.class),
+                new CastControllerLogger(logcatLogBuffer("CastControllerImplTest")));
     }
 
     @Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastDeviceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastDeviceTest.kt
index 03ad66c..16061df 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastDeviceTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/CastDeviceTest.kt
@@ -25,6 +25,7 @@
 import android.media.projection.MediaProjectionInfo
 import androidx.test.filters.SmallTest
 import com.android.systemui.SysuiTestCase
+import com.android.systemui.log.logcatLogBuffer
 import com.android.systemui.res.R
 import com.android.systemui.statusbar.policy.CastDevice.Companion.toCastDevice
 import com.google.common.truth.Truth.assertThat
@@ -40,6 +41,7 @@
 class CastDeviceTest : SysuiTestCase() {
     private val mockAppInfo =
         mock<ApplicationInfo>().apply { whenever(this.loadLabel(any())).thenReturn("") }
+    private val logger = CastControllerLogger(logcatLogBuffer("CastDeviceTest"))
 
     private val packageManager =
         mock<PackageManager>().apply {
@@ -322,7 +324,7 @@
                 whenever(this.packageName).thenReturn("fake.package")
             }
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.id).isEqualTo("fake.package")
     }
@@ -334,7 +336,7 @@
                 whenever(this.packageName).thenReturn(HEADLESS_REMOTE_PACKAGE)
             }
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.name).isEmpty()
     }
@@ -349,7 +351,7 @@
         whenever(packageManager.getApplicationInfo(eq(NORMAL_PACKAGE), any<Int>()))
             .thenThrow(PackageManager.NameNotFoundException())
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.name).isEqualTo(NORMAL_PACKAGE)
     }
@@ -366,7 +368,7 @@
         whenever(packageManager.getApplicationInfo(eq(NORMAL_PACKAGE), any<Int>()))
             .thenReturn(appInfo)
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.name).isEqualTo(NORMAL_PACKAGE)
     }
@@ -383,7 +385,7 @@
         whenever(packageManager.getApplicationInfo(eq(NORMAL_PACKAGE), any<Int>()))
             .thenReturn(appInfo)
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.name).isEqualTo("Valid App Name")
     }
@@ -392,7 +394,7 @@
     fun projectionToCastDevice_descriptionIsCasting() {
         val projection = mockProjectionInfo()
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.description).isEqualTo(context.getString(R.string.quick_settings_casting))
     }
@@ -401,7 +403,7 @@
     fun projectionToCastDevice_stateIsConnected() {
         val projection = mockProjectionInfo()
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.state).isEqualTo(CastDevice.CastState.Connected)
     }
@@ -410,7 +412,7 @@
     fun projectionToCastDevice_tagIsProjection() {
         val projection = mockProjectionInfo()
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.tag).isEqualTo(projection)
     }
@@ -419,7 +421,7 @@
     fun projectionToCastDevice_originIsMediaProjection() {
         val projection = mockProjectionInfo()
 
-        val device = projection.toCastDevice(context, packageManager)
+        val device = projection.toCastDevice(context, packageManager, logger)
 
         assertThat(device.origin).isEqualTo(CastDevice.CastOrigin.MediaProjection)
     }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelKosmos.kt
index 4b64416..de5f0f3 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/bouncer/ui/viewmodel/BouncerMessageViewModelKosmos.kt
@@ -24,7 +24,7 @@
 import com.android.systemui.deviceentry.domain.interactor.biometricMessageInteractor
 import com.android.systemui.deviceentry.domain.interactor.deviceEntryFaceAuthInteractor
 import com.android.systemui.deviceentry.domain.interactor.deviceEntryFingerprintAuthInteractor
-import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor
+import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
 import com.android.systemui.kosmos.Kosmos
 import com.android.systemui.kosmos.testScope
 import com.android.systemui.user.ui.viewmodel.userSwitcherViewModel
@@ -44,7 +44,7 @@
             clock = systemClock,
             biometricMessageInteractor = biometricMessageInteractor,
             faceAuthInteractor = deviceEntryFaceAuthInteractor,
-            deviceEntryInteractor = deviceEntryInteractor,
+            deviceUnlockedInteractor = deviceUnlockedInteractor,
             fingerprintInteractor = deviceEntryFingerprintAuthInteractor,
             flags = composeBouncerFlags,
         )
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/data/repository/FakeDeviceEntryRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/data/repository/FakeDeviceEntryRepository.kt
index 25e7729..045bd5d 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/data/repository/FakeDeviceEntryRepository.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/data/repository/FakeDeviceEntryRepository.kt
@@ -30,16 +30,10 @@
     private val _isBypassEnabled = MutableStateFlow(false)
     override val isBypassEnabled: StateFlow<Boolean> = _isBypassEnabled
 
-    var userPresentCount = 0
-
     override suspend fun isLockscreenEnabled(): Boolean {
         return isLockscreenEnabled
     }
 
-    override suspend fun reportUserPresent() {
-        userPresentCount++
-    }
-
     fun setLockscreenEnabled(isLockscreenEnabled: Boolean) {
         this.isLockscreenEnabled = isLockscreenEnabled
     }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorKosmos.kt
index a8fc27a..b9be04d 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthInteractorKosmos.kt
@@ -57,5 +57,6 @@
             powerInteractor = powerInteractor,
             biometricSettingsRepository = biometricSettingsRepository,
             trustManager = trustManager,
+            deviceEntryFaceAuthStatusInteractor = deviceEntryFaceAuthStatusInteractor,
         )
     }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorKosmos.kt
new file mode 100644
index 0000000..66d3709
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryFaceAuthStatusInteractorKosmos.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.deviceentry.domain.interactor
+
+import android.content.res.mainResources
+import com.android.systemui.keyguard.data.repository.deviceEntryFaceAuthRepository
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.applicationCoroutineScope
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+
+val Kosmos.deviceEntryFaceAuthStatusInteractor by
+    Kosmos.Fixture {
+        DeviceEntryFaceAuthStatusInteractor(
+            repository = deviceEntryFaceAuthRepository,
+            resources = mainResources,
+            applicationScope = applicationCoroutineScope,
+        )
+    }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorKosmos.kt
index 1200866..caa6e99 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorKosmos.kt
@@ -19,8 +19,6 @@
 import com.android.systemui.authentication.domain.interactor.authenticationInteractor
 import com.android.systemui.bouncer.domain.interactor.alternateBouncerInteractor
 import com.android.systemui.deviceentry.data.repository.deviceEntryRepository
-import com.android.systemui.flags.fakeSystemPropertiesHelper
-import com.android.systemui.keyguard.domain.interactor.trustInteractor
 import com.android.systemui.kosmos.Kosmos
 import com.android.systemui.kosmos.applicationCoroutineScope
 import com.android.systemui.scene.domain.interactor.sceneInteractor
@@ -34,12 +32,7 @@
             repository = deviceEntryRepository,
             authenticationInteractor = authenticationInteractor,
             sceneInteractor = sceneInteractor,
-            faceAuthInteractor = deviceEntryFaceAuthInteractor,
-            fingerprintAuthInteractor = deviceEntryFingerprintAuthInteractor,
-            biometricSettingsInteractor = deviceEntryBiometricSettingsInteractor,
-            trustInteractor = trustInteractor,
             deviceUnlockedInteractor = deviceUnlockedInteractor,
-            systemPropertiesHelper = fakeSystemPropertiesHelper,
             alternateBouncerInteractor = alternateBouncerInteractor,
         )
     }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorKosmos.kt
index 14210bc..1ed10fbe 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorKosmos.kt
@@ -18,6 +18,8 @@
 
 import com.android.systemui.authentication.domain.interactor.authenticationInteractor
 import com.android.systemui.deviceentry.data.repository.deviceEntryRepository
+import com.android.systemui.flags.fakeSystemPropertiesHelper
+import com.android.systemui.flags.systemPropertiesHelper
 import com.android.systemui.keyguard.domain.interactor.trustInteractor
 import com.android.systemui.kosmos.Kosmos
 import com.android.systemui.kosmos.Kosmos.Fixture
@@ -33,5 +35,7 @@
         faceAuthInteractor = deviceEntryFaceAuthInteractor,
         fingerprintAuthInteractor = deviceEntryFingerprintAuthInteractor,
         powerInteractor = powerInteractor,
+        biometricSettingsInteractor = deviceEntryBiometricSettingsInteractor,
+        systemPropertiesHelper = fakeSystemPropertiesHelper,
     )
 }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionRepositoryKosmos.kt
index 81ba77a..0412274 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionRepositoryKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/mediaprojection/data/repository/MediaProjectionRepositoryKosmos.kt
@@ -21,6 +21,7 @@
 import com.android.systemui.kosmos.Kosmos
 import com.android.systemui.kosmos.applicationCoroutineScope
 import com.android.systemui.kosmos.testDispatcher
+import com.android.systemui.log.logcatLogBuffer
 import com.android.systemui.mediaprojection.taskswitcher.activityTaskManagerTasksRepository
 import com.android.systemui.mediaprojection.taskswitcher.fakeMediaProjectionManager
 
@@ -37,5 +38,6 @@
             tasksRepository = activityTaskManagerTasksRepository,
             backgroundDispatcher = testDispatcher,
             mediaProjectionServiceHelper = fakeMediaProjectionManager.helper,
+            logger = logcatLogBuffer("TestMediaProjection"),
         )
     }
diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
index e031eb2..8a1fe62 100644
--- a/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/Os.java
@@ -30,7 +30,6 @@
         return RavenwoodRuntimeNative.lseek(fd, offset, whence);
     }
 
-
     public static FileDescriptor[] pipe2(int flags) throws ErrnoException {
         return RavenwoodRuntimeNative.pipe2(flags);
     }
@@ -42,4 +41,16 @@
     public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException {
         return RavenwoodRuntimeNative.fcntlInt(fd, cmd, arg);
     }
+
+    public static StructStat fstat(FileDescriptor fd) throws ErrnoException {
+        return RavenwoodRuntimeNative.fstat(fd);
+    }
+
+    public static StructStat lstat(String path) throws ErrnoException {
+        return RavenwoodRuntimeNative.lstat(path);
+    }
+
+    public static StructStat stat(String path) throws ErrnoException {
+        return RavenwoodRuntimeNative.stat(path);
+    }
 }
diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/StructStat.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/StructStat.java
new file mode 100644
index 0000000..a8b1fca
--- /dev/null
+++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/StructStat.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2011 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 android.system;
+
+import libcore.util.Objects;
+
+/**
+ * File information returned by {@link Os#fstat}, {@link Os#lstat}, and {@link Os#stat}.
+ * Corresponds to C's {@code struct stat} from {@code <stat.h>}.
+ */
+public final class StructStat {
+    /** Device ID of device containing file. */
+    public final long st_dev; /*dev_t*/
+
+    /** File serial number (inode). */
+    public final long st_ino; /*ino_t*/
+
+    /** Mode (permissions) of file. */
+    public final int st_mode; /*mode_t*/
+
+    /** Number of hard links to the file. */
+    public final long st_nlink; /*nlink_t*/
+
+    /** User ID of file. */
+    public final int st_uid; /*uid_t*/
+
+    /** Group ID of file. */
+    public final int st_gid; /*gid_t*/
+
+    /** Device ID (if file is character or block special). */
+    public final long st_rdev; /*dev_t*/
+
+    /**
+     * For regular files, the file size in bytes.
+     * For symbolic links, the length in bytes of the pathname contained in the symbolic link.
+     * For a shared memory object, the length in bytes.
+     * For a typed memory object, the length in bytes.
+     * For other file types, the use of this field is unspecified.
+     */
+    public final long st_size; /*off_t*/
+
+    /** Seconds part of time of last access. */
+    public final long st_atime; /*time_t*/
+
+    /** StructTimespec with time of last access. */
+    public final StructTimespec st_atim;
+
+    /** Seconds part of time of last data modification. */
+    public final long st_mtime; /*time_t*/
+
+    /** StructTimespec with time of last modification. */
+    public final StructTimespec st_mtim;
+
+    /** Seconds part of time of last status change */
+    public final long st_ctime; /*time_t*/
+
+    /** StructTimespec with time of last status change. */
+    public final StructTimespec st_ctim;
+
+    /**
+     * A file system-specific preferred I/O block size for this object.
+     * For some file system types, this may vary from file to file.
+     */
+    public final long st_blksize; /*blksize_t*/
+
+    /** Number of blocks allocated for this object. */
+    public final long st_blocks; /*blkcnt_t*/
+
+    /**
+     * Constructs an instance with the given field values.
+     */
+    public StructStat(long st_dev, long st_ino, int st_mode, long st_nlink, int st_uid, int st_gid,
+            long st_rdev, long st_size, long st_atime, long st_mtime, long st_ctime,
+            long st_blksize, long st_blocks) {
+        this(st_dev, st_ino, st_mode, st_nlink, st_uid, st_gid,
+                st_rdev, st_size, new StructTimespec(st_atime, 0L), new StructTimespec(st_mtime, 0L),
+                new StructTimespec(st_ctime, 0L), st_blksize, st_blocks);
+    }
+
+    /**
+     * Constructs an instance with the given field values.
+     */
+    public StructStat(long st_dev, long st_ino, int st_mode, long st_nlink, int st_uid, int st_gid,
+            long st_rdev, long st_size, StructTimespec st_atim, StructTimespec st_mtim,
+            StructTimespec st_ctim, long st_blksize, long st_blocks) {
+        this.st_dev = st_dev;
+        this.st_ino = st_ino;
+        this.st_mode = st_mode;
+        this.st_nlink = st_nlink;
+        this.st_uid = st_uid;
+        this.st_gid = st_gid;
+        this.st_rdev = st_rdev;
+        this.st_size = st_size;
+        this.st_atime = st_atim.tv_sec;
+        this.st_mtime = st_mtim.tv_sec;
+        this.st_ctime = st_ctim.tv_sec;
+        this.st_atim = st_atim;
+        this.st_mtim = st_mtim;
+        this.st_ctim = st_ctim;
+        this.st_blksize = st_blksize;
+        this.st_blocks = st_blocks;
+    }
+
+    @Override public String toString() {
+        return Objects.toString(this);
+    }
+}
diff --git a/ravenwood/runtime-helper-src/libcore-fake/android/system/StructTimespec.java b/ravenwood/runtime-helper-src/libcore-fake/android/system/StructTimespec.java
new file mode 100644
index 0000000..c106780
--- /dev/null
+++ b/ravenwood/runtime-helper-src/libcore-fake/android/system/StructTimespec.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 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 android.system;
+
+import libcore.util.Objects;;
+
+/**
+ * Corresponds to C's {@code struct timespec} from {@code <time.h>}.
+ */
+public final class StructTimespec implements Comparable<StructTimespec> {
+    /** Seconds part of time of last data modification. */
+    public final long tv_sec; /*time_t*/
+
+    /** Nanoseconds (values are [0, 999999999]). */
+    public final long tv_nsec;
+
+    public StructTimespec(long tv_sec, long tv_nsec) {
+        this.tv_sec = tv_sec;
+        this.tv_nsec = tv_nsec;
+        if (tv_nsec < 0 || tv_nsec > 999_999_999) {
+            throw new IllegalArgumentException(
+                    "tv_nsec value " + tv_nsec + " is not in [0, 999999999]");
+        }
+    }
+
+    @Override
+    public int compareTo(StructTimespec other) {
+        if (tv_sec > other.tv_sec) {
+            return 1;
+        }
+        if (tv_sec < other.tv_sec) {
+            return -1;
+        }
+        if (tv_nsec > other.tv_nsec) {
+            return 1;
+        }
+        if (tv_nsec < other.tv_nsec) {
+            return -1;
+        }
+        return 0;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        StructTimespec that = (StructTimespec) o;
+
+        if (tv_sec != that.tv_sec) return false;
+        return tv_nsec == that.tv_nsec;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = (int) (tv_sec ^ (tv_sec >>> 32));
+        result = 31 * result + (int) (tv_nsec ^ (tv_nsec >>> 32));
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return Objects.toString(this);
+    }
+}
diff --git a/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
similarity index 65%
rename from ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodRuntimeNative.java
rename to ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
index 6540221..e9b305e 100644
--- a/ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodRuntimeNative.java
+++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/common/RavenwoodRuntimeNative.java
@@ -15,6 +15,9 @@
  */
 package com.android.ravenwood.common;
 
+import android.system.ErrnoException;
+import android.system.StructStat;
+
 import java.io.FileDescriptor;
 
 /**
@@ -31,19 +34,25 @@
 
     public static native void applyFreeFunction(long freeFunction, long nativePtr);
 
-    public static native long nLseek(int fd, long offset, int whence);
+    private static native long nLseek(int fd, long offset, int whence) throws ErrnoException;
 
-    public static native int[] nPipe2(int flags);
+    private static native int[] nPipe2(int flags) throws ErrnoException;
 
-    public static native int nDup(int oldfd);
+    private static native int nDup(int oldfd) throws ErrnoException;
 
-    public static native int nFcntlInt(int fd, int cmd, int arg);
+    private static native int nFcntlInt(int fd, int cmd, int arg) throws ErrnoException;
 
-    public static long lseek(FileDescriptor fd, long offset, int whence) {
+    private static native StructStat nFstat(int fd) throws ErrnoException;
+
+    public static native StructStat lstat(String path) throws ErrnoException;
+
+    public static native StructStat stat(String path) throws ErrnoException;
+
+    public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException {
         return nLseek(JvmWorkaround.getInstance().getFdInt(fd), offset, whence);
     }
 
-    public static FileDescriptor[] pipe2(int flags) {
+    public static FileDescriptor[] pipe2(int flags) throws ErrnoException {
         var fds = nPipe2(flags);
         var ret = new FileDescriptor[] {
                 new FileDescriptor(),
@@ -55,7 +64,7 @@
         return ret;
     }
 
-    public static FileDescriptor dup(FileDescriptor fd) {
+    public static FileDescriptor dup(FileDescriptor fd) throws ErrnoException {
         var fdInt = nDup(JvmWorkaround.getInstance().getFdInt(fd));
 
         var retFd = new java.io.FileDescriptor();
@@ -63,9 +72,15 @@
         return retFd;
     }
 
-    public static int fcntlInt(FileDescriptor fd, int cmd, int arg) {
+    public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException {
         var fdInt = JvmWorkaround.getInstance().getFdInt(fd);
 
         return nFcntlInt(fdInt, cmd, arg);
     }
+
+    public static StructStat fstat(FileDescriptor fd) throws ErrnoException {
+        var fdInt = JvmWorkaround.getInstance().getFdInt(fd);
+
+        return nFstat(fdInt);
+    }
 }
diff --git a/ravenwood/runtime-helper-src/libcore-fake/libcore/util/Objects.java b/ravenwood/runtime-helper-src/libcore-fake/libcore/util/Objects.java
new file mode 100644
index 0000000..3781fcf
--- /dev/null
+++ b/ravenwood/runtime-helper-src/libcore-fake/libcore/util/Objects.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010 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 libcore.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+
+public final class Objects {
+    private Objects() {}
+
+    /**
+     * Returns a string reporting the value of each declared field, via reflection.
+     * Static and transient fields are automatically skipped. Produces output like
+     * "SimpleClassName[integer=1234,string="hello",character='c',intArray=[1,2,3]]".
+     */
+    public static String toString(Object o) {
+        Class<?> c = o.getClass();
+        StringBuilder sb = new StringBuilder();
+        sb.append(c.getSimpleName()).append('[');
+        int i = 0;
+        for (Field f : c.getDeclaredFields()) {
+            if ((f.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) {
+                continue;
+            }
+            f.setAccessible(true);
+            try {
+                Object value = f.get(o);
+
+                if (i++ > 0) {
+                    sb.append(',');
+                }
+
+                sb.append(f.getName());
+                sb.append('=');
+
+                if (value.getClass().isArray()) {
+                    if (value.getClass() == boolean[].class) {
+                        sb.append(Arrays.toString((boolean[]) value));
+                    } else if (value.getClass() == byte[].class) {
+                        sb.append(Arrays.toString((byte[]) value));
+                    } else if (value.getClass() == char[].class) {
+                        sb.append(Arrays.toString((char[]) value));
+                    } else if (value.getClass() == double[].class) {
+                        sb.append(Arrays.toString((double[]) value));
+                    } else if (value.getClass() == float[].class) {
+                        sb.append(Arrays.toString((float[]) value));
+                    } else if (value.getClass() == int[].class) {
+                        sb.append(Arrays.toString((int[]) value));
+                    } else if (value.getClass() == long[].class) {
+                        sb.append(Arrays.toString((long[]) value));
+                    } else if (value.getClass() == short[].class) {
+                        sb.append(Arrays.toString((short[]) value));
+                    } else {
+                        sb.append(Arrays.toString((Object[]) value));
+                    }
+                } else if (value.getClass() == Character.class) {
+                    sb.append('\'').append(value).append('\'');
+                } else if (value.getClass() == String.class) {
+                    sb.append('"').append(value).append('"');
+                } else {
+                    sb.append(value);
+                }
+            } catch (IllegalAccessException unexpected) {
+                throw new AssertionError(unexpected);
+            }
+        }
+        sb.append("]");
+        return sb.toString();
+    }
+}
diff --git a/ravenwood/runtime-jni/ravenwood_runtime.cpp b/ravenwood/runtime-jni/ravenwood_runtime.cpp
index 34cf9f9..e0a3e1c 100644
--- a/ravenwood/runtime-jni/ravenwood_runtime.cpp
+++ b/ravenwood/runtime-jni/ravenwood_runtime.cpp
@@ -19,6 +19,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <nativehelper/JNIHelp.h>
+#include <nativehelper/ScopedLocalRef.h>
+#include <nativehelper/ScopedUtfChars.h>
+
 #include "jni.h"
 #include "utils/Log.h"
 #include "utils/misc.h"
@@ -41,6 +44,75 @@
     return rc;
 }
 
+// ---- Helper functions ---
+
+static jclass g_StructStat;
+static jclass g_StructTimespecClass;
+
+static jclass findClass(JNIEnv* env, const char* name) {
+    ScopedLocalRef<jclass> localClass(env, env->FindClass(name));
+    jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(localClass.get()));
+    if (result == NULL) {
+        ALOGE("failed to find class '%s'", name);
+        abort();
+    }
+    return result;
+}
+
+static jobject makeStructTimespec(JNIEnv* env, const struct timespec& ts) {
+    static jmethodID ctor = env->GetMethodID(g_StructTimespecClass, "<init>",
+            "(JJ)V");
+    if (ctor == NULL) {
+        return NULL;
+    }
+    return env->NewObject(g_StructTimespecClass, ctor,
+            static_cast<jlong>(ts.tv_sec), static_cast<jlong>(ts.tv_nsec));
+}
+
+static jobject makeStructStat(JNIEnv* env, const struct stat64& sb) {
+    static jmethodID ctor = env->GetMethodID(g_StructStat, "<init>",
+            "(JJIJIIJJLandroid/system/StructTimespec;Landroid/system/StructTimespec;Landroid/system/StructTimespec;JJ)V");
+    if (ctor == NULL) {
+        return NULL;
+    }
+
+    jobject atim_timespec = makeStructTimespec(env, sb.st_atim);
+    if (atim_timespec == NULL) {
+        return NULL;
+    }
+    jobject mtim_timespec = makeStructTimespec(env, sb.st_mtim);
+    if (mtim_timespec == NULL) {
+        return NULL;
+    }
+    jobject ctim_timespec = makeStructTimespec(env, sb.st_ctim);
+    if (ctim_timespec == NULL) {
+        return NULL;
+    }
+
+    return env->NewObject(g_StructStat, ctor,
+            static_cast<jlong>(sb.st_dev), static_cast<jlong>(sb.st_ino),
+            static_cast<jint>(sb.st_mode), static_cast<jlong>(sb.st_nlink),
+            static_cast<jint>(sb.st_uid), static_cast<jint>(sb.st_gid),
+            static_cast<jlong>(sb.st_rdev), static_cast<jlong>(sb.st_size),
+            atim_timespec, mtim_timespec, ctim_timespec,
+            static_cast<jlong>(sb.st_blksize), static_cast<jlong>(sb.st_blocks));
+}
+
+static jobject doStat(JNIEnv* env, jstring javaPath, bool isLstat) {
+    ScopedUtfChars path(env, javaPath);
+    if (path.c_str() == NULL) {
+        return NULL;
+    }
+    struct stat64 sb;
+    int rc = isLstat ? TEMP_FAILURE_RETRY(lstat64(path.c_str(), &sb))
+                     : TEMP_FAILURE_RETRY(stat64(path.c_str(), &sb));
+    if (rc == -1) {
+        throwErrnoException(env, isLstat ? "lstat" : "stat");
+        return NULL;
+    }
+    return makeStructStat(env, sb);
+}
+
 // ---- JNI methods ----
 
 typedef void (*FreeFunction)(void*);
@@ -77,6 +149,24 @@
     return throwIfMinusOne(env, "fcntl", TEMP_FAILURE_RETRY(fcntl(fd, F_DUPFD_CLOEXEC, 0)));
 }
 
+static jobject nFstat(JNIEnv* env, jobject, jint fd) {
+    struct stat64 sb;
+    int rc = TEMP_FAILURE_RETRY(fstat64(fd, &sb));
+    if (rc == -1) {
+        throwErrnoException(env, "fstat");
+        return NULL;
+    }
+    return makeStructStat(env, sb);
+}
+
+static jobject Linux_lstat(JNIEnv* env, jobject, jstring javaPath) {
+    return doStat(env, javaPath, true);
+}
+
+static jobject Linux_stat(JNIEnv* env, jobject, jstring javaPath) {
+    return doStat(env, javaPath, false);
+}
+
 // ---- Registration ----
 
 static const JNINativeMethod sMethods[] =
@@ -86,6 +176,9 @@
     { "nLseek", "(IJI)J", (void*)nLseek },
     { "nPipe2", "(I)[I", (void*)nPipe2 },
     { "nDup", "(I)I", (void*)nDup },
+    { "nFstat", "(I)Landroid/system/StructStat;", (void*)nFstat },
+    { "lstat", "(Ljava/lang/String;)Landroid/system/StructStat;", (void*)Linux_lstat },
+    { "stat", "(Ljava/lang/String;)Landroid/system/StructStat;", (void*)Linux_stat },
 };
 
 extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
@@ -101,6 +194,9 @@
 
     ALOGI("%s: JNI_OnLoad", __FILE__);
 
+    g_StructStat = findClass(env, "android/system/StructStat");
+    g_StructTimespecClass = findClass(env, "android/system/StructTimespec");
+
     jint res = jniRegisterNativeMethods(env, "com/android/ravenwood/common/RavenwoodRuntimeNative",
             sMethods, NELEM(sMethods));
     if (res < 0) {
diff --git a/ravenwood/runtime-test/test/com/android/ravenwood/runtimetest/OsTest.java b/ravenwood/runtime-test/test/com/android/ravenwood/runtimetest/OsTest.java
index b5038e6..05275b2 100644
--- a/ravenwood/runtime-test/test/com/android/ravenwood/runtimetest/OsTest.java
+++ b/ravenwood/runtime-test/test/com/android/ravenwood/runtimetest/OsTest.java
@@ -15,15 +15,26 @@
  */
 package com.android.ravenwood.runtimetest;
 
+import static android.system.OsConstants.S_ISBLK;
+import static android.system.OsConstants.S_ISCHR;
+import static android.system.OsConstants.S_ISDIR;
+import static android.system.OsConstants.S_ISFIFO;
+import static android.system.OsConstants.S_ISLNK;
+import static android.system.OsConstants.S_ISREG;
+import static android.system.OsConstants.S_ISSOCK;
+
 import static org.junit.Assert.assertEquals;
 
+import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
+
 import android.system.Os;
 import android.system.OsConstants;
+import android.system.StructStat;
+import android.system.StructTimespec;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 
 import com.android.ravenwood.common.JvmWorkaround;
-import com.android.ravenwood.common.RavenwoodRuntimeNative;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -32,8 +43,15 @@
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.FileTime;
+import java.nio.file.attribute.PosixFileAttributes;
+import java.nio.file.attribute.PosixFilePermission;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 @RunWith(AndroidJUnit4.class)
 public class OsTest {
@@ -41,7 +59,7 @@
         void accept(T var1) throws Exception;
     }
 
-    private void withTestFile(ConsumerWithThrow<FileDescriptor> consumer) throws Exception {
+    private void withTestFileFD(ConsumerWithThrow<FileDescriptor> consumer) throws Exception {
         File file = File.createTempFile("osTest", "bin");
         try (var raf = new RandomAccessFile(file, "rw")) {
             var fd = raf.getFD();
@@ -57,9 +75,20 @@
         }
     }
 
+    private void withTestFile(ConsumerWithThrow<Path> consumer) throws Exception {
+        var path = Files.createTempFile("osTest", "bin");
+        try (var os = Files.newOutputStream(path)) {
+            os.write(1);
+            os.write(2);
+            os.write(3);
+            os.write(4);
+        }
+        consumer.accept(path);
+    }
+
     @Test
     public void testLseek() throws Exception {
-        withTestFile((fd) -> {
+        withTestFileFD((fd) -> {
             assertEquals(4, Os.lseek(fd, 4, OsConstants.SEEK_SET));
             assertEquals(4, Os.lseek(fd, 0, OsConstants.SEEK_CUR));
             assertEquals(6, Os.lseek(fd, 2, OsConstants.SEEK_CUR));
@@ -68,7 +97,7 @@
 
     @Test
     public void testDup() throws Exception {
-        withTestFile((fd) -> {
+        withTestFileFD((fd) -> {
             var dup = Os.dup(fd);
 
             checkAreDup(fd, dup);
@@ -85,7 +114,7 @@
 
     @Test
     public void testFcntlInt() throws Exception {
-        withTestFile((fd) -> {
+        withTestFileFD((fd) -> {
             var dupInt = Os.fcntlInt(fd, 0, 0);
 
             var dup = new FileDescriptor();
@@ -95,16 +124,90 @@
         });
     }
 
-    private static void write(FileDescriptor fd, int oneByte)  throws IOException {
+    @Test
+    public void testStat() throws Exception {
+        withTestFile(path -> {
+            var attr = Files.readAttributes(path, PosixFileAttributes.class);
+            var stat = Os.stat(path.toAbsolutePath().toString());
+            assertAttributesEqual(attr, stat);
+        });
+    }
+
+    @Test
+    public void testLstat() throws Exception {
+        withTestFile(path -> {
+            // Create a symbolic link
+            var lnk = Files.createTempFile("osTest", "lnk");
+            Files.delete(lnk);
+            Files.createSymbolicLink(lnk, path);
+
+            // Test lstat
+            var attr = Files.readAttributes(lnk, PosixFileAttributes.class, NOFOLLOW_LINKS);
+            var stat = Os.lstat(lnk.toAbsolutePath().toString());
+            assertAttributesEqual(attr, stat);
+
+            // Test stat
+            var followAttr = Files.readAttributes(lnk, PosixFileAttributes.class);
+            var followStat = Os.stat(lnk.toAbsolutePath().toString());
+            assertAttributesEqual(followAttr, followStat);
+        });
+    }
+
+    @Test
+    public void testFstat() throws Exception {
+        withTestFile(path -> {
+            var attr = Files.readAttributes(path, PosixFileAttributes.class);
+            try (var raf = new RandomAccessFile(path.toFile(), "r")) {
+                var fd = raf.getFD();
+                var stat = Os.fstat(fd);
+                assertAttributesEqual(attr, stat);
+            }
+        });
+    }
+
+    // Verify StructStat values from libcore against native JVM PosixFileAttributes
+    private static void assertAttributesEqual(PosixFileAttributes attr, StructStat stat) {
+        assertEquals(attr.lastModifiedTime(), convertTimespecToFileTime(stat.st_mtim));
+        assertEquals(attr.size(), stat.st_size);
+        assertEquals(attr.isDirectory(), S_ISDIR(stat.st_mode));
+        assertEquals(attr.isRegularFile(), S_ISREG(stat.st_mode));
+        assertEquals(attr.isSymbolicLink(), S_ISLNK(stat.st_mode));
+        assertEquals(attr.isOther(), S_ISCHR(stat.st_mode)
+                || S_ISBLK(stat.st_mode) || S_ISFIFO(stat.st_mode) || S_ISSOCK(stat.st_mode));
+        assertEquals(attr.permissions(), convertModeToPosixPerms(stat.st_mode));
+
+    }
+
+    private static FileTime convertTimespecToFileTime(StructTimespec ts) {
+        var nanos = TimeUnit.SECONDS.toNanos(ts.tv_sec);
+        nanos += ts.tv_nsec;
+        return FileTime.from(nanos, TimeUnit.NANOSECONDS);
+    }
+
+    private static Set<PosixFilePermission> convertModeToPosixPerms(int mode) {
+        var set = new HashSet<PosixFilePermission>();
+        if ((mode & OsConstants.S_IRUSR) != 0) set.add(PosixFilePermission.OWNER_READ);
+        if ((mode & OsConstants.S_IWUSR) != 0) set.add(PosixFilePermission.OWNER_WRITE);
+        if ((mode & OsConstants.S_IXUSR) != 0) set.add(PosixFilePermission.OWNER_EXECUTE);
+        if ((mode & OsConstants.S_IRGRP) != 0) set.add(PosixFilePermission.GROUP_READ);
+        if ((mode & OsConstants.S_IWGRP) != 0) set.add(PosixFilePermission.GROUP_WRITE);
+        if ((mode & OsConstants.S_IXGRP) != 0) set.add(PosixFilePermission.GROUP_EXECUTE);
+        if ((mode & OsConstants.S_IROTH) != 0) set.add(PosixFilePermission.OTHERS_READ);
+        if ((mode & OsConstants.S_IWOTH) != 0) set.add(PosixFilePermission.OTHERS_WRITE);
+        if ((mode & OsConstants.S_IXOTH) != 0) set.add(PosixFilePermission.OTHERS_EXECUTE);
+        return set;
+    }
+
+    private static void write(FileDescriptor fd, int oneByte) throws Exception {
         // Create a dup to avoid closing the FD.
-        try (var dup = new FileOutputStream(RavenwoodRuntimeNative.dup(fd))) {
+        try (var dup = new FileOutputStream(Os.dup(fd))) {
             dup.write(oneByte);
         }
     }
 
-    private static int read(FileDescriptor fd) throws IOException {
+    private static int read(FileDescriptor fd) throws Exception {
         // Create a dup to avoid closing the FD.
-        try (var dup = new FileInputStream(RavenwoodRuntimeNative.dup(fd))) {
+        try (var dup = new FileInputStream(Os.dup(fd))) {
             return dup.read();
         }
     }
diff --git a/services/accessibility/Android.bp b/services/accessibility/Android.bp
index 7a99b60..311addb 100644
--- a/services/accessibility/Android.bp
+++ b/services/accessibility/Android.bp
@@ -29,10 +29,12 @@
         "//frameworks/base/packages/SettingsLib/RestrictedLockUtils:SettingsLibRestrictedLockUtilsSrc",
     ],
     libs: [
+        "aatf",
         "services.core",
         "androidx.annotation_annotation",
     ],
     static_libs: [
+        "a11ychecker-protos-java-proto-lite",
         "com_android_server_accessibility_flags_lib",
         "//frameworks/base/packages/SystemUI/aconfig:com_android_systemui_flags_lib",
 
@@ -68,3 +70,14 @@
     name: "com_android_server_accessibility_flags_lib",
     aconfig_declarations: "com_android_server_accessibility_flags",
 }
+
+java_library_static {
+    name: "a11ychecker-protos-java-proto-lite",
+    proto: {
+        type: "lite",
+        canonical_path_from_root: false,
+    },
+    srcs: [
+        "java/**/a11ychecker/proto/*.proto",
+    ],
+}
diff --git a/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtils.java b/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtils.java
new file mode 100644
index 0000000..55af9a0
--- /dev/null
+++ b/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtils.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2024 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.server.accessibility.a11ychecker;
+
+
+import android.annotation.Nullable;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.util.Slog;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.accessibility.a11ychecker.A11yCheckerProto.AccessibilityCheckClass;
+import com.android.server.accessibility.a11ychecker.A11yCheckerProto.AccessibilityCheckResultReported;
+import com.android.server.accessibility.a11ychecker.A11yCheckerProto.AccessibilityCheckResultType;
+
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult;
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheck;
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheckResult;
+import com.google.android.apps.common.testing.accessibility.framework.checks.ClassNameCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.ClickableSpanCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateClickableBoundsCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.DuplicateSpeakableTextCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.EditableContentDescCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.ImageContrastCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.LinkPurposeUnclearCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.RedundantDescriptionCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.SpeakableTextPresentCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TextContrastCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TextSizeCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TraversalOrderCheck;
+
+import java.util.AbstractMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Util class to process a11y checker results for logging.
+ *
+ * @hide
+ */
+public class AccessibilityCheckerUtils {
+
+    private static final String LOG_TAG = "AccessibilityCheckerUtils";
+    @VisibleForTesting
+    // LINT.IfChange
+    static final Map<Class<? extends AccessibilityHierarchyCheck>, AccessibilityCheckClass>
+            CHECK_CLASS_TO_ENUM_MAP =
+            Map.ofEntries(
+                    classMapEntry(ClassNameCheck.class, AccessibilityCheckClass.CLASS_NAME_CHECK),
+                    classMapEntry(ClickableSpanCheck.class,
+                            AccessibilityCheckClass.CLICKABLE_SPAN_CHECK),
+                    classMapEntry(DuplicateClickableBoundsCheck.class,
+                            AccessibilityCheckClass.DUPLICATE_CLICKABLE_BOUNDS_CHECK),
+                    classMapEntry(DuplicateSpeakableTextCheck.class,
+                            AccessibilityCheckClass.DUPLICATE_SPEAKABLE_TEXT_CHECK),
+                    classMapEntry(EditableContentDescCheck.class,
+                            AccessibilityCheckClass.EDITABLE_CONTENT_DESC_CHECK),
+                    classMapEntry(ImageContrastCheck.class,
+                            AccessibilityCheckClass.IMAGE_CONTRAST_CHECK),
+                    classMapEntry(LinkPurposeUnclearCheck.class,
+                            AccessibilityCheckClass.LINK_PURPOSE_UNCLEAR_CHECK),
+                    classMapEntry(RedundantDescriptionCheck.class,
+                            AccessibilityCheckClass.REDUNDANT_DESCRIPTION_CHECK),
+                    classMapEntry(SpeakableTextPresentCheck.class,
+                            AccessibilityCheckClass.SPEAKABLE_TEXT_PRESENT_CHECK),
+                    classMapEntry(TextContrastCheck.class,
+                            AccessibilityCheckClass.TEXT_CONTRAST_CHECK),
+                    classMapEntry(TextSizeCheck.class, AccessibilityCheckClass.TEXT_SIZE_CHECK),
+                    classMapEntry(TouchTargetSizeCheck.class,
+                            AccessibilityCheckClass.TOUCH_TARGET_SIZE_CHECK),
+                    classMapEntry(TraversalOrderCheck.class,
+                            AccessibilityCheckClass.TRAVERSAL_ORDER_CHECK));
+    // LINT.ThenChange(/services/accessibility/java/com/android/server/accessibility/a11ychecker/proto/a11ychecker.proto)
+
+    static Set<AccessibilityCheckResultReported> processResults(
+            Context context,
+            AccessibilityNodeInfo nodeInfo,
+            List<AccessibilityHierarchyCheckResult> checkResults,
+            @Nullable AccessibilityEvent accessibilityEvent,
+            ComponentName a11yServiceComponentName) {
+        return processResults(nodeInfo, checkResults, accessibilityEvent,
+                context.getPackageManager(), a11yServiceComponentName);
+    }
+
+    @VisibleForTesting
+    static Set<AccessibilityCheckResultReported> processResults(
+            AccessibilityNodeInfo nodeInfo,
+            List<AccessibilityHierarchyCheckResult> checkResults,
+            @Nullable AccessibilityEvent accessibilityEvent,
+            PackageManager packageManager,
+            ComponentName a11yServiceComponentName) {
+        String appPackageName = nodeInfo.getPackageName().toString();
+        AccessibilityCheckResultReported.Builder builder;
+        try {
+            builder = AccessibilityCheckResultReported.newBuilder()
+                    .setPackageName(appPackageName)
+                    .setAppVersionCode(getAppVersionCode(packageManager, appPackageName))
+                    .setUiElementPath(AccessibilityNodePathBuilder.createNodePath(nodeInfo))
+                    .setActivityName(getActivityName(packageManager, accessibilityEvent))
+                    .setWindowTitle(getWindowTitle(nodeInfo))
+                    .setSourceComponentName(a11yServiceComponentName.flattenToString())
+                    .setSourceVersionCode(
+                            getAppVersionCode(packageManager,
+                                    a11yServiceComponentName.getPackageName()));
+        } catch (PackageManager.NameNotFoundException e) {
+            Slog.e(LOG_TAG, "Unknown package name", e);
+            return Set.of();
+        }
+
+        return checkResults.stream()
+                .filter(checkResult -> checkResult.getType()
+                        == AccessibilityCheckResult.AccessibilityCheckResultType.ERROR
+                        || checkResult.getType()
+                        == AccessibilityCheckResult.AccessibilityCheckResultType.WARNING)
+                .map(checkResult -> builder.setResultCheckClass(
+                        getCheckClass(checkResult)).setResultType(
+                        getCheckResultType(checkResult)).setResultId(
+                        checkResult.getResultId()).build())
+                .collect(Collectors.toUnmodifiableSet());
+    }
+
+    private static long getAppVersionCode(PackageManager packageManager, String packageName) throws
+            PackageManager.NameNotFoundException {
+        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
+        return packageInfo.getLongVersionCode();
+    }
+
+    /**
+     * Returns the simple class name of the Activity providing the cache update, if available,
+     * or an empty String if not.
+     */
+    @VisibleForTesting
+    static String getActivityName(
+            PackageManager packageManager, @Nullable AccessibilityEvent accessibilityEvent) {
+        if (accessibilityEvent == null) {
+            return "";
+        }
+        CharSequence activityName = accessibilityEvent.getClassName();
+        if (accessibilityEvent.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
+                && accessibilityEvent.getPackageName() != null
+                && activityName != null) {
+            try {
+                // Check class is for a valid Activity.
+                packageManager
+                        .getActivityInfo(
+                                new ComponentName(accessibilityEvent.getPackageName().toString(),
+                                        activityName.toString()), 0);
+                int qualifierEnd = activityName.toString().lastIndexOf('.');
+                return activityName.toString().substring(qualifierEnd + 1);
+            } catch (PackageManager.NameNotFoundException e) {
+                // No need to spam the logs. This is very frequent when the class doesn't match
+                // an activity.
+            }
+        }
+        return "";
+    }
+
+    /**
+     * Returns the title of the window containing the a11y node.
+     */
+    private static String getWindowTitle(AccessibilityNodeInfo nodeInfo) {
+        if (nodeInfo.getWindow() == null) {
+            return "";
+        }
+        CharSequence windowTitle = nodeInfo.getWindow().getTitle();
+        return windowTitle == null ? "" : windowTitle.toString();
+    }
+
+    /**
+     * Maps the {@link AccessibilityHierarchyCheck} class that produced the given result, with the
+     * corresponding {@link AccessibilityCheckClass} enum. This enumeration is to avoid relying on
+     * String class names in the logging, which can be proguarded. It also reduces the logging size.
+     */
+    private static AccessibilityCheckClass getCheckClass(
+            AccessibilityHierarchyCheckResult checkResult) {
+        if (CHECK_CLASS_TO_ENUM_MAP.containsKey(checkResult.getSourceCheckClass())) {
+            return CHECK_CLASS_TO_ENUM_MAP.get(checkResult.getSourceCheckClass());
+        }
+        return AccessibilityCheckClass.UNKNOWN_CHECK;
+    }
+
+    private static AccessibilityCheckResultType getCheckResultType(
+            AccessibilityHierarchyCheckResult checkResult) {
+        return switch (checkResult.getType()) {
+            case ERROR -> AccessibilityCheckResultType.ERROR;
+            case WARNING -> AccessibilityCheckResultType.WARNING;
+            default -> AccessibilityCheckResultType.UNKNOWN_RESULT_TYPE;
+        };
+    }
+
+    private static Map.Entry<Class<? extends AccessibilityHierarchyCheck>,
+            AccessibilityCheckClass> classMapEntry(
+            Class<? extends AccessibilityHierarchyCheck> checkClass,
+            AccessibilityCheckClass checkClassEnum) {
+        return new AbstractMap.SimpleImmutableEntry<>(checkClass, checkClassEnum);
+    }
+}
diff --git a/core/java/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilder.java b/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilder.java
similarity index 98%
rename from core/java/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilder.java
rename to services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilder.java
index 2996dde..bbfb217 100644
--- a/core/java/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilder.java
+++ b/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilder.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.view.accessibility.a11ychecker;
+package com.android.server.accessibility.a11ychecker;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
diff --git a/core/java/android/view/accessibility/a11ychecker/OWNERS b/services/accessibility/java/com/android/server/accessibility/a11ychecker/OWNERS
similarity index 100%
rename from core/java/android/view/accessibility/a11ychecker/OWNERS
rename to services/accessibility/java/com/android/server/accessibility/a11ychecker/OWNERS
diff --git a/services/accessibility/java/com/android/server/accessibility/a11ychecker/proto/a11ychecker.proto b/services/accessibility/java/com/android/server/accessibility/a11ychecker/proto/a11ychecker.proto
new file mode 100644
index 0000000..8beed4a
--- /dev/null
+++ b/services/accessibility/java/com/android/server/accessibility/a11ychecker/proto/a11ychecker.proto
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+syntax = "proto2";
+package android.accessibility;
+
+option java_package = "com.android.server.accessibility.a11ychecker";
+option java_outer_classname = "A11yCheckerProto";
+
+// TODO(b/326385939): remove and replace usage with the atom extension proto, when submitted.
+/** Logs the result of an AccessibilityCheck. */
+message AccessibilityCheckResultReported {
+  // Package name of the app containing the checked View.
+  optional string package_name = 1;
+  // Version code of the app containing the checked View.
+  optional int64 app_version_code = 2;
+  // The path of the View starting from the root element in the window. Each element is
+  // represented by the View's resource id, when available, or the View's class name.
+  optional string ui_element_path = 3;
+  // Class name of the activity containing the checked View.
+  optional string activity_name = 4;
+  // Title of the window containing the checked View.
+  optional string window_title = 5;
+  // The flattened component name of the app running the AccessibilityService which provided the a11y node.
+  optional string source_component_name = 6;
+  // Version code of the app running the AccessibilityService that provided the a11y node.
+  optional int64 source_version_code = 7;
+  // Class Name of the AccessibilityCheck that produced the result.
+  optional AccessibilityCheckClass result_check_class = 8;
+  // Result type of the AccessibilityCheckResult.
+  optional AccessibilityCheckResultType result_type = 9;
+  // Result ID of the AccessibilityCheckResult.
+  optional int32 result_id = 10;
+}
+
+/** The AccessibilityCheck class. */
+// LINT.IfChange
+enum AccessibilityCheckClass {
+  UNKNOWN_CHECK = 0;
+  CLASS_NAME_CHECK = 1;
+  CLICKABLE_SPAN_CHECK = 2;
+  DUPLICATE_CLICKABLE_BOUNDS_CHECK = 3;
+  DUPLICATE_SPEAKABLE_TEXT_CHECK = 4;
+  EDITABLE_CONTENT_DESC_CHECK = 5;
+  IMAGE_CONTRAST_CHECK = 6;
+  LINK_PURPOSE_UNCLEAR_CHECK = 7;
+  REDUNDANT_DESCRIPTION_CHECK = 8;
+  SPEAKABLE_TEXT_PRESENT_CHECK = 9;
+  TEXT_CONTRAST_CHECK = 10;
+  TEXT_SIZE_CHECK = 11;
+  TOUCH_TARGET_SIZE_CHECK = 12;
+  TRAVERSAL_ORDER_CHECK = 13;
+}
+// LINT.ThenChange(/services/accessibility/java/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtils.java)
+
+/** The type of AccessibilityCheckResult */
+enum AccessibilityCheckResultType {
+  UNKNOWN_RESULT_TYPE = 0;
+  ERROR = 1;
+  WARNING = 2;
+}
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index a84306b..0d309eb 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -739,8 +739,6 @@
     // Broadcast receiver for device connections intent broadcasts
     private final BroadcastReceiver mReceiver = new AudioServiceBroadcastReceiver();
 
-    private final Executor mAudioServerLifecycleExecutor;
-
     private IMediaProjectionManager mProjectionService; // to validate projection token
 
     /** Interface for UserManagerService. */
@@ -1061,8 +1059,7 @@
                               audioserverPermissions() ?
                                 initializeAudioServerPermissionProvider(
                                     context, audioPolicyFacade, audioserverLifecycleExecutor) :
-                                    null,
-                              audioserverLifecycleExecutor
+                                    null
                               );
         }
 
@@ -1148,16 +1145,13 @@
      *               {@link AudioSystemThread} is created as the messaging thread instead.
      * @param appOps {@link AppOpsManager} system service
      * @param enforcer Used for permission enforcing
-     * @param permissionProvider Used to push permissions to audioserver
-     * @param audioserverLifecycleExecutor Used for tasks managing audioserver lifecycle
      */
     @RequiresPermission(Manifest.permission.READ_DEVICE_CONFIG)
     public AudioService(Context context, AudioSystemAdapter audioSystem,
             SystemServerAdapter systemServer, SettingsAdapter settings,
             AudioVolumeGroupHelperBase audioVolumeGroupHelper, AudioPolicyFacade audioPolicy,
             @Nullable Looper looper, AppOpsManager appOps, @NonNull PermissionEnforcer enforcer,
-            /* @NonNull */ AudioServerPermissionProvider permissionProvider,
-            Executor audioserverLifecycleExecutor) {
+            /* @NonNull */ AudioServerPermissionProvider permissionProvider) {
         super(enforcer);
         sLifecycleLogger.enqueue(new EventLogger.StringEvent("AudioService()"));
         mContext = context;
@@ -1165,7 +1159,6 @@
         mAppOps = appOps;
 
         mPermissionProvider = permissionProvider;
-        mAudioServerLifecycleExecutor = audioserverLifecycleExecutor;
 
         mAudioSystem = audioSystem;
         mSystemServer = systemServer;
@@ -1177,34 +1170,6 @@
         mBroadcastHandlerThread = new HandlerThread("AudioService Broadcast");
         mBroadcastHandlerThread.start();
 
-        // Listen to permission invalidations for the PermissionProvider
-        if (audioserverPermissions()) {
-            final Handler broadcastHandler = mBroadcastHandlerThread.getThreadHandler();
-            mAudioSystem.listenForSystemPropertyChange(PermissionManager.CACHE_KEY_PACKAGE_INFO,
-                    new Runnable() {
-                        // Roughly chosen to be long enough to suppress the autocork behavior
-                        // of the permission cache (50ms), and longer than the task could reasonably
-                        // take, even with many packages and users, while not introducing visible
-                        // permission leaks - since the app needs to restart, and trigger an action
-                        // which requires permissions from audioserver before this delay.
-                        // For RECORD_AUDIO, we are additionally protected by appops.
-                        final long UPDATE_DELAY_MS = 110;
-                        final AtomicLong scheduledUpdateTimestamp = new AtomicLong(0);
-                        @Override
-                        public void run() {
-                            var currentTime = SystemClock.uptimeMillis();
-                            if (currentTime > scheduledUpdateTimestamp.get()) {
-                                scheduledUpdateTimestamp.set(currentTime + UPDATE_DELAY_MS);
-                                broadcastHandler.postAtTime( () ->
-                                        mAudioServerLifecycleExecutor.execute(mPermissionProvider
-                                            ::onPermissionStateChanged),
-                                        currentTime + UPDATE_DELAY_MS
-                                    );
-                            }
-                        }
-            });
-        }
-
         mDeviceBroker = new AudioDeviceBroker(mContext, this, mAudioSystem);
 
         mIsSingleVolume = AudioSystem.isSingleVolume(context);
@@ -12000,6 +11965,29 @@
             provider.onServiceStart(audioPolicy.getPermissionController());
         });
 
+        // Set up event listeners
+        // Must be kept in sync with PermissionManager
+        Runnable cacheSysPropHandler = new Runnable() {
+            private AtomicReference<SystemProperties.Handle> mHandle = new AtomicReference();
+            private AtomicLong mNonce = new AtomicLong();
+            @Override
+            public void run() {
+                if (mHandle.get() == null) {
+                    // Cache the handle
+                    mHandle.compareAndSet(null, SystemProperties.find(
+                            PermissionManager.CACHE_KEY_PACKAGE_INFO));
+                }
+                long nonce;
+                SystemProperties.Handle ref;
+                if ((ref = mHandle.get()) != null && (nonce = ref.getLong(0)) != 0 &&
+                        mNonce.getAndSet(nonce) != nonce) {
+                    audioserverExecutor.execute(() -> provider.onPermissionStateChanged());
+                }
+            }
+        };
+
+        SystemProperties.addChangeCallback(cacheSysPropHandler);
+
         IntentFilter packageUpdateFilter = new IntentFilter();
         packageUpdateFilter.addAction(ACTION_PACKAGE_ADDED);
         packageUpdateFilter.addAction(ACTION_PACKAGE_REMOVED);
diff --git a/services/core/java/com/android/server/audio/AudioSystemAdapter.java b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
index d083c68..7f4bc74 100644
--- a/services/core/java/com/android/server/audio/AudioSystemAdapter.java
+++ b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
@@ -748,10 +748,6 @@
         return AudioSystem.setMasterMute(mute);
     }
 
-    public void listenForSystemPropertyChange(String systemPropertyName, Runnable callback) {
-        AudioSystem.listenForSystemPropertyChange(systemPropertyName, callback);
-    }
-
     /**
      * Part of AudioService dump
      * @param pw
diff --git a/services/core/java/com/android/server/display/LogicalDisplayMapper.java b/services/core/java/com/android/server/display/LogicalDisplayMapper.java
index d3b41b8..e9ecfc6 100644
--- a/services/core/java/com/android/server/display/LogicalDisplayMapper.java
+++ b/services/core/java/com/android/server/display/LogicalDisplayMapper.java
@@ -25,6 +25,7 @@
 import android.annotation.Nullable;
 import android.content.Context;
 import android.hardware.devicestate.DeviceState;
+import android.hardware.devicestate.DeviceStateManager;
 import android.hardware.devicestate.feature.flags.FeatureFlags;
 import android.hardware.devicestate.feature.flags.FeatureFlagsImpl;
 import android.os.Handler;
@@ -614,7 +615,11 @@
                     && isBootCompleted
                     && !mFoldSettingProvider.shouldStayAwakeOnFold();
         } else {
-            return mDeviceStatesOnWhichToSelectiveSleep.get(pendingState.getIdentifier())
+            return currentState.getIdentifier()
+                    != DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER
+                    && pendingState.getIdentifier()
+                    != DeviceStateManager.INVALID_DEVICE_STATE_IDENTIFIER
+                    && mDeviceStatesOnWhichToSelectiveSleep.get(pendingState.getIdentifier())
                     && !mDeviceStatesOnWhichToSelectiveSleep.get(currentState.getIdentifier())
                     && isInteractive
                     && isBootCompleted
diff --git a/services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java b/services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java
index 5ff421a..7c93c8b 100644
--- a/services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java
+++ b/services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java
@@ -89,8 +89,8 @@
     void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken,
             @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver,
             @SoftInputShowHideReason int reason, @UserIdInt int userId) {
-        final var bindingController = mService.getInputMethodBindingController(userId);
         final var userData = mService.getUserData(userId);
+        final var bindingController = userData.mBindingController;
         final IInputMethodInvoker curMethod = bindingController.getCurMethod();
         if (curMethod != null) {
             if (DEBUG) {
@@ -128,9 +128,9 @@
     void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken,
             ResultReceiver resultReceiver, @SoftInputShowHideReason int reason,
             @UserIdInt int userId) {
-        final var bindingController = mService.getInputMethodBindingController(userId);
-        final IInputMethodInvoker curMethod = bindingController.getCurMethod();
         final var userData = mService.getUserData(userId);
+        final var bindingController = userData.mBindingController;
+        final IInputMethodInvoker curMethod = bindingController.getCurMethod();
         if (curMethod != null) {
             // The IME will report its visible state again after the following message finally
             // delivered to the IME process as an IPC.  Hence the inconsistency between
@@ -171,8 +171,8 @@
     void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken,
             @ImeVisibilityStateComputer.VisibilityState int state,
             @SoftInputShowHideReason int reason, @UserIdInt int userId) {
-        final var bindingController = mService.getInputMethodBindingController(userId);
         final var userData = mService.getUserData(userId);
+        final var bindingController = userData.mBindingController;
         final int displayIdToShowIme = bindingController.getDisplayIdToShowIme();
         switch (state) {
             case STATE_SHOW_IME:
diff --git a/services/core/java/com/android/server/inputmethod/IInputMethodManagerImpl.java b/services/core/java/com/android/server/inputmethod/IInputMethodManagerImpl.java
index 3f28c47..a7280e6 100644
--- a/services/core/java/com/android/server/inputmethod/IInputMethodManagerImpl.java
+++ b/services/core/java/com/android/server/inputmethod/IInputMethodManagerImpl.java
@@ -138,6 +138,9 @@
         @PermissionVerified(Manifest.permission.TEST_INPUT_METHOD)
         boolean isInputMethodPickerShownForTest();
 
+        @PermissionVerified(Manifest.permission.WRITE_SECURE_SETTINGS)
+        void onImeSwitchButtonClickFromSystem(int displayId);
+
         InputMethodSubtype getCurrentInputMethodSubtype(@UserIdInt int userId);
 
         void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes,
@@ -344,6 +347,14 @@
         return mCallback.isInputMethodPickerShownForTest();
     }
 
+    @EnforcePermission(Manifest.permission.WRITE_SECURE_SETTINGS)
+    @Override
+    public void onImeSwitchButtonClickFromSystem(int displayId) {
+        super.onImeSwitchButtonClickFromSystem_enforcePermission();
+
+        mCallback.onImeSwitchButtonClickFromSystem(displayId);
+    }
+
     @Override
     public InputMethodSubtype getCurrentInputMethodSubtype(@UserIdInt int userId) {
         return mCallback.getCurrentInputMethodSubtype(userId);
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index f5faeef..540c21c 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -53,6 +53,7 @@
 import static com.android.server.inputmethod.ImeVisibilityStateComputer.ImeVisibilityResult;
 import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME;
 import static com.android.server.inputmethod.InputMethodBindingController.TIME_TO_RECONNECT;
+import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.MODE_AUTO;
 import static com.android.server.inputmethod.InputMethodUtils.isSoftInputModeStateVisibleAllowed;
 
 import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -475,7 +476,7 @@
 
     @AnyThread
     @NonNull
-    UserDataRepository.UserData getUserData(@UserIdInt int userId) {
+    UserData getUserData(@UserIdInt int userId) {
         return mUserDataRepository.getOrCreate(userId);
     }
 
@@ -1708,7 +1709,7 @@
         clearClientSessionLocked(client);
         clearClientSessionForAccessibilityLocked(client);
         // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
-        @SuppressWarnings("GuardedBy") Consumer<UserDataRepository.UserData> clientRemovedForUser =
+        @SuppressWarnings("GuardedBy") Consumer<UserData> clientRemovedForUser =
                 userData -> onClientRemovedInternalLocked(client, userData);
         mUserDataRepository.forAllUserData(clientRemovedForUser);
     }
@@ -1718,15 +1719,14 @@
      */
     // TODO(b/325515685): Move this method to InputMethodBindingController
     @GuardedBy("ImfLock.class")
-    private void onClientRemovedInternalLocked(ClientState client,
-            @NonNull UserDataRepository.UserData userData) {
+    private void onClientRemovedInternalLocked(ClientState client, @NonNull UserData userData) {
         final int userId = userData.mUserId;
         if (userData.mCurClient == client) {
             hideCurrentInputLocked(userData.mImeBindingState.mFocusedWindow, 0 /* flags */,
                     SoftInputShowHideReason.HIDE_REMOVE_CLIENT, userId);
             if (userData.mBoundToMethod) {
                 userData.mBoundToMethod = false;
-                final var userBindingController = getInputMethodBindingController(userId);
+                final var userBindingController = userData.mBindingController;
                 IInputMethodInvoker curMethod = userBindingController.getCurMethod();
                 if (curMethod != null) {
                     // When we unbind input, we are unbinding the client, so we always
@@ -1758,7 +1758,7 @@
                 Slog.v(TAG, "unbindCurrentInputLocked: client="
                         + userData.mCurClient.mClient.asBinder());
             }
-            final var bindingController = getInputMethodBindingController(userId);
+            final var bindingController = userData.mBindingController;
             if (userData.mBoundToMethod) {
                 userData.mBoundToMethod = false;
                 IInputMethodInvoker curMethod = bindingController.getCurMethod();
@@ -1844,8 +1844,8 @@
     @NonNull
     InputBindResult attachNewInputLocked(@StartInputReason int startInputReason, boolean initial,
             @UserIdInt int userId) {
-        final var bindingController = getInputMethodBindingController(userId);
         final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         if (!userData.mBoundToMethod) {
             bindingController.getCurMethod().bindInput(userData.mCurClient.mBinding);
             userData.mBoundToMethod = true;
@@ -2316,8 +2316,8 @@
                     channel.dispose();
                     return;
                 }
-                final var bindingController = getInputMethodBindingController(userId);
                 final var userData = getUserData(userId);
+                final var bindingController = userData.mBindingController;
                 IInputMethodInvoker curMethod = bindingController.getCurMethod();
                 if (curMethod != null && method != null
                         && curMethod.asBinder() == method.asBinder()) {
@@ -2575,8 +2575,7 @@
 
     @GuardedBy("ImfLock.class")
     @InputMethodNavButtonFlags
-    private int getInputMethodNavButtonFlagsLocked(
-            @NonNull UserDataRepository.UserData userData) {
+    private int getInputMethodNavButtonFlagsLocked(@NonNull UserData userData) {
         final int userId = userData.mUserId;
         final var bindingController = userData.mBindingController;
         // Whether the current display has a navigation bar. When this is false (e.g. emulator),
@@ -2746,8 +2745,8 @@
 
     @GuardedBy("ImfLock.class")
     private void updateSystemUiLocked(int vis, int backDisposition, @UserIdInt int userId) {
-        final var bindingController = getInputMethodBindingController(userId);
         final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         final var curToken = bindingController.getCurToken();
         if (curToken == null) {
             return;
@@ -2845,11 +2844,11 @@
                 settings.putSelectedInputMethod(id);
             }
         }
-        final var bindingController = getInputMethodBindingController(userId);
+        final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         bindingController.setSelectedMethodId(id);
 
         // Also re-initialize controllers.
-        final var userData = getUserData(userId);
         userData.mSwitchingController.resetCircularListLocked(mContext, settings);
         userData.mHardwareKeyboardShortcutController.update(settings);
     }
@@ -2886,7 +2885,8 @@
             }
         }
 
-        final var bindingController = getInputMethodBindingController(userId);
+        final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         if (bindingController.getDeviceIdToShowIme() == DEVICE_ID_DEFAULT) {
             String ime = SecureSettingsWrapper.getString(
                     Settings.Secure.DEFAULT_INPUT_METHOD, null, userId);
@@ -2926,7 +2926,6 @@
             resetCurrentMethodAndClientLocked(UnbindReason.NO_IME, userId);
         }
 
-        final var userData = getUserData(userId);
         userData.mSwitchingController.resetCircularListLocked(mContext, settings);
         userData.mHardwareKeyboardShortcutController.update(settings);
         sendOnNavButtonFlagsChangedLocked(userData);
@@ -3408,8 +3407,8 @@
         mVisibilityStateComputer.requestImeVisibility(windowToken, true);
 
         // Ensure binding the connection when IME is going to show.
-        final var bindingController = getInputMethodBindingController(userId);
         final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         bindingController.setCurrentMethodVisible();
         final IInputMethodInvoker curMethod = bindingController.getCurMethod();
         ImeTracker.forLogging().onCancelled(userData.mCurStatsToken,
@@ -3542,7 +3541,8 @@
     boolean hideCurrentInputLocked(IBinder windowToken, @NonNull ImeTracker.Token statsToken,
             @InputMethodManager.HideFlags int flags, @Nullable ResultReceiver resultReceiver,
             @SoftInputShowHideReason int reason, @UserIdInt int userId) {
-        final var bindingController = getInputMethodBindingController(userId);
+        final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         if (!mVisibilityStateComputer.canHideIme(statsToken, flags)) {
             return false;
         }
@@ -3555,7 +3555,6 @@
         // since Android Eclair.  That's why we need to accept IMM#hideSoftInput() even when only
         // IMMS#InputShown indicates that the software keyboard is shown.
         // TODO(b/246309664): Clean up IMMS#mImeWindowVis
-        final var userData = getUserData(userId);
         IInputMethodInvoker curMethod = bindingController.getCurMethod();
         final boolean shouldHideSoftInput = curMethod != null
                 && (isInputShownLocked()
@@ -3635,6 +3634,7 @@
             Slog.w(TAG, "User #" + userId + " is not running.");
             return InputBindResult.INVALID_USER;
         }
+        final var userData = getUserData(userId);
         try {
             Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
                     "IMMS.startInputOrWindowGainedFocus");
@@ -3642,7 +3642,7 @@
                     "InputMethodManagerService#startInputOrWindowGainedFocus", mDumper);
             final InputBindResult result;
             synchronized (ImfLock.class) {
-                final var bindingController = getInputMethodBindingController(userId);
+                final var bindingController = userData.mBindingController;
                 // If the system is not yet ready, we shouldn't be running third party code.
                 if (!mSystemReady) {
                     return new InputBindResult(
@@ -3707,7 +3707,6 @@
                     final boolean shouldClearFlag =
                             mImePlatformCompatUtils.shouldClearShowForcedFlag(cs.mUid);
                     final boolean showForced = mVisibilityStateComputer.mShowForced;
-                    final var userData = getUserData(userId);
                     if (userData.mImeBindingState.mFocusedWindow != windowToken
                             && showForced && shouldClearFlag) {
                         mVisibilityStateComputer.mShowForced = false;
@@ -3967,6 +3966,29 @@
         }
     }
 
+    @BinderThread
+    private void onImeSwitchButtonClickFromClient(@NonNull IBinder token, int displayId,
+            @UserIdInt int userId) {
+        userId = mActivityManagerInternal.handleIncomingUser(
+                Binder.getCallingPid(), Binder.getCallingUid(), userId, false,
+                ActivityManagerInternal.ALLOW_FULL_ONLY, "onImeSwitchButtonClickFromClient", null);
+
+        synchronized (ImfLock.class) {
+            if (!calledWithValidTokenLocked(token, userId)) {
+                return;
+            }
+            showInputMethodPickerFromSystem(
+                    InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, displayId);
+        }
+    }
+
+    @IInputMethodManagerImpl.PermissionVerified(Manifest.permission.WRITE_SECURE_SETTINGS)
+    @Override
+    public void onImeSwitchButtonClickFromSystem(int displayId) {
+        showInputMethodPickerFromSystem(
+                InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, displayId);
+    }
+
     @NonNull
     private static IllegalArgumentException getExceptionForUnknownImeId(
             @Nullable String imeId) {
@@ -4112,7 +4134,8 @@
         final var currentImi = bindingController.getSelectedMethod();
         final ImeSubtypeListItem nextSubtype = getUserData(userId).mSwitchingController
                 .getNextInputMethodLocked(onlyCurrentIme, currentImi,
-                        bindingController.getCurrentSubtype());
+                        bindingController.getCurrentSubtype(),
+                        MODE_AUTO, true /* forward */);
         if (nextSubtype == null) {
             return false;
         }
@@ -4132,7 +4155,8 @@
             final var currentImi = bindingController.getSelectedMethod();
             final ImeSubtypeListItem nextSubtype = getUserData(userId).mSwitchingController
                     .getNextInputMethodLocked(false /* onlyCurrentIme */, currentImi,
-                            bindingController.getCurrentSubtype());
+                            bindingController.getCurrentSubtype(),
+                            MODE_AUTO, true /* forward */);
             return nextSubtype != null;
         }
     }
@@ -4530,8 +4554,8 @@
     private void dumpDebug(ProtoOutputStream proto, long fieldId) {
         synchronized (ImfLock.class) {
             final int userId = mCurrentUserId;
-            final var bindingController = getInputMethodBindingController(userId);
             final var userData = getUserData(userId);
+            final var bindingController = userData.mBindingController;
             final long token = proto.start(fieldId);
             proto.write(CUR_METHOD_ID, bindingController.getSelectedMethodId());
             proto.write(CUR_SEQ, bindingController.getSequenceNumber());
@@ -4664,8 +4688,8 @@
             @UserIdInt int userId) {
         final IBinder requestToken = mVisibilityStateComputer.getWindowTokenFrom(requestImeToken,
                 userId);
-        final var bindingController = getInputMethodBindingController(userId);
         final var userData = getUserData(userId);
+        final var bindingController = userData.mBindingController;
         final WindowManagerInternal.ImeTargetInfo info =
                 mWindowManagerInternal.onToggleImeRequested(
                         show, userData.mImeBindingState.mFocusedWindow, requestToken,
@@ -4778,8 +4802,7 @@
     }
 
     @GuardedBy("ImfLock.class")
-    void setEnabledSessionLocked(SessionState session,
-            @NonNull UserDataRepository.UserData userData) {
+    void setEnabledSessionLocked(SessionState session, @NonNull UserData userData) {
         if (userData.mEnabledSession != session) {
             if (userData.mEnabledSession != null && userData.mEnabledSession.mSession != null) {
                 if (DEBUG) Slog.v(TAG, "Disabling: " + userData.mEnabledSession);
@@ -4798,7 +4821,7 @@
     @GuardedBy("ImfLock.class")
     void setEnabledSessionForAccessibilityLocked(
             SparseArray<AccessibilitySessionState> accessibilitySessions,
-            @NonNull UserDataRepository.UserData userData) {
+            @NonNull UserData userData) {
         // mEnabledAccessibilitySessions could the same object as accessibilitySessions.
         SparseArray<IAccessibilityInputMethodSession> disabledSessions = new SparseArray<>();
         for (int i = 0; i < userData.mEnabledAccessibilitySessions.size(); i++) {
@@ -5008,8 +5031,8 @@
                 final var handwritingRequest = (HandwritingRequest) msg.obj;
                 synchronized (ImfLock.class) {
                     final int userId = handwritingRequest.userId;
-                    final var bindingController = getInputMethodBindingController(userId);
                     final var userData = getUserData(userId);
+                    final var bindingController = userData.mBindingController;
                     IInputMethodInvoker curMethod = bindingController.getCurMethod();
                     if (curMethod == null || userData.mImeBindingState.mFocusedWindow == null) {
                         return true;
@@ -5066,12 +5089,12 @@
         synchronized (ImfLock.class) {
             // TODO(b/305849394): Support multiple IMEs.
             final int userId = mCurrentUserId;
-            final var bindingController = getInputMethodBindingController(userId);
+            final var userData = getUserData(userId);
+            final var bindingController = userData.mBindingController;
             mIsInteractive = interactive;
             updateSystemUiLocked(
                     interactive ? bindingController.getImeWindowVis() : 0,
                     bindingController.getBackDisposition(), userId);
-            final var userData = getUserData(userId);
             // Inform the current client of the change in active status
             if (userData.mCurClient == null || userData.mCurClient.mClient == null) {
                 return;
@@ -5303,7 +5326,7 @@
     }
 
     @GuardedBy("ImfLock.class")
-    void sendOnNavButtonFlagsChangedLocked(@NonNull UserDataRepository.UserData userData) {
+    void sendOnNavButtonFlagsChangedLocked(@NonNull UserData userData) {
         final var bindingController = userData.mBindingController;
         final IInputMethodInvoker curMethod = bindingController.getCurMethod();
         if (curMethod == null) {
@@ -5319,7 +5342,7 @@
         final boolean value =
                 InputMethodDrawsNavBarResourceMonitor.evaluate(mContext, profileParentId);
         final var profileUserIds = mUserManagerInternal.getProfileIds(profileParentId, false);
-        final ArrayList<UserDataRepository.UserData> updatedUsers = new ArrayList<>();
+        final ArrayList<UserData> updatedUsers = new ArrayList<>();
         for (int profileUserId : profileUserIds) {
             final var userData = getUserData(profileUserId);
             userData.mImeDrawsNavBar.set(value);
@@ -5457,6 +5480,10 @@
             // Set InputMethod here
             settings.putSelectedInputMethod(imi != null ? imi.getId() : "");
         }
+
+        if (Flags.imeSwitcherRevamp()) {
+            getUserData(userId).mSwitchingController.onInputMethodSubtypeChanged();
+        }
     }
 
     @GuardedBy("ImfLock.class")
@@ -5577,11 +5604,29 @@
         if (currentImi == null) {
             return;
         }
-        final InputMethodSubtypeHandle currentSubtypeHandle =
-                InputMethodSubtypeHandle.of(currentImi, bindingController.getCurrentSubtype());
-        final InputMethodSubtypeHandle nextSubtypeHandle =
-                getUserData(userId).mHardwareKeyboardShortcutController.onSubtypeSwitch(
+        final var currentSubtype = bindingController.getCurrentSubtype();
+        final InputMethodSubtypeHandle nextSubtypeHandle;
+        if (Flags.imeSwitcherRevamp()) {
+            final var nextItem = getUserData(userId).mSwitchingController
+                    .getNextInputMethodForHardware(
+                            false /* onlyCurrentIme */, currentImi, currentSubtype, MODE_AUTO,
+                            direction > 0 /* forward */);
+            if (nextItem == null) {
+                Slog.i(TAG, "Hardware keyboard switching shortcut,"
+                        + " next input method and subtype not found");
+                return;
+            }
+
+            final var nextSubtype = nextItem.mSubtypeId > NOT_A_SUBTYPE_ID
+                    ? nextItem.mImi.getSubtypeAt(nextItem.mSubtypeId) : null;
+            nextSubtypeHandle = InputMethodSubtypeHandle.of(nextItem.mImi, nextSubtype);
+        } else {
+            final InputMethodSubtypeHandle currentSubtypeHandle =
+                    InputMethodSubtypeHandle.of(currentImi, currentSubtype);
+            nextSubtypeHandle =
+                    getUserData(userId).mHardwareKeyboardShortcutController.onSubtypeSwitch(
                         currentSubtypeHandle, direction > 0);
+        }
         if (nextSubtypeHandle == null) {
             return;
         }
@@ -5727,7 +5772,7 @@
                 if (displayId != bindingController.getCurTokenDisplayId()) {
                     return false;
                 }
-                curHostInputToken = getInputMethodBindingController(userId).getCurHostInputToken();
+                curHostInputToken = bindingController.getCurHostInputToken();
                 if (curHostInputToken == null) {
                     return false;
                 }
@@ -5783,8 +5828,8 @@
         public void onSessionForAccessibilityCreated(int accessibilityConnectionId,
                 IAccessibilityInputMethodSession session, @UserIdInt int userId) {
             synchronized (ImfLock.class) {
-                final var bindingController = getInputMethodBindingController(userId);
                 final var userData = getUserData(userId);
+                final var bindingController = userData.mBindingController;
                 // TODO(b/305829876): Implement user ID verification
                 if (userData.mCurClient != null) {
                     clearClientSessionForAccessibilityLocked(userData.mCurClient,
@@ -5821,8 +5866,8 @@
         public void unbindAccessibilityFromCurrentClient(int accessibilityConnectionId,
                 @UserIdInt int userId) {
             synchronized (ImfLock.class) {
-                final var bindingController = getInputMethodBindingController(userId);
                 final var userData = getUserData(userId);
+                final var bindingController = userData.mBindingController;
                 // TODO(b/305829876): Implement user ID verification
                 if (userData.mCurClient != null) {
                     if (DEBUG) {
@@ -5890,7 +5935,8 @@
 
         synchronized (ImfLock.class) {
             final int uid = Binder.getCallingUid();
-            final var bindingController = getInputMethodBindingController(imeUserId);
+            final var userData = getUserData(imeUserId);
+            final var bindingController = userData.mBindingController;
             if (bindingController.getSelectedMethodId() == null) {
                 return null;
             }
@@ -5902,7 +5948,6 @@
             // We cannot simply distinguish a bad IME that reports an arbitrary package name from
             // an unfortunate IME whose internal state is already obsolete due to the asynchronous
             // nature of our system.  Let's compare it with our internal record.
-            final var userData = getUserData(imeUserId);
             final var curPackageName = userData.mCurEditorInfo != null
                     ? userData.mCurEditorInfo.packageName : null;
             if (!TextUtils.equals(curPackageName, packageName)) {
@@ -6061,8 +6106,8 @@
                 p.println("    pid=" + c.mPid);
             };
             mClientController.forAllClients(clientControllerDump);
-            final var bindingController = getInputMethodBindingController(mCurrentUserId);
-            p.println("  mCurrentUserId=" + mCurrentUserId);
+            final var bindingController = userData.mBindingController;
+            p.println("  mCurrentUserId=" + userData.mUserId);
             p.println("  mCurMethodId=" + bindingController.getSelectedMethodId());
             client = userData.mCurClient;
             p.println("  mCurClient=" + client + " mCurSeq="
@@ -6077,7 +6122,7 @@
 
             p.println("  mUserDataRepository=");
             // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
-            @SuppressWarnings("GuardedBy") Consumer<UserDataRepository.UserData> userDataDump =
+            @SuppressWarnings("GuardedBy") Consumer<UserData> userDataDump =
                     u -> {
                         p.println("    mUserId=" + u.mUserId);
                         p.println("      hasMainConnection="
@@ -6614,7 +6659,7 @@
                                     0 /* flags */,
                                     SoftInputShowHideReason.HIDE_RESET_SHELL_COMMAND, userId);
                         }
-                        final var bindingController = getInputMethodBindingController(userId);
+                        final var bindingController = userData.mBindingController;
                         bindingController.unbindCurrentMethod();
 
                         // Enable default IMEs, disable others
@@ -6905,6 +6950,12 @@
 
         @BinderThread
         @Override
+        public void onImeSwitchButtonClickFromClient(int displayId, @UserIdInt int userId) {
+            mImms.onImeSwitchButtonClickFromClient(mToken, displayId, userId);
+        }
+
+        @BinderThread
+        @Override
         public void notifyUserActionAsync() {
             mImms.notifyUserAction(mToken, mUserId);
         }
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java b/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java
index bb1b9df..05cc598 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java
@@ -16,6 +16,8 @@
 
 package com.android.server.inputmethod;
 
+import android.annotation.IntDef;
+import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
@@ -24,11 +26,14 @@
 import android.util.ArraySet;
 import android.util.Printer;
 import android.util.Slog;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.internal.annotations.VisibleForTesting;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -45,6 +50,34 @@
     private static final boolean DEBUG = false;
     private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
 
+    @IntDef(prefix = {"MODE_"}, value = {
+            MODE_STATIC,
+            MODE_RECENT,
+            MODE_AUTO
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface SwitchMode {
+    }
+
+    /**
+     * Switch using the static order (the order of the given list of input methods and subtypes).
+     * This order is only set when given a new list, and never updated.
+     */
+    public static final int MODE_STATIC = 0;
+
+    /**
+     * Switch using the recency based order, going from most recent to least recent,
+     * updated on {@link #onUserActionLocked user action}.
+     */
+    public static final int MODE_RECENT = 1;
+
+    /**
+     * If there was a {@link #onUserActionLocked user action} since the last
+     * {@link #onInputMethodSubtypeChanged() switch}, and direction is forward,
+     * use {@link #MODE_RECENT}, otherwise use {@link #MODE_STATIC}.
+     */
+    public static final int MODE_AUTO = 2;
+
     public static class ImeSubtypeListItem implements Comparable<ImeSubtypeListItem> {
 
         @NonNull
@@ -117,20 +150,25 @@
             if (result != 0) {
                 return result;
             }
-            // Subtype that has the same locale of the system's has higher priority.
-            result = (mIsSystemLocale ? -1 : 0) - (other.mIsSystemLocale ? -1 : 0);
-            if (result != 0) {
-                return result;
+            if (!Flags.imeSwitcherRevamp()) {
+                // Subtype that has the same locale of the system's has higher priority.
+                result = (mIsSystemLocale ? -1 : 0) - (other.mIsSystemLocale ? -1 : 0);
+                if (result != 0) {
+                    return result;
+                }
+                // Subtype that has the same language of the system's has higher priority.
+                result = (mIsSystemLanguage ? -1 : 0) - (other.mIsSystemLanguage ? -1 : 0);
+                if (result != 0) {
+                    return result;
+                }
+                result = compareNullableCharSequences(mSubtypeName, other.mSubtypeName);
+                if (result != 0) {
+                    return result;
+                }
             }
-            // Subtype that has the same language of the system's has higher priority.
-            result = (mIsSystemLanguage ? -1 : 0) - (other.mIsSystemLanguage ? -1 : 0);
-            if (result != 0) {
-                return result;
-            }
-            result = compareNullableCharSequences(mSubtypeName, other.mSubtypeName);
-            if (result != 0) {
-                return result;
-            }
+            // This will no longer compare by subtype name, however as {@link Collections.sort} is
+            // guaranteed to be a stable sorting, this allows sorting by the IME name (and ID),
+            // while maintaining the order of subtypes (given by each IME) at the IME level.
             return mImi.getId().compareTo(other.mImi.getId());
         }
 
@@ -226,6 +264,59 @@
         return imList;
     }
 
+    @NonNull
+    private static List<ImeSubtypeListItem> getInputMethodAndSubtypeListForHardwareKeyboard(
+            @NonNull Context context, @NonNull InputMethodSettings settings) {
+        if (!Flags.imeSwitcherRevamp()) {
+            return new ArrayList<>();
+        }
+        final int userId = settings.getUserId();
+        final Context userAwareContext = context.getUserId() == userId
+                ? context
+                : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
+        final String mSystemLocaleStr = SystemLocaleWrapper.get(userId).get(0).toLanguageTag();
+
+        final ArrayList<InputMethodInfo> imis = settings.getEnabledInputMethodList();
+        if (imis.isEmpty()) {
+            Slog.w(TAG, "Enabled input method list is empty.");
+            return new ArrayList<>();
+        }
+
+        final ArrayList<ImeSubtypeListItem> imList = new ArrayList<>();
+        final int numImes = imis.size();
+        for (int i = 0; i < numImes; ++i) {
+            final InputMethodInfo imi = imis.get(i);
+            if (!imi.shouldShowInInputMethodPicker()) {
+                continue;
+            }
+            final var subtypes = settings.getEnabledInputMethodSubtypeList(imi, true);
+            final ArraySet<InputMethodSubtype> enabledSubtypeSet = new ArraySet<>(subtypes);
+            final CharSequence imeLabel = imi.loadLabel(userAwareContext.getPackageManager());
+            if (!subtypes.isEmpty()) {
+                final int subtypeCount = imi.getSubtypeCount();
+                if (DEBUG) {
+                    Slog.v(TAG, "Add subtypes: " + subtypeCount + ", " + imi.getId());
+                }
+                for (int j = 0; j < subtypeCount; j++) {
+                    final InputMethodSubtype subtype = imi.getSubtypeAt(j);
+                    if (enabledSubtypeSet.contains(subtype)
+                            && subtype.isSuitableForPhysicalKeyboardLayoutMapping()) {
+                        final CharSequence subtypeLabel =
+                                subtype.overridesImplicitlyEnabledSubtype() ? null : subtype
+                                        .getDisplayName(userAwareContext, imi.getPackageName(),
+                                                imi.getServiceInfo().applicationInfo);
+                        imList.add(new ImeSubtypeListItem(imeLabel,
+                                subtypeLabel, imi, j, subtype.getLocale(), mSystemLocaleStr));
+                    }
+                }
+            } else {
+                imList.add(new ImeSubtypeListItem(imeLabel, null, imi, NOT_A_SUBTYPE_ID, null,
+                        mSystemLocaleStr));
+            }
+        }
+        return imList;
+    }
+
     private static int calculateSubtypeId(@NonNull InputMethodInfo imi,
             @Nullable InputMethodSubtype subtype) {
         return subtype != null ? SubtypeUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode())
@@ -385,6 +476,132 @@
         }
     }
 
+    /**
+     * List container that allows getting the next item in either forwards or backwards direction,
+     * in either static or recency order, and either in the same IME or not.
+     */
+    private static class RotationList {
+
+        /**
+         * List of items in a static order.
+         */
+        @NonNull
+        private final List<ImeSubtypeListItem> mItems;
+
+        /**
+         * Mapping of recency index to static index (in {@link #mItems}), with lower indices being
+         * more recent.
+         */
+        @NonNull
+        private final int[] mRecencyMap;
+
+        RotationList(@NonNull List<ImeSubtypeListItem> items) {
+            mItems = items;
+            mRecencyMap = new int[items.size()];
+            for (int i = 0; i < mItems.size(); i++) {
+                mRecencyMap[i] = i;
+            }
+        }
+
+        /**
+         * Gets the next input method and subtype from the given ones.
+         *
+         * @param imi            the input method to find the next value from.
+         * @param subtype        the input method subtype to find the next value from, if any.
+         * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+         * @param useRecency     whether to use the recency order, or the static order.
+         * @param forward        whether to search forwards to backwards in the list.
+         * @return the next input method and subtype if found, otherwise {@code null}.
+         */
+        @Nullable
+        public ImeSubtypeListItem next(@NonNull InputMethodInfo imi,
+                @Nullable InputMethodSubtype subtype, boolean onlyCurrentIme,
+                boolean useRecency, boolean forward) {
+            final int size = mItems.size();
+            if (size <= 1) {
+                return null;
+            }
+            final int index = getIndex(imi, subtype, useRecency);
+            if (index < 0) {
+                return null;
+            }
+
+            final int incrementSign = (forward ? 1 : -1);
+
+            for (int i = 1; i < size; i++) {
+                final int nextIndex = (index + i * incrementSign + size) % size;
+                final int mappedIndex = useRecency ? mRecencyMap[nextIndex] : nextIndex;
+                final var nextItem = mItems.get(mappedIndex);
+                if (!onlyCurrentIme || nextItem.mImi.equals(imi)) {
+                    return nextItem;
+                }
+            }
+            return null;
+        }
+
+        /**
+         * Sets the given input method and subtype as the most recent one.
+         *
+         * @param imi     the input method to set as the most recent.
+         * @param subtype the input method subtype to set as the most recent, if any.
+         * @return {@code true} if the recency was updated, otherwise {@code false}.
+         */
+        public boolean setMostRecent(@NonNull InputMethodInfo imi,
+                @Nullable InputMethodSubtype subtype) {
+            if (mItems.size() <= 1) {
+                return false;
+            }
+
+            final int recencyIndex = getIndex(imi, subtype, true /* useRecency */);
+            if (recencyIndex <= 0) {
+                // Already most recent or not found.
+                return false;
+            }
+            final int staticIndex = mRecencyMap[recencyIndex];
+            System.arraycopy(mRecencyMap, 0, mRecencyMap, 1, recencyIndex);
+            mRecencyMap[0] = staticIndex;
+            return true;
+        }
+
+        /**
+         * Gets the index of the given input method and subtype, in either recency or static order.
+         *
+         * @param imi        the input method to get the index of.
+         * @param subtype    the input method subtype to get the index of, if any.
+         * @param useRecency whether to get the index in the recency or static order.
+         * @return an index in either {@link #mItems} or {@link #mRecencyMap}, or {@code -1}
+         * if not found.
+         */
+        @IntRange(from = -1)
+        private int getIndex(@NonNull InputMethodInfo imi, @Nullable InputMethodSubtype subtype,
+                boolean useRecency) {
+            final int subtypeIndex = calculateSubtypeId(imi, subtype);
+            for (int i = 0; i < mItems.size(); i++) {
+                final int mappedIndex = useRecency ? mRecencyMap[i] : i;
+                final var item = mItems.get(mappedIndex);
+                if (item.mImi.equals(imi) && item.mSubtypeId == subtypeIndex) {
+                    return i;
+                }
+            }
+            return -1;
+        }
+
+        /** Dumps the state of the list into the given printer. */
+        private void dump(@NonNull Printer pw, @NonNull String prefix) {
+            pw.println(prefix + "Static order:");
+            for (int i = 0; i < mItems.size(); ++i) {
+                final var item = mItems.get(i);
+                pw.println(prefix + "i=" + i + " item=" + item);
+            }
+            pw.println(prefix + "Recency order:");
+            for (int i = 0; i < mRecencyMap.length; ++i) {
+                final int index = mRecencyMap[i];
+                final var item = mItems.get(index);
+                pw.println(prefix + "i=" + i + " item=" + item);
+            }
+        }
+    }
+
     @VisibleForTesting
     public static class ControllerImpl {
 
@@ -392,10 +609,23 @@
         private final DynamicRotationList mSwitchingAwareRotationList;
         @NonNull
         private final StaticRotationList mSwitchingUnawareRotationList;
+        /** List of input methods and subtypes. */
+        @Nullable
+        private final RotationList mRotationList;
+        /** List of input methods and subtypes suitable for hardware keyboards. */
+        @Nullable
+        private final RotationList mHardwareRotationList;
+
+        /**
+         * Whether there was a user action since the last input method and subtype switch.
+         * Used to determine the switching behaviour for {@link #MODE_AUTO}.
+         */
+        private boolean mUserActionSinceSwitch;
 
         @NonNull
         public static ControllerImpl createFrom(@Nullable ControllerImpl currentInstance,
-                @NonNull List<ImeSubtypeListItem> sortedEnabledItems) {
+                @NonNull List<ImeSubtypeListItem> sortedEnabledItems,
+                @NonNull List<ImeSubtypeListItem> hardwareKeyboardItems) {
             final var switchingAwareImeSubtypes = filterImeSubtypeList(sortedEnabledItems,
                     true /* supportsSwitchingToNextInputMethod */);
             final var switchingUnawareImeSubtypes = filterImeSubtypeList(sortedEnabledItems,
@@ -421,22 +651,55 @@
                 switchingUnawareRotationList = new StaticRotationList(switchingUnawareImeSubtypes);
             }
 
-            return new ControllerImpl(switchingAwareRotationList, switchingUnawareRotationList);
+            final RotationList rotationList;
+            if (!Flags.imeSwitcherRevamp()) {
+                rotationList = null;
+            } else if (currentInstance != null && currentInstance.mRotationList != null
+                    && Objects.equals(
+                            currentInstance.mRotationList.mItems, sortedEnabledItems)) {
+                // Can reuse the current instance.
+                rotationList = currentInstance.mRotationList;
+            } else {
+                rotationList = new RotationList(sortedEnabledItems);
+            }
+
+            final RotationList hardwareRotationList;
+            if (!Flags.imeSwitcherRevamp()) {
+                hardwareRotationList = null;
+            } else if (currentInstance != null && currentInstance.mHardwareRotationList != null
+                    && Objects.equals(
+                            currentInstance.mHardwareRotationList.mItems, hardwareKeyboardItems)) {
+                // Can reuse the current instance.
+                hardwareRotationList = currentInstance.mHardwareRotationList;
+            } else {
+                hardwareRotationList = new RotationList(hardwareKeyboardItems);
+            }
+
+            return new ControllerImpl(switchingAwareRotationList, switchingUnawareRotationList,
+                    rotationList, hardwareRotationList);
         }
 
         private ControllerImpl(@NonNull DynamicRotationList switchingAwareRotationList,
-                @NonNull StaticRotationList switchingUnawareRotationList) {
+                @NonNull StaticRotationList switchingUnawareRotationList,
+                @Nullable RotationList rotationList,
+                @Nullable RotationList hardwareRotationList) {
             mSwitchingAwareRotationList = switchingAwareRotationList;
             mSwitchingUnawareRotationList = switchingUnawareRotationList;
+            mRotationList = rotationList;
+            mHardwareRotationList = hardwareRotationList;
         }
 
         @Nullable
         public ImeSubtypeListItem getNextInputMethod(boolean onlyCurrentIme,
-                @Nullable InputMethodInfo imi, @Nullable InputMethodSubtype subtype) {
+                @Nullable InputMethodInfo imi, @Nullable InputMethodSubtype subtype,
+                @SwitchMode int mode, boolean forward) {
             if (imi == null) {
                 return null;
             }
-            if (imi.supportsSwitchingToNextInputMethod()) {
+            if (Flags.imeSwitcherRevamp() && mRotationList != null) {
+                return mRotationList.next(imi, subtype, onlyCurrentIme,
+                        isRecency(mode, forward), forward);
+            } else if (imi.supportsSwitchingToNextInputMethod()) {
                 return mSwitchingAwareRotationList.getNextInputMethodLocked(onlyCurrentIme, imi,
                         subtype);
             } else {
@@ -445,11 +708,66 @@
             }
         }
 
-        public void onUserActionLocked(@NonNull InputMethodInfo imi,
+        @Nullable
+        public ImeSubtypeListItem getNextInputMethodForHardware(boolean onlyCurrentIme,
+                @NonNull InputMethodInfo imi, @Nullable InputMethodSubtype subtype,
+                @SwitchMode int mode, boolean forward) {
+            if (Flags.imeSwitcherRevamp() && mHardwareRotationList != null) {
+                return mHardwareRotationList.next(imi, subtype, onlyCurrentIme,
+                        isRecency(mode, forward), forward);
+            }
+            return null;
+        }
+
+        /**
+         * Called when the user took an action that should update the recency of the current
+         * input method and subtype in the switching list.
+         *
+         * @param imi     the currently selected input method.
+         * @param subtype the currently selected input method subtype, if any.
+         * @return {@code true} if the recency was updated, otherwise {@code false}.
+         * @see android.inputmethodservice.InputMethodServiceInternal#notifyUserActionIfNecessary()
+         */
+        public boolean onUserActionLocked(@NonNull InputMethodInfo imi,
                 @Nullable InputMethodSubtype subtype) {
-            if (imi.supportsSwitchingToNextInputMethod()) {
+            boolean recencyUpdated = false;
+            if (Flags.imeSwitcherRevamp()) {
+                if (mRotationList != null) {
+                    recencyUpdated |= mRotationList.setMostRecent(imi, subtype);
+                }
+                if (mHardwareRotationList != null) {
+                    recencyUpdated |= mHardwareRotationList.setMostRecent(imi, subtype);
+                }
+                if (recencyUpdated) {
+                    mUserActionSinceSwitch = true;
+                }
+            } else if (imi.supportsSwitchingToNextInputMethod()) {
                 mSwitchingAwareRotationList.onUserAction(imi, subtype);
             }
+            return recencyUpdated;
+        }
+
+        /** Called when the input method and subtype was changed. */
+        public void onInputMethodSubtypeChanged() {
+            mUserActionSinceSwitch = false;
+        }
+
+        /**
+         * Whether the given mode and direction result in recency or static order.
+         *
+         * <p>{@link #MODE_AUTO} resolves to the recency order for the first forwards switch
+         * after an {@link #onUserActionLocked user action}, and otherwise to the static order.</p>
+         *
+         * @param mode    the switching mode.
+         * @param forward the switching direction.
+         * @return {@code true} for the recency order, otherwise {@code false}.
+         */
+        private boolean isRecency(@SwitchMode int mode, boolean forward) {
+            if (mode == MODE_AUTO && mUserActionSinceSwitch && forward) {
+                return true;
+            } else {
+                return mode == MODE_RECENT;
+            }
         }
 
         @NonNull
@@ -473,6 +791,17 @@
             mSwitchingAwareRotationList.dump(pw, prefix + "  ");
             pw.println(prefix + "mSwitchingUnawareRotationList:");
             mSwitchingUnawareRotationList.dump(pw, prefix + "  ");
+            if (Flags.imeSwitcherRevamp()) {
+                if (mRotationList != null) {
+                    pw.println(prefix + "mRotationList:");
+                    mRotationList.dump(pw, prefix + "  ");
+                }
+                if (mHardwareRotationList != null) {
+                    pw.println(prefix + "mHardwareRotationList:");
+                    mHardwareRotationList.dump(pw, prefix + "  ");
+                }
+                pw.println("User action since last switch: " + mUserActionSinceSwitch);
+            }
         }
     }
 
@@ -480,26 +809,71 @@
     private ControllerImpl mController;
 
     InputMethodSubtypeSwitchingController() {
-        mController = ControllerImpl.createFrom(null, Collections.emptyList());
+        mController = ControllerImpl.createFrom(null, Collections.emptyList(),
+                Collections.emptyList());
     }
 
+    /**
+     * Called when the user took an action that should update the recency of the current
+     * input method and subtype in the switching list.
+     *
+     * @param imi     the currently selected input method.
+     * @param subtype the currently selected input method subtype, if any.
+     * @see android.inputmethodservice.InputMethodServiceInternal#notifyUserActionIfNecessary()
+     */
     public void onUserActionLocked(@NonNull InputMethodInfo imi,
             @Nullable InputMethodSubtype subtype) {
         mController.onUserActionLocked(imi, subtype);
     }
 
+    /** Called when the input method and subtype was changed. */
+    public void onInputMethodSubtypeChanged() {
+        mController.onInputMethodSubtypeChanged();
+    }
+
     public void resetCircularListLocked(@NonNull Context context,
             @NonNull InputMethodSettings settings) {
         mController = ControllerImpl.createFrom(mController,
                 getSortedInputMethodAndSubtypeList(
                         false /* includeAuxiliarySubtypes */, false /* isScreenLocked */,
-                        false /* forImeMenu */, context, settings));
+                        false /* forImeMenu */, context, settings),
+                getInputMethodAndSubtypeListForHardwareKeyboard(context, settings));
     }
 
+    /**
+     * Gets the next input method and subtype, starting from the given ones, in the given direction.
+     *
+     * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+     * @param imi            the input method to find the next value from.
+     * @param subtype        the input method subtype to find the next value from, if any.
+     * @param mode           the switching mode.
+     * @param forward        whether to search search forwards or backwards in the list.
+     * @return the next input method and subtype if found, otherwise {@code null}.
+     */
     @Nullable
     public ImeSubtypeListItem getNextInputMethodLocked(boolean onlyCurrentIme,
-            @Nullable InputMethodInfo imi, @Nullable InputMethodSubtype subtype) {
-        return mController.getNextInputMethod(onlyCurrentIme, imi, subtype);
+            @Nullable InputMethodInfo imi, @Nullable InputMethodSubtype subtype,
+            @SwitchMode int mode, boolean forward) {
+        return mController.getNextInputMethod(onlyCurrentIme, imi, subtype, mode, forward);
+    }
+
+    /**
+     * Gets the next input method and subtype suitable for hardware keyboards, starting from the
+     * given ones, in the given direction.
+     *
+     * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+     * @param imi            the input method to find the next value from.
+     * @param subtype        the input method subtype to find the next value from, if any.
+     * @param mode           the switching mode
+     * @param forward        whether to search search forwards or backwards in the list.
+     * @return the next input method and subtype if found, otherwise {@code null}.
+     */
+    @Nullable
+    public ImeSubtypeListItem getNextInputMethodForHardware(boolean onlyCurrentIme,
+            @NonNull InputMethodInfo imi, @Nullable InputMethodSubtype subtype,
+            @SwitchMode int mode, boolean forward) {
+        return mController.getNextInputMethodForHardware(onlyCurrentIme, imi, subtype, mode,
+                forward);
     }
 
     public void dump(@NonNull Printer pw, @NonNull String prefix) {
diff --git a/services/core/java/com/android/server/inputmethod/UserData.java b/services/core/java/com/android/server/inputmethod/UserData.java
new file mode 100644
index 0000000..ec5c9e6
--- /dev/null
+++ b/services/core/java/com/android/server/inputmethod/UserData.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2024 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.server.inputmethod;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.UserIdInt;
+import android.util.SparseArray;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.ImeTracker;
+import android.window.ImeOnBackInvokedDispatcher;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
+import com.android.internal.inputmethod.IRemoteInputConnection;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/** Placeholder for all IMMS user specific fields */
+final class UserData {
+    @UserIdInt
+    final int mUserId;
+
+    @NonNull
+    final InputMethodBindingController mBindingController;
+
+    @NonNull
+    final InputMethodSubtypeSwitchingController mSwitchingController =
+            new InputMethodSubtypeSwitchingController();
+
+    @NonNull
+    final HardwareKeyboardShortcutController mHardwareKeyboardShortcutController =
+            new HardwareKeyboardShortcutController();
+
+    /**
+     * Have we called mCurMethod.bindInput()?
+     */
+    @GuardedBy("ImfLock.class")
+    boolean mBoundToMethod = false;
+
+    /**
+     * Have we called bindInput() for accessibility services?
+     */
+    @GuardedBy("ImfLock.class")
+    boolean mBoundToAccessibility;
+
+    @GuardedBy("ImfLock.class")
+    @NonNull
+    ImeBindingState mImeBindingState = ImeBindingState.newEmptyState();
+
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    ClientState mCurClient = null;
+
+    @GuardedBy("ImfLock.class")
+    boolean mInFullscreenMode;
+
+    /**
+     * The {@link IRemoteInputConnection} last provided by the current client.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    IRemoteInputConnection mCurInputConnection;
+
+    /**
+     * The {@link ImeOnBackInvokedDispatcher} last provided by the current client to
+     * receive {@link android.window.OnBackInvokedCallback}s forwarded from IME.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    ImeOnBackInvokedDispatcher mCurImeDispatcher;
+
+    /**
+     * The {@link IRemoteAccessibilityInputConnection} last provided by the current client.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    IRemoteAccessibilityInputConnection mCurRemoteAccessibilityInputConnection;
+
+    /**
+     * The {@link EditorInfo} last provided by the current client.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    EditorInfo mCurEditorInfo;
+
+    /**
+     * The token tracking the current IME show request that is waiting for a connection to an
+     * IME, otherwise {@code null}.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    ImeTracker.Token mCurStatsToken;
+
+    /**
+     * Currently enabled session.
+     */
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    InputMethodManagerService.SessionState mEnabledSession;
+
+    @GuardedBy("ImfLock.class")
+    @Nullable
+    SparseArray<InputMethodManagerService.AccessibilitySessionState>
+            mEnabledAccessibilitySessions = new SparseArray<>();
+
+    /**
+     * A per-user cache of {@link InputMethodSettings#getEnabledInputMethodsStr()}.
+     */
+    @GuardedBy("ImfLock.class")
+    @NonNull
+    String mLastEnabledInputMethodsStr = "";
+
+    /**
+     * {@code true} when the IME is responsible for drawing the navigation bar and its buttons.
+     */
+    @NonNull
+    final AtomicBoolean mImeDrawsNavBar = new AtomicBoolean();
+
+    /**
+     * Intended to be instantiated only from this file.
+     */
+    UserData(@UserIdInt int userId,
+            @NonNull InputMethodBindingController bindingController) {
+        mUserId = userId;
+        mBindingController = bindingController;
+    }
+
+    @Override
+    public String toString() {
+        return "UserData{" + "mUserId=" + mUserId + '}';
+    }
+}
diff --git a/services/core/java/com/android/server/inputmethod/UserDataRepository.java b/services/core/java/com/android/server/inputmethod/UserDataRepository.java
index 7c68d54..6f831cc 100644
--- a/services/core/java/com/android/server/inputmethod/UserDataRepository.java
+++ b/services/core/java/com/android/server/inputmethod/UserDataRepository.java
@@ -18,18 +18,11 @@
 
 import android.annotation.AnyThread;
 import android.annotation.NonNull;
-import android.annotation.Nullable;
 import android.annotation.UserIdInt;
 import android.util.SparseArray;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.ImeTracker;
-import android.window.ImeOnBackInvokedDispatcher;
 
 import com.android.internal.annotations.GuardedBy;
-import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
-import com.android.internal.inputmethod.IRemoteInputConnection;
 
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.function.Consumer;
 import java.util.function.IntFunction;
@@ -87,120 +80,4 @@
             mUserDataLock.writeLock().unlock();
         }
     }
-
-    /** Placeholder for all IMMS user specific fields */
-    static final class UserData {
-        @UserIdInt
-        final int mUserId;
-
-        @NonNull
-        final InputMethodBindingController mBindingController;
-
-        @NonNull
-        final InputMethodSubtypeSwitchingController mSwitchingController;
-
-        @NonNull
-        final HardwareKeyboardShortcutController mHardwareKeyboardShortcutController;
-
-        /**
-         * Have we called mCurMethod.bindInput()?
-         */
-        @GuardedBy("ImfLock.class")
-        boolean mBoundToMethod = false;
-
-        /**
-         * Have we called bindInput() for accessibility services?
-         */
-        @GuardedBy("ImfLock.class")
-        boolean mBoundToAccessibility;
-
-        @GuardedBy("ImfLock.class")
-        @NonNull
-        ImeBindingState mImeBindingState = ImeBindingState.newEmptyState();
-
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        ClientState mCurClient = null;
-
-        @GuardedBy("ImfLock.class")
-        boolean mInFullscreenMode;
-
-        /**
-         * The {@link IRemoteInputConnection} last provided by the current client.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        IRemoteInputConnection mCurInputConnection;
-
-        /**
-         * The {@link ImeOnBackInvokedDispatcher} last provided by the current client to
-         * receive {@link android.window.OnBackInvokedCallback}s forwarded from IME.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        ImeOnBackInvokedDispatcher mCurImeDispatcher;
-
-        /**
-         * The {@link IRemoteAccessibilityInputConnection} last provided by the current client.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        IRemoteAccessibilityInputConnection mCurRemoteAccessibilityInputConnection;
-
-        /**
-         * The {@link EditorInfo} last provided by the current client.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        EditorInfo mCurEditorInfo;
-
-        /**
-         * The token tracking the current IME show request that is waiting for a connection to an
-         * IME, otherwise {@code null}.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        ImeTracker.Token mCurStatsToken;
-
-        /**
-         * Currently enabled session.
-         */
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        InputMethodManagerService.SessionState mEnabledSession;
-
-        @GuardedBy("ImfLock.class")
-        @Nullable
-        SparseArray<InputMethodManagerService.AccessibilitySessionState>
-                mEnabledAccessibilitySessions = new SparseArray<>();
-
-        /**
-         * A per-user cache of {@link InputMethodSettings#getEnabledInputMethodsStr()}.
-         */
-        @GuardedBy("ImfLock.class")
-        @NonNull
-        String mLastEnabledInputMethodsStr = "";
-
-        /**
-         * {@code true} when the IME is responsible for drawing the navigation bar and its buttons.
-         */
-        @NonNull
-        final AtomicBoolean mImeDrawsNavBar = new AtomicBoolean();
-
-        /**
-         * Intended to be instantiated only from this file.
-         */
-        private UserData(@UserIdInt int userId,
-                @NonNull InputMethodBindingController bindingController) {
-            mUserId = userId;
-            mBindingController = bindingController;
-            mSwitchingController = new InputMethodSubtypeSwitchingController();
-            mHardwareKeyboardShortcutController = new HardwareKeyboardShortcutController();
-        }
-
-        @Override
-        public String toString() {
-            return "UserData{" + "mUserId=" + mUserId + '}';
-        }
-    }
 }
diff --git a/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java b/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
index 41aac32..770e12d 100644
--- a/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
+++ b/services/core/java/com/android/server/inputmethod/ZeroJankProxy.java
@@ -296,6 +296,12 @@
         return mInner.isInputMethodPickerShownForTest();
     }
 
+    @IInputMethodManagerImpl.PermissionVerified(Manifest.permission.WRITE_SECURE_SETTINGS)
+    @Override
+    public void onImeSwitchButtonClickFromSystem(int displayId) {
+        mInner.onImeSwitchButtonClickFromSystem(displayId);
+    }
+
     @Override
     public InputMethodSubtype getCurrentInputMethodSubtype(int userId) {
         return mInner.getCurrentInputMethodSubtype(userId);
diff --git a/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java b/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
index 68a4172..2755a80 100644
--- a/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
+++ b/services/core/java/com/android/server/wm/CameraCompatFreeformPolicy.java
@@ -26,13 +26,14 @@
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.CameraCompatTaskInfo;
 import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
 
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.protolog.ProtoLogGroup;
 import com.android.internal.protolog.ProtoLog;
+import com.android.internal.protolog.ProtoLogGroup;
 import com.android.window.flags.Flags;
 
 /**
@@ -56,6 +57,9 @@
 
     private boolean mIsCameraCompatTreatmentPending = false;
 
+    @Nullable
+    private Task mCameraTask;
+
     CameraCompatFreeformPolicy(@NonNull DisplayContent displayContent,
             @NonNull CameraStateMonitor cameraStateMonitor,
             @NonNull ActivityRefresher activityRefresher) {
@@ -116,6 +120,7 @@
         final int newCameraCompatMode = getCameraCompatMode(cameraActivity);
         if (newCameraCompatMode != existingCameraCompatMode) {
             mIsCameraCompatTreatmentPending = true;
+            mCameraTask = cameraActivity.getTask();
             cameraActivity.mAppCompatController.getAppCompatCameraOverrides()
                     .setFreeformCameraCompatMode(newCameraCompatMode);
             forceUpdateActivityAndTask(cameraActivity);
@@ -127,18 +132,22 @@
     }
 
     @Override
-    public boolean onCameraClosed(@NonNull ActivityRecord cameraActivity,
-            @NonNull String cameraId) {
-        if (isActivityForCameraIdRefreshing(cameraId)) {
-            ProtoLog.v(ProtoLogGroup.WM_DEBUG_STATES,
-                    "Display id=%d is notified that Camera %s is closed but activity is"
-                            + " still refreshing. Rescheduling an update.",
-                    mDisplayContent.mDisplayId, cameraId);
-            return false;
+    public boolean onCameraClosed(@NonNull String cameraId) {
+        // Top activity in the same task as the camera activity, or `null` if the task is
+        // closed.
+        final ActivityRecord topActivity = mCameraTask != null
+                ? mCameraTask.getTopActivity(/* isFinishing */ false, /* includeOverlays */ false)
+                : null;
+        if (topActivity != null) {
+            if (isActivityForCameraIdRefreshing(topActivity, cameraId)) {
+                ProtoLog.v(ProtoLogGroup.WM_DEBUG_STATES,
+                        "Display id=%d is notified that Camera %s is closed but activity is"
+                                + " still refreshing. Rescheduling an update.",
+                        mDisplayContent.mDisplayId, cameraId);
+                return false;
+            }
         }
-        cameraActivity.mAppCompatController.getAppCompatCameraOverrides()
-                .setFreeformCameraCompatMode(CameraCompatTaskInfo.CAMERA_COMPAT_FREEFORM_NONE);
-        forceUpdateActivityAndTask(cameraActivity);
+        mCameraTask = null;
         mIsCameraCompatTreatmentPending = false;
         return true;
     }
@@ -186,10 +195,9 @@
                 && !activity.isEmbedded();
     }
 
-    private boolean isActivityForCameraIdRefreshing(@NonNull String cameraId) {
-        final ActivityRecord topActivity = mDisplayContent.topRunningActivity(
-                /* considerKeyguardState= */ true);
-        if (topActivity == null || !isTreatmentEnabledForActivity(topActivity)
+    private boolean isActivityForCameraIdRefreshing(@NonNull ActivityRecord topActivity,
+            @NonNull String cameraId) {
+        if (!isTreatmentEnabledForActivity(topActivity)
                 || mCameraStateMonitor.isCameraWithIdRunningForActivity(topActivity, cameraId)) {
             return false;
         }
diff --git a/services/core/java/com/android/server/wm/CameraStateMonitor.java b/services/core/java/com/android/server/wm/CameraStateMonitor.java
index a54141c..068fc00 100644
--- a/services/core/java/com/android/server/wm/CameraStateMonitor.java
+++ b/services/core/java/com/android/server/wm/CameraStateMonitor.java
@@ -61,9 +61,6 @@
     @NonNull
     private final Handler mHandler;
 
-    @Nullable
-    private ActivityRecord mCameraActivity;
-
     // Bi-directional map between package names and active camera IDs since we need to 1) get a
     // camera id by a package name when resizing the window; 2) get a package name by a camera id
     // when camera connection is closed and we need to clean up our records.
@@ -91,13 +88,13 @@
                 @Override
                 public void onCameraOpened(@NonNull String cameraId, @NonNull String packageId) {
                     synchronized (mWmService.mGlobalLock) {
-                        notifyCameraOpened(cameraId, packageId);
+                        notifyCameraOpenedWithDelay(cameraId, packageId);
                     }
                 }
                 @Override
                 public void onCameraClosed(@NonNull String cameraId) {
                     synchronized (mWmService.mGlobalLock) {
-                        notifyCameraClosed(cameraId);
+                        notifyCameraClosedWithDelay(cameraId);
                     }
                 }
             };
@@ -131,8 +128,8 @@
         mCameraStateListeners.remove(listener);
     }
 
-    private void notifyCameraOpened(
-            @NonNull String cameraId, @NonNull String packageName) {
+    private void notifyCameraOpenedWithDelay(@NonNull String cameraId,
+            @NonNull String packageName) {
         // If an activity is restarting or camera is flipping, the camera connection can be
         // quickly closed and reopened.
         mScheduledToBeRemovedCameraIdSet.remove(cameraId);
@@ -142,25 +139,30 @@
         // Some apps can’t handle configuration changes coming at the same time with Camera setup so
         // delaying orientation update to accommodate for that.
         mScheduledCompatModeUpdateCameraIdSet.add(cameraId);
-        mHandler.postDelayed(
-                () -> {
-                    synchronized (mWmService.mGlobalLock) {
-                        if (!mScheduledCompatModeUpdateCameraIdSet.remove(cameraId)) {
-                            // Camera compat mode update has happened already or was cancelled
-                            // because camera was closed.
-                            return;
-                        }
-                        mCameraIdPackageBiMapping.put(packageName, cameraId);
-                        mCameraActivity = findCameraActivity(packageName);
-                        if (mCameraActivity == null || mCameraActivity.getTask() == null) {
-                            return;
-                        }
-                        notifyListenersCameraOpened(mCameraActivity, cameraId);
-                    }
-                },
+        mHandler.postDelayed(() -> notifyCameraOpenedInternal(cameraId, packageName),
                 CAMERA_OPENED_LETTERBOX_UPDATE_DELAY_MS);
     }
 
+    private void notifyCameraOpenedInternal(@NonNull String cameraId, @NonNull String packageName) {
+        synchronized (mWmService.mGlobalLock) {
+            if (!mScheduledCompatModeUpdateCameraIdSet.remove(cameraId)) {
+                // Camera compat mode update has happened already or was cancelled
+                // because camera was closed.
+                return;
+            }
+            mCameraIdPackageBiMapping.put(packageName, cameraId);
+            // If there are multiple activities of the same package name and none of
+            // them are the top running activity, we do not apply treatment (rather than
+            // guessing and applying it to the wrong activity).
+            final ActivityRecord cameraActivity =
+                    findUniqueActivityWithPackageName(packageName);
+            if (cameraActivity == null || cameraActivity.getTask() == null) {
+                return;
+            }
+            notifyListenersCameraOpened(cameraActivity, cameraId);
+        }
+    }
+
     private void notifyListenersCameraOpened(@NonNull ActivityRecord cameraActivity,
             @NonNull String cameraId) {
         for (int i = 0; i < mCameraStateListeners.size(); i++) {
@@ -174,7 +176,13 @@
         }
     }
 
-    private void notifyCameraClosed(@NonNull String cameraId) {
+    /**
+     * Processes camera closed, and schedules notifying listeners.
+     *
+     * <p>The delay is introduced to avoid flickering when switching between front and back camera,
+     * and when an activity is refreshed due to camera compat treatment.
+     */
+    private void notifyCameraClosedWithDelay(@NonNull String cameraId) {
         ProtoLog.v(WM_DEBUG_STATES,
                 "Display id=%d is notified that Camera %s is closed.",
                 mDisplayContent.mDisplayId, cameraId);
@@ -217,9 +225,10 @@
                 // Already reconnected to this camera, no need to clean up.
                 return;
             }
-            if (mCameraActivity != null && mCurrentListenerForCameraActivity != null) {
+
+            if (mCurrentListenerForCameraActivity != null) {
                 boolean closeSuccessful =
-                        mCurrentListenerForCameraActivity.onCameraClosed(mCameraActivity, cameraId);
+                        mCurrentListenerForCameraActivity.onCameraClosed(cameraId);
                 if (closeSuccessful) {
                     mCameraIdPackageBiMapping.removeCameraId(cameraId);
                     mCurrentListenerForCameraActivity = null;
@@ -231,8 +240,14 @@
     }
 
     // TODO(b/335165310): verify that this works in multi instance and permission dialogs.
+    /**
+     * Finds a visible activity with the given package name.
+     *
+     * <p>If there are multiple visible activities with a given package name, and none of them are
+     * the `topRunningActivity`, returns null.
+     */
     @Nullable
-    private ActivityRecord findCameraActivity(@NonNull String packageName) {
+    private ActivityRecord findUniqueActivityWithPackageName(@NonNull String packageName) {
         final ActivityRecord topActivity = mDisplayContent.topRunningActivity(
                 /* considerKeyguardState= */ true);
         if (topActivity != null && topActivity.packageName.equals(packageName)) {
@@ -277,11 +292,11 @@
         // TODO(b/336474959): try to decouple `cameraId` from the listeners.
         boolean onCameraOpened(@NonNull ActivityRecord cameraActivity, @NonNull String cameraId);
         /**
-         * Notifies the compat listener that an activity has closed the camera.
+         * Notifies the compat listener that camera is closed.
          *
          * @return true if cleanup has been successful - the notifier might try again if false.
          */
         // TODO(b/336474959): try to decouple `cameraId` from the listeners.
-        boolean onCameraClosed(@NonNull ActivityRecord cameraActivity, @NonNull String cameraId);
+        boolean onCameraClosed(@NonNull String cameraId);
     }
 }
diff --git a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
index 9998e1a..1a0124a 100644
--- a/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayRotationCompatPolicy.java
@@ -342,12 +342,19 @@
     }
 
     @Override
-    public boolean onCameraClosed(@NonNull ActivityRecord cameraActivity,
-            @NonNull String cameraId) {
+    public boolean onCameraClosed(@NonNull String cameraId) {
+        // Top activity in the same task as the camera activity, or `null` if the task is
+        // closed.
+        final ActivityRecord topActivity = mDisplayContent.topRunningActivity(
+                /* considerKeyguardState= */ true);
+        if (topActivity == null) {
+            return true;
+        }
+
         synchronized (this) {
             // TODO(b/336474959): Once refresh is implemented in `CameraCompatFreeformPolicy`,
             // consider checking this in CameraStateMonitor before notifying the listeners (this).
-            if (isActivityForCameraIdRefreshing(cameraId)) {
+            if (isActivityForCameraIdRefreshing(topActivity, cameraId)) {
                 ProtoLog.v(WM_DEBUG_ORIENTATION,
                         "Display id=%d is notified that camera is closed but activity is"
                                 + " still refreshing. Rescheduling an update.",
@@ -355,15 +362,15 @@
                 return false;
             }
         }
+
         ProtoLog.v(WM_DEBUG_ORIENTATION,
                 "Display id=%d is notified that Camera is closed, updating rotation.",
                 mDisplayContent.mDisplayId);
-        final ActivityRecord topActivity = mDisplayContent.topRunningActivity(
-                /* considerKeyguardState= */ true);
-        if (topActivity == null
-                // Checking whether an activity in fullscreen rather than the task as this
-                // camera compat treatment doesn't cover activity embedding.
-                || topActivity.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) {
+        // Checking whether an activity in fullscreen rather than the task as this camera compat
+        // treatment doesn't cover activity embedding.
+        // TODO(b/350495350): Consider checking whether this activity is the camera activity, or
+        // whether the top activity has the same task as the one which opened camera.
+        if (topActivity.getWindowingMode() != WINDOWING_MODE_FULLSCREEN) {
             return true;
         }
         recomputeConfigurationForCameraCompatIfNeeded(topActivity);
@@ -372,14 +379,13 @@
     }
 
     // TODO(b/336474959): Do we need cameraId here?
-    private boolean isActivityForCameraIdRefreshing(@NonNull String cameraId) {
-        final ActivityRecord topActivity = mDisplayContent.topRunningActivity(
-                /* considerKeyguardState= */ true);
-        if (!isTreatmentEnabledForActivity(topActivity)
-                || !mCameraStateMonitor.isCameraWithIdRunningForActivity(topActivity, cameraId)) {
+    private boolean isActivityForCameraIdRefreshing(@NonNull ActivityRecord activity,
+            @NonNull String cameraId) {
+        if (!isTreatmentEnabledForActivity(activity)
+                || !mCameraStateMonitor.isCameraWithIdRunningForActivity(activity, cameraId)) {
             return false;
         }
-        return mActivityRefresher.isActivityRefreshing(topActivity);
+        return mActivityRefresher.isActivityRefreshing(activity);
     }
 
     private void recomputeConfigurationForCameraCompatIfNeeded(
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index e122fe0..032d6b5 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1131,9 +1131,9 @@
         }
 
         @Override
-        public void onUserUnlocked(@NonNull TargetUser user) {
-            if (user.isPreCreated()) return;
-            mService.handleOnUserUnlocked(user.getUserIdentifier());
+        public void onUserSwitching(@NonNull TargetUser from, @NonNull TargetUser to) {
+            if (to.isPreCreated()) return;
+            mService.handleOnUserSwitching(from.getUserIdentifier(), to.getUserIdentifier());
         }
     }
 
@@ -3831,8 +3831,8 @@
         mDevicePolicyEngine.handleUnlockUser(userId);
     }
 
-    void handleOnUserUnlocked(int userId) {
-        showNewUserDisclaimerIfNecessary(userId);
+    void handleOnUserSwitching(int fromUserId, int toUserId) {
+        showNewUserDisclaimerIfNecessary(toUserId);
     }
 
     void handleStopUser(int userId) {
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
index 8f630af..ce68b86 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/inputmethodservice/InputMethodServiceTest.java
@@ -21,6 +21,7 @@
 import static com.android.compatibility.common.util.SystemUtil.eventually;
 
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -33,18 +34,20 @@
 import android.graphics.Insets;
 import android.os.RemoteException;
 import android.provider.Settings;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.Until;
 import android.util.Log;
 import android.view.WindowManagerGlobal;
+import android.view.WindowManagerPolicyConstants;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 
+import androidx.annotation.NonNull;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.MediumTest;
 import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.uiautomator.By;
+import androidx.test.uiautomator.UiDevice;
+import androidx.test.uiautomator.UiObject2;
+import androidx.test.uiautomator.Until;
 
 import com.android.apps.inputmethod.simpleime.ims.InputMethodServiceWrapper;
 import com.android.apps.inputmethod.simpleime.testing.TestActivity;
@@ -66,6 +69,10 @@
     private static final String TAG = "SimpleIMSTest";
     private static final String INPUT_METHOD_SERVICE_NAME = ".SimpleInputMethodService";
     private static final String EDIT_TEXT_DESC = "Input box";
+    private static final String INPUT_METHOD_NAV_BACK_ID =
+            "android:id/input_method_nav_back";
+    private static final String INPUT_METHOD_NAV_IME_SWITCHER_ID =
+            "android:id/input_method_nav_ime_switcher";
     private static final long TIMEOUT_IN_SECONDS = 3;
     private static final String ENABLE_SHOW_IME_WITH_HARD_KEYBOARD_CMD =
             "settings put secure " + Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD + " 1";
@@ -697,6 +704,151 @@
         assertThat(mInputMethodService.isImeNavigationBarShownForTesting()).isFalse();
     }
 
+    /**
+     * Verifies that clicking on the IME navigation bar back button hides the IME.
+     */
+    @Test
+    public void testBackButtonClick() throws Exception {
+        boolean hasNavigationBar = WindowManagerGlobal.getWindowManagerService()
+                .hasNavigationBar(mInputMethodService.getDisplayId());
+        assumeTrue("Must have a navigation bar", hasNavigationBar);
+        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());
+
+        setShowImeWithHardKeyboard(true /* enabled */);
+
+        verifyInputViewStatusOnMainSync(
+                () -> {
+                    // Ensure the IME navigation bar and the IME switch button are drawn.
+                    mInputMethodService.getInputMethodInternal().onNavButtonFlagsChanged(
+                            InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR
+                                    | InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN
+                    );
+                    assertThat(mActivity.showImeWithWindowInsetsController()).isTrue();
+                },
+                true /* expected */,
+                true /* inputViewStarted */);
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        final var backButtonUiObject = getUiObjectById(INPUT_METHOD_NAV_BACK_ID);
+        backButtonUiObject.click();
+        mInstrumentation.waitForIdleSync();
+
+        assertThat(mInputMethodService.isInputViewShown()).isFalse();
+    }
+
+    /**
+     * Verifies that long clicking on the IME navigation bar back button hides the IME.
+     */
+    @Test
+    public void testBackButtonLongClick() throws Exception {
+        boolean hasNavigationBar = WindowManagerGlobal.getWindowManagerService()
+                .hasNavigationBar(mInputMethodService.getDisplayId());
+        assumeTrue("Must have a navigation bar", hasNavigationBar);
+        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());
+
+        setShowImeWithHardKeyboard(true /* enabled */);
+
+        verifyInputViewStatusOnMainSync(
+                () -> {
+                    // Ensure the IME navigation bar and the IME switch button are drawn.
+                    mInputMethodService.getInputMethodInternal().onNavButtonFlagsChanged(
+                            InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR
+                                    | InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN
+                    );
+                    assertThat(mActivity.showImeWithWindowInsetsController()).isTrue();
+                },
+                true /* expected */,
+                true /* inputViewStarted */);
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        final var backButtonUiObject = getUiObjectById(INPUT_METHOD_NAV_BACK_ID);
+        backButtonUiObject.longClick();
+        mInstrumentation.waitForIdleSync();
+
+        assertThat(mInputMethodService.isInputViewShown()).isFalse();
+    }
+
+    /**
+     * Verifies that clicking on the IME switch button shows the Input Method Switcher Menu.
+     */
+    @Test
+    public void testImeSwitchButtonClick() throws Exception {
+        boolean hasNavigationBar = WindowManagerGlobal.getWindowManagerService()
+                .hasNavigationBar(mInputMethodService.getDisplayId());
+        assumeTrue("Must have a navigation bar", hasNavigationBar);
+        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());
+
+        setShowImeWithHardKeyboard(true /* enabled */);
+
+        verifyInputViewStatusOnMainSync(
+                () -> {
+                    // Ensure the IME navigation bar and the IME switch button are drawn.
+                    mInputMethodService.getInputMethodInternal().onNavButtonFlagsChanged(
+                            InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR
+                                    | InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN
+                    );
+                    assertThat(mActivity.showImeWithWindowInsetsController()).isTrue();
+                },
+                true /* expected */,
+                true /* inputViewStarted */);
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        final var imm = mContext.getSystemService(InputMethodManager.class);
+
+        final var imeSwitchButtonUiObject = getUiObjectById(INPUT_METHOD_NAV_IME_SWITCHER_ID);
+        imeSwitchButtonUiObject.click();
+        mInstrumentation.waitForIdleSync();
+
+        assertWithMessage("Input Method Switcher Menu is shown")
+                .that(isInputMethodPickerShown(imm))
+                .isTrue();
+
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        // Hide the Picker menu before finishing.
+        mUiDevice.pressBack();
+    }
+
+    /**
+     * Verifies that long clicking on the IME switch button shows the Input Method Switcher Menu.
+     */
+    @Test
+    public void testImeSwitchButtonLongClick() throws Exception {
+        boolean hasNavigationBar = WindowManagerGlobal.getWindowManagerService()
+                .hasNavigationBar(mInputMethodService.getDisplayId());
+        assumeTrue("Must have a navigation bar", hasNavigationBar);
+        assumeTrue("Must be in gesture navigation mode", isGestureNavEnabled());
+
+        setShowImeWithHardKeyboard(true /* enabled */);
+
+        verifyInputViewStatusOnMainSync(
+                () -> {
+                    // Ensure the IME navigation bar and the IME switch button are drawn.
+                    mInputMethodService.getInputMethodInternal().onNavButtonFlagsChanged(
+                            InputMethodNavButtonFlags.IME_DRAWS_IME_NAV_BAR
+                                    | InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN
+                    );
+                    assertThat(mActivity.showImeWithWindowInsetsController()).isTrue();
+                },
+                true /* expected */,
+                true /* inputViewStarted */);
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        final var imm = mContext.getSystemService(InputMethodManager.class);
+
+        final var imeSwitchButtonUiObject = getUiObjectById(INPUT_METHOD_NAV_IME_SWITCHER_ID);
+        imeSwitchButtonUiObject.longClick();
+        mInstrumentation.waitForIdleSync();
+
+        assertWithMessage("Input Method Switcher Menu is shown")
+                .that(isInputMethodPickerShown(imm))
+                .isTrue();
+        assertThat(mInputMethodService.isInputViewShown()).isTrue();
+
+        // Hide the Picker menu before finishing.
+        mUiDevice.pressBack();
+    }
+
     private void verifyInputViewStatus(
             Runnable runnable, boolean expected, boolean inputViewStarted)
             throws InterruptedException {
@@ -844,6 +996,32 @@
         return SystemUtil.runShellCommandOrThrow(cmd);
     }
 
+    /**
+     * Checks if the Input Method Switcher Menu is shown. This runs by adopting the Shell's
+     * permission to ensure we have TEST_INPUT_METHOD permission.
+     */
+    private static boolean isInputMethodPickerShown(@NonNull InputMethodManager imm) {
+        return SystemUtil.runWithShellPermissionIdentity(imm::isInputMethodPickerShown);
+    }
+
+    @NonNull
+    private UiObject2 getUiObjectById(@NonNull String id) {
+        final var uiObject = mUiDevice.wait(
+                Until.findObject(By.res(id)),
+                TimeUnit.SECONDS.toMillis(TIMEOUT_IN_SECONDS));
+        assertThat(uiObject).isNotNull();
+        return uiObject;
+    }
+
+    /**
+     * Returns {@code true} if the navigation mode is gesture nav, and {@code false} otherwise.
+     */
+    private boolean isGestureNavEnabled() {
+        return mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_navBarInteractionMode)
+                == WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
+    }
+
     private void clickOnEditorText() {
         // Find the editText and click it.
         UiObject2 editTextUiObject =
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodSubtypeSwitchingControllerTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
index e81cf9d..dc03732 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodSubtypeSwitchingControllerTest.java
@@ -16,15 +16,26 @@
 
 package com.android.server.inputmethod;
 
+import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.MODE_AUTO;
+import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.MODE_RECENT;
+import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.MODE_STATIC;
+import static com.android.server.inputmethod.InputMethodSubtypeSwitchingController.SwitchMode;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import android.content.ComponentName;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.view.inputmethod.Flags;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodSubtype;
 import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
@@ -35,6 +46,7 @@
 import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ControllerImpl;
 import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
 
+import org.junit.Rule;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -51,6 +63,9 @@
     private static final String SYSTEM_LOCALE = "en_US";
     private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
 
+    @Rule
+    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
     @NonNull
     private static InputMethodSubtype createTestSubtype(@NonNull String locale) {
         return new InputMethodSubtypeBuilder()
@@ -170,7 +185,7 @@
             subtype = createTestSubtype(currentItem.mSubtypeName.toString());
         }
         final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme,
-                currentItem.mImi, subtype);
+                currentItem.mImi, subtype, MODE_STATIC, true /* forward */);
         assertEquals(nextItem, nextIme);
     }
 
@@ -185,15 +200,16 @@
         }
     }
 
-    private void onUserAction(@NonNull ControllerImpl controller,
+    private boolean onUserAction(@NonNull ControllerImpl controller,
             @NonNull ImeSubtypeListItem subtypeListItem) {
         InputMethodSubtype subtype = null;
         if (subtypeListItem.mSubtypeName != null) {
             subtype = createTestSubtype(subtypeListItem.mSubtypeName.toString());
         }
-        controller.onUserActionLocked(subtypeListItem.mImi, subtype);
+        return controller.onUserActionLocked(subtypeListItem.mImi, subtype);
     }
 
+    @RequiresFlagsDisabled(Flags.FLAG_IME_SWITCHER_REVAMP)
     @Test
     public void testControllerImpl() {
         final List<ImeSubtypeListItem> disabledItems = createDisabledImeSubtypes();
@@ -213,7 +229,7 @@
         final ImeSubtypeListItem switchUnawareJapaneseIme_ja_jp = enabledItems.get(7);
 
         final ControllerImpl controller = ControllerImpl.createFrom(
-                null /* currentInstance */, enabledItems);
+                null /* currentInstance */, enabledItems, new ArrayList<>());
 
         // switching-aware loop
         assertRotationOrder(controller, false /* onlyCurrentIme */,
@@ -257,6 +273,7 @@
                 disabledSubtypeUnawareIme, null);
     }
 
+    @RequiresFlagsDisabled(Flags.FLAG_IME_SWITCHER_REVAMP)
     @Test
     public void testControllerImplWithUserAction() {
         final List<ImeSubtypeListItem> enabledItems = createEnabledImeSubtypes();
@@ -270,7 +287,7 @@
         final ImeSubtypeListItem switchUnawareJapaneseIme_ja_jp = enabledItems.get(7);
 
         final ControllerImpl controller = ControllerImpl.createFrom(
-                null /* currentInstance */, enabledItems);
+                null /* currentInstance */, enabledItems, new ArrayList<>());
 
         // === switching-aware loop ===
         assertRotationOrder(controller, false /* onlyCurrentIme */,
@@ -320,7 +337,7 @@
         // Rotation order should be preserved when created with the same subtype list.
         final List<ImeSubtypeListItem> sameEnabledItems = createEnabledImeSubtypes();
         final ControllerImpl newController = ControllerImpl.createFrom(controller,
-                sameEnabledItems);
+                sameEnabledItems, new ArrayList<>());
         assertRotationOrder(newController, false /* onlyCurrentIme */,
                 subtypeAwareIme, latinIme_fr, latinIme_en_us, japaneseIme_ja_jp);
         assertRotationOrder(newController, false /* onlyCurrentIme */,
@@ -332,7 +349,7 @@
                 latinIme_en_us, latinIme_fr, subtypeAwareIme, switchingUnawareLatinIme_en_uk,
                 switchUnawareJapaneseIme_ja_jp, subtypeUnawareIme);
         final ControllerImpl anotherController = ControllerImpl.createFrom(controller,
-                differentEnabledItems);
+                differentEnabledItems, new ArrayList<>());
         assertRotationOrder(anotherController, false /* onlyCurrentIme */,
                 latinIme_en_us, latinIme_fr, subtypeAwareIme);
         assertRotationOrder(anotherController, false /* onlyCurrentIme */,
@@ -370,6 +387,7 @@
         assertFalse(item_en_us_allcaps.mIsSystemLanguage);
     }
 
+    @RequiresFlagsDisabled(Flags.FLAG_IME_SWITCHER_REVAMP)
     @SuppressWarnings("SelfComparison")
     @Test
     public void testImeSubtypeListComparator() {
@@ -471,4 +489,739 @@
             assertNotEquals(ime2, ime1);
         }
     }
+
+    /** Verifies the static mode. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testModeStatic() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(items, "SimpleIme", "SimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var english = items.get(0);
+        final var french = items.get(1);
+        final var italian = items.get(2);
+        final var simple = items.get(3);
+        final var latinIme = List.of(english, french, italian);
+        final var simpleIme = List.of(simple);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareLatinIme", "HardwareLatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(hardwareItems, "HardwareSimpleIme", "HardwareSimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareEnglish = hardwareItems.get(0);
+        final var hardwareFrench = hardwareItems.get(1);
+        final var hardwareItalian = hardwareItems.get(2);
+        final var hardwareSimple = hardwareItems.get(3);
+        final var hardwareLatinIme = List.of(hardwareEnglish, hardwareFrench, hardwareItalian);
+        final var hardwareSimpleIme = List.of(hardwareSimple);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        final int mode = MODE_STATIC;
+
+        // Static mode matches the given items order.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // Set french IME as most recent.
+        assertTrue("Recency updated for french IME", onUserAction(controller, french));
+
+        // Static mode is not influenced by recency updates on non-hardware item.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertTrue("Recency updated for french hardware IME",
+                onUserAction(controller, hardwareFrench));
+
+        // Static mode is not influenced by recency updates on hardware item.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+    }
+
+    /** Verifies the recency mode. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testModeRecent() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(items, "SimpleIme", "SimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var english = items.get(0);
+        final var french = items.get(1);
+        final var italian = items.get(2);
+        final var simple = items.get(3);
+        final var latinIme = List.of(english, french, italian);
+        final var simpleIme = List.of(simple);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareLatinIme", "HardwareLatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(hardwareItems, "HardwareSimpleIme", "HardwareSimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareEnglish = hardwareItems.get(0);
+        final var hardwareFrench = hardwareItems.get(1);
+        final var hardwareItalian = hardwareItems.get(2);
+        final var hardwareSimple = hardwareItems.get(3);
+        final var hardwareLatinIme = List.of(hardwareEnglish, hardwareFrench, hardwareItalian);
+        final var hardwareSimpleIme = List.of(hardwareSimple);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        final int mode = MODE_RECENT;
+
+        // Recency order is initialized to static order.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertTrue("Recency updated for french IME", onUserAction(controller, french));
+        final var recencyItems = List.of(french, english, italian, simple);
+        final var recencyLatinIme = List.of(french, english, italian);
+        final var recencySimpleIme = List.of(simple);
+
+        // The order of non-hardware items is updated.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        // The order of hardware items remains unchanged for an action on a non-hardware item.
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertFalse("Recency not updated again for same IME", onUserAction(controller, french));
+
+        // The order of non-hardware items remains unchanged.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        // The order of hardware items remains unchanged.
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertTrue("Recency updated for french hardware IME",
+                onUserAction(controller, hardwareFrench));
+
+        final var recencyHardwareItems =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian, hardwareSimple);
+        final var recencyHardwareLatinIme =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian);
+        final var recencyHardwareSimpleIme = List.of(hardwareSimple);
+
+        // The order of non-hardware items is unchanged.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        // The order of hardware items is updated.
+        assertNextOrder(controller, true /* forHardware */, mode,
+                recencyHardwareItems, List.of(recencyHardwareLatinIme, recencyHardwareSimpleIme));
+    }
+
+    /** Verifies the auto mode. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testModeAuto() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(items, "SimpleIme", "SimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var english = items.get(0);
+        final var french = items.get(1);
+        final var italian = items.get(2);
+        final var simple = items.get(3);
+        final var latinIme = List.of(english, french, italian);
+        final var simpleIme = List.of(simple);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareLatinIme", "HardwareLatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(hardwareItems, "HardwareSimpleIme", "HardwareSimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareEnglish = hardwareItems.get(0);
+        final var hardwareFrench = hardwareItems.get(1);
+        final var hardwareItalian = hardwareItems.get(2);
+        final var hardwareSimple = hardwareItems.get(3);
+        final var hardwareLatinIme = List.of(hardwareEnglish, hardwareFrench, hardwareItalian);
+        final var hardwareSimpleIme = List.of(hardwareSimple);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        final int mode = MODE_AUTO;
+
+        // Auto mode resolves to static order initially.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // User action on french IME.
+        assertTrue("Recency updated for french IME", onUserAction(controller, french));
+
+        final var recencyItems = List.of(french, english, italian, simple);
+        final var recencyLatinIme = List.of(french, english, italian);
+        final var recencySimpleIme = List.of(simple);
+
+        // Auto mode resolves to recency order for the first forward after user action, and to
+        // static order for the backwards direction.
+        assertNextOrder(controller, false /* forHardware */, mode, true /* forward */,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+        assertNextOrder(controller, false /* forHardware */, mode, false /* forward */,
+                items.reversed(), List.of(latinIme.reversed(), simpleIme.reversed()));
+
+        // Auto mode resolves to recency order for the first forward after user action,
+        // but the recency was not updated for hardware items, so it's equivalent to static order.
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // Change IME, reset user action having happened.
+        controller.onInputMethodSubtypeChanged();
+
+        // Auto mode resolves to static order as there was no user action since changing IMEs.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // User action on french IME again.
+        assertFalse("Recency not updated again for same IME", onUserAction(controller, french));
+
+        // Auto mode still resolves to static order, as a user action on the currently most
+        // recent IME has no effect.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // User action on hardware french IME.
+        assertTrue("Recency updated for french hardware IME",
+                onUserAction(controller, hardwareFrench));
+
+        final var recencyHardware =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian, hardwareSimple);
+        final var recencyHardwareLatin =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian);
+        final var recencyHardwareSimple = List.of(hardwareSimple);
+
+        // Auto mode resolves to recency order for the first forward direction after a user action
+        // on a hardware IME, and to static order for the backwards direction.
+        assertNextOrder(controller, false /* forHardware */, mode, true /* forward */,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+        assertNextOrder(controller, false /* forHardware */, mode, false /* forward */,
+                items.reversed(), List.of(latinIme.reversed(), simpleIme.reversed()));
+
+        assertNextOrder(controller, true /* forHardware */, mode, true /* forward */,
+                recencyHardware, List.of(recencyHardwareLatin, recencyHardwareSimple));
+
+        assertNextOrder(controller, true /* forHardware */, mode, false /* forward */,
+                hardwareItems.reversed(),
+                List.of(hardwareLatinIme.reversed(), hardwareSimpleIme.reversed()));
+    }
+
+    /**
+     * Verifies that the recency order is preserved only when updating with an equal list of items.
+     */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testUpdateList() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(items, "SimpleIme", "SimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var english = items.get(0);
+        final var french = items.get(1);
+        final var italian = items.get(2);
+        final var simple = items.get(3);
+
+        final var latinIme = List.of(english, french, italian);
+        final var simpleIme = List.of(simple);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareLatinIme", "HardwareLatinIme",
+                List.of("en", "fr", "it"), true /* supportsSwitchingToNextInputMethod */);
+        addTestImeSubtypeListItems(hardwareItems, "HardwareSimpleIme", "HardwareSimpleIme",
+                null, true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareEnglish = hardwareItems.get(0);
+        final var hardwareFrench = hardwareItems.get(1);
+        final var hardwareItalian = hardwareItems.get(2);
+        final var hardwareSimple = hardwareItems.get(3);
+
+        final var hardwareLatinIme = List.of(hardwareEnglish, hardwareFrench, hardwareItalian);
+        final var hardwareSimpleIme = List.of(hardwareSimple);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        final int mode = MODE_RECENT;
+
+        // Recency order is initialized to static order.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                items, List.of(latinIme, simpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        // User action on french IME.
+        assertTrue("Recency updated for french IME", onUserAction(controller, french));
+
+        final var equalItems = new ArrayList<>(items);
+        final var otherItems = new ArrayList<>(items);
+        otherItems.remove(simple);
+
+        final var equalController = ControllerImpl.createFrom(controller, equalItems,
+                hardwareItems);
+        final var otherController = ControllerImpl.createFrom(controller, otherItems,
+                hardwareItems);
+
+        final var recencyItems = List.of(french, english, italian, simple);
+        final var recencyLatinIme = List.of(french, english, italian);
+        final var recencySimpleIme = List.of(simple);
+
+        assertNextOrder(controller, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        // The order of equal non-hardware items is unchanged.
+        assertNextOrder(equalController, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        // The order of other hardware items is reset.
+        assertNextOrder(otherController, false /* forHardware */, mode,
+                latinIme, List.of(latinIme));
+
+        // The order of hardware remains unchanged.
+        assertNextOrder(controller, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertNextOrder(equalController, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertNextOrder(otherController, true /* forHardware */, mode,
+                hardwareItems, List.of(hardwareLatinIme, hardwareSimpleIme));
+
+        assertTrue("Recency updated for french hardware IME",
+                onUserAction(controller, hardwareFrench));
+
+        final var equalHardwareItems = new ArrayList<>(hardwareItems);
+        final var otherHardwareItems = new ArrayList<>(hardwareItems);
+        otherHardwareItems.remove(hardwareSimple);
+
+        final var equalHardwareController = ControllerImpl.createFrom(controller, items,
+                equalHardwareItems);
+        final var otherHardwareController = ControllerImpl.createFrom(controller, items,
+                otherHardwareItems);
+
+        final var recencyHardwareItems =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian, hardwareSimple);
+        final var recencyHardwareLatinIme =
+                List.of(hardwareFrench, hardwareEnglish, hardwareItalian);
+        final var recencyHardwareSimpleIme = List.of(hardwareSimple);
+
+        // The order of non-hardware items remains unchanged.
+        assertNextOrder(controller, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        assertNextOrder(equalHardwareController, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        assertNextOrder(otherHardwareController, false /* forHardware */, mode,
+                recencyItems, List.of(recencyLatinIme, recencySimpleIme));
+
+        assertNextOrder(controller, true /* forHardware */, mode,
+                recencyHardwareItems, List.of(recencyHardwareLatinIme, recencyHardwareSimpleIme));
+
+        // The order of equal hardware items is unchanged.
+        assertNextOrder(equalHardwareController, true /* forHardware */, mode,
+                recencyHardwareItems, List.of(recencyHardwareLatinIme, recencyHardwareSimpleIme));
+
+        // The order of other hardware items is reset.
+        assertNextOrder(otherHardwareController, true /* forHardware */, mode,
+                hardwareLatinIme, List.of(hardwareLatinIme));
+    }
+
+    /** Verifies that switch aware and switch unaware IMEs are combined together. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testSwitchAwareAndUnawareCombined() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "switchAware", "switchAware",
+                null, true /* supportsSwitchingToNextInputMethod*/);
+        addTestImeSubtypeListItems(items, "switchUnaware", "switchUnaware",
+                null, false /* supportsSwitchingToNextInputMethod*/);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "hardwareSwitchAware", "hardwareSwitchAware",
+                null, true /* supportsSwitchingToNextInputMethod*/);
+        addTestImeSubtypeListItems(hardwareItems, "hardwareSwitchUnaware", "hardwareSwitchUnaware",
+                null, false /* supportsSwitchingToNextInputMethod*/);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        for (int mode = MODE_STATIC; mode <= MODE_AUTO; mode++) {
+            assertNextOrder(controller, false /* forHardware */, false /* onlyCurrentIme */,
+                    mode, true /* forward */, items);
+            assertNextOrder(controller, false /* forHardware */, false /* onlyCurrentIme */,
+                    mode, false /* forward */, items.reversed());
+
+            assertNextOrder(controller, true /* forHardware */, false /* onlyCurrentIme */,
+                    mode, true /* forward */, hardwareItems);
+            assertNextOrder(controller, true /* forHardware */, false /* onlyCurrentIme */,
+                    mode, false /* forward */, hardwareItems.reversed());
+        }
+    }
+
+    /** Verifies that an empty controller can't take any actions. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testEmptyList() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareIme", "HardwareIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, List.of(),
+                List.of());
+
+        assertNoAction(controller, false /* forHardware */, items);
+        assertNoAction(controller, true /* forHardware */, hardwareItems);
+    }
+
+    /** Verifies that a controller with a single item can't take any actions. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testSingleItemList() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareIme", "HardwareIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */,
+                List.of(items.get(0)), List.of(hardwareItems.get(0)));
+
+        assertNoAction(controller, false /* forHardware */, items);
+        assertNoAction(controller, true /* forHardware */, hardwareItems);
+    }
+
+    /** Verifies that a controller can't take any actions for unknown items. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testUnknownItems() {
+        final var items = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(items, "LatinIme", "LatinIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+        final var unknownItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(unknownItems, "UnknownIme", "UnknownIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var hardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(hardwareItems, "HardwareIme", "HardwareIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+        final var unknownHardwareItems = new ArrayList<ImeSubtypeListItem>();
+        addTestImeSubtypeListItems(unknownHardwareItems, "HardwareUnknownIme", "HardwareUnknownIme",
+                List.of("en", "fr"), true /* supportsSwitchingToNextInputMethod */);
+
+        final var controller = ControllerImpl.createFrom(null /* currentInstance */, items,
+                hardwareItems);
+
+        assertNoAction(controller, false /* forHardware */, unknownItems);
+        assertNoAction(controller, true /* forHardware */, unknownHardwareItems);
+    }
+
+    /** Verifies that the IME name does influence the comparison order. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareImeName() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var imeX = createTestItem(component, "ImeX", "A", "en_US", 0);
+        final var imeY = createTestItem(component, "ImeY", "A", "en_US", 0);
+
+        assertTrue("Smaller IME name should be smaller.", imeX.compareTo(imeY) < 0);
+        assertTrue("Larger IME name should be larger.", imeY.compareTo(imeX) > 0);
+    }
+
+    /** Verifies that the IME ID does influence the comparison order. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareImeId() {
+        final var component1 = new ComponentName("com.example.ime1", "Ime");
+        final var component2 = new ComponentName("com.example.ime2", "Ime");
+        final var ime1 = createTestItem(component1, "Ime", "A", "en_US", 0);
+        final var ime2 = createTestItem(component2, "Ime", "A", "en_US", 0);
+
+        assertTrue("Smaller IME ID should be smaller.", ime1.compareTo(ime2) < 0);
+        assertTrue("Larger IME ID should be larger.", ime2.compareTo(ime1) > 0);
+    }
+
+    /** Verifies that comparison on self returns an equal order. */
+    @SuppressWarnings("SelfComparison")
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareSelf() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var item = createTestItem(component, "Ime", "A", "en_US", 0);
+
+        assertEquals("Item should have the same order to itself.", 0, item.compareTo(item));
+    }
+
+    /** Verifies that comparison on an equivalent item returns an equal order. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareEquivalent() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var item = createTestItem(component, "Ime", "A", "en_US", 0);
+        final var equivalent = createTestItem(component, "Ime", "A", "en_US", 0);
+
+        assertEquals("Equivalent items should have the same order.", 0, item.compareTo(equivalent));
+    }
+
+    /**
+     * Verifies that the system locale and system language do not the influence comparison order.
+     */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareSystemLocaleSystemLanguage() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var japanese = createTestItem(component, "Ime", "A", "ja_JP", 0);
+        final var systemLanguage = createTestItem(component, "Ime", "A", "en_GB", 0);
+        final var systemLocale = createTestItem(component, "Ime", "A", "en_US", 0);
+
+        assertFalse(japanese.mIsSystemLanguage);
+        assertFalse(japanese.mIsSystemLocale);
+        assertTrue(systemLanguage.mIsSystemLanguage);
+        assertFalse(systemLanguage.mIsSystemLocale);
+        assertTrue(systemLocale.mIsSystemLanguage);
+        assertTrue(systemLocale.mIsSystemLocale);
+
+        assertEquals("System language shouldn't influence comparison over non-system language.",
+                0, japanese.compareTo(systemLanguage));
+        assertEquals("System locale shouldn't influence comparison over non-system locale.",
+                0, japanese.compareTo(systemLocale));
+        assertEquals("System locale shouldn't influence comparison over system language.",
+                0, systemLanguage.compareTo(systemLocale));
+    }
+
+    /** Verifies that the subtype name does not influence the comparison order. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareSubtypeName() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var subtypeA = createTestItem(component, "Ime", "A", "en_US", 0);
+        final var subtypeB = createTestItem(component, "Ime", "B", "en_US", 0);
+
+        assertEquals("Subtype name shouldn't influence comparison.",
+                0, subtypeA.compareTo(subtypeB));
+    }
+
+    /** Verifies that the subtype index does not influence the comparison order. */
+    @RequiresFlagsEnabled(Flags.FLAG_IME_SWITCHER_REVAMP)
+    @Test
+    public void testCompareSubtypeIndex() {
+        final var component = new ComponentName("com.example.ime", "Ime");
+        final var subtype0 = createTestItem(component, "Ime1", "A", "en_US", 0);
+        final var subtype1 = createTestItem(component, "Ime1", "A", "en_US", 1);
+
+        assertEquals("Subtype index shouldn't influence comparison.",
+                0, subtype0.compareTo(subtype1));
+    }
+
+    /**
+     * Verifies that the controller's next item order matches the given one, and cycles back at
+     * the end, both across all IMEs, and also per each IME. If a single item is given, verifies
+     * that no next item is returned.
+     *
+     * @param controller  the controller to use for finding the next items.
+     * @param forHardware whether to find the next hardware item, or software item.
+     * @param mode        the switching mode.
+     * @param forward     whether to search forwards or backwards in the list.
+     * @param allItems    the list of items across all IMEs.
+     * @param perImeItems the list of lists of items per IME.
+     */
+    private static void assertNextOrder(@NonNull ControllerImpl controller, boolean forHardware,
+            @SwitchMode int mode, boolean forward, @NonNull List<ImeSubtypeListItem> allItems,
+            @NonNull List<List<ImeSubtypeListItem>> perImeItems) {
+        assertNextOrder(controller, forHardware, false /* onlyCurrentIme */, mode,
+                forward, allItems);
+
+        for (var imeItems : perImeItems) {
+            assertNextOrder(controller, forHardware, true /* onlyCurrentIme */, mode,
+                    forward, imeItems);
+        }
+    }
+
+    /**
+     * Verifies that the controller's next item order matches the given one, and cycles back at
+     * the end, both across all IMEs, and also per each IME. This checks the forward direction
+     * with the given items, and the backwards order with the items reversed. If a single item is
+     * given, verifies that no next item is returned.
+     *
+     * @param controller  the controller to use for finding the next items.
+     * @param forHardware whether to find the next hardware item, or software item.
+     * @param mode        the switching mode.
+     * @param allItems    the list of items across all IMEs.
+     * @param perImeItems the list of lists of items per IME.
+     */
+    private static void assertNextOrder(@NonNull ControllerImpl controller, boolean forHardware,
+            @SwitchMode int mode, @NonNull List<ImeSubtypeListItem> allItems,
+            @NonNull List<List<ImeSubtypeListItem>> perImeItems) {
+        assertNextOrder(controller, forHardware, false /* onlyCurrentIme */, mode,
+                true /* forward */, allItems);
+        assertNextOrder(controller, forHardware, false /* onlyCurrentIme */, mode,
+                false /* forward */, allItems.reversed());
+
+        for (var imeItems : perImeItems) {
+            assertNextOrder(controller, forHardware, true /* onlyCurrentIme */, mode,
+                    true /* forward */, imeItems);
+            assertNextOrder(controller, forHardware, true /* onlyCurrentIme */, mode,
+                    false /* forward */, imeItems.reversed());
+        }
+    }
+
+    /**
+     * Verifies that the controller's next item order (starting from the first one in {@code items}
+     * matches the given on, and cycles back at the end. If a single item is given, verifies that
+     * no next item is returned.
+     *
+     * @param controller     the controller to use for finding the next items.
+     * @param forHardware    whether to find the next hardware item, or software item.
+     * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+     * @param mode           the switching mode.
+     * @param forward        whether to search forwards or backwards in the list.
+     * @param items          the list of items to verify, in the expected order.
+     */
+    private static void assertNextOrder(@NonNull ControllerImpl controller,
+            boolean forHardware, boolean onlyCurrentIme, @SwitchMode int mode, boolean forward,
+            @NonNull List<ImeSubtypeListItem> items) {
+        final int numItems = items.size();
+        if (numItems == 0) {
+            return;
+        } else if (numItems == 1) {
+            // Single item controllers should never return a next item.
+            assertNextItem(controller, forHardware, onlyCurrentIme, mode, forward, items.get(0),
+                    null /* expectedNext*/);
+            return;
+        }
+
+        var item = items.get(0);
+
+        final var expectedNextItems = new ArrayList<>(items);
+        // Add first item in the last position of expected order, to ensure the order is cyclic.
+        expectedNextItems.add(item);
+
+        final var nextItems = new ArrayList<>();
+        // Add first item in the first position of actual order, to ensure the order is cyclic.
+        nextItems.add(item);
+
+        // Compute the nextItems starting from the first given item, and compare the order.
+        for (int i = 0; i < numItems; i++) {
+            item = getNextItem(controller, forHardware, onlyCurrentIme, mode, forward, item);
+            assertNotNull("Next item shouldn't be null.", item);
+            nextItems.add(item);
+        }
+
+        assertEquals("Rotation order doesn't match.", expectedNextItems, nextItems);
+    }
+
+    /**
+     * Verifies that the controller gets the expected next value from the given item.
+     *
+     * @param controller     the controller to sue for finding the next value.
+     * @param forHardware    whether to find the next hardware item, or software item.
+     * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+     * @param mode           the switching mode.
+     * @param forward        whether to search forwards or backwards in the list.
+     * @param item           the item to find the next value from.
+     * @param expectedNext   the expected next value.
+     */
+    private static void assertNextItem(@NonNull ControllerImpl controller,
+            boolean forHardware, boolean onlyCurrentIme, @SwitchMode int mode, boolean forward,
+            @NonNull ImeSubtypeListItem item, @Nullable ImeSubtypeListItem expectedNext) {
+        final var nextItem = getNextItem(controller, forHardware, onlyCurrentIme, mode, forward,
+                item);
+        assertEquals("Next item doesn't match.", expectedNext, nextItem);
+    }
+
+    /**
+     * Gets the next value from the given item.
+     *
+     * @param controller     the controller to use for finding the next value.
+     * @param forHardware    whether to find the next hardware item, or software item.
+     * @param onlyCurrentIme whether to consider only subtypes of the current input method.
+     * @param mode           the switching mode.
+     * @param forward        whether to search forwards or backwards in the list.
+     * @param item           the item to find the next value from.
+     * @return the next item found, otherwise {@code null}.
+     */
+    @Nullable
+    private static ImeSubtypeListItem getNextItem(@NonNull ControllerImpl controller,
+            boolean forHardware, boolean onlyCurrentIme, @SwitchMode int mode, boolean forward,
+            @NonNull ImeSubtypeListItem item) {
+        final var subtype = item.mSubtypeName != null
+                ? createTestSubtype(item.mSubtypeName.toString()) : null;
+        return forHardware
+                ? controller.getNextInputMethodForHardware(
+                        onlyCurrentIme, item.mImi, subtype, mode, forward)
+                : controller.getNextInputMethod(
+                        onlyCurrentIme, item.mImi, subtype, mode, forward);
+    }
+
+    /**
+     * Verifies that no next items can be found, and the recency cannot be updated for the
+     * given items.
+     *
+     * @param controller  the controller to verify the items on.
+     * @param forHardware whether to try finding the next hardware item, or software item.
+     * @param items       the list of items to verify.
+     */
+    private void assertNoAction(@NonNull ControllerImpl controller, boolean forHardware,
+            @NonNull List<ImeSubtypeListItem> items) {
+        for (var item : items) {
+            for (int mode = MODE_STATIC; mode <= MODE_AUTO; mode++) {
+                assertNextItem(controller, forHardware, false /* onlyCurrentIme */, mode,
+                        false /* forward */, item, null /* expectedNext */);
+                assertNextItem(controller, forHardware, false /* onlyCurrentIme */, mode,
+                        true /* forward */, item, null /* expectedNext */);
+                assertNextItem(controller, forHardware, true /* onlyCurrentIme */, mode,
+                        false /* forward */, item, null /* expectedNext */);
+                assertNextItem(controller, forHardware, true /* onlyCurrentIme */, mode,
+                        true /* forward */, item, null /* expectedNext */);
+            }
+
+            assertFalse("User action shouldn't have updated the recency.",
+                    onUserAction(controller, item));
+        }
+    }
 }
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java
index 81fb1a0..d59f28b 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/UserDataRepositoryTest.java
@@ -98,8 +98,8 @@
         assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID);
     }
 
-    private List<UserDataRepository.UserData> collectUserData(UserDataRepository repository) {
-        final var collected = new ArrayList<UserDataRepository.UserData>();
+    private List<UserData> collectUserData(UserDataRepository repository) {
+        final var collected = new ArrayList<UserData>();
         repository.forAllUserData(userData -> collected.add(userData));
         return collected;
     }
diff --git a/services/tests/servicestests/Android.bp b/services/tests/servicestests/Android.bp
index 753db12..b9e99dd 100644
--- a/services/tests/servicestests/Android.bp
+++ b/services/tests/servicestests/Android.bp
@@ -36,6 +36,8 @@
         "-Werror",
     ],
     static_libs: [
+        "a11ychecker-protos-java-proto-lite",
+        "aatf",
         "cts-input-lib",
         "frameworks-base-testutils",
         "services.accessibility",
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtilsTest.java b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtilsTest.java
new file mode 100644
index 0000000..90d4275
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityCheckerUtilsTest.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2024 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.server.accessibility.a11ychecker;
+
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_A11Y_SERVICE_CLASS_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_A11Y_SERVICE_SOURCE_VERSION_CODE;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_ACTIVITY_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_APP_PACKAGE_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_APP_VERSION_CODE;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_WINDOW_TITLE;
+import static com.android.server.accessibility.a11ychecker.TestUtils.getMockPackageManagerWithInstalledApps;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.pm.PackageManager;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckPreset;
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult;
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheck;
+import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheckResult;
+import com.google.android.apps.common.testing.accessibility.framework.checks.ClassNameCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.ClickableSpanCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.SpeakableTextPresentCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck;
+import com.google.common.collect.ImmutableSet;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@RunWith(AndroidJUnit4.class)
+public class AccessibilityCheckerUtilsTest {
+
+    PackageManager mMockPackageManager;
+
+    @Before
+    public void setUp() throws PackageManager.NameNotFoundException {
+        mMockPackageManager = getMockPackageManagerWithInstalledApps();
+    }
+
+    @Test
+    public void processResults_happyPath_setsAllFields() {
+        AccessibilityNodeInfo mockNodeInfo =
+                new MockAccessibilityNodeInfoBuilder()
+                        .setViewIdResourceName("TargetNode")
+                        .build();
+        AccessibilityHierarchyCheckResult result1 =
+                new AccessibilityHierarchyCheckResult(
+                        SpeakableTextPresentCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.WARNING, null, 1,
+                        null);
+        AccessibilityHierarchyCheckResult result2 =
+                new AccessibilityHierarchyCheckResult(
+                        TouchTargetSizeCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.ERROR, null, 2, null);
+        AccessibilityHierarchyCheckResult result3 =
+                new AccessibilityHierarchyCheckResult(
+                        ClassNameCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.INFO, null, 5, null);
+        AccessibilityHierarchyCheckResult result4 =
+                new AccessibilityHierarchyCheckResult(
+                        ClickableSpanCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.NOT_RUN, null, 5,
+                        null);
+
+        Set<A11yCheckerProto.AccessibilityCheckResultReported> atoms =
+                AccessibilityCheckerUtils.processResults(
+                        mockNodeInfo,
+                        List.of(result1, result2, result3, result4),
+                        null,
+                        mMockPackageManager,
+                        new ComponentName(TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME,
+                                TEST_A11Y_SERVICE_CLASS_NAME));
+
+        assertThat(atoms).containsExactly(
+                createAtom(A11yCheckerProto.AccessibilityCheckClass.SPEAKABLE_TEXT_PRESENT_CHECK,
+                        A11yCheckerProto.AccessibilityCheckResultType.WARNING, 1),
+                createAtom(A11yCheckerProto.AccessibilityCheckClass.TOUCH_TARGET_SIZE_CHECK,
+                        A11yCheckerProto.AccessibilityCheckResultType.ERROR, 2)
+        );
+    }
+
+    @Test
+    public void processResults_packageNameNotFound_returnsEmptySet()
+            throws PackageManager.NameNotFoundException {
+        when(mMockPackageManager.getPackageInfo("com.uninstalled.app", 0))
+                .thenThrow(PackageManager.NameNotFoundException.class);
+        AccessibilityNodeInfo mockNodeInfo =
+                new MockAccessibilityNodeInfoBuilder()
+                        .setPackageName("com.uninstalled.app")
+                        .setViewIdResourceName("TargetNode")
+                        .build();
+        AccessibilityHierarchyCheckResult result1 =
+                new AccessibilityHierarchyCheckResult(
+                        TouchTargetSizeCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.WARNING, null, 1,
+                        null);
+        AccessibilityHierarchyCheckResult result2 =
+                new AccessibilityHierarchyCheckResult(
+                        TouchTargetSizeCheck.class,
+                        AccessibilityCheckResult.AccessibilityCheckResultType.ERROR, null, 2, null);
+
+        Set<A11yCheckerProto.AccessibilityCheckResultReported> atoms =
+                AccessibilityCheckerUtils.processResults(
+                        mockNodeInfo,
+                        List.of(result1, result2),
+                        null,
+                        mMockPackageManager,
+                        new ComponentName(TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME,
+                                TEST_A11Y_SERVICE_CLASS_NAME));
+
+        assertThat(atoms).isEmpty();
+    }
+
+    @Test
+    public void getActivityName_hasWindowStateChangedEvent_returnsActivityName() {
+        AccessibilityEvent accessibilityEvent =
+                AccessibilityEvent.obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+        accessibilityEvent.setPackageName(TEST_APP_PACKAGE_NAME);
+        accessibilityEvent.setClassName(TEST_ACTIVITY_NAME);
+
+        assertThat(AccessibilityCheckerUtils.getActivityName(mMockPackageManager,
+                accessibilityEvent)).isEqualTo("MainActivity");
+    }
+
+    // Makes sure the AccessibilityHierarchyCheck class to enum mapping is up to date with the
+    // latest prod preset.
+    @Test
+    public void checkClassToEnumMap_hasAllLatestPreset() {
+        ImmutableSet<AccessibilityHierarchyCheck> checkPreset =
+                AccessibilityCheckPreset.getAccessibilityHierarchyChecksForPreset(
+                        AccessibilityCheckPreset.LATEST);
+        Set<Class<? extends AccessibilityHierarchyCheck>> latestCheckClasses =
+                checkPreset.stream().map(AccessibilityHierarchyCheck::getClass).collect(
+                        Collectors.toUnmodifiableSet());
+
+        assertThat(AccessibilityCheckerUtils.CHECK_CLASS_TO_ENUM_MAP.keySet())
+                .containsExactlyElementsIn(latestCheckClasses);
+    }
+
+
+    private static A11yCheckerProto.AccessibilityCheckResultReported createAtom(
+            A11yCheckerProto.AccessibilityCheckClass checkClass,
+            A11yCheckerProto.AccessibilityCheckResultType resultType,
+            int resultId) {
+        return A11yCheckerProto.AccessibilityCheckResultReported.newBuilder()
+                .setPackageName(TEST_APP_PACKAGE_NAME)
+                .setAppVersionCode(TEST_APP_VERSION_CODE)
+                .setUiElementPath(TEST_APP_PACKAGE_NAME + ":TargetNode")
+                .setWindowTitle(TEST_WINDOW_TITLE)
+                .setActivityName("")
+                .setSourceComponentName(new ComponentName(TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME,
+                        TEST_A11Y_SERVICE_CLASS_NAME).flattenToString())
+                .setSourceVersionCode(TEST_A11Y_SERVICE_SOURCE_VERSION_CODE)
+                .setResultCheckClass(checkClass)
+                .setResultType(resultType)
+                .setResultId(resultId)
+                .build();
+    }
+
+}
diff --git a/core/tests/coretests/src/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java
similarity index 80%
rename from core/tests/coretests/src/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java
rename to services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java
index 438277b..a53f42e 100644
--- a/core/tests/coretests/src/android/view/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/AccessibilityNodePathBuilderTest.java
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-package android.view.accessibility.a11ychecker;
+package com.android.server.accessibility.a11ychecker;
 
-import static android.view.accessibility.a11ychecker.MockAccessibilityNodeInfoBuilder.PACKAGE_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_APP_PACKAGE_NAME;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -36,7 +36,7 @@
 @RunWith(AndroidJUnit4.class)
 public class AccessibilityNodePathBuilderTest {
 
-    public static final String RESOURCE_ID_PREFIX = PACKAGE_NAME + ":id/";
+    public static final String RESOURCE_ID_PREFIX = TEST_APP_PACKAGE_NAME + ":id/";
 
     @Test
     public void createNodePath_pathWithResourceNames() {
@@ -55,11 +55,11 @@
                         .build();
 
         assertThat(AccessibilityNodePathBuilder.createNodePath(child))
-                .isEqualTo(PACKAGE_NAME + ":root_node/parent_node[1]/child_node[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":root_node/parent_node[1]/child_node[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(parent))
-                .isEqualTo(PACKAGE_NAME + ":root_node/parent_node[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":root_node/parent_node[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(root))
-                .isEqualTo(PACKAGE_NAME + ":root_node");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":root_node");
     }
 
     @Test
@@ -81,11 +81,11 @@
                         .build();
 
         assertThat(AccessibilityNodePathBuilder.createNodePath(child))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout/RecyclerView[1]/TextView[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout/RecyclerView[1]/TextView[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(parent))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout/RecyclerView[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout/RecyclerView[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(root))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout");
     }
 
     @Test
@@ -105,11 +105,11 @@
                         .build();
 
         assertThat(AccessibilityNodePathBuilder.createNodePath(child1))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout/child1[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout/child1[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(child2))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout/TextView[2]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout/TextView[2]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(parent))
-                .isEqualTo(PACKAGE_NAME + ":FrameLayout");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":FrameLayout");
     }
 
     @Test
@@ -133,13 +133,13 @@
                         .build();
 
         assertThat(AccessibilityNodePathBuilder.createNodePath(child1))
-                .isEqualTo(PACKAGE_NAME + ":parentId/childId[1]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":parentId/childId[1]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(child2))
-                .isEqualTo(PACKAGE_NAME + ":parentId/child/Id/With/Slash[2]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":parentId/child/Id/With/Slash[2]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(child3))
-                .isEqualTo(PACKAGE_NAME + ":parentId/childIdWithoutPrefix[3]");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":parentId/childIdWithoutPrefix[3]");
         assertThat(AccessibilityNodePathBuilder.createNodePath(parent))
-                .isEqualTo(PACKAGE_NAME + ":parentId");
+                .isEqualTo(TEST_APP_PACKAGE_NAME + ":parentId");
     }
 
 }
diff --git a/core/tests/coretests/src/android/view/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java
similarity index 72%
rename from core/tests/coretests/src/android/view/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java
rename to services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java
index e363f0c..7cd3535 100644
--- a/core/tests/coretests/src/android/view/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/MockAccessibilityNodeInfoBuilder.java
@@ -14,21 +14,33 @@
  * limitations under the License.
  */
 
-package android.view.accessibility.a11ychecker;
+package com.android.server.accessibility.a11ychecker;
+
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_APP_PACKAGE_NAME;
+import static com.android.server.accessibility.a11ychecker.TestUtils.TEST_WINDOW_TITLE;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.AccessibilityWindowInfo;
 
 import java.util.List;
 
 final class MockAccessibilityNodeInfoBuilder {
-    static final String PACKAGE_NAME = "com.example.app";
     private final AccessibilityNodeInfo mMockNodeInfo = mock(AccessibilityNodeInfo.class);
 
     MockAccessibilityNodeInfoBuilder() {
-        when(mMockNodeInfo.getPackageName()).thenReturn(PACKAGE_NAME);
+        setPackageName(TEST_APP_PACKAGE_NAME);
+
+        AccessibilityWindowInfo windowInfo = new AccessibilityWindowInfo();
+        windowInfo.setTitle(TEST_WINDOW_TITLE);
+        when(mMockNodeInfo.getWindow()).thenReturn(windowInfo);
+    }
+
+    MockAccessibilityNodeInfoBuilder setPackageName(String packageName) {
+        when(mMockNodeInfo.getPackageName()).thenReturn(packageName);
+        return this;
     }
 
     MockAccessibilityNodeInfoBuilder setClassName(String className) {
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/OWNERS b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/OWNERS
new file mode 100644
index 0000000..7bdc029
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/OWNERS
@@ -0,0 +1 @@
+include /services/accessibility/java/com/android/server/accessibility/a11ychecker/OWNERS
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/TestUtils.java b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/TestUtils.java
new file mode 100644
index 0000000..a04bbee
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/accessibility/a11ychecker/TestUtils.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2024 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.server.accessibility.a11ychecker;
+
+import static org.mockito.Mockito.when;
+
+import android.annotation.Nullable;
+import android.content.ComponentName;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+
+import org.mockito.Mockito;
+
+public class TestUtils {
+    static final String TEST_APP_PACKAGE_NAME = "com.example.app";
+    static final int TEST_APP_VERSION_CODE = 12321;
+    static final String TEST_ACTIVITY_NAME = "com.example.app.MainActivity";
+    static final String TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME = "com.assistive.app";
+    static final String TEST_A11Y_SERVICE_CLASS_NAME = "MyA11yService";
+    static final int TEST_A11Y_SERVICE_SOURCE_VERSION_CODE = 333555;
+    static final String TEST_WINDOW_TITLE = "Example window";
+
+    static PackageManager getMockPackageManagerWithInstalledApps()
+            throws PackageManager.NameNotFoundException {
+        PackageManager mockPackageManager = Mockito.mock(PackageManager.class);
+        ActivityInfo testActivityInfo = getTestActivityInfo();
+        ComponentName testActivityComponentName = new ComponentName(TEST_APP_PACKAGE_NAME,
+                TEST_ACTIVITY_NAME);
+
+        when(mockPackageManager.getActivityInfo(testActivityComponentName, 0))
+                .thenReturn(testActivityInfo);
+        when(mockPackageManager.getPackageInfo(TEST_APP_PACKAGE_NAME, 0))
+                .thenReturn(createPackageInfo(TEST_APP_PACKAGE_NAME, TEST_APP_VERSION_CODE,
+                        testActivityInfo));
+        when(mockPackageManager.getPackageInfo(TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME, 0))
+                .thenReturn(createPackageInfo(TEST_A11Y_SERVICE_SOURCE_PACKAGE_NAME,
+                        TEST_A11Y_SERVICE_SOURCE_VERSION_CODE, null));
+        return mockPackageManager;
+    }
+
+    static ActivityInfo getTestActivityInfo() {
+        ActivityInfo activityInfo = new ActivityInfo();
+        activityInfo.packageName = TEST_APP_PACKAGE_NAME;
+        activityInfo.name = TEST_ACTIVITY_NAME;
+        return activityInfo;
+    }
+
+    static PackageInfo createPackageInfo(String packageName, int versionCode,
+            @Nullable ActivityInfo activityInfo) {
+        PackageInfo packageInfo = new PackageInfo();
+        packageInfo.packageName = packageName;
+        packageInfo.setLongVersionCode(versionCode);
+        if (activityInfo != null) {
+            packageInfo.activities = new ActivityInfo[]{activityInfo};
+        }
+        return packageInfo;
+
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java b/services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java
index ef9580c..758c84a 100644
--- a/services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/AbsoluteVolumeBehaviorTest.java
@@ -101,7 +101,7 @@
         mAudioService = new AudioService(mContext, mSpyAudioSystem, mSystemServer,
                 mSettingsAdapter, mAudioVolumeGroupHelper, mMockAudioPolicy,
                 mTestLooper.getLooper(), mock(AppOpsManager.class), mock(PermissionEnforcer.class),
-                mock(AudioServerPermissionProvider.class), r -> r.run()) {
+                mock(AudioServerPermissionProvider.class)) {
             @Override
             public int getDeviceForStream(int stream) {
                 return AudioSystem.DEVICE_OUT_SPEAKER;
diff --git a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java
index 4645156..2cb02bd 100644
--- a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java
@@ -78,7 +78,7 @@
         mAudioService = new AudioService(mContext, mSpyAudioSystem, mSystemServer,
                 mSettingsAdapter, mAudioVolumeGroupHelper, mAudioPolicyMock,
                 mTestLooper.getLooper(), mock(AppOpsManager.class), mock(PermissionEnforcer.class),
-                mock(AudioServerPermissionProvider.class), r -> r.run()) {
+                mock(AudioServerPermissionProvider.class)) {
             @Override
             public int getDeviceForStream(int stream) {
                 return AudioSystem.DEVICE_OUT_SPEAKER;
diff --git a/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java b/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java
index b7100ea..037c3c0 100644
--- a/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java
@@ -87,7 +87,7 @@
                 .thenReturn(AppOpsManager.MODE_ALLOWED);
         mAudioService = new AudioService(mContext, mSpyAudioSystem, mSpySystemServer,
                 mSettingsAdapter, mAudioVolumeGroupHelper, mMockAudioPolicy, null,
-                mMockAppOpsManager, mMockPermissionEnforcer, mMockPermissionProvider, r -> r.run());
+                mMockAppOpsManager, mMockPermissionEnforcer, mMockPermissionProvider);
     }
 
     /**
diff --git a/services/tests/servicestests/src/com/android/server/audio/DeviceVolumeBehaviorTest.java b/services/tests/servicestests/src/com/android/server/audio/DeviceVolumeBehaviorTest.java
index 746645a..27b552f 100644
--- a/services/tests/servicestests/src/com/android/server/audio/DeviceVolumeBehaviorTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/DeviceVolumeBehaviorTest.java
@@ -78,7 +78,7 @@
         mAudioService = new AudioService(mContext, mAudioSystem, mSystemServer,
                 mSettingsAdapter, mAudioVolumeGroupHelper, mAudioPolicyMock,
                 mTestLooper.getLooper(), mock(AppOpsManager.class), mock(PermissionEnforcer.class),
-                mock(AudioServerPermissionProvider.class), r -> r.run());
+                mock(AudioServerPermissionProvider.class));
         mTestLooper.dispatchAll();
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java b/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java
index e45ab31..8e34ee1 100644
--- a/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java
@@ -160,7 +160,7 @@
                 @NonNull PermissionEnforcer enforcer,
                 AudioServerPermissionProvider permissionProvider) {
             super(context, audioSystem, systemServer, settings, audioVolumeGroupHelper,
-                    audioPolicy, looper, appOps, enforcer, permissionProvider, r -> r.run());
+                    audioPolicy, looper, appOps, enforcer, permissionProvider);
         }
 
         public void setDeviceForStream(int stream, int device) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
index 564c29f..11e6d90 100644
--- a/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/CameraCompatFreeformPolicyTests.java
@@ -23,7 +23,6 @@
 import static android.content.pm.ActivityInfo.OVERRIDE_CAMERA_COMPAT_DISABLE_FREEFORM_WINDOWING_TREATMENT;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
 
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
@@ -176,6 +175,7 @@
         configureActivity(SCREEN_ORIENTATION_PORTRAIT);
 
         mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1);
+        callOnActivityConfigurationChanging(mActivity);
         mCameraAvailabilityCallback.onCameraClosed(CAMERA_ID_1);
         mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1);
         callOnActivityConfigurationChanging(mActivity);
@@ -185,34 +185,6 @@
     }
 
     @Test
-    public void testReconnectedToDifferentCamera_activatesCameraCompatModeAndRefresh()
-            throws Exception {
-        configureActivity(SCREEN_ORIENTATION_PORTRAIT);
-
-        mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1);
-        mCameraAvailabilityCallback.onCameraClosed(CAMERA_ID_1);
-        mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_2, TEST_PACKAGE_1);
-        callOnActivityConfigurationChanging(mActivity);
-
-        assertInCameraCompatMode();
-        assertActivityRefreshRequested(/* refreshRequested */ true);
-    }
-
-    @Test
-    public void testCameraDisconnected_deactivatesCameraCompatMode() {
-        configureActivityAndDisplay(SCREEN_ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE,
-                WINDOWING_MODE_FREEFORM);
-        // Open camera and test for compat treatment
-        mCameraAvailabilityCallback.onCameraOpened(CAMERA_ID_1, TEST_PACKAGE_1);
-        assertInCameraCompatMode();
-
-        // Close camera and test for revert
-        mCameraAvailabilityCallback.onCameraClosed(CAMERA_ID_1);
-
-        assertNotInCameraCompatMode();
-    }
-
-    @Test
     public void testCameraOpenedForDifferentPackage_notInCameraCompatMode() {
         configureActivity(SCREEN_ORIENTATION_PORTRAIT);
 
diff --git a/services/tests/wmtests/src/com/android/server/wm/CameraStateMonitorTests.java b/services/tests/wmtests/src/com/android/server/wm/CameraStateMonitorTests.java
index e468fd8..1c8dc05 100644
--- a/services/tests/wmtests/src/com/android/server/wm/CameraStateMonitorTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/CameraStateMonitorTests.java
@@ -256,8 +256,7 @@
         }
 
         @Override
-        public boolean onCameraClosed(@NonNull ActivityRecord cameraActivity,
-                @NonNull String cameraId) {
+        public boolean onCameraClosed(@NonNull String cameraId) {
             mOnCameraClosedCounter++;
             boolean returnValue = mOnCameraClosedReturnValue;
             // If false, return false only the first time, so it doesn't fall in the infinite retry
diff --git a/telephony/java/android/telephony/satellite/SatelliteManager.java b/telephony/java/android/telephony/satellite/SatelliteManager.java
index aebae4e..4b83b65 100644
--- a/telephony/java/android/telephony/satellite/SatelliteManager.java
+++ b/telephony/java/android/telephony/satellite/SatelliteManager.java
@@ -1078,6 +1078,11 @@
      * @hide
      */
     public static final int DATAGRAM_TYPE_LAST_SOS_MESSAGE_NO_HELP_NEEDED = 5;
+    /**
+     * Datagram type indicating that the message to be sent or received is of type SMS.
+     * @hide
+     */
+    public static final int DATAGRAM_TYPE_SMS = 6;
 
     /** @hide */
     @IntDef(prefix = "DATAGRAM_TYPE_", value = {
@@ -1086,7 +1091,8 @@
             DATAGRAM_TYPE_LOCATION_SHARING,
             DATAGRAM_TYPE_KEEP_ALIVE,
             DATAGRAM_TYPE_LAST_SOS_MESSAGE_STILL_NEED_HELP,
-            DATAGRAM_TYPE_LAST_SOS_MESSAGE_NO_HELP_NEEDED
+            DATAGRAM_TYPE_LAST_SOS_MESSAGE_NO_HELP_NEEDED,
+            DATAGRAM_TYPE_SMS
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface DatagramType {}
diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
index 238f2af..5121f667 100644
--- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
+++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/DesktopModeAppHelper.kt
@@ -119,7 +119,7 @@
     ): UiObject2? {
         if (
             wmHelper.getWindow(innerHelper)?.windowingMode !=
-                WindowingMode.WINDOWING_MODE_FREEFORM.value
+            WindowingMode.WINDOWING_MODE_FREEFORM.value
         )
             error("expected a freeform window with caption but window is not in freeform mode")
         val captions =
@@ -147,7 +147,17 @@
         val endX = startX + horizontalChange
 
         // drag the specified corner of the window to the end coordinate.
-        device.drag(startX, startY, endX, endY, 100)
+        dragWindow(startX, startY, endX, endY, wmHelper, device)
+    }
+
+    /** Drag a window from a source coordinate to a destination coordinate. */
+    fun dragWindow(
+        startX: Int, startY: Int,
+        endX: Int, endY: Int,
+        wmHelper: WindowManagerStateHelper,
+        device: UiDevice
+    ) {
+        device.drag(startX, startY, endX, endY, /* steps= */ 100)
         wmHelper
             .StateSyncBuilder()
             .withAppTransitionIdle()
diff --git a/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt b/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt
index d0148fb..abfe549 100644
--- a/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt
+++ b/tests/Input/src/com/android/test/input/PointerIconLoadingTest.kt
@@ -136,11 +136,20 @@
         assumeTrue(enableVectorCursors())
         assumeTrue(enableVectorCursorA11ySettings())
 
+        val theme: Resources.Theme = context.getResources().newTheme()
+        theme.setTo(context.getTheme())
+        theme.applyStyle(
+            PointerIcon.vectorFillStyleToResource(PointerIcon.POINTER_ICON_VECTOR_STYLE_FILL_BLACK),
+            /* force= */ true)
+        theme.applyStyle(
+            PointerIcon.vectorStrokeStyleToResource(
+                PointerIcon.POINTER_ICON_VECTOR_STYLE_STROKE_WHITE),
+            /* force= */ true)
         val pointerScale = 2f
 
         val pointerIcon =
             PointerIcon.getLoadedSystemIcon(
-                context,
+                ContextThemeWrapper(context, theme),
                 PointerIcon.TYPE_ARROW,
                 /* useLargeIcons= */ false,
                 pointerScale)