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

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

Introduce IWindowManager#isEligibleForDesktopMode()

The difference of this API and existing shouldShowSystemDecors(displayId) is:

- shouldShowSystemDecors(displayId) returns true for all the displays
  that should show system decors, including virtual displays enabled
  with FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS, which is not allowed to
  dynamically add / remove system decors.
- This new API return true if the display is either default display, or
  the display is allowed to dynamically add / remove system decors, and it
  should currently show system decors.

The client of this API will be WMShell, such as DesktopModeStatus and
DesktopDisplayModeController. This API will be used to check whether a
display is eligible for the desktop mode.

Bug: 400808149
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: I596fae668403f6490d5c27f333324ee073ff185f
parent 5f8775bb
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -699,7 +699,7 @@ interface IWindowManager
    /**
     * Indicates the display should show system decors.
     * <p>
     * System decors include status bar, navigation bar, launcher.
     * System decors include status bar, navigation bar, launcher, and wallpaper.
     * </p>
     *
     * @param displayId The id of the display.
@@ -718,6 +718,23 @@ interface IWindowManager
     */
    void setShouldShowSystemDecors(int displayId, boolean shouldShow);

    /**
     * Indicates that the display is eligible for the desktop mode from WindowManager's perspective.
     * This includes:
     * - The default display;
     * - Any display that is allowed to switch the content mode between extended and mirroring
     * (which means it can dynamically add or remove system decors), and it is now in extended mode
     * (should currently show system decors).
     * <p>
     * System decors include status bar, navigation bar, launcher, and wallpaper.
     * </p>
     *
     * @param displayId The id of the display.
     * @return {@code true} if the display is eligible for the desktop mode from WindowManager's
     * perspective.
     */
    boolean isEligibleForDesktopMode(int displayId);

    /**
     * Indicates the policy for how the display should show IME.
     *
+20 −0
Original line number Diff line number Diff line
@@ -7613,6 +7613,26 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    @Override
    public boolean isEligibleForDesktopMode(int displayId) {
        if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "isEligibleForDesktopMode()")) {
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }

        synchronized (mGlobalLock) {
            final DisplayContent displayContent = mRoot.getDisplayContent(displayId);
            if (displayContent == null) {
                ProtoLog.e(WM_ERROR, "Attempted to check isEligibleForDesktopMode() "
                        + "for a display that does not exist: %d", displayId);
                return false;
            }
            if (!displayContent.isSystemDecorationsSupported()) {
                return false;
            }
            return displayContent.isDefaultDisplay || displayContent.allowContentModeSwitch();
        }
    }

    @Override
    public void setShouldShowSystemDecors(int displayId, boolean shouldShow) {
        if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "setShouldShowSystemDecors()")) {