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

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

Remove the ability to override dev options from adb

This is not required anymore and had a large performance implication,
even if for userdebug builds only.

Bug: 416813838
Bug: 422446965
Flag: com.android.window.flags.show_desktop_experience_dev_option
Test: manual
Test: atest DesktopExperienceFlagsTest
Change-Id: I73132470f87cb8c73491bbb159adac143664293d
parent 656f5a68
Loading
Loading
Loading
Loading
+8 −38
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.ActivityThread;
import android.content.Context;
import android.content.Context;
import android.os.Build;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
@@ -315,16 +314,14 @@ public enum DesktopExperienceFlags {
        // Name of the flag, used for adb commands.
        // Name of the flag, used for adb commands.
        private final String mFlagName;
        private final String mFlagName;
        // Whether the flag state should be affected by developer option.
        // Whether the flag state should be affected by developer option.
        private final boolean mShouldOverrideByDevOptionDefault;
        private final boolean mShouldOverrideByDevOption;
        // Cached value for that flag: null if not read yet.
        private Boolean mCachedIsOverrideByDevOption;


        public DesktopExperienceFlag(BooleanSupplier flagFunction,
        public DesktopExperienceFlag(BooleanSupplier flagFunction,
                boolean shouldOverrideByDevOption,
                boolean shouldOverrideByDevOption,
                @Nullable String flagName) {
                @Nullable String flagName) {
            this.mFlagFunction = flagFunction;
            this.mFlagFunction = flagFunction;
            this.mFlagName = flagName;
            this.mFlagName = flagName;
            this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption;
            this.mShouldOverrideByDevOption = shouldOverrideByDevOption;
            if (Flags.showDesktopExperienceDevOption()) {
            if (Flags.showDesktopExperienceDevOption()) {
                registerFlag(flagName, this);
                registerFlag(flagName, this);
            }
            }
@@ -338,11 +335,7 @@ public enum DesktopExperienceFlags {
         * user will reboot very soon so being inconsistent across threads is ok.
         * user will reboot very soon so being inconsistent across threads is ok.
         */
         */
        public boolean isTrue() {
        public boolean isTrue() {
            if (mCachedIsOverrideByDevOption == null) {
            return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption);
                mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName,
                        mShouldOverrideByDevOptionDefault);
            }
            return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption);
        }
        }


        public String getFlagName() {
        public String getFlagName() {
@@ -354,7 +347,7 @@ public enum DesktopExperienceFlags {
        }
        }


        public boolean isOverridable() {
        public boolean isOverridable() {
            return mShouldOverrideByDevOptionDefault;
            return mShouldOverrideByDevOption;
        }
        }
    }
    }


@@ -364,9 +357,7 @@ public enum DesktopExperienceFlags {
    // Name of the flag, used for adb commands.
    // Name of the flag, used for adb commands.
    private final String mFlagName;
    private final String mFlagName;
    // Whether the flag state should be affected by developer option.
    // Whether the flag state should be affected by developer option.
    private final boolean mShouldOverrideByDevOptionDefault;
    private final boolean mShouldOverrideByDevOption;
    // 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
    // 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.
    // be refreshed only on reboots as overridden state is expected to take effect on reboots.
@@ -392,7 +383,7 @@ public enum DesktopExperienceFlags {
            @NonNull String flagName) {
            @NonNull String flagName) {
        this.mFlagFunction = flagFunction;
        this.mFlagFunction = flagFunction;
        this.mFlagName = flagName;
        this.mFlagName = flagName;
        this.mShouldOverrideByDevOptionDefault = shouldOverrideByDevOption;
        this.mShouldOverrideByDevOption = shouldOverrideByDevOption;
    }
    }


    /**
    /**
@@ -403,11 +394,7 @@ public enum DesktopExperienceFlags {
     * user will reboot very soon so being inconsistent across threads is ok.
     * user will reboot very soon so being inconsistent across threads is ok.
     */
     */
    public boolean isTrue() {
    public boolean isTrue() {
        if (mCachedIsOverrideByDevOption == null) {
        return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption);
            mCachedIsOverrideByDevOption = checkIfFlagShouldBeOverridden(mFlagName,
                    mShouldOverrideByDevOptionDefault);
        }
        return isFlagTrue(mFlagFunction, mCachedIsOverrideByDevOption);
    }
    }


    public boolean getFlagValue() {
    public boolean getFlagValue() {
@@ -420,7 +407,7 @@ public enum DesktopExperienceFlags {


    /** Returns whether or not the developer option can override that flag. */
    /** Returns whether or not the developer option can override that flag. */
    public boolean isOverridable() {
    public boolean isOverridable() {
        return mShouldOverrideByDevOptionDefault;
        return mShouldOverrideByDevOption;
    }
    }


    private static boolean isFlagTrue(
    private static boolean isFlagTrue(
@@ -439,23 +426,6 @@ public enum DesktopExperienceFlags {
        return new ArrayList<>(sDynamicFlags.values());
        return new ArrayList<>(sDynamicFlags.values());
    }
    }


    private static boolean checkIfFlagShouldBeOverridden(@Nullable String flagName,
            boolean defaultValue) {
        if (!Build.IS_ENG && !Build.IS_USERDEBUG) {
            return 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);
    }

    /** Check whether the flags are overridden to true or not. */
    /** Check whether the flags are overridden to true or not. */
    public static boolean getToggleOverride() {
    public static boolean getToggleOverride() {
        // If cached, return it
        // If cached, return it