Merge "Check group channels for FGSes" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7005df1312
@@ -2478,7 +2478,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) {
|
boolean fromApp, boolean fromListener) {
|
||||||
Objects.requireNonNull(group);
|
Objects.requireNonNull(group);
|
||||||
Objects.requireNonNull(pkg);
|
Objects.requireNonNull(pkg);
|
||||||
@@ -3498,7 +3498,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
|
|
||||||
final int callingUid = Binder.getCallingUid();
|
final int callingUid = Binder.getCallingUid();
|
||||||
NotificationChannelGroup groupToDelete =
|
NotificationChannelGroup groupToDelete =
|
||||||
mPreferencesHelper.getNotificationChannelGroup(groupId, pkg, callingUid);
|
mPreferencesHelper.getNotificationChannelGroupWithChannels(
|
||||||
|
pkg, callingUid, groupId, false);
|
||||||
if (groupToDelete != null) {
|
if (groupToDelete != null) {
|
||||||
// Preflight for allowability
|
// Preflight for allowability
|
||||||
final int userId = UserHandle.getUserId(callingUid);
|
final int userId = UserHandle.getUserId(callingUid);
|
||||||
|
|||||||
63
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
Executable file → Normal file
63
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
Executable file → Normal file
@@ -179,6 +179,8 @@ import com.android.server.uri.UriGrantsManagerInternal;
|
|||||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||||
import com.android.server.wm.WindowManagerInternal;
|
import com.android.server.wm.WindowManagerInternal;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -202,6 +204,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
||||||
@@ -279,6 +282,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
AppOpsManager mAppOpsManager;
|
AppOpsManager mAppOpsManager;
|
||||||
@Mock
|
@Mock
|
||||||
|
ActivityManagerInternal mAmi;
|
||||||
|
@Mock
|
||||||
private TestableNotificationManagerService.NotificationAssistantAccessGrantedCallback
|
private TestableNotificationManagerService.NotificationAssistantAccessGrantedCallback
|
||||||
mNotificationAssistantAccessGrantedCallback;
|
mNotificationAssistantAccessGrantedCallback;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -418,7 +423,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
|
|
||||||
DeviceIdleInternal deviceIdleInternal = mock(DeviceIdleInternal.class);
|
DeviceIdleInternal deviceIdleInternal = mock(DeviceIdleInternal.class);
|
||||||
when(deviceIdleInternal.getNotificationWhitelistDuration()).thenReturn(3000L);
|
when(deviceIdleInternal.getNotificationWhitelistDuration()).thenReturn(3000L);
|
||||||
ActivityManagerInternal activityManagerInternal = mock(ActivityManagerInternal.class);
|
|
||||||
|
|
||||||
LocalServices.removeServiceForTest(UriGrantsManagerInternal.class);
|
LocalServices.removeServiceForTest(UriGrantsManagerInternal.class);
|
||||||
LocalServices.addService(UriGrantsManagerInternal.class, mUgmInternal);
|
LocalServices.addService(UriGrantsManagerInternal.class, mUgmInternal);
|
||||||
@@ -429,7 +433,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
LocalServices.removeServiceForTest(DeviceIdleInternal.class);
|
LocalServices.removeServiceForTest(DeviceIdleInternal.class);
|
||||||
LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal);
|
LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal);
|
||||||
LocalServices.removeServiceForTest(ActivityManagerInternal.class);
|
LocalServices.removeServiceForTest(ActivityManagerInternal.class);
|
||||||
LocalServices.addService(ActivityManagerInternal.class, activityManagerInternal);
|
LocalServices.addService(ActivityManagerInternal.class, mAmi);
|
||||||
mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager);
|
mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager);
|
||||||
|
|
||||||
|
|
||||||
@@ -506,7 +510,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
|
mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
|
||||||
mAppOpsManager, mUm, mHistoryManager, mStatsManager,
|
mAppOpsManager, mUm, mHistoryManager, mStatsManager,
|
||||||
mock(TelephonyManager.class),
|
mock(TelephonyManager.class),
|
||||||
mock(ActivityManagerInternal.class));
|
mAmi);
|
||||||
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
|
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
|
||||||
|
|
||||||
mService.setAudioManager(mAudioManager);
|
mService.setAudioManager(mAudioManager);
|
||||||
@@ -2473,7 +2477,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
.thenReturn(associations);
|
.thenReturn(associations);
|
||||||
NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c");
|
NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c");
|
||||||
mService.setPreferencesHelper(mPreferencesHelper);
|
mService.setPreferencesHelper(mPreferencesHelper);
|
||||||
when(mPreferencesHelper.getNotificationChannelGroup(eq(ncg.getId()), eq(PKG), anyInt()))
|
when(mPreferencesHelper.getNotificationChannelGroupWithChannels(
|
||||||
|
eq(PKG), anyInt(), eq(ncg.getId()), anyBoolean()))
|
||||||
.thenReturn(ncg);
|
.thenReturn(ncg);
|
||||||
reset(mListeners);
|
reset(mListeners);
|
||||||
mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId());
|
mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId());
|
||||||
@@ -2482,6 +2487,56 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED));
|
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
|
@Test
|
||||||
public void testUpdateNotificationChannelFromPrivilegedListener_success() throws Exception {
|
public void testUpdateNotificationChannelFromPrivilegedListener_success() throws Exception {
|
||||||
mService.setPreferencesHelper(mPreferencesHelper);
|
mService.setPreferencesHelper(mPreferencesHelper);
|
||||||
|
|||||||
Reference in New Issue
Block a user