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

Commit f9f3e3e4 authored by Ashley Holton's avatar Ashley Holton
Browse files

Test getDisplayIdsByGroupsIds

Flag: TEST_ONLY
Bug: 370829939
Test: atest
DisplayManagerServiceTest#testGetDisplayIdsByGroupIds,
testGetDisplayIdsByGroupIds_noDisplays

Change-Id: Idcb78316c52f2a2f21888a099c2b7b211aae9922
parent e25e5692
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
@@ -1657,6 +1657,70 @@ public class DisplayManagerServiceTest {
        assertEquals(0, displayIds.length);
    }

    @Test
    public void testGetDisplayIdsByGroupsIds() throws Exception {
        DisplayManagerService displayManager = new DisplayManagerService(mContext, mBasicInjector);
        displayManager.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
        DisplayManagerInternal localService = displayManager.new LocalService();
        LogicalDisplayMapper logicalDisplayMapper = displayManager.getLogicalDisplayMapper();
        // Create display 1
        FakeDisplayDevice displayDevice1 =
                createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_INTERNAL);
        LogicalDisplay display1 = logicalDisplayMapper.getDisplayLocked(displayDevice1);
        final int groupId1 = display1.getDisplayInfoLocked().displayGroupId;
        // Create display 2
        FakeDisplayDevice displayDevice2 =
                createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_INTERNAL);
        LogicalDisplay display2 = logicalDisplayMapper.getDisplayLocked(displayDevice2);
        final int groupId2 = display2.getDisplayInfoLocked().displayGroupId;
        // Both displays should be in the same display group
        assertEquals(groupId1, groupId2);
        final int[] displayIds = new int[]{
                display1.getDisplayIdLocked(), display2.getDisplayIdLocked()};
        final SparseArray<int[]> expectedDisplayGroups = new SparseArray<>();
        expectedDisplayGroups.put(groupId1, displayIds);

        final SparseArray<int[]> displayGroups = localService.getDisplayIdsByGroupsIds();

        for (int i = 0; i < expectedDisplayGroups.size(); i++) {
            final int groupId = expectedDisplayGroups.keyAt(i);
            assertTrue(displayGroups.contains(groupId));
            assertArrayEquals(expectedDisplayGroups.get(groupId), displayGroups.get(groupId));
        }
    }

    @Test
    public void testGetDisplayIdsByGroupsIds_multipleDisplayGroups() throws Exception {
        DisplayManagerService displayManager = new DisplayManagerService(mContext, mBasicInjector);
        displayManager.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
        DisplayManagerInternal localService = displayManager.new LocalService();
        LogicalDisplayMapper logicalDisplayMapper = displayManager.getLogicalDisplayMapper();
        // Create display 1
        FakeDisplayDevice displayDevice1 =
                createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_INTERNAL);
        LogicalDisplay display1 = logicalDisplayMapper.getDisplayLocked(displayDevice1);
        final int groupId1 = display1.getDisplayInfoLocked().displayGroupId;
        // Create display 2
        FakeDisplayDevice displayDevice2 =
                createFakeDisplayDevice(displayManager, new float[]{60f}, Display.TYPE_EXTERNAL);
        LogicalDisplay display2 = logicalDisplayMapper.getDisplayLocked(displayDevice2);
        final int groupId2 = display2.getDisplayInfoLocked().displayGroupId;
        // Both displays should be in different display groups
        assertNotEquals(groupId1, groupId2);
        final SparseArray<int[]> expectedDisplayGroups = new SparseArray<>();
        expectedDisplayGroups.put(groupId1, new int[]{display1.getDisplayIdLocked()});
        expectedDisplayGroups.put(groupId2, new int[]{display2.getDisplayIdLocked()});

        final SparseArray<int[]> displayGroups = localService.getDisplayIdsByGroupsIds();

        assertEquals(expectedDisplayGroups.size(), displayGroups.size());
        for (int i = 0; i < expectedDisplayGroups.size(); i++) {
            final int groupId = expectedDisplayGroups.keyAt(i);
            assertTrue(displayGroups.contains(groupId));
            assertArrayEquals(expectedDisplayGroups.get(groupId), displayGroups.get(groupId));
        }
    }

    @Test
    public void testCreateVirtualDisplay_isValidProjection_notValid()
            throws RemoteException {