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

Commit 63fd04ad authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Notifications channels are not locked at first boot" am: 1dcde702 am:...

Merge "Notifications channels are not locked at first boot" am: 1dcde702 am: 4dca7937 am: 47f8aee5 am: ab2a2b61

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2276931



Change-Id: I61caa45c30d5a770080e117f2b419a66b4e0dc97
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7aeea239 ab2a2b61
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2340,7 +2340,6 @@ public class NotificationManagerService extends SystemService {
                mAppOps,
                new SysUiStatsEvent.BuilderFactory(),
                mShowReviewPermissionsNotification);
        mPreferencesHelper.updateFixedImportance(mUm.getUsers());
        mRankingHelper = new RankingHelper(getContext(),
                mRankingHandler,
                mPreferencesHelper,
@@ -2771,6 +2770,9 @@ public class NotificationManagerService extends SystemService {
            maybeShowInitialReviewPermissionsNotification();
        } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
            mSnoozeHelper.scheduleRepostsForPersistedNotifications(System.currentTimeMillis());
        } else if (phase == SystemService.PHASE_DEVICE_SPECIFIC_SERVICES_READY) {
            mPreferencesHelper.updateFixedImportance(mUm.getUsers());
            mPreferencesHelper.migrateNotificationPermissions(mUm.getUsers());
        }
    }
+27 −20
Original line number Diff line number Diff line
@@ -237,7 +237,6 @@ public class PreferencesHelper implements RankingConfig {
                    Settings.Global.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
                    NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW);
        }
        ArrayList<PermissionHelper.PackagePermission> pkgPerms = new ArrayList<>();
        synchronized (mPackagePreferences) {
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
                tag = parser.getName();
@@ -255,27 +254,18 @@ public class PreferencesHelper implements RankingConfig {
                        String name = parser.getAttributeValue(null, ATT_NAME);
                        if (!TextUtils.isEmpty(name)) {
                            restorePackage(parser, forRestore, userId, name, upgradeForBubbles,
                                    migrateToPermission, pkgPerms);
                                    migrateToPermission);
                        }
                    }
                }
            }
        }
        if (migrateToPermission) {
            for (PackagePermission p : pkgPerms) {
                try {
                    mPermissionHelper.setNotificationPermission(p);
                } catch (Exception e) {
                    Slog.e(TAG, "could not migrate setting for " + p.packageName, e);
                }
            }
        }
    }

    @GuardedBy("mPackagePreferences")
    private void restorePackage(TypedXmlPullParser parser, boolean forRestore,
            @UserIdInt int userId, String name, boolean upgradeForBubbles,
            boolean migrateToPermission, ArrayList<PermissionHelper.PackagePermission> pkgPerms) {
            boolean migrateToPermission) {
        try {
            int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
            if (forRestore) {
@@ -379,14 +369,6 @@ 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(
                            r.pkg, UserHandle.getUserId(r.uid),
                            r.importance != IMPORTANCE_NONE,
                            hasUserConfiguredSettings(r));
                    pkgPerms.add(pkgPerm);
                }
            }
        } catch (Exception e) {
            Slog.w(TAG, "Failed to restore pkg", e);
@@ -2663,6 +2645,31 @@ public class PreferencesHelper implements RankingConfig {
        }
    }

    public void migrateNotificationPermissions(List<UserInfo> users) {
        for (UserInfo user : users) {
            List<PackageInfo> packages = mPm.getInstalledPackagesAsUser(
                    PackageManager.PackageInfoFlags.of(PackageManager.MATCH_ALL),
                    user.getUserHandle().getIdentifier());
            for (PackageInfo pi : packages) {
                synchronized (mPackagePreferences) {
                    PackagePreferences p = getOrCreatePackagePreferencesLocked(
                            pi.packageName, pi.applicationInfo.uid);
                    if (p.migrateToPm && p.uid != UNKNOWN_UID) {
                        try {
                            PackagePermission pkgPerm = new PackagePermission(
                                    p.pkg, UserHandle.getUserId(p.uid),
                                    p.importance != IMPORTANCE_NONE,
                                    hasUserConfiguredSettings(p));
                            mPermissionHelper.setNotificationPermission(pkgPerm);
                        } catch (Exception e) {
                            Slog.e(TAG, "could not migrate setting for " + p.pkg, e);
                        }
                    }
                }
            }
        }
    }

    private void updateConfig() {
        mRankingHandler.requestSort();
    }
+0 −4
Original line number Diff line number Diff line
@@ -679,10 +679,6 @@ public class PreferencesHelperTest extends UiServiceTestCase {
        compareChannels(ido, mHelper.getNotificationChannel(PKG_O, UID_O, ido.getId(), false));
        compareChannels(idp, mHelper.getNotificationChannel(PKG_P, UID_P, idp.getId(), false));

        verify(mPermissionHelper).setNotificationPermission(nMr1Expected);
        verify(mPermissionHelper).setNotificationPermission(oExpected);
        verify(mPermissionHelper).setNotificationPermission(pExpected);

        // verify that we also write a state for review_permissions_notification to eventually
        // show a notification
        assertEquals(NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW,