Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bcc1ef6 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Simplify DesktopModeFlags

If the Desktop Experience developer option flag is enabled,
DesktopModeFlags will look at the same signal as DesktopExperienceFlags
(i.e. the system property).

If not, it will look at the previous signal (i.e. the settings config).

This will simplify the code and avoid some expensive blocking calls.

Fix: 416813838
Bug: 389092752
Test: atest DesktopModeStatusTest DesktopStateImplTest
Test: atest DesktopExperienceFlagsTest DesktopModeFlagsTest
Flag: EXEMPT (bug fix)
Change-Id: I2e5753202f38de2f39d475fcf50c7fffb1fc4849
parent 4ecc9607
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -411,16 +411,9 @@ public enum DesktopExperienceFlags {

    /** Returns whether the toggle is overridden by the relevant system property.. */
    private static boolean isToggleOverriddenBySystem() {
        // We never override if display content mode management is enabled.
        if (enableDisplayContentModeManagement()) {
            return false;
        }
        final Context context = getApplicationContext();
        if (context == null) {
            return false;
        }
        // If the developer option is not supported, we don't override.
        if (!isDesktopExperienceDevOptionSupported()) {
        // We never override if display content mode management is enabled or
        // if the desktop experience dev option is not enabled in the build.
        if (enableDisplayContentModeManagement() || !Flags.showDesktopExperienceDevOption()) {
            return false;
        }
        return SystemProperties.getBoolean(SYSTEM_PROPERTY_NAME, false);
+1 −1
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public enum DesktopModeFlags {
     *  Returns {@link ToggleOverride} from Settings.Global set by toggle.
     */
    private static ToggleOverride getToggleOverrideFromSystem() {
        if (DesktopExperienceFlags.isDesktopExperienceDevOptionSupported()) {
        if (Flags.showDesktopExperienceDevOption()) {
            if (DesktopExperienceFlags.getToggleOverride()) {
                return ToggleOverride.OVERRIDE_ON;
            }
+2 −2
Original line number Diff line number Diff line
@@ -505,7 +505,7 @@ public class DesktopModeFlagsTest {
    }

    private boolean showDesktopWindowingDevOpts() {
        return Flags.showDesktopWindowingDevOption() && !showDesktopExperienceDevOpts();
        return Flags.showDesktopWindowingDevOption() && !Flags.showDesktopExperienceDevOption();
    }

    private boolean showDesktopExperienceDevOpts() {
@@ -513,7 +513,7 @@ public class DesktopModeFlagsTest {
    }

    private boolean showAnyDevOpts() {
        return Flags.showDesktopWindowingDevOption() || showDesktopExperienceDevOpts();
        return Flags.showDesktopWindowingDevOption() || Flags.showDesktopExperienceDevOption();
    }

    private void setDesktopModeSupported(boolean isSupported) {
+16 −5
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class DesktopModeStatus {
     */
    public static boolean canShowDesktopExperienceDevOption(@NonNull Context context) {
        return Flags.showDesktopExperienceDevOption()
                && isDeviceEligibleForDesktopMode(context);
                && isDeviceEligibleForDesktopExperienceDevOption(context);
    }

    /** Returns if desktop mode dev option should be enabled if there is no user override. */
@@ -222,11 +222,9 @@ public class DesktopModeStatus {
    }

    /**
     * Return {@code true} if the developer option for desktop mode is unrestricted and is supported
     * in the device.
     * Return {@code true} if the developer option for desktop mode is supported on this device.
     *
     * Note that, if {@link #isDeviceEligibleForDesktopMode(Context)} is true, then
     * {@link #isDeviceEligibleForDesktopModeDevOption(Context)} is also true.
     * <p> This method doesn't check if the developer option flag is enabled or not.
     */
    private static boolean isDeviceEligibleForDesktopModeDevOption(@NonNull Context context) {
        if (!enforceDeviceRestrictions()) {
@@ -237,6 +235,19 @@ public class DesktopModeStatus {
        return desktopModeSupported || isDesktopModeDevOptionSupported(context);
    }

    /**
     * Return {@code true} if the developer option for desktop experience is supported on this
     * device.
     *
     * <p> This method doesn't check if the developer option flag is enabled or not.
     */
    private static boolean isDeviceEligibleForDesktopExperienceDevOption(@NonNull Context context) {
        if (!enforceDeviceRestrictions()) {
            return true;
        }
        return isDesktopModeSupported(context) || isDesktopModeDevOptionSupported(context);
    }

    /**
     * @return {@code true} if this device has an internal large screen
     */
+4 −1
Original line number Diff line number Diff line
@@ -73,8 +73,11 @@ class DesktopStateImpl(context: Context) : DesktopState {
        desktopModeEnabled || isDesktopModeEnabledByDevOption
    }

    private val isDeviceEligibleForDesktopExperienceDevOption =
        !enforceDeviceRestrictions || isDesktopModeSupported || isDesktopModeDevOptionSupported

    override val canShowDesktopExperienceDevOption: Boolean =
        Flags.showDesktopExperienceDevOption() && isDeviceEligibleForDesktopMode
        Flags.showDesktopExperienceDevOption() && isDeviceEligibleForDesktopExperienceDevOption

    override val enterDesktopByDefaultOnFreeformDisplay: Boolean =
        DesktopExperienceFlags.ENABLE_DESKTOP_FIRST_BASED_DEFAULT_TO_DESKTOP_BUGFIX.isTrue ||
Loading