From cb6810c3d8b34aacf613d12333cae40fecefadb7 Mon Sep 17 00:00:00 2001 From: Shan Huang Date: Tue, 29 Mar 2022 07:51:15 +0000 Subject: [PATCH] Split predictive back bitmask flags into a few boolean flags. This is such that they can be controlled from Flag Flipper UI. Boolean flags introduced: persist.wm.debug.predictive_back - Overall switch for the new back infra persist.wm.debug.predictive_back_anim - Animation switch persist.wm.debug.predictive_back_always_enforce - Switch to ignore per app opt-in flag and always enforce new behavior persist.wm.debug.predictive_back_screenshot - Screenshot switch. Not added to Flipper yet. Test: Flip the flags in Flipper and verify behavior is as expected. Change-Id: Icff098035119fb83f393e20c6ac590be2f22c845 --- .../window/WindowOnBackInvokedDispatcher.java | 15 ++++++++------- .../wm/shell/back/BackAnimationController.java | 18 ++++++++---------- .../src/com/android/systemui/flags/Flags.java | 11 +++++++++++ .../server/wm/BackNavigationController.java | 12 +++--------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/core/java/android/window/WindowOnBackInvokedDispatcher.java b/core/java/android/window/WindowOnBackInvokedDispatcher.java index 9a6b5efb32b88..f9838bf539d45 100644 --- a/core/java/android/window/WindowOnBackInvokedDispatcher.java +++ b/core/java/android/window/WindowOnBackInvokedDispatcher.java @@ -50,9 +50,10 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { private IWindowSession mWindowSession; private IWindow mWindow; private static final String TAG = "WindowOnBackDispatcher"; - private static final String BACK_PREDICTABILITY_PROP = "persist.debug.back_predictability"; - private static final boolean IS_BACK_PREDICTABILITY_ENABLED = SystemProperties - .getInt(BACK_PREDICTABILITY_PROP, 1) > 0; + private static final boolean ENABLE_PREDICTIVE_BACK = SystemProperties + .getInt("persist.wm.debug.predictive_back", 1) != 0; + private static final boolean ALWAYS_ENFORCE_PREDICTIVE_BACK = SystemProperties + .getInt("persist.wm.debug.predictive_back_always_enforce", 0) != 0; /** Convenience hashmap to quickly decide if a callback has been added. */ private final HashMap mAllCallbacks = new HashMap<>(); @@ -249,18 +250,18 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher { public static boolean isOnBackInvokedCallbackEnabled(@Nullable Context context) { // new back is enabled if the feature flag is enabled AND the app does not explicitly // request legacy back. - boolean featureFlagEnabled = IS_BACK_PREDICTABILITY_ENABLED; + boolean featureFlagEnabled = ENABLE_PREDICTIVE_BACK; // If the context is null, we assume true and fallback on the two other conditions. boolean appRequestsPredictiveBack = context != null && context.getApplicationInfo().isOnBackInvokedCallbackEnabled(); if (DEBUG) { Log.d(TAG, TextUtils.formatSimple("App: %s featureFlagEnabled=%s " - + "appRequestsPredictiveBack=%s", + + "appRequestsPredictiveBack=%s alwaysEnforce=%s", context != null ? context.getApplicationInfo().packageName : "null context", - featureFlagEnabled, appRequestsPredictiveBack)); + featureFlagEnabled, appRequestsPredictiveBack, ALWAYS_ENFORCE_PREDICTIVE_BACK)); } - return featureFlagEnabled && appRequestsPredictiveBack; + return featureFlagEnabled && (appRequestsPredictiveBack || ALWAYS_ENFORCE_PREDICTIVE_BACK); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java index 08cb252cdf432..cf978756ebaec 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java @@ -51,18 +51,16 @@ import com.android.wm.shell.common.annotations.ShellMainThread; * Controls the window animation run when a user initiates a back gesture. */ public class BackAnimationController implements RemoteCallable { - - private static final String BACK_PREDICTABILITY_PROGRESS_THRESHOLD_PROP = - "persist.debug.back_predictability_progress_threshold"; - // By default, enable new back dispatching without any animations. - private static final int BACK_PREDICTABILITY_PROP = - SystemProperties.getInt("persist.debug.back_predictability", 1); - public static final boolean IS_ENABLED = BACK_PREDICTABILITY_PROP > 0; - private static final int PROGRESS_THRESHOLD = SystemProperties - .getInt(BACK_PREDICTABILITY_PROGRESS_THRESHOLD_PROP, -1); private static final String TAG = "BackAnimationController"; + private static final String PREDICTIVE_BACK_PROGRESS_THRESHOLD_PROP = + "persist.wm.debug.predictive_back_progress_threshold"; + public static final boolean IS_ENABLED = + SystemProperties.getInt("persist.wm.debug.predictive_back", 1) != 0; + private static final int PROGRESS_THRESHOLD = SystemProperties + .getInt(PREDICTIVE_BACK_PROGRESS_THRESHOLD_PROP, -1); @VisibleForTesting - boolean mEnableAnimations = (BACK_PREDICTABILITY_PROP & (1 << 1)) != 0; + boolean mEnableAnimations = SystemProperties.getInt( + "persist.wm.debug.predictive_back_anim", 0) != 0; /** * Location of the initial touch event of the back gesture. diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.java b/packages/SystemUI/src/com/android/systemui/flags/Flags.java index 9356b16806f10..33a570c11c1ff 100644 --- a/packages/SystemUI/src/com/android/systemui/flags/Flags.java +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.java @@ -158,6 +158,17 @@ public class Flags { public static final SysPropBooleanFlag WM_ENABLE_SHELL_TRANSITIONS = new SysPropBooleanFlag(1100, "persist.wm.debug.shell_transit", false); + // 1200 - predictive back + @Keep + public static final SysPropBooleanFlag WM_ENABLE_PREDICTIVE_BACK = new SysPropBooleanFlag( + 1200, "persist.wm.debug.predictive_back", true); + @Keep + public static final SysPropBooleanFlag WM_ENABLE_PREDICTIVE_BACK_ANIM = new SysPropBooleanFlag( + 1201, "persist.wm.debug.predictive_back_anim", false); + @Keep + public static final SysPropBooleanFlag WM_ALWAYS_ENFORCE_PREDICTIVE_BACK = + new SysPropBooleanFlag(1202, "persist.wm.debug.predictive_back_always_enforce", false); + // Pay no attention to the reflection behind the curtain. // ========================== Curtain ========================== // | | diff --git a/services/core/java/com/android/server/wm/BackNavigationController.java b/services/core/java/com/android/server/wm/BackNavigationController.java index dbc01413e6fa0..af3f9fb09c248 100644 --- a/services/core/java/com/android/server/wm/BackNavigationController.java +++ b/services/core/java/com/android/server/wm/BackNavigationController.java @@ -45,12 +45,6 @@ import com.android.internal.protolog.common.ProtoLog; class BackNavigationController { private static final String TAG = "BackNavigationController"; - // By default, enable new back dispatching without any animations. - private static final int BACK_PREDICTABILITY_PROP = - SystemProperties.getInt("persist.debug.back_predictability", 1); - private static final int ANIMATIONS_MASK = 1 << 1; - private static final int SCREENSHOT_MASK = 1 << 2; - @Nullable private TaskSnapshotController mTaskSnapshotController; @@ -58,15 +52,15 @@ class BackNavigationController { * Returns true if the back predictability feature is enabled */ static boolean isEnabled() { - return BACK_PREDICTABILITY_PROP > 0; + return SystemProperties.getInt("persist.wm.debug.predictive_back", 1) != 0; } static boolean isScreenshotEnabled() { - return (BACK_PREDICTABILITY_PROP & SCREENSHOT_MASK) != 0; + return SystemProperties.getInt("persist.wm.debug.predictive_back_screenshot", 0) != 0; } private static boolean isAnimationEnabled() { - return (BACK_PREDICTABILITY_PROP & ANIMATIONS_MASK) != 0; + return SystemProperties.getInt("persist.wm.debug.predictive_back_anim", 0) != 0; } /**