Merge "Notifications channels are not locked at first boot"

This commit is contained in:
Julia Reynolds
2023-03-17 17:28:43 +00:00
committed by Gerrit Code Review
3 changed files with 30 additions and 25 deletions

View File

@@ -2317,7 +2317,6 @@ public class NotificationManagerService extends SystemService {
mAppOps,
new SysUiStatsEvent.BuilderFactory(),
mShowReviewPermissionsNotification);
mPreferencesHelper.updateFixedImportance(mUm.getUsers());
mRankingHelper = new RankingHelper(getContext(),
mRankingHandler,
mPreferencesHelper,
@@ -2760,6 +2759,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());
}
}

View File

@@ -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) {
@@ -382,14 +372,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);
@@ -2681,6 +2663,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();
}

View File

@@ -676,10 +676,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,