Skip the back button on UserPicker

Bug: 277162140
Test: adb shell input -d 2 keyevent KEYCODE_BACK
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3fa0bf20d85e8c6c1a566622b6cc1dcba79b3aad)
Merged-In: Ib665e11c5a84b13dcfcb6260026966689d50daae
Change-Id: Ib665e11c5a84b13dcfcb6260026966689d50daae
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 0564c3a..bc30d24 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -88,6 +88,7 @@
             android:exported="true"
             android:excludeFromRecents="true"
             android:directBootAware="true"
+            android:enableOnBackInvokedCallback="true"
             android:theme="@style/Theme.UserPicker">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/src/com/android/systemui/car/userpicker/UserPickerActivity.java b/src/com/android/systemui/car/userpicker/UserPickerActivity.java
index f1b9169..e0aa324 100644
--- a/src/com/android/systemui/car/userpicker/UserPickerActivity.java
+++ b/src/com/android/systemui/car/userpicker/UserPickerActivity.java
@@ -17,6 +17,7 @@
 package com.android.systemui.car.userpicker;
 
 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT;
 
 import static com.android.systemui.car.userpicker.HeaderState.HEADER_STATE_CHANGE_USER;
 import static com.android.systemui.car.userpicker.HeaderState.HEADER_STATE_LOGOUT;
@@ -35,6 +36,7 @@
 import android.view.WindowInsets;
 import android.view.WindowInsetsController;
 import android.view.WindowManager;
+import android.window.OnBackInvokedCallback;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
@@ -94,6 +96,11 @@
     @VisibleForTesting
     View mBackButton;
 
+    private final OnBackInvokedCallback mIgnoreBackCallback = () -> {
+        // Ignore back press.
+        if (DEBUG) Log.d(TAG, "Skip Back");
+    };
+
     @Inject
     UserPickerActivity(
             Context context, //application context
@@ -153,6 +160,8 @@
         super.onCreate(savedInstanceState);
         setShowWhenLocked(true);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
+        getOnBackInvokedDispatcher()
+                .registerOnBackInvokedCallback(PRIORITY_DEFAULT, mIgnoreBackCallback);
         init();
     }
 
@@ -265,6 +274,7 @@
         if (DEBUG) {
             Slog.d(TAG, "onDestroy: displayId=" + getDisplayId());
         }
+        getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mIgnoreBackCallback);
         if (mController != null) {
             mController.onDestroy();
         }