Loading core/java/android/window/DesktopExperienceFlags.java +43 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.window; import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT; import static com.android.server.display.feature.flags.Flags.enableDisplayContentModeManagement; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -150,31 +151,46 @@ public enum DesktopExperienceFlags { public static class DesktopExperienceFlag { // Function called to obtain aconfig flag value. private final BooleanSupplier mFlagFunction; // Name of the flag, used for adb commands. private final String mFlagName; // Whether the flag state should be affected by developer option. private final boolean mShouldOverrideByDevOption; private final boolean mShouldOverrideByDevOptionDefault; // Cached value for that flag: null if not read yet. private Boolean mCachedIsOverrideByDevOption; public DesktopExperienceFlag(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption, @Nullable String flagName) { this.mFlagFunction = flagFunction; this.mShouldOverrideByDevOption = checkIfFlagShouldBeOverridden(flagName, shouldOverrideByDevOption); this.mFlagName = flagName; this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption; } /** * Determines state of flag based on the actual flag and desktop experience developer option * overrides. * * The assumption is that the flag's value doesn't change at runtime, or if it changes the * user will reboot very soon so being inconsistent across threads is ok. */ public boolean isTrue() { return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption); if (mCachedIsOverrideByDevOption == null) { mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName, mShouldOverrideByDevOptionDefault); } return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption); } } private static final String TAG = "DesktopExperienceFlags"; // Function called to obtain aconfig flag value. private final BooleanSupplier mFlagFunction; // Name of the flag, used for adb commands. private final String mFlagName; // Whether the flag state should be affected by developer option. private final boolean mShouldOverrideByDevOption; private final boolean mShouldOverrideByDevOptionDefault; // Cached value for that flag: null if not read yet. private Boolean mCachedIsOverrideByDevOption; // Local cache for toggle override, which is initialized once on its first access. It needs to // be refreshed only on reboots as overridden state is expected to take effect on reboots. Loading @@ -188,22 +204,29 @@ public enum DesktopExperienceFlags { DesktopExperienceFlags(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption, @NonNull String flagName) { this.mFlagFunction = flagFunction; this.mShouldOverrideByDevOption = checkIfFlagShouldBeOverridden(flagName, shouldOverrideByDevOption); this.mFlagName = flagName; this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption; } /** * Determines state of flag based on the actual flag and desktop experience developer option * overrides. * * The assumption is that the flag's value doesn't change at runtime, or if it changes the * user will reboot very soon so being inconsistent across threads is ok. */ public boolean isTrue() { return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption); if (mCachedIsOverrideByDevOption == null) { mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName, mShouldOverrideByDevOptionDefault); } return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption); } private static boolean isFlagTrue( BooleanSupplier flagFunction, boolean shouldOverrideByDevOption) { if (shouldOverrideByDevOption && Flags.showDesktopExperienceDevOption() if (Flags.showDesktopExperienceDevOption() && shouldOverrideByDevOption && getToggleOverride()) { return true; } Loading @@ -212,8 +235,17 @@ public enum DesktopExperienceFlags { private static boolean checkIfFlagShouldBeOverridden(@Nullable String flagName, boolean defaultValue) { if (!Flags.showDesktopExperienceDevOption() || enableDisplayContentModeManagement()) { return false; } if (flagName == null || flagName.isEmpty()) { return defaultValue; } int lastDot = flagName.lastIndexOf('.'); String baseName = lastDot >= 0 ? flagName.substring(lastDot + 1) : flagName; return SystemProperties.getBoolean(SYSTEM_PROPERTY_OVERRIDE_PREFIX + baseName, defaultValue); } private static boolean getToggleOverride() { // If cached, return it Loading core/tests/coretests/src/android/window/DesktopExperienceFlagsTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.window; import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT; import static com.android.window.flags.Flags.FLAG_SHOW_DESKTOP_EXPERIENCE_DEV_OPTION; import static com.google.common.truth.Truth.assertThat; Loading @@ -23,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.flag.junit.FlagsParameterization; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -57,6 +59,7 @@ import java.util.Objects; @SmallTest @Presubmit @RunWith(ParameterizedAndroidJunit4.class) @DisableFlags(FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT) public class DesktopExperienceFlagsTest { @Parameters(name = "{0}") Loading Loading
core/java/android/window/DesktopExperienceFlags.java +43 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.window; import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT; import static com.android.server.display.feature.flags.Flags.enableDisplayContentModeManagement; import android.annotation.NonNull; import android.annotation.Nullable; Loading Loading @@ -150,31 +151,46 @@ public enum DesktopExperienceFlags { public static class DesktopExperienceFlag { // Function called to obtain aconfig flag value. private final BooleanSupplier mFlagFunction; // Name of the flag, used for adb commands. private final String mFlagName; // Whether the flag state should be affected by developer option. private final boolean mShouldOverrideByDevOption; private final boolean mShouldOverrideByDevOptionDefault; // Cached value for that flag: null if not read yet. private Boolean mCachedIsOverrideByDevOption; public DesktopExperienceFlag(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption, @Nullable String flagName) { this.mFlagFunction = flagFunction; this.mShouldOverrideByDevOption = checkIfFlagShouldBeOverridden(flagName, shouldOverrideByDevOption); this.mFlagName = flagName; this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption; } /** * Determines state of flag based on the actual flag and desktop experience developer option * overrides. * * The assumption is that the flag's value doesn't change at runtime, or if it changes the * user will reboot very soon so being inconsistent across threads is ok. */ public boolean isTrue() { return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption); if (mCachedIsOverrideByDevOption == null) { mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName, mShouldOverrideByDevOptionDefault); } return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption); } } private static final String TAG = "DesktopExperienceFlags"; // Function called to obtain aconfig flag value. private final BooleanSupplier mFlagFunction; // Name of the flag, used for adb commands. private final String mFlagName; // Whether the flag state should be affected by developer option. private final boolean mShouldOverrideByDevOption; private final boolean mShouldOverrideByDevOptionDefault; // Cached value for that flag: null if not read yet. private Boolean mCachedIsOverrideByDevOption; // Local cache for toggle override, which is initialized once on its first access. It needs to // be refreshed only on reboots as overridden state is expected to take effect on reboots. Loading @@ -188,22 +204,29 @@ public enum DesktopExperienceFlags { DesktopExperienceFlags(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption, @NonNull String flagName) { this.mFlagFunction = flagFunction; this.mShouldOverrideByDevOption = checkIfFlagShouldBeOverridden(flagName, shouldOverrideByDevOption); this.mFlagName = flagName; this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption; } /** * Determines state of flag based on the actual flag and desktop experience developer option * overrides. * * The assumption is that the flag's value doesn't change at runtime, or if it changes the * user will reboot very soon so being inconsistent across threads is ok. */ public boolean isTrue() { return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption); if (mCachedIsOverrideByDevOption == null) { mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName, mShouldOverrideByDevOptionDefault); } return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption); } private static boolean isFlagTrue( BooleanSupplier flagFunction, boolean shouldOverrideByDevOption) { if (shouldOverrideByDevOption && Flags.showDesktopExperienceDevOption() if (Flags.showDesktopExperienceDevOption() && shouldOverrideByDevOption && getToggleOverride()) { return true; } Loading @@ -212,8 +235,17 @@ public enum DesktopExperienceFlags { private static boolean checkIfFlagShouldBeOverridden(@Nullable String flagName, boolean defaultValue) { if (!Flags.showDesktopExperienceDevOption() || enableDisplayContentModeManagement()) { return false; } if (flagName == null || flagName.isEmpty()) { return defaultValue; } int lastDot = flagName.lastIndexOf('.'); String baseName = lastDot >= 0 ? flagName.substring(lastDot + 1) : flagName; return SystemProperties.getBoolean(SYSTEM_PROPERTY_OVERRIDE_PREFIX + baseName, defaultValue); } private static boolean getToggleOverride() { // If cached, return it Loading
core/tests/coretests/src/android/window/DesktopExperienceFlagsTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.window; import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT; import static com.android.window.flags.Flags.FLAG_SHOW_DESKTOP_EXPERIENCE_DEV_OPTION; import static com.google.common.truth.Truth.assertThat; Loading @@ -23,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.Presubmit; import android.platform.test.flag.junit.FlagsParameterization; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -57,6 +59,7 @@ import java.util.Objects; @SmallTest @Presubmit @RunWith(ParameterizedAndroidJunit4.class) @DisableFlags(FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT) public class DesktopExperienceFlagsTest { @Parameters(name = "{0}") Loading