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

Commit 8d5cd346 authored by Diego Vela's avatar Diego Vela
Browse files

Add display category for built in.

Add a category to get built in displays. A built in display is any
display that has the internal type.
Add a flag to guard the category.

Flag: com.android.server.display.feature.flags.display_category_built_in
Bug: 293651324
Test: atest CtsDisplayTestCases:DisplayManagerTest
Change-Id: I2d4f4de3bc34c11a8bf1b4649a0f354a96588c85
parent b11886a4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20784,6 +20784,7 @@ package android.hardware.display {
    method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler);
    method @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public void registerDisplayListener(@NonNull java.util.concurrent.Executor, long, @NonNull android.hardware.display.DisplayManager.DisplayListener);
    method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener);
    field @FlaggedApi("com.android.server.display.feature.flags.display_category_built_in") public static final String DISPLAY_CATEGORY_BUILT_IN_DISPLAYS = "android.hardware.display.category.BUILT_IN_DISPLAYS";
    field public static final String DISPLAY_CATEGORY_PRESENTATION = "android.hardware.display.category.PRESENTATION";
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_ADDED = 1L; // 0x1L
    field @FlaggedApi("com.android.server.display.feature.flags.display_listener_performance_improvements") public static final long EVENT_TYPE_DISPLAY_CHANGED = 4L; // 0x4L
+1 −0
Original line number Diff line number Diff line
@@ -1723,6 +1723,7 @@ package android.hardware.display {
    method @RequiresPermission(android.Manifest.permission.OVERRIDE_DISPLAY_MODE_REQUESTS) public void setShouldAlwaysRespectAppRequestedMode(boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setUserDisabledHdrTypes(@NonNull int[]);
    method @RequiresPermission(android.Manifest.permission.OVERRIDE_DISPLAY_MODE_REQUESTS) public boolean shouldAlwaysRespectAppRequestedMode();
    field public static final String DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED = "android.hardware.display.category.ALL_INCLUDING_DISABLED";
    field public static final String DISPLAY_CATEGORY_REAR = "android.hardware.display.category.REAR";
    field public static final String HDR_OUTPUT_CONTROL_FLAG = "enable_hdr_output_control";
    field public static final int SWITCHING_TYPE_ACROSS_AND_WITHIN_GROUPS = 2; // 0x2
+41 −3
Original line number Diff line number Diff line
@@ -145,6 +145,22 @@ public final class DisplayManager {
    public static final String DISPLAY_CATEGORY_PRESENTATION =
            "android.hardware.display.category.PRESENTATION";

    /**
     * Display category: Built in displays.
     *
     * <p>
     *     This category can be used to identify displays that are built into the device. The
     *     displays that are returned may be inactive or disabled at the current moment. The
     *     returned displays are useful in identifying the various sizes of built-in displays. The
     *     id from {@link Display#getDisplayId()} is not guaranteed to be stable and may change
     *     when the display becomes active.
     * </p>
     * @see #getDisplays(String)
     */
    @FlaggedApi(com.android.server.display.feature.flags.Flags.FLAG_DISPLAY_CATEGORY_BUILT_IN)
    public static final String DISPLAY_CATEGORY_BUILT_IN_DISPLAYS =
            "android.hardware.display.category.BUILT_IN_DISPLAYS";

    /**
     * Display category: Rear displays.
     * <p>
@@ -171,6 +187,8 @@ public final class DisplayManager {
     * @see #getDisplays(String)
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public static final String DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED =
            "android.hardware.display.category.ALL_INCLUDING_DISABLED";

@@ -729,10 +747,13 @@ public final class DisplayManager {
     * @see #DISPLAY_CATEGORY_PRESENTATION
     */
    public Display[] getDisplays(String category) {
        boolean includeDisabled = (category != null
                && category.equals(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED));
        boolean includeDisabled = shouldIncludeDisabledDisplays(category);
        final int[] displayIds = mGlobal.getDisplayIds(includeDisabled);
        if (DISPLAY_CATEGORY_PRESENTATION.equals(category)) {
        if (Flags.displayCategoryBuiltIn()
                && DISPLAY_CATEGORY_BUILT_IN_DISPLAYS.equals(category)) {
            Display[] value = getDisplays(displayIds, DisplayManager::isBuiltInDisplay);
            return value;
        } else if (DISPLAY_CATEGORY_PRESENTATION.equals(category)) {
            return getDisplays(displayIds, DisplayManager::isPresentationDisplay);
        } else if (DISPLAY_CATEGORY_REAR.equals(category)) {
            return getDisplays(displayIds, DisplayManager::isRearDisplay);
@@ -742,6 +763,16 @@ public final class DisplayManager {
        return new Display[0];
    }

    private boolean shouldIncludeDisabledDisplays(@Nullable String category) {
        if (DISPLAY_CATEGORY_BUILT_IN_DISPLAYS.equals(category)) {
            return true;
        }
        if (DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED.equals(category)) {
            return true;
        }
        return false;
    }

    private Display[] getDisplays(int[] displayIds, Predicate<Display> predicate) {
        ArrayList<Display> tmpDisplays = new ArrayList<>();
        for (int displayId : displayIds) {
@@ -753,6 +784,13 @@ public final class DisplayManager {
        return tmpDisplays.toArray(new Display[tmpDisplays.size()]);
    }

    private static boolean isBuiltInDisplay(@Nullable Display display) {
        if (display == null) {
            return false;
        }
        return display.getType() == Display.TYPE_INTERNAL;
    }

    private static boolean isPresentationDisplay(@Nullable Display display) {
        if (display == null || (display.getDisplayId() == DEFAULT_DISPLAY)
                || (display.getFlags() & Display.FLAG_PRESENTATION) == 0) {
+8 −0
Original line number Diff line number Diff line
@@ -501,3 +501,11 @@ flag {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "display_category_built_in"
    namespace: "display_manager"
    description: "Add a new category to get the built in displays."
    bug: "293651324"
    is_fixed_read_only: false
}