Loading services/core/java/com/android/server/notification/NotificationManagerService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -4685,8 +4685,10 @@ public class NotificationManagerService extends SystemService { for (int userId : mUm.getProfileIds(info.userid, false)) { for (int userId : mUm.getProfileIds(info.userid, false)) { try { try { int uid = getUidForPackageAndUser(pkg, UserHandle.of(userId)); int uid = getUidForPackageAndUser(pkg, UserHandle.of(userId)); if (uid != INVALID_UID) { VersionedPackage vp = new VersionedPackage(pkg, uid); VersionedPackage vp = new VersionedPackage(pkg, uid); nlf.addPackage(vp); nlf.addPackage(vp); } } catch (Exception e) { } catch (Exception e) { // pkg doesn't exist on that user; skip // pkg doesn't exist on that user; skip } } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +35 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,7 @@ import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static junit.framework.Assert.fail; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyBoolean; Loading Loading @@ -9389,6 +9390,40 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertTrue(captor.getValue().isPackageAllowed(new VersionedPackage("apples", 10000))); assertTrue(captor.getValue().isPackageAllowed(new VersionedPackage("apples", 10000))); } } @Test public void testMigrateNotificationFilter_invalidPackage() throws Exception { int[] userIds = new int[] {UserHandle.getUserId(mUid), 1000}; when(mUm.getProfileIds(anyInt(), anyBoolean())).thenReturn(userIds); List<String> disallowedApps = ImmutableList.of("apples", "bananas", "cherries"); for (int userId : userIds) { when(mPackageManager.getPackageUid("apples", 0, userId)).thenThrow( new RemoteException("")); when(mPackageManager.getPackageUid("bananas", 0, userId)).thenReturn(9000); when(mPackageManager.getPackageUid("cherries", 0, userId)).thenReturn(9001); } when(mListeners.getNotificationListenerFilter(any())).thenReturn( new NotificationListenerFilter()); mBinderService.migrateNotificationFilter(null, FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ONGOING, disallowedApps); ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class); verify(mListeners).setNotificationListenerFilter(any(), captor.capture()); assertEquals(FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ONGOING, captor.getValue().getTypes()); // valid values stay assertFalse(captor.getValue().isPackageAllowed(new VersionedPackage("bananas", 9000))); assertFalse(captor.getValue().isPackageAllowed(new VersionedPackage("cherries", 9001))); // don't store invalid values for (VersionedPackage vp : captor.getValue().getDisallowedPackages()) { assertNotEquals("apples", vp.getPackageName()); } } @Test @Test public void testMigrateNotificationFilter_noPreexistingFilter() throws Exception { public void testMigrateNotificationFilter_noPreexistingFilter() throws Exception { int[] userIds = new int[] {UserHandle.getUserId(mUid)}; int[] userIds = new int[] {UserHandle.getUserId(mUid)}; Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +4 −2 Original line number Original line Diff line number Diff line Loading @@ -4685,8 +4685,10 @@ public class NotificationManagerService extends SystemService { for (int userId : mUm.getProfileIds(info.userid, false)) { for (int userId : mUm.getProfileIds(info.userid, false)) { try { try { int uid = getUidForPackageAndUser(pkg, UserHandle.of(userId)); int uid = getUidForPackageAndUser(pkg, UserHandle.of(userId)); if (uid != INVALID_UID) { VersionedPackage vp = new VersionedPackage(pkg, uid); VersionedPackage vp = new VersionedPackage(pkg, uid); nlf.addPackage(vp); nlf.addPackage(vp); } } catch (Exception e) { } catch (Exception e) { // pkg doesn't exist on that user; skip // pkg doesn't exist on that user; skip } } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +35 −0 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,7 @@ import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static junit.framework.Assert.fail; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertThrows; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyBoolean; Loading Loading @@ -9389,6 +9390,40 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertTrue(captor.getValue().isPackageAllowed(new VersionedPackage("apples", 10000))); assertTrue(captor.getValue().isPackageAllowed(new VersionedPackage("apples", 10000))); } } @Test public void testMigrateNotificationFilter_invalidPackage() throws Exception { int[] userIds = new int[] {UserHandle.getUserId(mUid), 1000}; when(mUm.getProfileIds(anyInt(), anyBoolean())).thenReturn(userIds); List<String> disallowedApps = ImmutableList.of("apples", "bananas", "cherries"); for (int userId : userIds) { when(mPackageManager.getPackageUid("apples", 0, userId)).thenThrow( new RemoteException("")); when(mPackageManager.getPackageUid("bananas", 0, userId)).thenReturn(9000); when(mPackageManager.getPackageUid("cherries", 0, userId)).thenReturn(9001); } when(mListeners.getNotificationListenerFilter(any())).thenReturn( new NotificationListenerFilter()); mBinderService.migrateNotificationFilter(null, FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ONGOING, disallowedApps); ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class); verify(mListeners).setNotificationListenerFilter(any(), captor.capture()); assertEquals(FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ONGOING, captor.getValue().getTypes()); // valid values stay assertFalse(captor.getValue().isPackageAllowed(new VersionedPackage("bananas", 9000))); assertFalse(captor.getValue().isPackageAllowed(new VersionedPackage("cherries", 9001))); // don't store invalid values for (VersionedPackage vp : captor.getValue().getDisallowedPackages()) { assertNotEquals("apples", vp.getPackageName()); } } @Test @Test public void testMigrateNotificationFilter_noPreexistingFilter() throws Exception { public void testMigrateNotificationFilter_noPreexistingFilter() throws Exception { int[] userIds = new int[] {UserHandle.getUserId(mUid)}; int[] userIds = new int[] {UserHandle.getUserId(mUid)}; Loading