From 3cb67dffb7758da16d06f7033b83128069a0be05 Mon Sep 17 00:00:00 2001 From: Bookatz Date: Wed, 16 Oct 2019 17:20:06 -0400 Subject: [PATCH] Wellbeing app can enable QUIET_MODE The designated Wellbeing app now has permission to toggle the "quiet mode" of a profile. Additionally, callers can only toggle the quiet mode of a userId that is of the same profile group as the caller (unless the caller has MANAGE_PERMISSIONS). Test: manual Bug: 140485433 Change-Id: Ie6253799b97113aff7d364f8cf9214c69252f704 --- core/res/AndroidManifest.xml | 4 ++-- .../com/android/server/pm/UserManagerService.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 7a0d0cbe60954..401ddb954ff87 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -4504,9 +4504,9 @@ android:protectionLevel="signature" /> + @hide --> + android:protectionLevel="signature|privileged|wellbeing" /> diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 5f8670809bfb1..f024c9c0450c9 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -861,7 +861,7 @@ public class UserManagerService extends IUserManager.Stub { "target should only be specified when we are disabling quiet mode."); } - ensureCanModifyQuietMode(callingPackage, Binder.getCallingUid(), target != null); + ensureCanModifyQuietMode(callingPackage, Binder.getCallingUid(), userId, target != null); final long identity = Binder.clearCallingIdentity(); try { boolean result = false; @@ -893,13 +893,15 @@ public class UserManagerService extends IUserManager.Stub { *
  • Has system UID or root UID
  • *
  • Has {@link Manifest.permission#MODIFY_QUIET_MODE}
  • *
  • Has {@link Manifest.permission#MANAGE_USERS}
  • + *
  • Is the foreground default launcher app
  • * *

    - * If caller wants to start an intent after disabling the quiet mode, it must has + * If caller wants to start an intent after disabling the quiet mode, or if it is targeting a + * user in a different profile group from the caller, it must have * {@link Manifest.permission#MANAGE_USERS}. */ private void ensureCanModifyQuietMode(String callingPackage, int callingUid, - boolean startIntent) { + @UserIdInt int targetUserId, boolean startIntent) { if (hasManageUsersPermission()) { return; } @@ -907,6 +909,10 @@ public class UserManagerService extends IUserManager.Stub { throw new SecurityException("MANAGE_USERS permission is required to start intent " + "after disabling quiet mode."); } + if (!isSameProfileGroupNoChecks(UserHandle.getUserId(callingUid), targetUserId)) { + throw new SecurityException("MANAGE_USERS permission is required to modify quiet mode " + + "for a different profile group."); + } final boolean hasModifyQuietModePermission = hasPermissionGranted( Manifest.permission.MODIFY_QUIET_MODE, callingUid); if (hasModifyQuietModePermission) {