Merge "Check group channels for FGSes" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a70be49294
@@ -2686,7 +2686,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) {
|
||||
Objects.requireNonNull(group);
|
||||
Objects.requireNonNull(pkg);
|
||||
@@ -3734,7 +3734,8 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
final int callingUid = Binder.getCallingUid();
|
||||
NotificationChannelGroup groupToDelete =
|
||||
mPreferencesHelper.getNotificationChannelGroup(groupId, pkg, callingUid);
|
||||
mPreferencesHelper.getNotificationChannelGroupWithChannels(
|
||||
pkg, callingUid, groupId, false);
|
||||
if (groupToDelete != null) {
|
||||
// Preflight for allowability
|
||||
final int userId = UserHandle.getUserId(callingUid);
|
||||
|
||||
@@ -93,6 +93,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.AlarmManager;
|
||||
@@ -221,12 +222,15 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
@SuppressLint("GuardedBy") // It's ok for this test to access guarded methods from the service.
|
||||
public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
|
||||
private static final int UID_HEADLESS = 1000000;
|
||||
@@ -2440,7 +2444,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
.thenReturn(associations);
|
||||
NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c");
|
||||
mService.setPreferencesHelper(mPreferencesHelper);
|
||||
when(mPreferencesHelper.getNotificationChannelGroup(eq(ncg.getId()), eq(PKG), anyInt()))
|
||||
when(mPreferencesHelper.getNotificationChannelGroupWithChannels(
|
||||
eq(PKG), anyInt(), eq(ncg.getId()), anyBoolean()))
|
||||
.thenReturn(ncg);
|
||||
reset(mListeners);
|
||||
mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId());
|
||||
@@ -2449,6 +2454,56 @@ 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, UserHandle.getUserId(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.setPreferencesHelper(mPreferencesHelper);
|
||||
|
||||
Reference in New Issue
Block a user