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

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

Merge "Fix a T -> T restore issue"

parents 0c2e7a63 3a001809
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -391,6 +391,7 @@ public class PreferencesHelper implements RankingConfig {

                            if (migrateToPermission) {
                                r.importance = appImportance;
                                r.migrateToPm = true;
                                if (r.uid != UNKNOWN_UID) {
                                    // Don't call into permission system until we have a valid uid
                                    PackagePermission pkgPerm = new PackagePermission(
@@ -2575,7 +2576,7 @@ public class PreferencesHelper implements RankingConfig {
                        synchronized (mPackagePreferences) {
                            mPackagePreferences.put(packagePreferencesKey(r.pkg, r.uid), r);
                        }
                        if (mPermissionHelper.isMigrationEnabled()) {
                        if (mPermissionHelper.isMigrationEnabled() && r.migrateToPm) {
                            try {
                                PackagePermission p = new PackagePermission(
                                        r.pkg, UserHandle.getUserId(r.uid),
@@ -2841,6 +2842,8 @@ public class PreferencesHelper implements RankingConfig {
        boolean userDemotedMsgApp = false;
        boolean hasSentValidBubble = false;

        boolean migrateToPm = false;

        Delegate delegate = null;
        ArrayMap<String, NotificationChannel> channels = new ArrayMap<>();
        Map<String, NotificationChannelGroup> groups = new ConcurrentHashMap<>();
+67 −0
Original line number Diff line number Diff line
@@ -788,6 +788,73 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        verify(mPermissionHelper, never()).setNotificationPermission(any());
    }

    @Test
    public void testReadXml_oldXml_migration_NoUid() throws Exception {
        when(mPermissionHelper.isMigrationEnabled()).thenReturn(true);
        mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
                mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory);

        when(mPm.getPackageUidAsUser("something", USER_SYSTEM)).thenReturn(UNKNOWN_UID);
        String xml = "<ranking version=\"2\">\n"
                + "<package name=\"something\" show_badge=\"true\">\n"
                + "<channel id=\"idn\" name=\"name\" importance=\"2\"/>\n"
                + "</package>\n"
                + "</ranking>\n";
        NotificationChannel idn = new NotificationChannel("idn", "name", IMPORTANCE_LOW);
        idn.setSound(null, new AudioAttributes.Builder()
                .setUsage(USAGE_NOTIFICATION)
                .setContentType(CONTENT_TYPE_SONIFICATION)
                .setFlags(0)
                .build());
        idn.setShowBadge(false);

        loadByteArrayXml(xml.getBytes(), true, USER_SYSTEM);
        verify(mPermissionHelper, never()).setNotificationPermission(any());

        when(mPm.getPackageUidAsUser("something", USER_SYSTEM)).thenReturn(1234);
        final ApplicationInfo app = new ApplicationInfo();
        app.targetSdkVersion = Build.VERSION_CODES.N_MR1 + 1;
        when(mPm.getApplicationInfoAsUser(eq("something"), anyInt(), anyInt())).thenReturn(app);

        mHelper.onPackagesChanged(false, 0, new String[] {"something"}, new int[] {1234});


        verify(mPermissionHelper, times(1)).setNotificationPermission(any());
    }

    @Test
    public void testReadXml_newXml_noMigration_NoUid() throws Exception {
        when(mPermissionHelper.isMigrationEnabled()).thenReturn(true);
        mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper,
                mPermissionHelper, mLogger, mAppOpsManager, mStatsEventBuilderFactory);

        when(mPm.getPackageUidAsUser("something", USER_SYSTEM)).thenReturn(UNKNOWN_UID);
        String xml = "<ranking version=\"3\">\n"
                + "<package name=\"something\" show_badge=\"true\">\n"
                + "<channel id=\"idn\" name=\"name\" importance=\"2\"/>\n"
                + "</package>\n"
                + "</ranking>\n";
        NotificationChannel idn = new NotificationChannel("idn", "name", IMPORTANCE_LOW);
        idn.setSound(null, new AudioAttributes.Builder()
                .setUsage(USAGE_NOTIFICATION)
                .setContentType(CONTENT_TYPE_SONIFICATION)
                .setFlags(0)
                .build());
        idn.setShowBadge(false);

        loadByteArrayXml(xml.getBytes(), true, USER_SYSTEM);

        when(mPm.getPackageUidAsUser("something", USER_SYSTEM)).thenReturn(1234);
        final ApplicationInfo app = new ApplicationInfo();
        app.targetSdkVersion = Build.VERSION_CODES.N_MR1 + 1;
        when(mPm.getApplicationInfoAsUser(eq("something"), anyInt(), anyInt())).thenReturn(app);

        mHelper.onPackagesChanged(false, 0, new String[] {"something"}, new int[] {1234});


        verify(mPermissionHelper, never()).setNotificationPermission(any());
    }

    @Test
    public void testChannelXmlForNonBackup_postMigration() throws Exception {
        when(mPermissionHelper.isMigrationEnabled()).thenReturn(true);