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

Commit 2257c467 authored by Lingyu Feng's avatar Lingyu Feng
Browse files

Notify DisplayTopology when shouldShowSystemDecors changes

Bug: 384013689
Bug: 397586907
Test: adb shell settings put secure mirror_built_in_display {1|0}
Flag: com.android.server.display.feature.flags.enable_display_content_mode_management
Change-Id: Idbb9ccc87c37e3a54203eb4880ac34628efa1ebb
parent 083631bf
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -3262,12 +3262,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            Slog.e(TAG, "ShouldShowSystemDecors shouldn't be updated when the flag is off.");
        }

        final boolean shouldShowContent;
        if (!allowContentModeSwitch()) {
            return;
        }
        shouldShowContent = mDisplay.canHostTasks();

        final boolean shouldShowContent = mDisplay.canHostTasks();
        if (shouldShowContent == mWmService.mDisplayWindowSettings
                .shouldShowSystemDecorsLocked(this)) {
            return;
@@ -3277,6 +3276,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (!shouldShowContent) {
            clearAllTasksOnDisplay(null /* clearTasksCallback */, false /* isRemovingDisplay */);
        }

        // If the display is allowed to show content, then it belongs to the display topology;
        // vice versa.
        mWmService.mDisplayManagerInternal.onDisplayBelongToTopologyChanged(mDisplayId,
                /* inTopology= */ shouldShowContent);
    }

     /**
@@ -3295,6 +3299,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            return false;
        }

        if (shouldNeverShowSystemDecorations()) {
            return false;
        }

        // TODO(b/391965805): Remove this after introducing FLAG_ALLOW_CONTENT_MODE_SWITCH.
        if ((mDisplay.getFlags() & Display.FLAG_REAR) != 0) {
            return false;
@@ -5659,16 +5667,23 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return type == TRANSIT_OPEN || type == TRANSIT_TO_FRONT;
    }

    /**
     * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
     */
    boolean isSystemDecorationsSupported() {
    private boolean shouldNeverShowSystemDecorations() {
        if (mDisplayId == mWmService.mVr2dDisplayId) {
            // VR virtual display will be used to run and render 2D app within a VR experience.
            return false;
            return true;
        }
        if (!isTrusted()) {
            // Do not show system decorations on untrusted virtual display.
            return true;
        }
        return false;
    }

    /**
     * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
     */
    boolean isSystemDecorationsSupported() {
        if (shouldNeverShowSystemDecorations()) {
            return false;
        }
        if (mWmService.mDisplayWindowSettings.shouldShowSystemDecorsLocked(this)
+5 −0
Original line number Diff line number Diff line
@@ -240,6 +240,11 @@ class DisplayWindowSettings {
        mSettingsProvider.updateOverrideSettings(displayInfo, overrideSettings);
    }

    /**
     * Returns {@code true} if either the display is the default display, or the display is allowed
     * to dynamically add/remove system decorations and the system decorations should be shown on it
     * currently.
     */
    boolean shouldShowSystemDecorsLocked(@NonNull DisplayContent dc) {
        if (dc.getDisplayId() == Display.DEFAULT_DISPLAY) {
            // Default display should show system decors.
+11 −5
Original line number Diff line number Diff line
@@ -2772,13 +2772,19 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                return;
            }

            if (ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT.isTrue()
                    && display.allowContentModeSwitch()) {
            if (ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT.isTrue()) {
                if (display.allowContentModeSwitch()) {
                    mWindowManager.mDisplayWindowSettings
                            .setShouldShowSystemDecorsInternalLocked(display,
                                    display.mDisplay.canHostTasks());
                }

                final boolean inTopology = mWindowManager.mDisplayWindowSettings
                        .shouldShowSystemDecorsLocked(display);
                mWmService.mDisplayManagerInternal.onDisplayBelongToTopologyChanged(displayId,
                        inTopology);
            }

            startSystemDecorations(display, "displayAdded");

            // Drop any cached DisplayInfos associated with this display id - the values are now
+19 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.window.DisplayAreaOrganizer.FEATURE_VENDOR_FIRST;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.display.feature.flags.Flags.FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT;
import static com.android.server.wm.ActivityRecord.State.FINISHING;
import static com.android.server.wm.ActivityRecord.State.PAUSED;
import static com.android.server.wm.ActivityRecord.State.PAUSING;
@@ -82,6 +83,7 @@ import android.os.UserHandle;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.Presubmit;
import android.util.Pair;
import android.view.DisplayInfo;

import androidx.test.filters.MediumTest;

@@ -1379,6 +1381,23 @@ public class RootWindowContainerTests extends WindowTestsBase {
        verify(controller, never()).notifyTaskProfileLocked(any(), anyInt());
    }

    @EnableFlags(FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT)
    @Test
    public void testOnDisplayBelongToTopologyChanged() {
        final DisplayInfo displayInfo = new DisplayInfo();
        displayInfo.copyFrom(mDisplayInfo);
        displayInfo.displayId = DEFAULT_DISPLAY + 1;
        final DisplayContent dc = createNewDisplay(displayInfo);
        final int displayId = dc.getDisplayId();

        doReturn(dc).when(mRootWindowContainer).getDisplayContentOrCreate(displayId);
        doReturn(true).when(mWm.mDisplayWindowSettings).shouldShowSystemDecorsLocked(dc);

        mRootWindowContainer.onDisplayAdded(displayId);
        verify(mWm.mDisplayManagerInternal, times(1)).onDisplayBelongToTopologyChanged(anyInt(),
                anyBoolean());
    }

    /**
     * Mock {@link RootWindowContainer#resolveHomeActivity} for returning consistent activity
     * info for test cases.