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

Commit a1ac2cc6 authored by Lingyu Feng's avatar Lingyu Feng
Browse files

Add setting constant to mirror built-in display

Add a new secure setting contant, which is used to mirror built-in
display in all the connected displays.

Bug: 352461502
Flag: com.android.server.display.feature.flags.enable_display_content_mode_management
Test: adb shell settings put secure mirror_built_in_display <1|0>

Change-Id: Ia7be29a2021cf8d5e565d5d0bfe3a51635ec5e53
parent c60efe59
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -10022,6 +10022,12 @@ public final class Settings {
        public static final String MINIMAL_POST_PROCESSING_ALLOWED =
                "minimal_post_processing_allowed";
        /**
         * Whether to mirror the built-in display on all connected displays.
         * @hide
         */
        public static final String MIRROR_BUILT_IN_DISPLAY = "mirror_built_in_display";
        /**
         * No mode switching will happen.
         *
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class SecureSettings {
        Settings.Secure.RTT_CALLING_MODE,
        Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
        Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED,
        Settings.Secure.MIRROR_BUILT_IN_DISPLAY,
        Settings.Secure.MATCH_CONTENT_FRAME_RATE,
        Settings.Secure.NIGHT_DISPLAY_CUSTOM_START_TIME,
        Settings.Secure.NIGHT_DISPLAY_CUSTOM_END_TIME,
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ public class SecureSettingsValidators {
                Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                new DiscreteValueValidator(new String[] {"1", "2"}));
        VALIDATORS.put(Secure.MINIMAL_POST_PROCESSING_ALLOWED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.MIRROR_BUILT_IN_DISPLAY, BOOLEAN_VALIDATOR);
        VALIDATORS.put(
                Secure.MATCH_CONTENT_FRAME_RATE,
                new DiscreteValueValidator(new String[] {"0", "1", "2"}));
+51 −6
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
import static android.os.Process.FIRST_APPLICATION_UID;
import static android.os.Process.ROOT_UID;
import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
import static android.provider.Settings.Secure.MIRROR_BUILT_IN_DISPLAY;
import static android.provider.Settings.Secure.RESOLUTION_MODE_FULL;
import static android.provider.Settings.Secure.RESOLUTION_MODE_HIGH;
import static android.provider.Settings.Secure.RESOLUTION_MODE_UNKNOWN;
@@ -71,6 +72,7 @@ import android.companion.virtual.VirtualDeviceManager;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -534,6 +536,8 @@ public final class DisplayManagerService extends SystemService {
    private final boolean mExtraDisplayEventLogging;
    private final String mExtraDisplayLoggingPackageName;

    private boolean mMirrorBuiltInDisplay;

    private final BroadcastReceiver mIdleModeReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -782,7 +786,11 @@ public final class DisplayManagerService extends SystemService {
                }
                dpc.onSwitchUser(newUserId, userSerial, newBrightness);
            });
            handleSettingsChange();
            handleMinimalPostProcessingAllowedSettingChange();

            if (mFlags.isDisplayContentModeManagementEnabled()) {
                updateMirrorBuiltInDisplaySettingLocked();
            }
        }
    }

@@ -825,12 +833,15 @@ public final class DisplayManagerService extends SystemService {
            // relevant configuration should be in place.
            recordTopInsetLocked(mLogicalDisplayMapper.getDisplayLocked(Display.DEFAULT_DISPLAY));

            updateSettingsLocked();
            updateMinimalPostProcessingAllowedSettingLocked();
            updateUserDisabledHdrTypesFromSettingsLocked();
            updateUserPreferredDisplayModeSettingsLocked();
            if (mIsHdrOutputControlEnabled) {
                updateHdrConversionModeSettingsLocked();
            }
            if (mFlags.isDisplayContentModeManagementEnabled()) {
                updateMirrorBuiltInDisplaySettingLocked();
            }
        }

        mDisplayModeDirector.setDesiredDisplayModeSpecsListener(
@@ -1180,27 +1191,61 @@ public final class DisplayManagerService extends SystemService {
            mContext.getContentResolver().registerContentObserver(
                    Settings.Secure.getUriFor(
                        Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED), false, this);

            if (mFlags.isDisplayContentModeManagementEnabled()) {
                mContext.getContentResolver().registerContentObserver(
                        Settings.Secure.getUriFor(
                                MIRROR_BUILT_IN_DISPLAY), false, this, UserHandle.USER_ALL);
            }
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            handleSettingsChange();
            if (Settings.Secure.getUriFor(
                    Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED).equals(uri)) {
                handleMinimalPostProcessingAllowedSettingChange();
                return;
            }

            if (Settings.Secure.getUriFor(MIRROR_BUILT_IN_DISPLAY).equals(uri)) {
                if (mFlags.isDisplayContentModeManagementEnabled()) {
                    updateMirrorBuiltInDisplaySettingLocked();
                }
                return;
            }
        }
    }

    private void handleSettingsChange() {
    private void handleMinimalPostProcessingAllowedSettingChange() {
        synchronized (mSyncRoot) {
            updateSettingsLocked();
            updateMinimalPostProcessingAllowedSettingLocked();
            scheduleTraversalLocked(false);
        }
    }

    private void updateSettingsLocked() {
    private void updateMinimalPostProcessingAllowedSettingLocked() {
        setMinimalPostProcessingAllowed(Settings.Secure.getIntForUser(
                mContext.getContentResolver(), Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED,
                1, UserHandle.USER_CURRENT) != 0);
    }

    private void updateMirrorBuiltInDisplaySettingLocked() {
        if (!mFlags.isDisplayContentModeManagementEnabled()) {
            Slog.e(TAG, "MirrorBuiltInDisplay setting shouldn't be updated when the flag is off.");
            return;
        }

        synchronized (mSyncRoot) {
            ContentResolver resolver = mContext.getContentResolver();
            final boolean mirrorBuiltInDisplay = Settings.Secure.getIntForUser(resolver,
                    MIRROR_BUILT_IN_DISPLAY, 0, UserHandle.USER_CURRENT) != 0;
            if (mMirrorBuiltInDisplay == mirrorBuiltInDisplay) {
                return;
            }
            mMirrorBuiltInDisplay = mirrorBuiltInDisplay;
        }
    }

    private void restoreResolutionFromBackup() {
        int savedMode = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREEN_RESOLUTION_MODE,
+9 −0
Original line number Diff line number Diff line
@@ -256,6 +256,10 @@ public class DisplayManagerFlags {
            Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS,
            Flags::displayListenerPerformanceImprovements
    );
    private final FlagState mEnableDisplayContentModeManagementFlagState = new FlagState(
            Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT,
            Flags::enableDisplayContentModeManagement
    );

    private final FlagState mSubscribeGranularDisplayEvents = new FlagState(
            Flags.FLAG_SUBSCRIBE_GRANULAR_DISPLAY_EVENTS,
@@ -556,6 +560,10 @@ public class DisplayManagerFlags {
        return mDisplayListenerPerformanceImprovementsFlagState.isEnabled();
    }

    public boolean isDisplayContentModeManagementEnabled() {
        return mEnableDisplayContentModeManagementFlagState.isEnabled();
    }

    /**
     * @return {@code true} if the flag for subscribing to granular display events is enabled
     */
@@ -618,6 +626,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mEnablePluginManagerFlagState);
        pw.println(" " + mDisplayListenerPerformanceImprovementsFlagState);
        pw.println(" " + mSubscribeGranularDisplayEvents);
        pw.println(" " + mEnableDisplayContentModeManagementFlagState);
    }

    private static class FlagState {