Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad9d3632 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Never use getApplicationInfo."

parents 59eb6ddd b3a04f08
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -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);
@@ -249,6 +252,7 @@ public class RankingHelper implements RankingConfig {
                        updateConfig();
                    }
                }
            }
        } catch (NameNotFoundException e) {
            // oh well.
        }
+9 −9
Original line number Diff line number Diff line
@@ -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);

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