Never use getApplicationInfo.

Always use getApplicationInfoAsUser.

Test: runtest, and install a work profile app and post a notification.

Bug: 32615127
Change-Id: I92cdf42d791d27eaff64b945be96b216e5866f6d
This commit is contained in:
Julia Reynolds
2016-11-04 09:08:52 -04:00
parent 3d36fac235
commit b3a04f0816
2 changed files with 21 additions and 17 deletions

View File

@@ -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) {

View File

@@ -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);