From 18446d018950ae8173a8f8cef5fd5cce0b7cd0d0 Mon Sep 17 00:00:00 2001 From: Yein Jo Date: Mon, 19 Sep 2022 22:18:09 +0000 Subject: [PATCH] Move OnBackInvoked to BaseActivity. In order to have all the activities in Launcher get the same OnBackInvoked behavior, the logic is moved to BaseActivity. Test: Manual, Tapl Bug: 238475344 Change-Id: I3f49091397e31fe1f183596f7fba3bf514697468 --- src/com/android/launcher3/BaseActivity.java | 17 +++++++++++++++++ src/com/android/launcher3/Launcher.java | 14 -------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index d34f535755..83ff0849a6 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -25,12 +25,16 @@ import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.content.res.Configuration; +import android.os.Bundle; +import android.window.OnBackInvokedDispatcher; import androidx.annotation.IntDef; import com.android.launcher3.DeviceProfile.DeviceProfileListenable; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.logging.StatsLogManager; +import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.ViewCache; import com.android.launcher3.views.AppLauncher; @@ -171,6 +175,19 @@ public abstract class BaseActivity extends Activity implements AppLauncher, super.onActivityResult(requestCode, resultCode, data); } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (Utilities.ATLEAST_T) { + getOnBackInvokedDispatcher().registerOnBackInvokedCallback( + OnBackInvokedDispatcher.PRIORITY_DEFAULT, + () -> { + onBackPressed(); + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked"); + }); + } + } + @Override protected void onStart() { addActivityFlags(ACTIVITY_STATE_STARTED); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 17fb7ebcd4..5e2187e844 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -114,7 +114,6 @@ import android.view.accessibility.AccessibilityEvent; 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; @@ -544,8 +543,6 @@ public class Launcher extends StatefulActivity getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } setTitle(R.string.home_screen); - - registerOnBackInvokedCallback(); } protected LauncherOverlayManager getDefaultOverlay() { @@ -2065,17 +2062,6 @@ public class Launcher extends StatefulActivity 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