Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -884,6 +884,8 @@ public class NotificationManagerService extends SystemService { } else if (action.equals(Intent.ACTION_USER_REMOVED)) { final int user = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); mZenModeHelper.onUserRemoved(user); mRankingHelper.onUserRemoved(user); savePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int user = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); mConditionProviders.onUserUnlocked(user); Loading services/core/java/com/android/server/notification/RankingHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -1040,6 +1040,18 @@ public class RankingHelper implements RankingConfig { return packageChannels; } public void onUserRemoved(int userId) { synchronized (mRecords) { int N = mRecords.size(); for (int i = N - 1; i >= 0 ; i--) { Record record = mRecords.valueAt(i); if (UserHandle.getUserId(record.uid) == userId) { mRecords.removeAt(i); } } } } public void onPackagesChanged(boolean removingPackage, int changeUserId, String[] pkgList, int[] uidList) { if (pkgList == null || pkgList.length == 0) { Loading services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -842,6 +842,36 @@ public class RankingHelperTest { assertEquals(1, mHelper.getNotificationChannelGroups(PKG, UID).size()); } @Test public void testOnUserRemoved() throws Exception { int[] user0Uids = {98, 235, 16, 3782}; int[] user1Uids = new int[user0Uids.length]; for (int i = 0; i < user0Uids.length; i++) { user1Uids[i] = UserHandle.PER_USER_RANGE + user0Uids[i]; final ApplicationInfo legacy = new ApplicationInfo(); legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(legacy); // create records with the default channel for all user 0 and user 1 uids mHelper.getImportance(PKG, user0Uids[i]); mHelper.getImportance(PKG, user1Uids[i]); } mHelper.onUserRemoved(1); // user 0 records remain for (int i = 0; i < user0Uids.length; i++) { assertEquals(1, mHelper.getNotificationChannels(PKG, user0Uids[i], false).getList().size()); } // user 1 records are gone for (int i = 0; i < user1Uids.length; i++) { assertEquals(0, mHelper.getNotificationChannels(PKG, user1Uids[i], false).getList().size()); } } @Test public void testOnPackageChanged_packageRemoval() throws Exception { // Deleted Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −0 Original line number Diff line number Diff line Loading @@ -884,6 +884,8 @@ public class NotificationManagerService extends SystemService { } else if (action.equals(Intent.ACTION_USER_REMOVED)) { final int user = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); mZenModeHelper.onUserRemoved(user); mRankingHelper.onUserRemoved(user); savePolicyFile(); } else if (action.equals(Intent.ACTION_USER_UNLOCKED)) { final int user = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); mConditionProviders.onUserUnlocked(user); Loading
services/core/java/com/android/server/notification/RankingHelper.java +12 −0 Original line number Diff line number Diff line Loading @@ -1040,6 +1040,18 @@ public class RankingHelper implements RankingConfig { return packageChannels; } public void onUserRemoved(int userId) { synchronized (mRecords) { int N = mRecords.size(); for (int i = N - 1; i >= 0 ; i--) { Record record = mRecords.valueAt(i); if (UserHandle.getUserId(record.uid) == userId) { mRecords.removeAt(i); } } } } public void onPackagesChanged(boolean removingPackage, int changeUserId, String[] pkgList, int[] uidList) { if (pkgList == null || pkgList.length == 0) { Loading
services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -842,6 +842,36 @@ public class RankingHelperTest { assertEquals(1, mHelper.getNotificationChannelGroups(PKG, UID).size()); } @Test public void testOnUserRemoved() throws Exception { int[] user0Uids = {98, 235, 16, 3782}; int[] user1Uids = new int[user0Uids.length]; for (int i = 0; i < user0Uids.length; i++) { user1Uids[i] = UserHandle.PER_USER_RANGE + user0Uids[i]; final ApplicationInfo legacy = new ApplicationInfo(); legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(legacy); // create records with the default channel for all user 0 and user 1 uids mHelper.getImportance(PKG, user0Uids[i]); mHelper.getImportance(PKG, user1Uids[i]); } mHelper.onUserRemoved(1); // user 0 records remain for (int i = 0; i < user0Uids.length; i++) { assertEquals(1, mHelper.getNotificationChannels(PKG, user0Uids[i], false).getList().size()); } // user 1 records are gone for (int i = 0; i < user1Uids.length; i++) { assertEquals(0, mHelper.getNotificationChannels(PKG, user1Uids[i], false).getList().size()); } } @Test public void testOnPackageChanged_packageRemoval() throws Exception { // Deleted Loading