summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java14
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java222
2 files changed, 145 insertions, 91 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index a9139adff4f9..b64e99168445 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2048,12 +2048,15 @@ public class NotificationManagerService extends SystemService {
mStripRemoteViewsSizeBytes = getContext().getResources().getInteger(
com.android.internal.R.integer.config_notificationStripRemoteViewSizeBytes);
- mMsgPkgsAllowedAsConvos = Set.of(
- getContext().getResources().getStringArray(
- com.android.internal.R.array.config_notificationMsgPkgsAllowedAsConvos));
+ mMsgPkgsAllowedAsConvos = Set.of(getStringArrayResource(
+ com.android.internal.R.array.config_notificationMsgPkgsAllowedAsConvos));
mStatsManager = statsManager;
}
+ protected String[] getStringArrayResource(int key) {
+ return getContext().getResources().getStringArray(key);
+ }
+
@Override
public void onStart() {
SnoozeHelper snoozeHelper = new SnoozeHelper(getContext(), (userId, r, muteOnReturn) -> {
@@ -2741,10 +2744,7 @@ public class NotificationManagerService extends SystemService {
}
protected void maybeRegisterMessageSent(NotificationRecord r) {
- Context appContext = r.getSbn().getPackageContext(getContext());
- Notification.Builder nb =
- Notification.Builder.recoverBuilder(appContext, r.getNotification());
- if (nb.getStyle() instanceof Notification.MessagingStyle) {
+ if (r.isConversation()) {
if (r.getShortcutInfo() != null) {
if (mPreferencesHelper.setValidMessageSent(
r.getSbn().getPackageName(), r.getUid())) {
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 9b8bb3592fc9..ef4d5db2f32f 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -348,6 +348,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
super.setNotificationAssistantAccessGrantedForUserInternal(assistant, userId, granted);
}
+ @Override
+ protected String[] getStringArrayResource(int key) {
+ return new String[] {PKG_O};
+ }
+
private void setNotificationAssistantAccessGrantedCallback(
@Nullable NotificationAssistantAccessGrantedCallback callback) {
this.mNotificationAssistantAccessGrantedCallback = callback;
@@ -435,7 +440,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// Setup managed services
mListener = mListeners.new ManagedServiceInfo(
- null, new ComponentName(PKG, "test_class"), mUid, true, null, 0);
+ null, new ComponentName(PKG, "test_class"),
+ UserHandle.getUserId(mUid), true, null, 0);
ComponentName defaultComponent = ComponentName.unflattenFromString("config/device");
ArraySet<ComponentName> components = new ArraySet<>();
components.add(defaultComponent);
@@ -445,7 +451,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.getDefaultComponents()).thenReturn(components);
when(mAssistants.queryPackageForServices(
anyString(), anyInt(), anyInt())).thenReturn(components);
- when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
+ when(mListeners.checkServiceTokenLocked(null)).thenReturn(mListener);
ManagedServices.Config listenerConfig = new ManagedServices.Config();
listenerConfig.xmlTag = NotificationListeners.TAG_ENABLED_NOTIFICATION_LISTENERS;
when(mListeners.getConfig()).thenReturn(listenerConfig);
@@ -498,6 +504,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mBinderService.createNotificationChannels(
PKG, new ParceledListSlice(Arrays.asList(mTestNotificationChannel)));
+ mBinderService.createNotificationChannels(
+ PKG_P, new ParceledListSlice(Arrays.asList(mTestNotificationChannel)));
+ mBinderService.createNotificationChannels(
+ PKG_O, new ParceledListSlice(Arrays.asList(mTestNotificationChannel)));
assertNotNull(mBinderService.getNotificationChannel(
PKG, mContext.getUserId(), PKG, TEST_CHANNEL_ID));
clearInvocations(mRankingHandler);
@@ -584,7 +594,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setGroupSummary(isSummary);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id,
"tag" + System.currentTimeMillis(), mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
return new NotificationRecord(mContext, sbn, channel);
}
@@ -604,7 +614,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nb.extend(extender);
}
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
return new NotificationRecord(mContext, sbn, channel);
}
@@ -636,7 +646,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb = getMessageStyleNotifBuilder(addMetadata, groupKey, isSummary);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id,
tag, mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
return new NotificationRecord(mContext, sbn, channel);
}
@@ -1689,7 +1699,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.build();
StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, null, mUid, 0,
- n, new UserHandle(mUid), null, 0);
+ n, UserHandle.getUserHandleForUid(mUid), null, 0);
sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE;
mBinderService.enqueueNotificationWithTag(PKG, PKG, null,
sbn.getId(), sbn.getNotification(), sbn.getUserId());
@@ -2193,7 +2203,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testCreateChannelNotifyListener() throws Exception {
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mService.setPreferencesHelper(mPreferencesHelper);
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
eq(mTestNotificationChannel.getId()), anyBoolean()))
@@ -2221,7 +2232,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testCreateChannelGroupNotifyListener() throws Exception {
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mService.setPreferencesHelper(mPreferencesHelper);
NotificationChannelGroup group1 = new NotificationChannelGroup("a", "b");
NotificationChannelGroup group2 = new NotificationChannelGroup("n", "m");
@@ -2241,7 +2253,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testUpdateChannelNotifyListener() throws Exception {
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mService.setPreferencesHelper(mPreferencesHelper);
mTestNotificationChannel.setLightColor(Color.CYAN);
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
@@ -2259,7 +2272,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testDeleteChannelNotifyListener() throws Exception {
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mService.setPreferencesHelper(mPreferencesHelper);
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
eq(mTestNotificationChannel.getId()), anyBoolean()))
@@ -2275,7 +2289,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testDeleteChannelGroupNotifyListener() throws Exception {
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c");
mService.setPreferencesHelper(mPreferencesHelper);
when(mPreferencesHelper.getNotificationChannelGroup(eq(ncg.getId()), eq(PKG), anyInt()))
@@ -2292,7 +2307,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(),
eq(mTestNotificationChannel.getId()), anyBoolean()))
.thenReturn(mTestNotificationChannel);
@@ -2312,7 +2328,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testUpdateNotificationChannelFromPrivilegedListener_noAccess() throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
try {
mBinderService.updateNotificationChannelFromPrivilegedListener(
@@ -2335,7 +2352,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mListener = mock(ManagedServices.ManagedServiceInfo.class);
mListener.component = new ComponentName(PKG, PKG);
when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
@@ -2362,7 +2380,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mBinderService.getNotificationChannelsFromPrivilegedListener(
null, PKG, Process.myUserHandle());
@@ -2375,7 +2394,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testGetNotificationChannelFromPrivilegedListener_cdm_noAccess() throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
try {
mBinderService.getNotificationChannelsFromPrivilegedListener(
@@ -2393,7 +2413,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testGetNotificationChannelFromPrivilegedListener_assistant_success()
throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(new ArrayList<>());
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(new ArrayList<>());
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
mBinderService.getNotificationChannelsFromPrivilegedListener(
@@ -2407,7 +2428,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testGetNotificationChannelFromPrivilegedListener_assistant_noAccess()
throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(new ArrayList<>());
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(new ArrayList<>());
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(false);
try {
@@ -2427,7 +2449,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mListener = mock(ManagedServices.ManagedServiceInfo.class);
when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
@@ -2449,7 +2472,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
associations.add("a");
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mBinderService.getNotificationChannelGroupsFromPrivilegedListener(
null, PKG, Process.myUserHandle());
@@ -2461,7 +2485,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testGetNotificationChannelGroupsFromPrivilegedListener_noAccess() throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
try {
mBinderService.getNotificationChannelGroupsFromPrivilegedListener(
@@ -2478,7 +2503,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testGetNotificationChannelGroupsFromPrivilegedListener_badUser() throws Exception {
mService.setPreferencesHelper(mPreferencesHelper);
List<String> associations = new ArrayList<>();
- when(mCompanionMgr.getAssociations(PKG, mUid)).thenReturn(associations);
+ when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid)))
+ .thenReturn(associations);
mListener = mock(ManagedServices.ManagedServiceInfo.class);
when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false);
when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener);
@@ -3028,8 +3054,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mBinderService.setNotificationAssistantAccessGranted(c, true);
verify(mListeners).migrateToXml();
- verify(mListeners).notifyNotificationChannelChanged(anyString(), any(), any(),
- anyInt());
verify(mConditionProviders).setPackageOrComponentEnabled(
anyString(), anyInt(), anyBoolean(), anyBoolean());
verify(mAssistants).migrateToXml();
@@ -3043,8 +3067,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mBinderService.setNotificationPolicyAccessGranted(c.getPackageName(), true);
verify(mListeners).migrateToXml();
- verify(mListeners).notifyNotificationChannelChanged(anyString(), any(), any(),
- anyInt());
verify(mConditionProviders).setPackageOrComponentEnabled(
anyString(), anyInt(), anyBoolean(), anyBoolean());
verify(mAssistants).migrateToXml();
@@ -3180,7 +3202,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setSmallIcon(android.R.drawable.sym_def_app_icon);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
"testNoFakeColorizedPermission", mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(),
@@ -3218,7 +3240,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.build();
StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "tag", mUid, 0,
- n, new UserHandle(mUid), null, 0);
+ n, UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord otherPackage =
new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.addEnqueuedNotification(otherPackage);
@@ -3226,7 +3248,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// Same notifications are enqueued as posted, everything counts b/c id and tag don't match
// anything that's currently enqueued or posted
- int userId = new UserHandle(mUid).getIdentifier();
+ int userId = UserHandle.getUserId(mUid);
assertEquals(40,
mService.getNotificationCountLocked(PKG, userId, 0, null));
assertEquals(40,
@@ -3443,8 +3465,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
StatusBarNotification sbn = new StatusBarNotification(preOPkg, preOPkg, 9,
"testBumpFGImportance_noChannelChangePreOApp",
- Binder.getCallingUid(), 0, nb.build(), new UserHandle(Binder.getCallingUid()), null,
- 0);
+ Binder.getCallingUid(), 0, nb.build(),
+ UserHandle.getUserHandleForUid(Binder.getCallingUid()), null, 0);
mBinderService.enqueueNotificationWithTag(sbn.getPackageName(), sbn.getOpPkg(),
sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId());
@@ -3461,7 +3483,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
sbn = new StatusBarNotification(preOPkg, preOPkg, 9,
"testBumpFGImportance_noChannelChangePreOApp", Binder.getCallingUid(),
- 0, nb.build(), new UserHandle(Binder.getCallingUid()), null, 0);
+ 0, nb.build(), UserHandle.getUserHandleForUid(Binder.getCallingUid()), null, 0);
mBinderService.enqueueNotificationWithTag(preOPkg, preOPkg,
"testBumpFGImportance_noChannelChangePreOApp",
@@ -3815,7 +3837,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.addMessage(message1)
.addMessage(message2));
NotificationRecord recordA = new NotificationRecord(mContext, new StatusBarNotification(
- PKG, PKG, 0, "tag", mUid, 0, nbA.build(), new UserHandle(mUid), null, 0), c);
+ PKG, PKG, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid),
+ null, 0), c);
// First post means we grant access to both
reset(mUgm);
@@ -3833,7 +3856,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setStyle(new Notification.MessagingStyle("").addMessage(message2));
NotificationRecord recordB = new NotificationRecord(mContext, new StatusBarNotification(PKG,
- PKG, 0, "tag", mUid, 0, nbB.build(), new UserHandle(mUid), null, 0), c);
+ PKG, 0, "tag", mUid, 0, nbB.build(), UserHandle.getUserHandleForUid(mUid), null, 0),
+ c);
// Update means we drop access to first
reset(mUgmInternal);
@@ -3872,7 +3896,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setStyle(new Notification.MessagingStyle("")
.addMessage(message1));
NotificationRecord recordA = new NotificationRecord(mContext, new StatusBarNotification(
- PKG, PKG, 0, "tag", mUid, 0, nbA.build(), new UserHandle(mUid), null, 0), c);
+ PKG, PKG, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid),
+ null, 0), c);
doThrow(new SecurityException("no access")).when(mUgm)
.grantUriPermissionFromOwner(
@@ -4031,7 +4056,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentTitle("foo");
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
@@ -4039,7 +4064,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setFlag(FLAG_FOREGROUND_SERVICE, true)
.setContentTitle("bar");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4051,14 +4076,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentTitle("foo");
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setContentTitle("bar");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4071,7 +4096,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setStyle(new Notification.InboxStyle()
.addLine("line1").addLine("line2"));
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
@@ -4079,7 +4104,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setStyle(new Notification.InboxStyle()
.addLine("line1").addLine("line2_changed"));
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4089,7 +4114,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setStyle(new Notification.InboxStyle()
.addLine("line1"));
StatusBarNotification sbn3 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb3.build(), new UserHandle(mUid), null, 0);
+ nb3.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r3 =
new NotificationRecord(mContext, sbn3, mock(NotificationChannel.class));
@@ -4099,7 +4124,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setStyle(new Notification.InboxStyle()
.addLine("line1").addLine("line2").addLine("line3"));
StatusBarNotification sbn4 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb4.build(), new UserHandle(mUid), null, 0);
+ nb4.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r4 =
new NotificationRecord(mContext, sbn4, mock(NotificationChannel.class));
@@ -4108,7 +4133,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb5 = new Notification.Builder(mContext, "")
.setContentText("not an inbox");
StatusBarNotification sbn5 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb5.build(), new UserHandle(mUid), null, 0);
+ nb5.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r5 =
new NotificationRecord(mContext, sbn5, mock(NotificationChannel.class));
@@ -4120,14 +4145,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentText("foo");
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setContentText("bar");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4139,14 +4164,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentText("foo");
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setContentText("foo");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4158,14 +4183,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentText(Html.fromHtml("<b>foo</b>"));
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setContentText(Html.fromHtml("<b>foo</b>"));
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4177,14 +4202,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setContentText(Html.fromHtml("<b>foo</b>"));
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setContentText(Html.fromHtml("<b>bar</b>"));
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4196,14 +4221,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setProgress(100, 90, false);
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setProgress(100, 100, false);
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4215,14 +4240,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setProgress(100, 90, false);
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setProgress(100, 91, false);
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4234,14 +4259,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb1 = new Notification.Builder(mContext, "")
.setProgress(100, 100, false);
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
Notification.Builder nb2 = new Notification.Builder(mContext, "")
.setProgress(100, 100, false);
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4255,7 +4280,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setFlag(Notification.FLAG_GROUP_SUMMARY, true)
.setContentText("foo");
StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb1.build(), new UserHandle(mUid), null, 0);
+ nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r1 =
new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class));
@@ -4264,7 +4289,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setFlag(Notification.FLAG_GROUP_SUMMARY, true)
.setContentText("bar");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4278,7 +4303,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setFlag(Notification.FLAG_GROUP_SUMMARY, true)
.setContentText("bar");
StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0,
- nb2.build(), new UserHandle(mUid), null, 0);
+ nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r2 =
new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class));
@@ -4696,7 +4721,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
n.flags |= FLAG_FOREGROUND_SERVICE;
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0,
- n, new UserHandle(mUid), null, 0);
+ n, UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.addEnqueuedNotification(r);
@@ -4715,7 +4740,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
n.flags |= FLAG_FOREGROUND_SERVICE;
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0,
- n, new UserHandle(mUid), null, 0);
+ n, UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.addNotification(r);
@@ -5028,7 +5053,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setSmallIcon(android.R.drawable.sym_def_app_icon);
StatusBarNotification sbn = new StatusBarNotification(PKG, "opPkg", 0, "tag", mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.reportSeen(r);
@@ -5052,7 +5077,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, r.getSbn().getId(),
r.getSbn().getTag(), mUid, 0,
new Notification.Builder(mContext, mTestNotificationChannel.getId()).build(),
- new UserHandle(mUid), null, 0);
+ UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord update = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mService.addEnqueuedNotification(update);
assertNull(update.getSbn().getNotification().getSmallIcon());
@@ -5086,7 +5111,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
}
@Test
- public void testgetNotificationChannels_crossUser() throws Exception {
+ public void testGetNotificationChannels_crossUser() throws Exception {
// same user no problem
mBinderService.getNotificationChannels("src", "target", mContext.getUserId());
@@ -5275,7 +5300,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setBubbleMetadata(getBubbleMetadata());
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "tag", mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
// Say we're foreground
@@ -5321,7 +5346,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nb.setShortcutId(null);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
null, mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(),
sbn.getId(), sbn.getNotification(), sbn.getUserId());
@@ -5365,7 +5390,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
"testFlagBubbleNotifs_noFlag_notBubble", mUid, 0,
- nb.build(), new UserHandle(mUid), null, 0);
+ nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
// Post the notification
@@ -6180,7 +6205,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nb.setShortcutId(VALID_CONVO_SHORTCUT_ID);
nb.setBubbleMetadata(metadata);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
- "tag", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
+ "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
// Test: Send the bubble notification
@@ -6205,7 +6230,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// Test: Remove the shortcut
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
launcherAppsCallback.getValue().onShortcutsChanged(PKG, Collections.emptyList(),
- new UserHandle(mUid));
+ UserHandle.getUserHandleForUid(mUid));
waitForIdle();
// Verify:
@@ -6240,7 +6265,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nb.setShortcutId(shortcutId);
nb.setBubbleMetadata(metadata);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
- "tag", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
+ "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
// Pretend the shortcut exists
@@ -6688,15 +6713,43 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Test
public void testRecordMessages_invalidMsg() throws RemoteException {
- NotificationRecord nr =
- generateMessageBubbleNotifRecord(mTestNotificationChannel,
- "testRecordMessages_invalidMsg");
+ Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */,
+ null /* groupKey */, false /* isSummary */);
+ nb.setShortcutId(null);
+ StatusBarNotification sbn = new StatusBarNotification(PKG_P, PKG_P, 1,
+ "testRecordMessages_invalidMsg", mUid, 0, nb.build(),
+ UserHandle.getUserHandleForUid(mUid), null, 0);
+ NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
+
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
- mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
+ mBinderService.enqueueNotificationWithTag(PKG_P, PKG_P, nr.getSbn().getTag(),
nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
waitForIdle();
- assertTrue(mBinderService.isInInvalidMsgState(PKG, mUid));
+ assertTrue(mBinderService.isInInvalidMsgState(PKG_P, mUid));
+ }
+
+ @Test
+ public void testRecordMessages_invalidMsg_notMessageStyle() throws RemoteException {
+ Notification.Builder nb = new Notification.Builder(mContext,
+ mTestNotificationChannel.getId())
+ .setContentTitle("foo")
+ .setShortcutId(null)
+ .setSmallIcon(android.R.drawable.sym_def_app_icon)
+ .setCategory(Notification.CATEGORY_MESSAGE);
+ StatusBarNotification sbn = new StatusBarNotification(PKG_O, PKG_O, 1,
+ "testRecordMessages_invalidMsg_notMessageStyle", mUid, 0, nb.build(),
+ UserHandle.getUserHandleForUid(mUid), null, 0);
+ NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
+
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
+ mBinderService.enqueueNotificationWithTag(PKG_O, PKG_O, nr.getSbn().getTag(),
+ nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
+ waitForIdle();
+
+ // PKG_O is allowed to be in conversation space b/c of override in
+ // TestableNotificationManagerService
+ assertTrue(mBinderService.isInInvalidMsgState(PKG_O, mUid));
}
@Test
@@ -6704,24 +6757,25 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */,
null /* groupKey */, false /* isSummary */);
nb.setShortcutId(null);
- StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
- "testRecordMessages_validMsg", mUid, 0, nb.build(), new UserHandle(mUid), null, 0);
+ StatusBarNotification sbn = new StatusBarNotification(PKG_P, PKG_P, 1,
+ "testRecordMessages_validMsg", mUid, 0, nb.build(),
+ UserHandle.getUserHandleForUid(mUid), null, 0);
NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
- mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
+ mBinderService.enqueueNotificationWithTag(PKG_P, PKG_P, nr.getSbn().getTag(),
nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
waitForIdle();
- assertTrue(mBinderService.isInInvalidMsgState(PKG, mUid));
+ assertTrue(mBinderService.isInInvalidMsgState(PKG_P, mUid));
nr = generateMessageBubbleNotifRecord(mTestNotificationChannel,
"testRecordMessages_validMsg");
- mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
+ mBinderService.enqueueNotificationWithTag(PKG_P, PKG_P, nr.getSbn().getTag(),
nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
waitForIdle();
- assertFalse(mBinderService.isInInvalidMsgState(PKG, mUid));
+ assertFalse(mBinderService.isInInvalidMsgState(PKG_P, mUid));
}
@Test
@@ -6741,7 +6795,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
nb.setShortcutId(null);
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
"testRecordMessages_invalidMsg_afterValidMsg_2", mUid, 0, nb.build(),
- new UserHandle(mUid), null, 0);
+ UserHandle.getUserHandleForUid(mUid), null, 0);
nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),