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

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

Merge "[2/n] Stop connected displays from being auto-enabled" into main

parents 22407da4 04a4d960
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -215,10 +215,7 @@ class ExternalDisplayPolicy {

        mExternalDisplayStatsService.onDisplayConnected(logicalDisplay);

        if (((Build.IS_ENG || Build.IS_USERDEBUG)
                        && SystemProperties.getBoolean(ENABLE_ON_CONNECT, false))
                || (mFlags.isDisplayContentModeManagementEnabled()
                        && logicalDisplay.canHostTasksLocked())) {
        if (shouldAutoEnable(logicalDisplay)) {
            Slog.w(TAG, "External display is enabled by default, bypassing user consent.");
            mInjector.sendExternalDisplayEventLocked(logicalDisplay, EVENT_DISPLAY_CONNECTED);
            return;
@@ -287,6 +284,18 @@ class ExternalDisplayPolicy {
        }
    }

    private boolean shouldAutoEnable(LogicalDisplay logicalDisplay) {
        if ((Build.IS_ENG || Build.IS_USERDEBUG)
                && SystemProperties.getBoolean(ENABLE_ON_CONNECT, false)) return true;

        // If using the new connection dialog, then don't auto enable displays so the dialog
        // has a reason to show
        if (mFlags.isUpdatedDisplayConnectionDialogEnabled()) return false;

        return mFlags.isDisplayContentModeManagementEnabled()
                && logicalDisplay.canHostTasksLocked();
    }

    @GuardedBy("mSyncRoot")
    private void disableExternalDisplayLocked(@NonNull final LogicalDisplay logicalDisplay) {
        if (!isExternalDisplayLocked(logicalDisplay)) {
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.display.feature;

import static com.android.window.flags.Flags.FLAG_ENABLE_UPDATED_DISPLAY_CONNECTION_DIALOG;

import android.content.Context;
import android.os.Build;
import android.os.SystemProperties;
@@ -245,6 +247,11 @@ public class DisplayManagerFlags {
            DesktopExperienceFlags.ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT::isTrue
    );

    private final FlagState mEnableUpdatedDisplayConnectionDialogFlagState = new FlagState(
            FLAG_ENABLE_UPDATED_DISPLAY_CONNECTION_DIALOG,
            DesktopExperienceFlags.ENABLE_UPDATED_DISPLAY_CONNECTION_DIALOG::isTrue
    );

    private final FlagState mSubscribeGranularDisplayEvents = new FlagState(
            Flags.FLAG_SUBSCRIBE_GRANULAR_DISPLAY_EVENTS,
            Flags::subscribeGranularDisplayEvents
@@ -582,6 +589,10 @@ public class DisplayManagerFlags {
        return mEnableDisplayContentModeManagementFlagState.isEnabled();
    }

    public boolean isUpdatedDisplayConnectionDialogEnabled() {
        return mEnableUpdatedDisplayConnectionDialogFlagState.isEnabled();
    }

    /**
     * @return {@code true} if the flag for subscribing to granular display events is enabled
     */
@@ -726,6 +737,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mModeSwitchWithoutSaving);
        pw.println(" " + mEnsureColorFadeWhenTurningOn);
        pw.println(" " + mIsOnDisplayAddedInObserverEnabled);
        pw.println(" " + mEnableUpdatedDisplayConnectionDialogFlagState);
    }

    private static class FlagState {
+10 −0
Original line number Diff line number Diff line
@@ -265,6 +265,16 @@ public class ExternalDisplayPolicyTest {
                .onHighTemperatureExternalDisplayNotAllowed();
    }

    @Test
    public void testExternalDisplayNoLongerAutoEnabledWithUpdatedDialogFlag() {
        when(mMockedFlags.isDisplayContentModeManagementEnabled()).thenReturn(true);
        when(mMockedFlags.isUpdatedDisplayConnectionDialogEnabled()).thenReturn(true);
        when(mMockedLogicalDisplay.canHostTasksLocked()).thenReturn(true);
        mExternalDisplayPolicy.handleExternalDisplayConnectedLocked(mMockedLogicalDisplay);
        assertNotAskedToEnableDisplay();
        verify(mMockedExternalDisplayStatsService, never()).onDisplayConnected(any());
    }

    @Test
    public void testOnCriticalTemperature_disallowAndAllowExternalDisplay() throws RemoteException {
        final var thermalListener = registerThermalListener();