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

Commit 2a79b677 authored by Kurt Dresner's avatar Kurt Dresner
Browse files

Update UiModeManagerServiceTest to use new value of PROJECTION_TYPE_ALL.

Bug: 175130323
Bug: 186462292
Change-Id: I1e6c197f801f217bfb9421c1e2a18e3d38cdaa8e
parent 7c8f0cb8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1051,9 +1051,9 @@ final class UiModeManagerService extends SystemService {
    }

    private static void assertSingleProjectionType(@UiModeManager.ProjectionType int p) {
        // To be a single projection type it must be greater than zero and an exact power of two.
        // To be a single projection type it must be non-zero and an exact power of two.
        boolean projectionTypeIsPowerOfTwoOrZero = (p & p - 1) == 0;
        if (p <= 0 || !projectionTypeIsPowerOfTwoOrZero) {
        if (p == 0 || !projectionTypeIsPowerOfTwoOrZero) {
            throw new IllegalArgumentException("Must specify exactly one projection type.");
        }
    }
+18 −15
Original line number Diff line number Diff line
@@ -555,12 +555,13 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
    public void requestProjection() throws Exception {
        when(mPackageManager.getPackageUid(PACKAGE_NAME, 0)).thenReturn(TestInjector.CALLING_UID);
        // Should work for all powers of two.
        for (int p = 1; p < PROJECTION_TYPE_ALL; p = p * 2) {
            assertTrue(mService.requestProjection(mBinder, p, PACKAGE_NAME));
            assertTrue((mService.getActiveProjectionTypes() & p) != 0);
            assertThat(mService.getProjectingPackages(p), contains(PACKAGE_NAME));
        for (int i = 0; i < Integer.SIZE; ++i) {
            int projectionType = 1 << i;
            assertTrue(mService.requestProjection(mBinder, projectionType, PACKAGE_NAME));
            assertTrue((mService.getActiveProjectionTypes() & projectionType) != 0);
            assertThat(mService.getProjectingPackages(projectionType), contains(PACKAGE_NAME));
            // Subsequent calls should still succeed.
            assertTrue(mService.requestProjection(mBinder, p, PACKAGE_NAME));
            assertTrue(mService.requestProjection(mBinder, projectionType, PACKAGE_NAME));
        }
        assertEquals(PROJECTION_TYPE_ALL, mService.getActiveProjectionTypes());
    }
@@ -613,19 +614,17 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
    @Test
    public void releaseProjection() throws Exception {
        when(mPackageManager.getPackageUid(PACKAGE_NAME, 0)).thenReturn(TestInjector.CALLING_UID);
        // Should work for all powers of two.
        for (int p = 1; p < PROJECTION_TYPE_ALL; p = p * 2) {
            mService.requestProjection(mBinder, p, PACKAGE_NAME);
        }
        requestAllPossibleProjectionTypes();
        assertEquals(PROJECTION_TYPE_ALL, mService.getActiveProjectionTypes());

        assertTrue(mService.releaseProjection(PROJECTION_TYPE_AUTOMOTIVE, PACKAGE_NAME));
        int everythingButAutomotive = PROJECTION_TYPE_ALL & ~PROJECTION_TYPE_AUTOMOTIVE;
        assertEquals(everythingButAutomotive, mService.getActiveProjectionTypes());

        for (int p = 1; p < PROJECTION_TYPE_ALL; p = p * 2) {
            assertEquals(p != PROJECTION_TYPE_AUTOMOTIVE,
                    (boolean) mService.releaseProjection(p, PACKAGE_NAME));
        for (int i = 0; i < Integer.SIZE; ++i) {
            int projectionType = 1 << i;
            assertEquals(projectionType != PROJECTION_TYPE_AUTOMOTIVE,
                    (boolean) mService.releaseProjection(projectionType, PACKAGE_NAME));
        }

        assertEquals(PROJECTION_TYPE_NONE, mService.getActiveProjectionTypes());
@@ -634,9 +633,7 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
    @Test
    public void binderDeath_releasesProjection() throws Exception {
        when(mPackageManager.getPackageUid(PACKAGE_NAME, 0)).thenReturn(TestInjector.CALLING_UID);
        for (int p = 1; p < PROJECTION_TYPE_ALL; p = p * 2) {
            mService.requestProjection(mBinder, p, PACKAGE_NAME);
        }
        requestAllPossibleProjectionTypes();
        assertEquals(PROJECTION_TYPE_ALL, mService.getActiveProjectionTypes());
        ArgumentCaptor<IBinder.DeathRecipient> deathRecipientCaptor = ArgumentCaptor.forClass(
                IBinder.DeathRecipient.class);
@@ -814,6 +811,12 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
        verify(listener, never()).onProjectionStateChanged(anyInt(), any());
    }

    private void requestAllPossibleProjectionTypes() throws RemoteException {
        for (int i = 0; i < Integer.SIZE; ++i) {
            mService.requestProjection(mBinder, 1 << i, PACKAGE_NAME);
        }
    }

    private static class TestInjector extends UiModeManagerService.Injector {
        private static final int CALLING_UID = 8675309;