summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kurt Dresner <kdresner@google.com> 2021-04-27 16:26:02 +0000
committer Kurt Dresner <kdresner@google.com> 2021-04-27 21:05:47 +0000
commit2a79b677cb514116689c3f1514445249030cff52 (patch)
tree1c21783d4f11df46d601764c39a6d29b12ea3747
parent7c8f0cb884ebe7aabb199f0d4d79c0092ae6feaf (diff)
Update UiModeManagerServiceTest to use new value of PROJECTION_TYPE_ALL.
Bug: 175130323 Bug: 186462292 Change-Id: I1e6c197f801f217bfb9421c1e2a18e3d38cdaa8e
-rw-r--r--services/core/java/com/android/server/UiModeManagerService.java4
-rw-r--r--services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java33
2 files changed, 20 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
index d8af01eb7bda..ab3060ae4bce 100644
--- a/services/core/java/com/android/server/UiModeManagerService.java
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -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.");
}
}
diff --git a/services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java
index 4df469e79814..81c237b8ccac 100644
--- a/services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/UiModeManagerServiceTest.java
@@ -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;