Loading services/core/java/com/android/server/notification/NotificationManagerService.java +12 −9 Original line number Diff line number Diff line Loading @@ -3815,7 +3815,9 @@ public class NotificationManagerService extends SystemService { enforceDeletingChannelHasNoFgService(pkg, callingUser, channelId); cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, callingUser, REASON_CHANNEL_REMOVED, null); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); boolean previouslyExisted = mPreferencesHelper.deleteNotificationChannel( pkg, callingUid, channelId); if (previouslyExisted) { // Remove from both recent notification archive and notification history mArchive.removeChannelNotifications(pkg, callingUser, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); Loading @@ -3825,6 +3827,7 @@ public class NotificationManagerService extends SystemService { NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); } } @Override public NotificationChannelGroup getNotificationChannelGroup(String pkg, String groupId) { Loading services/core/java/com/android/server/notification/PreferencesHelper.java +7 −4 Original line number Diff line number Diff line Loading @@ -1126,20 +1126,21 @@ public class PreferencesHelper implements RankingConfig { } @Override public void deleteNotificationChannel(String pkg, int uid, String channelId) { public boolean deleteNotificationChannel(String pkg, int uid, String channelId) { synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { return; return false; } NotificationChannel channel = r.channels.get(channelId); if (channel != null) { deleteNotificationChannelLocked(channel, pkg, uid); return deleteNotificationChannelLocked(channel, pkg, uid); } return false; } } private void deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) { private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) { if (!channel.isDeleted()) { channel.setDeleted(true); channel.setDeletedTimeMs(System.currentTimeMillis()); Loading @@ -1151,7 +1152,9 @@ public class PreferencesHelper implements RankingConfig { if (mAreChannelsBypassingDnd && channel.canBypassDnd()) { updateChannelsBypassingDnd(); } return true; } return false; } @Override Loading services/core/java/com/android/server/notification/RankingConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ public interface RankingConfig { NotificationChannel getConversationNotificationChannel(String pkg, int uid, String channelId, String conversationId, boolean returnParentIfNoConversationChannel, boolean includeDeleted); void deleteNotificationChannel(String pkg, int uid, String channelId); boolean deleteNotificationChannel(String pkg, int uid, String channelId); void permanentlyDeleteNotificationChannel(String pkg, int uid, String channelId); void permanentlyDeleteNotificationChannels(String pkg, int uid); ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid, Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.ActivityManager; Loading Loading @@ -2425,6 +2426,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); when(mPreferencesHelper.deleteNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()))).thenReturn(true); reset(mListeners); mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG), Loading @@ -2432,6 +2435,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelOnlyDoExtraWorkIfExisted() throws Exception { List<String> associations = new ArrayList<>(); associations.add("a"); when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid))) .thenReturn(associations); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(null); reset(mListeners); mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); verifyNoMoreInteractions(mListeners); verifyNoMoreInteractions(mHistoryManager); } @Test public void testDeleteChannelGroupNotifyListener() throws Exception { List<String> associations = new ArrayList<>(); Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -3332,6 +3332,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, "id", true)); } @Test public void testDeleted_twice() throws Exception { mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false); assertTrue(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); assertFalse(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); } @Test public void testDeleted_recentTime() throws Exception { mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +12 −9 Original line number Diff line number Diff line Loading @@ -3815,7 +3815,9 @@ public class NotificationManagerService extends SystemService { enforceDeletingChannelHasNoFgService(pkg, callingUser, channelId); cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, callingUser, REASON_CHANNEL_REMOVED, null); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); boolean previouslyExisted = mPreferencesHelper.deleteNotificationChannel( pkg, callingUid, channelId); if (previouslyExisted) { // Remove from both recent notification archive and notification history mArchive.removeChannelNotifications(pkg, callingUser, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); Loading @@ -3825,6 +3827,7 @@ public class NotificationManagerService extends SystemService { NOTIFICATION_CHANNEL_OR_GROUP_DELETED); handleSavePolicyFile(); } } @Override public NotificationChannelGroup getNotificationChannelGroup(String pkg, String groupId) { Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +7 −4 Original line number Diff line number Diff line Loading @@ -1126,20 +1126,21 @@ public class PreferencesHelper implements RankingConfig { } @Override public void deleteNotificationChannel(String pkg, int uid, String channelId) { public boolean deleteNotificationChannel(String pkg, int uid, String channelId) { synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { return; return false; } NotificationChannel channel = r.channels.get(channelId); if (channel != null) { deleteNotificationChannelLocked(channel, pkg, uid); return deleteNotificationChannelLocked(channel, pkg, uid); } return false; } } private void deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) { private boolean deleteNotificationChannelLocked(NotificationChannel channel, String pkg, int uid) { if (!channel.isDeleted()) { channel.setDeleted(true); channel.setDeletedTimeMs(System.currentTimeMillis()); Loading @@ -1151,7 +1152,9 @@ public class PreferencesHelper implements RankingConfig { if (mAreChannelsBypassingDnd && channel.canBypassDnd()) { updateChannelsBypassingDnd(); } return true; } return false; } @Override Loading
services/core/java/com/android/server/notification/RankingConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ public interface RankingConfig { NotificationChannel getConversationNotificationChannel(String pkg, int uid, String channelId, String conversationId, boolean returnParentIfNoConversationChannel, boolean includeDeleted); void deleteNotificationChannel(String pkg, int uid, String channelId); boolean deleteNotificationChannel(String pkg, int uid, String channelId); void permanentlyDeleteNotificationChannel(String pkg, int uid, String channelId); void permanentlyDeleteNotificationChannels(String pkg, int uid); ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid, Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import android.app.ActivityManager; Loading Loading @@ -2425,6 +2426,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); when(mPreferencesHelper.deleteNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()))).thenReturn(true); reset(mListeners); mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG), Loading @@ -2432,6 +2435,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelOnlyDoExtraWorkIfExisted() throws Exception { List<String> associations = new ArrayList<>(); associations.add("a"); when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid))) .thenReturn(associations); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(null); reset(mListeners); mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); verifyNoMoreInteractions(mListeners); verifyNoMoreInteractions(mHistoryManager); } @Test public void testDeleteChannelGroupNotifyListener() throws Exception { List<String> associations = new ArrayList<>(); Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -3332,6 +3332,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertNull(mHelper.getNotificationChannel(PKG_O, UID_O, "id", true)); } @Test public void testDeleted_twice() throws Exception { mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false); assertTrue(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); assertFalse(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); } @Test public void testDeleted_recentTime() throws Exception { mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger, Loading