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

Commit 6ebe6396 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Make virtual displays never blank only if in default group

If a private non-mirror virtual display is not in the default
group (either its own or in a virtual device group), then it
already doesn't share the power state with the default display.

So we should not treat such displays as never blank because then
they can never be turned off, even if their power group is off.

Fix: 433644644
Bug: 421917324
Test: presubmit
Flag: EXEMPT bugfix
Change-Id: I41b8dba8efa3c03ad908bd25be5861e58eced628
parent 56a5da35
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
    @VisibleForTesting
    static final String UNIQUE_ID_PREFIX = "virtual:";

    // If any of these bits are set, the display is not in the default display group.
    private static final int VIRTUAL_DISPLAY_FLAGS_NON_DEFAULT_DISPLAY_GROUP =
            VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP | VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP;

    // Unique id suffix for virtual displays
    private static final AtomicInteger sNextUniqueIndex = new AtomicInteger(0);

@@ -318,9 +322,10 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
    }

    private static boolean isNeverBlank(int flags) {
        // Private non-mirror displays are never blank and always on.
        // Private non-mirror displays in the default display group are never blank and always on.
        return (flags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) == 0
                && (flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0;
                && (flags & VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0
                && (flags & VIRTUAL_DISPLAY_FLAGS_NON_DEFAULT_DISPLAY_GROUP) == 0;
    }

    private final class VirtualDisplayDevice extends DisplayDevice implements DeathRecipient {
+25 −0
Original line number Diff line number Diff line
@@ -371,6 +371,31 @@ public class VirtualDisplayAdapterTest {
        }
    }

    @Test
    public void ownDisplayGroup_notNeverBlank() {
        DisplayDevice device = mAdapter.createVirtualDisplayLocked(mMockCallback,
                /* projection= */ null, /* ownerUid= */ 10, /* packageName= */ "testpackage",
                "uniqueId", /* surface= */ mSurfaceMock,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP, mVirtualDisplayConfigMock);

        DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        assertThat(info.state).isEqualTo(Display.STATE_UNKNOWN);
        assertThat(info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK).isEqualTo(0);
    }

    @Test
    public void deviceDisplayGroup_notNeverBlank() {
        DisplayDevice device = mAdapter.createVirtualDisplayLocked(mMockCallback,
                /* projection= */ null, /* ownerUid= */ 10, /* packageName= */ "testpackage",
                "uniqueId", /* surface= */ mSurfaceMock,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_DEVICE_DISPLAY_GROUP,
                mVirtualDisplayConfigMock);

        DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
        assertThat(info.state).isEqualTo(Display.STATE_UNKNOWN);
        assertThat(info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK).isEqualTo(0);
    }

    @EnableFlags(
            android.companion.virtualdevice.flags.Flags.FLAG_CORRECT_VIRTUAL_DISPLAY_POWER_STATE)
    @Test