Loading services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1775,7 +1775,7 @@ public class NotificationManagerService extends SystemService { } } private void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromApp, boolean fromListener) { Preconditions.checkNotNull(group); Preconditions.checkNotNull(pkg); Loading Loading @@ -2402,7 +2402,8 @@ public class NotificationManagerService extends SystemService { final int callingUid = Binder.getCallingUid(); NotificationChannelGroup groupToDelete = mRankingHelper.getNotificationChannelGroup(groupId, pkg, callingUid); mRankingHelper.getNotificationChannelGroupWithChannels( pkg, callingUid, groupId, false); if (groupToDelete != null) { // Preflight for allowability final int userId = UserHandle.getUserId(callingUid); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +54 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,8 @@ import com.android.server.notification.NotificationManagerService.NotificationAs import com.android.server.notification.NotificationManagerService.NotificationListeners; import com.android.server.pm.PackageManagerService; import com.google.common.collect.ImmutableList; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading @@ -144,6 +146,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; @SmallTest @RunWith(AndroidTestingRunner.class) Loading Loading @@ -1523,7 +1526,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations); NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c"); mService.setRankingHelper(mRankingHelper); when(mRankingHelper.getNotificationChannelGroup(eq(ncg.getId()), eq(PKG), anyInt())) when(mRankingHelper.getNotificationChannelGroupWithChannels( eq(PKG), anyInt(), eq(ncg.getId()), anyBoolean())) .thenReturn(ncg); reset(mListeners); mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId()); Loading @@ -1532,6 +1536,55 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelGroupChecksForFgses() throws Exception { List<String> associations = new ArrayList<>(); associations.add("a"); when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations); CountDownLatch latch = new CountDownLatch(2); mService.createNotificationChannelGroup( PKG, mUid, new NotificationChannelGroup("group", "group"), true, false); new Thread(() -> { NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("group"); ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); } catch (RemoteException e) { throw new RuntimeException(e); } latch.countDown(); }).start(); new Thread(() -> { try { synchronized (this) { wait(5000); } mService.createNotificationChannelGroup(PKG, mUid, new NotificationChannelGroup("new", "new group"), true, false); NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("new"); ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); mBinderService.deleteNotificationChannelGroup(PKG, "group"); } catch (RemoteException e) { throw new RuntimeException(e); } } catch (Exception e) { e.printStackTrace(); } latch.countDown(); }).start(); latch.await(); verify(mAmi).hasForegroundServiceNotification(anyString(), anyInt(), anyString()); } @Test public void testUpdateNotificationChannelFromPrivilegedListener_success() throws Exception { mService.setRankingHelper(mRankingHelper); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -1775,7 +1775,7 @@ public class NotificationManagerService extends SystemService { } } private void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromApp, boolean fromListener) { Preconditions.checkNotNull(group); Preconditions.checkNotNull(pkg); Loading Loading @@ -2402,7 +2402,8 @@ public class NotificationManagerService extends SystemService { final int callingUid = Binder.getCallingUid(); NotificationChannelGroup groupToDelete = mRankingHelper.getNotificationChannelGroup(groupId, pkg, callingUid); mRankingHelper.getNotificationChannelGroupWithChannels( pkg, callingUid, groupId, false); if (groupToDelete != null) { // Preflight for allowability final int userId = UserHandle.getUserId(callingUid); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +54 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,8 @@ import com.android.server.notification.NotificationManagerService.NotificationAs import com.android.server.notification.NotificationManagerService.NotificationListeners; import com.android.server.pm.PackageManagerService; import com.google.common.collect.ImmutableList; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading @@ -144,6 +146,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; @SmallTest @RunWith(AndroidTestingRunner.class) Loading Loading @@ -1523,7 +1526,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations); NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c"); mService.setRankingHelper(mRankingHelper); when(mRankingHelper.getNotificationChannelGroup(eq(ncg.getId()), eq(PKG), anyInt())) when(mRankingHelper.getNotificationChannelGroupWithChannels( eq(PKG), anyInt(), eq(ncg.getId()), anyBoolean())) .thenReturn(ncg); reset(mListeners); mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId()); Loading @@ -1532,6 +1536,55 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelGroupChecksForFgses() throws Exception { List<String> associations = new ArrayList<>(); associations.add("a"); when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations); CountDownLatch latch = new CountDownLatch(2); mService.createNotificationChannelGroup( PKG, mUid, new NotificationChannelGroup("group", "group"), true, false); new Thread(() -> { NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("group"); ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); } catch (RemoteException e) { throw new RuntimeException(e); } latch.countDown(); }).start(); new Thread(() -> { try { synchronized (this) { wait(5000); } mService.createNotificationChannelGroup(PKG, mUid, new NotificationChannelGroup("new", "new group"), true, false); NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("new"); ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); mBinderService.deleteNotificationChannelGroup(PKG, "group"); } catch (RemoteException e) { throw new RuntimeException(e); } } catch (Exception e) { e.printStackTrace(); } latch.countDown(); }).start(); latch.await(); verify(mAmi).hasForegroundServiceNotification(anyString(), anyInt(), anyString()); } @Test public void testUpdateNotificationChannelFromPrivilegedListener_success() throws Exception { mService.setRankingHelper(mRankingHelper); Loading