summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Reynolds <juliacr@google.com>2023-12-27 11:26:49 -0500
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-08 05:19:51 +0000
commitffd616dc3b919fe7705dbc7a25868483ae45466b (patch)
tree5c43d2ca0f67ce0b0d0d3ccd1f1150aa81152eb4
parent6beb68ca17d1220f3f09a53cf0a0c541db4ead62 (diff)
downloadbase-ffd616dc3b919fe7705dbc7a25868483ae45466b.tar.gz
Don't store invalid pkgs when migrating filters
Test: NotificationManagerServiceTest Test: call method from test app, view policy xml file Flag: none Bug: 305926929 (cherry picked from commit bfa04e208995b05eee2a5336667f4e2dcd19fd30) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:85ccbd33e3766bbd22ced332cb5b9e983c2707db) Merged-In: Ib7fcb733edd2cf2cbac0a7699763a5fe993b467e Change-Id: Ib7fcb733edd2cf2cbac0a7699763a5fe993b467e
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java6
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java35
2 files changed, 39 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 647087de1c04..d997c8940b2f 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -4809,8 +4809,10 @@ public class NotificationManagerService extends SystemService {
for (int userId : mUm.getProfileIds(info.userid, false)) {
try {
int uid = getUidForPackageAndUser(pkg, UserHandle.of(userId));
- VersionedPackage vp = new VersionedPackage(pkg, uid);
- nlf.addPackage(vp);
+ if (uid != INVALID_UID) {
+ VersionedPackage vp = new VersionedPackage(pkg, uid);
+ nlf.addPackage(vp);
+ }
} catch (Exception e) {
// pkg doesn't exist on that user; skip
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 86d2b2fc6b56..c31d0d778025 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -99,6 +99,7 @@ import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Matchers.anyBoolean;
@@ -10249,6 +10250,40 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
}
@Test
+ public void testMigrateNotificationFilter_invalidPackage() throws Exception {
+ int[] userIds = new int[] {mUserId, 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
public void testMigrateNotificationFilter_noPreexistingFilter() throws Exception {
int[] userIds = new int[] {mUserId};
when(mUm.getProfileIds(anyInt(), anyBoolean())).thenReturn(userIds);