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

Commit 6503ce70 authored by Lingyu Feng's avatar Lingyu Feng
Browse files

Introduce DesktopModeHelper#isDesktopModeSupportedOnInternalDisplay()

When persist.wm.debug.desktop_mode_enforce_device_restrictions is set to
false, the internal display can host desktop mode, and the connected
displays should be treated as extended mode rather than projected mode.

DisplayManager should use this new API to differentiate extended and
projected mode, replacing
DesktopModeHelper#canInternalDisplayHostDesktops().

DisplayManagerService will use this new API to decide if the default
display should be excluded from the topology by default.

Bug: 422292780
Test: passed the modified unit tests
Test: adb shell setprop
persist.wm.debug.desktop_mode_enforce_device_restrictions false and
checked the display topology
Flag: EXEMPT bug fix

Change-Id: I1f5325b4b3bffae4fc74b9bdaf6cedce8aaf853d
parent 568155ad
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ class DisplayGroupAllocator {
    public void initLater(Context context) {
        mContext = context;
        mCanDeviceEnterDesktopMode = mInjector.canEnterDesktopMode(mContext);
        mCanDefaultDisplayEnterDesktopMode = mInjector.canInternalDisplayHostDesktops(mContext);
        mCanDefaultDisplayEnterDesktopMode =
                mInjector.isDesktopModeSupportedOnInternalDisplay(mContext);
    }

    /**
@@ -154,8 +155,8 @@ class DisplayGroupAllocator {
            return DesktopModeHelper.canEnterDesktopMode(context);
        }

        boolean canInternalDisplayHostDesktops(Context context) {
            return DesktopModeHelper.canInternalDisplayHostDesktops(context);
        boolean isDesktopModeSupportedOnInternalDisplay(Context context) {
            return DesktopModeHelper.isDesktopModeSupportedOnInternalDisplay(context);
        }

        boolean canDisplayHostTasksLocked(LogicalDisplay display) {
+15 −11
Original line number Diff line number Diff line
@@ -885,9 +885,9 @@ public final class DisplayManagerService extends SystemService {
            }

            if (mFlags.isDefaultDisplayInTopologySwitchEnabled()) {
                mIncludeDefaultDisplayInTopology = mInjector.canInternalDisplayHostDesktops(
                        mContext) || (Settings.Secure.getIntForUser(mContext.getContentResolver(),
                        INCLUDE_DEFAULT_DISPLAY_IN_TOPOLOGY, 0, UserHandle.USER_CURRENT) != 0);
                mIncludeDefaultDisplayInTopology =
                        mInjector.isDesktopModeSupportedOnInternalDisplay(mContext)
                                || getIncludeDefaultDisplayInTopologySetting();
            }
        }

@@ -1247,7 +1247,7 @@ public final class DisplayManagerService extends SystemService {
            }

            if (mFlags.isDefaultDisplayInTopologySwitchEnabled()
                    && !mInjector.canInternalDisplayHostDesktops(mContext)) {
                    && !mInjector.isDesktopModeSupportedOnInternalDisplay(mContext)) {
                mContext.getContentResolver().registerContentObserver(
                        Settings.Secure.getUriFor(
                                Settings.Secure.INCLUDE_DEFAULT_DISPLAY_IN_TOPOLOGY),
@@ -1278,7 +1278,7 @@ public final class DisplayManagerService extends SystemService {
            if (Settings.Secure.getUriFor(INCLUDE_DEFAULT_DISPLAY_IN_TOPOLOGY).equals(uri)) {
                synchronized (mSyncRoot) {
                    if (mFlags.isDefaultDisplayInTopologySwitchEnabled()
                            && !mInjector.canInternalDisplayHostDesktops(mContext)) {
                            && !mInjector.isDesktopModeSupportedOnInternalDisplay(mContext)) {
                        handleIncludeDefaultDisplayInTopologySettingChangeLocked();
                    }
                }
@@ -1320,9 +1320,7 @@ public final class DisplayManagerService extends SystemService {
    }

    private void handleIncludeDefaultDisplayInTopologySettingChangeLocked() {
        ContentResolver resolver = mContext.getContentResolver();
        final boolean includeDefaultDisplayInTopology = Settings.Secure.getIntForUser(resolver,
                INCLUDE_DEFAULT_DISPLAY_IN_TOPOLOGY, 0, UserHandle.USER_CURRENT) != 0;
        final boolean includeDefaultDisplayInTopology = getIncludeDefaultDisplayInTopologySetting();

        if (mIncludeDefaultDisplayInTopology == includeDefaultDisplayInTopology) {
            return;
@@ -1349,6 +1347,12 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    private boolean getIncludeDefaultDisplayInTopologySetting() {
        ContentResolver resolver = mContext.getContentResolver();
        return Settings.Secure.getIntForUser(resolver, INCLUDE_DEFAULT_DISPLAY_IN_TOPOLOGY, 0,
                UserHandle.USER_CURRENT) != 0;
    }

    private void restoreResolutionFromBackup() {
        int savedMode = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREEN_RESOLUTION_MODE,
@@ -2502,7 +2506,7 @@ public final class DisplayManagerService extends SystemService {
    }

    boolean shouldIncludeDefaultDisplayInTopology() {
        return mInjector.canInternalDisplayHostDesktops(mContext)
        return mInjector.isDesktopModeSupportedOnInternalDisplay(mContext)
                || mIncludeDefaultDisplayInTopology;
    }

@@ -4108,8 +4112,8 @@ public final class DisplayManagerService extends SystemService {
                    onBrightnessChangeRunnable, hbmMetadata, bootCompleted, flags);
        }

        boolean canInternalDisplayHostDesktops(Context context) {
            return DesktopModeHelper.canInternalDisplayHostDesktops(context);
        boolean isDesktopModeSupportedOnInternalDisplay(Context context) {
            return DesktopModeHelper.isDesktopModeSupportedOnInternalDisplay(context);
        }

        PersistentDataStore getPersistentDataStore() {
+9 −1
Original line number Diff line number Diff line
@@ -62,10 +62,18 @@ public final class DesktopModeHelper {
        return context.getResources().getBoolean(R.bool.config_isDesktopModeDevOptionSupported);
    }

    /**
     * Return {@code true} if desktop mode is unrestricted on the current device or it can host
     * desktop sessions on its internal display.
     */
    public static boolean isDesktopModeSupportedOnInternalDisplay(@NonNull Context context) {
        return !shouldEnforceDeviceRestrictions() ||  canInternalDisplayHostDesktops(context);
    }

    /**
     * Return {@code true} if the current device can hosts desktop sessions on its internal display.
     */
    public static boolean canInternalDisplayHostDesktops(@NonNull Context context) {
    private static boolean canInternalDisplayHostDesktops(@NonNull Context context) {
        return context.getResources().getBoolean(R.bool.config_canInternalDisplayHostDesktops);
    }

+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class DisplayGroupAllocatorTest {
            }

            @Override
            boolean canInternalDisplayHostDesktops(Context context) {
            boolean isDesktopModeSupportedOnInternalDisplay(Context context) {
                return simulateExtendedMode;
            }

+2 −2
Original line number Diff line number Diff line
@@ -387,7 +387,7 @@ public class DisplayManagerServiceTest {
        }

        @Override
        boolean canInternalDisplayHostDesktops(Context context) {
        boolean isDesktopModeSupportedOnInternalDisplay(Context context) {
            return false;
        }

@@ -4440,7 +4440,7 @@ public class DisplayManagerServiceTest {
        DisplayManagerService displayManager = new DisplayManagerService(
                mContext, new BasicInjector() {
            @Override
            boolean canInternalDisplayHostDesktops(Context context) {
            boolean isDesktopModeSupportedOnInternalDisplay(Context context) {
                return true;
            }
        });
Loading