Merge "Migrate Launcher to use the new OnBackInvokedCallback" into tm-qpr-dev
This commit is contained in:
@@ -114,6 +114,7 @@ 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;
|
||||
@@ -543,6 +544,8 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
|
||||
}
|
||||
setTitle(R.string.home_screen);
|
||||
|
||||
registerOnBackInvokedCallback();
|
||||
}
|
||||
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
@@ -2062,6 +2065,17 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
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
|
||||
|
||||
@@ -110,8 +110,11 @@ public final class LauncherInstrumentation {
|
||||
static final Pattern EVENT_TOUCH_UP_TIS = getTouchEventPatternTIS("ACTION_UP");
|
||||
static final Pattern EVENT_TOUCH_CANCEL_TIS = getTouchEventPatternTIS("ACTION_CANCEL");
|
||||
|
||||
static final Pattern EVENT_KEY_BACK_DOWN = getKeyEventPattern("ACTION_DOWN", "KEYCODE_BACK");
|
||||
static final Pattern EVENT_KEY_BACK_UP = getKeyEventPattern("ACTION_UP", "KEYCODE_BACK");
|
||||
private static final Pattern EVENT_KEY_BACK_DOWN =
|
||||
getKeyEventPattern("ACTION_DOWN", "KEYCODE_BACK");
|
||||
private static final Pattern EVENT_KEY_BACK_UP =
|
||||
getKeyEventPattern("ACTION_UP", "KEYCODE_BACK");
|
||||
private static final Pattern EVENT_ON_BACK_INVOKED = Pattern.compile("onBackInvoked");
|
||||
|
||||
private final String mLauncherPackage;
|
||||
private Boolean mIsLauncher3;
|
||||
@@ -983,8 +986,12 @@ public final class LauncherInstrumentation {
|
||||
}
|
||||
}
|
||||
if (launcherVisible) {
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_DOWN);
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_UP);
|
||||
if (getContext().getApplicationInfo().isOnBackInvokedCallbackEnabled()) {
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ON_BACK_INVOKED);
|
||||
} else {
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_DOWN);
|
||||
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user