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

Commit 9cf8d0f7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "add-cd-devopts" into main

* changes:
  Add the Dev Option for Desktop Experience
  Update DesktopModeFlags to use sysprop.
  Create flag to enable CD dev options
parents c0345a61 e38430db
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -13787,6 +13787,16 @@ public final class Settings {
        public static final String DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT
                = "enable_freeform_support";
        /**
         * Whether to override the availability of the desktop experiences features on the
         * device. With desktop experiences enabled, secondary displays can be used to run
         * apps, in desktop mode by default. Otherwise they can only be used for mirroring.
         * @hide
         */
        @Readable
        public static final String DEVELOPMENT_OVERRIDE_DESKTOP_EXPERIENCE_FEATURES =
                "override_desktop_experience_features";
        /**
         * Whether to override the availability of the desktop mode on the main display of the
         * device. If on, users can make move an app to the desktop, allowing a freeform windowing
+77 −21
Original line number Diff line number Diff line
@@ -20,12 +20,13 @@ import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.Application;
import android.content.ContentResolver;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;

import com.android.window.flags.Flags;

import java.util.function.Supplier;
import java.util.function.BooleanSupplier;

/**
 * Checks desktop mode flag state.
@@ -90,9 +91,35 @@ public enum DesktopModeFlags {
    INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC(
            Flags::includeTopTransparentFullscreenTaskInDesktopHeuristic, true);

    private static final String TAG = "DesktopModeFlagsUtil";
    /**
     * Flag class, to be used in case the enum cannot be used because the flag is not accessible.
     *
     * <p> This class will still use the process-wide cache.
     */
    public static class DesktopModeFlag {
        // Function called to obtain aconfig flag value.
        private final BooleanSupplier mFlagFunction;
        // Whether the flag state should be affected by developer option.
        private final boolean mShouldOverrideByDevOption;

        public DesktopModeFlag(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption) {
            this.mFlagFunction = flagFunction;
            this.mShouldOverrideByDevOption = shouldOverrideByDevOption;
        }

        /**
         * Determines state of flag based on the actual flag and desktop mode developer option
         * overrides.
         */
        public boolean isTrue() {
            return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption);
        }

    }

    private static final String TAG = "DesktopModeFlags";
    // Function called to obtain aconfig flag value.
    private final Supplier<Boolean> mFlagFunction;
    private final BooleanSupplier mFlagFunction;
    // Whether the flag state should be affected by developer option.
    private final boolean mShouldOverrideByDevOption;

@@ -100,7 +127,9 @@ public enum DesktopModeFlags {
    // be refreshed only on reboots as overridden state is expected to take effect on reboots.
    private static ToggleOverride sCachedToggleOverride;

    DesktopModeFlags(Supplier<Boolean> flagFunction, boolean shouldOverrideByDevOption) {
    public static final String SYSTEM_PROPERTY_NAME = "persist.wm.debug.desktop_experience_devopts";

    DesktopModeFlags(BooleanSupplier flagFunction, boolean shouldOverrideByDevOption) {
        this.mFlagFunction = flagFunction;
        this.mShouldOverrideByDevOption = shouldOverrideByDevOption;
    }
@@ -110,24 +139,42 @@ public enum DesktopModeFlags {
     * overrides.
     */
    public boolean isTrue() {
        return isFlagTrue(mFlagFunction, mShouldOverrideByDevOption);
    }

    private static boolean isFlagTrue(BooleanSupplier flagFunction,
            boolean shouldOverrideByDevOption) {
        if (!shouldOverrideByDevOption) return flagFunction.getAsBoolean();
        if (Flags.showDesktopExperienceDevOption()) {
            return switch (getToggleOverride(null)) {
                case OVERRIDE_UNSET, OVERRIDE_OFF -> flagFunction.getAsBoolean();
                case OVERRIDE_ON -> true;
            };
        }
        if (Flags.showDesktopWindowingDevOption()) {
            Application application = ActivityThread.currentApplication();
        if (!Flags.showDesktopWindowingDevOption()
                || !mShouldOverrideByDevOption
                || application == null) {
            return mFlagFunction.get();
        } else {
            if (application == null) {
                Log.w(TAG, "Could not get the current application.");
                return flagFunction.getAsBoolean();
            }
            ContentResolver contentResolver = application.getContentResolver();
            if (contentResolver == null) {
                Log.w(TAG, "Could not get the content resolver for the application.");
                return flagFunction.getAsBoolean();
            }
            boolean shouldToggleBeEnabledByDefault = Flags.enableDesktopWindowingMode();
            return switch (getToggleOverride(application.getContentResolver())) {
                case OVERRIDE_UNSET -> mFlagFunction.get();
            return switch (getToggleOverride(contentResolver)) {
                case OVERRIDE_UNSET -> flagFunction.getAsBoolean();
                // When toggle override matches its default state, don't override flags. This
                // helps users reset their feature overrides.
                case OVERRIDE_OFF -> !shouldToggleBeEnabledByDefault && mFlagFunction.get();
                case OVERRIDE_ON -> shouldToggleBeEnabledByDefault ? mFlagFunction.get() : true;
                case OVERRIDE_OFF -> !shouldToggleBeEnabledByDefault && flagFunction.getAsBoolean();
                case OVERRIDE_ON -> !shouldToggleBeEnabledByDefault || flagFunction.getAsBoolean();
            };
        }
        return flagFunction.getAsBoolean();
    }

    private ToggleOverride getToggleOverride(ContentResolver contentResolver) {
    private static ToggleOverride getToggleOverride(@Nullable ContentResolver contentResolver) {
        // If cached, return it
        if (sCachedToggleOverride != null) {
            return sCachedToggleOverride;
@@ -143,12 +190,21 @@ public enum DesktopModeFlags {
    /**
     *  Returns {@link ToggleOverride} from Settings.Global set by toggle.
     */
    private ToggleOverride getToggleOverrideFromSystem(ContentResolver contentResolver) {
        int settingValue = Settings.Global.getInt(
    private static ToggleOverride getToggleOverrideFromSystem(
            @Nullable ContentResolver contentResolver) {
        int settingValue;
        if (Flags.showDesktopExperienceDevOption()) {
            settingValue = SystemProperties.getInt(
                    SYSTEM_PROPERTY_NAME,
                    ToggleOverride.OVERRIDE_UNSET.getSetting()
            );
        } else {
            settingValue = Settings.Global.getInt(
                    contentResolver,
                    Settings.Global.DEVELOPMENT_OVERRIDE_DESKTOP_MODE_FEATURES,
                    ToggleOverride.OVERRIDE_UNSET.getSetting()
            );
        }
        return ToggleOverride.fromSetting(settingValue, ToggleOverride.OVERRIDE_UNSET);
    }

+8 −1
Original line number Diff line number Diff line
@@ -556,3 +556,10 @@ flag {
       purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "show_desktop_experience_dev_option"
    namespace: "lse_desktop_experience"
    description: "Replace the freeform windowing dev options with a desktop experience one."
    bug: "389092752"
}
+162 −122

File changed.

Preview size limit exceeded, changes collapsed.

+8 −1
Original line number Diff line number Diff line
@@ -218,6 +218,13 @@ public class DesktopModeStatus {
        return isDeviceEligibleForDesktopMode(context) && Flags.showDesktopWindowingDevOption();
    }

    /**
     * Return {@code true} if desktop mode dev option should be shown on current device
     */
    public static boolean canShowDesktopExperienceDevOption(@NonNull Context context) {
        return Flags.showDesktopExperienceDevOption();
    }

    /** Returns if desktop mode dev option should be enabled if there is no user override. */
    public static boolean shouldDevOptionBeEnabledByDefault() {
        return Flags.enableDesktopWindowingMode();
@@ -290,7 +297,7 @@ public class DesktopModeStatus {
    /**
     * Return {@code true} if desktop mode is unrestricted and is supported in the device.
     */
    private static boolean isDeviceEligibleForDesktopMode(@NonNull Context context) {
    public static boolean isDeviceEligibleForDesktopMode(@NonNull Context context) {
        return !enforceDeviceRestrictions() || isDesktopModeSupported(context);
    }

Loading