diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 18bf7a1e54602..1bb8b3bcd3265 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 @@ public class RankingHelper implements RankingConfig { // 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 41e1f404c9973..629146f190061 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 @@ public class RankingHelperTest { 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 @@ public class RankingHelperTest { } @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);