Never use getApplicationInfo.
Always use getApplicationInfoAsUser.
Test: runtest, and install a work profile app and post a notification.
Bug: 32615127
Change-Id: I92cdf42d791d27eaff64b945be96b216e5866f6d
(cherry picked from commit b3a04f0816a1c8e16468c9906e0fc9e1a4cd99d4)
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 18bf7a1..1bb8b3b 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -239,14 +239,18 @@
// unless the user has already changed the importance.
private void clampDefaultChannel(Record r) {
try {
- final ApplicationInfo applicationInfo = mPm.getApplicationInfo(r.pkg, 0);
- if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) {
- final NotificationChannel defaultChannel =
- r.channels.get(NotificationChannel.DEFAULT_CHANNEL_ID);
- if ((defaultChannel.getUserLockedFields()
- & NotificationChannel.USER_LOCKED_IMPORTANCE) == 0) {
- defaultChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
- updateConfig();
+ if (r.uid != Record.UNKNOWN_UID) {
+ int userId = UserHandle.getUserId(r.uid);
+ final ApplicationInfo applicationInfo =
+ mPm.getApplicationInfoAsUser(r.pkg, 0, userId);
+ if (applicationInfo.targetSdkVersion > Build.VERSION_CODES.N_MR1) {
+ final NotificationChannel defaultChannel =
+ r.channels.get(NotificationChannel.DEFAULT_CHANNEL_ID);
+ if ((defaultChannel.getUserLockedFields()
+ & NotificationChannel.USER_LOCKED_IMPORTANCE) == 0) {
+ defaultChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
+ updateConfig();
+ }
}
}
} catch (NameNotFoundException e) {
diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
index 41e1f40..629146f 100644
--- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
@@ -141,8 +141,8 @@
final ApplicationInfo upgrade = new ApplicationInfo();
upgrade.targetSdkVersion = Build.VERSION_CODES.N_MR1 + 1;
try {
- when(mPm.getApplicationInfo(eq(pkg), anyInt())).thenReturn(legacy);
- when(mPm.getApplicationInfo(eq(pkg2), anyInt())).thenReturn(upgrade);
+ when(mPm.getApplicationInfoAsUser(eq(pkg), anyInt(), anyInt())).thenReturn(legacy);
+ when(mPm.getApplicationInfoAsUser(eq(pkg2), anyInt(), anyInt())).thenReturn(upgrade);
} catch (PackageManager.NameNotFoundException e) {}
}
@@ -277,16 +277,16 @@
}
@Test
- public void testChannelXml_defaultChannelUpdatedApp() throws Exception {
- final ApplicationInfo updated = new ApplicationInfo();
- updated.targetSdkVersion = Build.VERSION_CODES.N_MR1 + 1;
- when(mPm.getApplicationInfo(anyString(), anyInt())).thenReturn(updated);
-
- NotificationChannel channel1 =
+ public void testChannelXml_defaultChannelUpdatedApp_userSettings() throws Exception {
+ NotificationChannel channel1 =
new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_MIN);
-
mHelper.createNotificationChannel(pkg, uid, channel1);
+ final NotificationChannel defaultChannel =
+ mHelper.getNotificationChannel(pkg, uid, NotificationChannel.DEFAULT_CHANNEL_ID);
+ defaultChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
+ mHelper.updateNotificationChannel(pkg, uid, defaultChannel);
+
ByteArrayOutputStream baos = writeXmlAndPurge(pkg, uid, channel1.getId(),
NotificationChannel.DEFAULT_CHANNEL_ID);