Migrate Launcher to use the new OnBackInvokedCallback
Bug: b/238475344
Test: Tapl & manual
Change-Id: Ieab329873f82890d95136e490086cc2cffff7ba8
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 4a52d3e..0d0b224 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -113,6 +113,7 @@
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.Toast;
+import android.window.OnBackInvokedDispatcher;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
@@ -545,6 +546,8 @@
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
setTitle(R.string.home_screen);
+
+ registerOnBackInvokedCallback();
}
protected LauncherOverlayManager getDefaultOverlay() {
@@ -2085,6 +2088,17 @@
mStateManager.getState().onBackPressed(this);
}
+ private void registerOnBackInvokedCallback() {
+ if (Utilities.ATLEAST_T) {
+ getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
+ OnBackInvokedDispatcher.PRIORITY_DEFAULT,
+ () -> {
+ onBackPressed();
+ TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
+ });
+ }
+ }
+
protected void onScreenOff() {
// Reset AllApps to its initial state only if we are not in the middle of
// processing a multi-step drop