Loading services/core/java/com/android/server/notification/NotificationManagerService.java +27 −20 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.PowerWhitelistManager.REASON_NOTIFICATION_SERVICE; import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import static android.os.Process.INVALID_UID; import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_SYSTEM; Loading Loading @@ -503,7 +504,6 @@ public class NotificationManagerService extends SystemService { */ private static final int NOTIFICATION_RAPID_CLEAR_THRESHOLD_MS = 5000; static final int INVALID_UID = -1; static final String ROOT_PKG = "root"; static final String[] DEFAULT_ALLOWED_ADJUSTMENTS = new String[] { Loading Loading @@ -5175,7 +5175,7 @@ public class NotificationManagerService extends SystemService { String conversationId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallerSystemOrSystemUiOrShell()) { int targetUid = -1; int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); } catch (NameNotFoundException e) { Loading Loading @@ -5477,7 +5477,7 @@ public class NotificationManagerService extends SystemService { String targetPkg, @CannotBeSpecialUser @UserIdInt int userId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallingUidSystem()) { int targetUid = -1; int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); } catch (NameNotFoundException e) { Loading Loading @@ -7410,9 +7410,6 @@ public class NotificationManagerService extends SystemService { } } int uid = getUidForPackageAndUser(pkg, user); if (uid == INVALID_UID) { return null; } NotificationChannel parentChannel = mPreferencesHelper.getNotificationChannel(pkg, uid, parentId, false); if (parentChannel == null) { Loading Loading @@ -7571,14 +7568,12 @@ public class NotificationManagerService extends SystemService { } private int getUidForPackageAndUser(String pkg, UserHandle user) throws RemoteException { int uid = INVALID_UID; final long identity = Binder.clearCallingIdentity(); try { uid = mPackageManager.getPackageUid(pkg, 0, user.getIdentifier()); return mPackageManager.getPackageUid(pkg, 0, user.getIdentifier()); } finally { Binder.restoreCallingIdentity(identity); } return uid; } @Override Loading Loading @@ -9225,12 +9220,10 @@ public class NotificationManagerService extends SystemService { if (canPostPromoted) { notification.flags |= FLAG_PROMOTED_ONGOING; } } } } /** * Whether a notification can be non-dismissible. * A notification should be dismissible, unless it's exempted for some reason. Loading Loading @@ -15019,15 +15012,22 @@ public class NotificationManagerService extends SystemService { List<UserHandle> users = mUm.getUserHandles(/* excludeDying */ true); mNonBlockableDefaultApps = new ArrayMap<>(); for (int i = 0; i < NON_BLOCKABLE_DEFAULT_ROLES.length; i++) { String role = NON_BLOCKABLE_DEFAULT_ROLES[i]; final ArrayMap<Integer, ArraySet<String>> userToApprovedList = new ArrayMap<>(); mNonBlockableDefaultApps.put(NON_BLOCKABLE_DEFAULT_ROLES[i], userToApprovedList); mNonBlockableDefaultApps.put(role, userToApprovedList); for (int j = 0; j < users.size(); j++) { Integer userId = users.get(j).getIdentifier(); int userId = users.get(j).getIdentifier(); ArraySet<String> approvedForUserId = new ArraySet<>(mRm.getRoleHoldersAsUser( NON_BLOCKABLE_DEFAULT_ROLES[i], UserHandle.of(userId))); role, UserHandle.of(userId))); ArraySet<Pair<String, Integer>> approvedAppUids = new ArraySet<>(); for (String pkg : approvedForUserId) { approvedAppUids.add(new Pair(pkg, getUidForPackage(pkg, userId))); int uid = getUidForPackage(pkg, userId); if (uid != INVALID_UID) { approvedAppUids.add(new Pair<>(pkg, uid)); } else { Slog.e(TAG, "init: Invalid package for role " + role + " (user " + userId + "): " + pkg); } } userToApprovedList.put(userId, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedAppUids); Loading Loading @@ -15097,8 +15097,13 @@ public class NotificationManagerService extends SystemService { } for (String nowApproved : roleHolders) { if (!previouslyApproved.contains(nowApproved)) { toAdd.add(new Pair(nowApproved, getUidForPackage(nowApproved, user.getIdentifier()))); int uid = getUidForPackage(nowApproved, user.getIdentifier()); if (uid != INVALID_UID) { toAdd.add(new Pair<>(nowApproved, uid)); } else { Slog.e(TAG, "onRoleHoldersChanged: Invalid package for role " + roleName + " (user " + user.getIdentifier() + "): " + nowApproved); } } } Loading Loading @@ -15138,10 +15143,12 @@ public class NotificationManagerService extends SystemService { UserHandle user = users[i]; for (String pkg : mRm.getRoleHoldersAsUser(RoleManager.ROLE_BROWSER, user)) { int uid = getUidForPackage(pkg, user.getIdentifier()); if (uid != -1) { if (uid != INVALID_UID) { newUids.add(uid); } else { Slog.e(TAG, "Bad uid (-1) for browser package " + pkg); Slog.e(TAG, "updateTrampoline: Invalid package for role " + RoleManager.ROLE_BROWSER + " (user " + user.getIdentifier() + "): " + pkg); } } } Loading @@ -15154,7 +15161,7 @@ public class NotificationManagerService extends SystemService { } catch (RemoteException e) { Slog.e(TAG, "role manager has bad default " + pkg + " " + userId); } return -1; return INVALID_UID; } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +27 −20 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.PowerWhitelistManager.REASON_NOTIFICATION_SERVICE; import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED; import static android.os.Process.INVALID_UID; import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_SYSTEM; Loading Loading @@ -503,7 +504,6 @@ public class NotificationManagerService extends SystemService { */ private static final int NOTIFICATION_RAPID_CLEAR_THRESHOLD_MS = 5000; static final int INVALID_UID = -1; static final String ROOT_PKG = "root"; static final String[] DEFAULT_ALLOWED_ADJUSTMENTS = new String[] { Loading Loading @@ -5175,7 +5175,7 @@ public class NotificationManagerService extends SystemService { String conversationId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallerSystemOrSystemUiOrShell()) { int targetUid = -1; int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); } catch (NameNotFoundException e) { Loading Loading @@ -5477,7 +5477,7 @@ public class NotificationManagerService extends SystemService { String targetPkg, @CannotBeSpecialUser @UserIdInt int userId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallingUidSystem()) { int targetUid = -1; int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); } catch (NameNotFoundException e) { Loading Loading @@ -7410,9 +7410,6 @@ public class NotificationManagerService extends SystemService { } } int uid = getUidForPackageAndUser(pkg, user); if (uid == INVALID_UID) { return null; } NotificationChannel parentChannel = mPreferencesHelper.getNotificationChannel(pkg, uid, parentId, false); if (parentChannel == null) { Loading Loading @@ -7571,14 +7568,12 @@ public class NotificationManagerService extends SystemService { } private int getUidForPackageAndUser(String pkg, UserHandle user) throws RemoteException { int uid = INVALID_UID; final long identity = Binder.clearCallingIdentity(); try { uid = mPackageManager.getPackageUid(pkg, 0, user.getIdentifier()); return mPackageManager.getPackageUid(pkg, 0, user.getIdentifier()); } finally { Binder.restoreCallingIdentity(identity); } return uid; } @Override Loading Loading @@ -9225,12 +9220,10 @@ public class NotificationManagerService extends SystemService { if (canPostPromoted) { notification.flags |= FLAG_PROMOTED_ONGOING; } } } } /** * Whether a notification can be non-dismissible. * A notification should be dismissible, unless it's exempted for some reason. Loading Loading @@ -15019,15 +15012,22 @@ public class NotificationManagerService extends SystemService { List<UserHandle> users = mUm.getUserHandles(/* excludeDying */ true); mNonBlockableDefaultApps = new ArrayMap<>(); for (int i = 0; i < NON_BLOCKABLE_DEFAULT_ROLES.length; i++) { String role = NON_BLOCKABLE_DEFAULT_ROLES[i]; final ArrayMap<Integer, ArraySet<String>> userToApprovedList = new ArrayMap<>(); mNonBlockableDefaultApps.put(NON_BLOCKABLE_DEFAULT_ROLES[i], userToApprovedList); mNonBlockableDefaultApps.put(role, userToApprovedList); for (int j = 0; j < users.size(); j++) { Integer userId = users.get(j).getIdentifier(); int userId = users.get(j).getIdentifier(); ArraySet<String> approvedForUserId = new ArraySet<>(mRm.getRoleHoldersAsUser( NON_BLOCKABLE_DEFAULT_ROLES[i], UserHandle.of(userId))); role, UserHandle.of(userId))); ArraySet<Pair<String, Integer>> approvedAppUids = new ArraySet<>(); for (String pkg : approvedForUserId) { approvedAppUids.add(new Pair(pkg, getUidForPackage(pkg, userId))); int uid = getUidForPackage(pkg, userId); if (uid != INVALID_UID) { approvedAppUids.add(new Pair<>(pkg, uid)); } else { Slog.e(TAG, "init: Invalid package for role " + role + " (user " + userId + "): " + pkg); } } userToApprovedList.put(userId, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedAppUids); Loading Loading @@ -15097,8 +15097,13 @@ public class NotificationManagerService extends SystemService { } for (String nowApproved : roleHolders) { if (!previouslyApproved.contains(nowApproved)) { toAdd.add(new Pair(nowApproved, getUidForPackage(nowApproved, user.getIdentifier()))); int uid = getUidForPackage(nowApproved, user.getIdentifier()); if (uid != INVALID_UID) { toAdd.add(new Pair<>(nowApproved, uid)); } else { Slog.e(TAG, "onRoleHoldersChanged: Invalid package for role " + roleName + " (user " + user.getIdentifier() + "): " + nowApproved); } } } Loading Loading @@ -15138,10 +15143,12 @@ public class NotificationManagerService extends SystemService { UserHandle user = users[i]; for (String pkg : mRm.getRoleHoldersAsUser(RoleManager.ROLE_BROWSER, user)) { int uid = getUidForPackage(pkg, user.getIdentifier()); if (uid != -1) { if (uid != INVALID_UID) { newUids.add(uid); } else { Slog.e(TAG, "Bad uid (-1) for browser package " + pkg); Slog.e(TAG, "updateTrampoline: Invalid package for role " + RoleManager.ROLE_BROWSER + " (user " + user.getIdentifier() + "): " + pkg); } } } Loading @@ -15154,7 +15161,7 @@ public class NotificationManagerService extends SystemService { } catch (RemoteException e) { Slog.e(TAG, "role manager has bad default " + pkg + " " + userId); } return -1; return INVALID_UID; } }