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
This commit is contained in:
Shan Huang
2022-03-29 07:51:15 +00:00
parent 778d3d83f8
commit cb6810c3d8
4 changed files with 30 additions and 26 deletions

View File

@@ -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<OnBackInvokedCallback, Integer> 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);
}
}

View File

@@ -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<BackAnimationController> {
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.

View File

@@ -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 ==========================
// | |

View File

@@ -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;
}
/**