Loading services/core/java/com/android/server/notification/RankingHelper.java +12 −8 Original line number Diff line number Diff line Loading @@ -239,7 +239,10 @@ 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 (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); Loading @@ -249,6 +252,7 @@ public class RankingHelper implements RankingConfig { updateConfig(); } } } } catch (NameNotFoundException e) { // oh well. } Loading services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -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) {} } Loading Loading @@ -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); 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); Loading Loading
services/core/java/com/android/server/notification/RankingHelper.java +12 −8 Original line number Diff line number Diff line Loading @@ -239,7 +239,10 @@ 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 (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); Loading @@ -249,6 +252,7 @@ public class RankingHelper implements RankingConfig { updateConfig(); } } } } catch (NameNotFoundException e) { // oh well. } Loading
services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -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) {} } Loading Loading @@ -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); 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); Loading