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

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

Change-Id: I61fc7a05d33eff5f96d1791687874294cc5856f6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Julia Reynolds
2023-03-17 18:10:10 +00:00
committed by Automerger Merge Worker
3 changed files with 30 additions and 25 deletions

View File

@@ -2317,7 +2317,6 @@ public class NotificationManagerService extends SystemService {
mAppOps, mAppOps,
new SysUiStatsEvent.BuilderFactory(), new SysUiStatsEvent.BuilderFactory(),
mShowReviewPermissionsNotification); mShowReviewPermissionsNotification);
mPreferencesHelper.updateFixedImportance(mUm.getUsers());
mRankingHelper = new RankingHelper(getContext(), mRankingHelper = new RankingHelper(getContext(),
mRankingHandler, mRankingHandler,
mPreferencesHelper, mPreferencesHelper,
@@ -2760,6 +2759,9 @@ public class NotificationManagerService extends SystemService {
maybeShowInitialReviewPermissionsNotification(); maybeShowInitialReviewPermissionsNotification();
} else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
mSnoozeHelper.scheduleRepostsForPersistedNotifications(System.currentTimeMillis()); 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, Settings.Global.REVIEW_PERMISSIONS_NOTIFICATION_STATE,
NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW); NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW);
} }
ArrayList<PermissionHelper.PackagePermission> pkgPerms = new ArrayList<>();
synchronized (mPackagePreferences) { synchronized (mPackagePreferences) {
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) { while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
tag = parser.getName(); tag = parser.getName();
@@ -255,27 +254,18 @@ public class PreferencesHelper implements RankingConfig {
String name = parser.getAttributeValue(null, ATT_NAME); String name = parser.getAttributeValue(null, ATT_NAME);
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
restorePackage(parser, forRestore, userId, name, upgradeForBubbles, 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") @GuardedBy("mPackagePreferences")
private void restorePackage(TypedXmlPullParser parser, boolean forRestore, private void restorePackage(TypedXmlPullParser parser, boolean forRestore,
@UserIdInt int userId, String name, boolean upgradeForBubbles, @UserIdInt int userId, String name, boolean upgradeForBubbles,
boolean migrateToPermission, ArrayList<PermissionHelper.PackagePermission> pkgPerms) { boolean migrateToPermission) {
try { try {
int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID); int uid = parser.getAttributeInt(null, ATT_UID, UNKNOWN_UID);
if (forRestore) { if (forRestore) {
@@ -382,14 +372,6 @@ public class PreferencesHelper implements RankingConfig {
if (migrateToPermission) { if (migrateToPermission) {
r.importance = appImportance; r.importance = appImportance;
r.migrateToPm = true; 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) { } catch (Exception e) {
Slog.w(TAG, "Failed to restore pkg", 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() { private void updateConfig() {
mRankingHandler.requestSort(); 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(ido, mHelper.getNotificationChannel(PKG_O, UID_O, ido.getId(), false));
compareChannels(idp, mHelper.getNotificationChannel(PKG_P, UID_P, idp.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 // verify that we also write a state for review_permissions_notification to eventually
// show a notification // show a notification
assertEquals(NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW, assertEquals(NotificationManagerService.REVIEW_NOTIF_STATE_SHOULD_SHOW,