diff options
author | Billy Lau <billylau@google.com> | 2015-07-29 22:42:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-29 22:42:27 +0000 |
commit | a6706627a9bf749cc591605272810e03983a9eea (patch) | |
tree | 76c28995e0b8a19ed13955fe1b710a38f933e2d6 /packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java | |
parent | 499f084d9e7bb3323ed447b16f548bad9b886aa7 (diff) | |
parent | 6ad2d66072795dd9836350b273dcde52910ab4c3 (diff) | |
download | frameworks_base-a6706627a9bf749cc591605272810e03983a9eea.zip frameworks_base-a6706627a9bf749cc591605272810e03983a9eea.tar.gz frameworks_base-a6706627a9bf749cc591605272810e03983a9eea.tar.bz2 |
Merge "Bug: 21589105 Rescope WRITE_SETTINGS permission (framework services perm check changes)" into mnc-dev
Diffstat (limited to 'packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java')
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 2a68252..3e9b122 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -643,11 +643,6 @@ public class SettingsProvider extends ContentProvider { // Make sure the caller can change the settings - treated as secure. enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); - // Verify whether this operation is allowed for the calling package. - if (!isAppOpWriteSettingsAllowedForCallingPackage()) { - return false; - } - // Resolve the userId on whose behalf the call is made. final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); @@ -773,11 +768,6 @@ public class SettingsProvider extends ContentProvider { // Make sure the caller can change the settings. enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); - // Verify whether this operation is allowed for the calling package. - if (!isAppOpWriteSettingsAllowedForCallingPackage()) { - return false; - } - // Resolve the userId on whose behalf the call is made. final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(requestingUserId); @@ -904,14 +894,13 @@ public class SettingsProvider extends ContentProvider { private boolean mutateSystemSetting(String name, String value, int runAsUserId, int operation) { - // Check for permissions first. - if (!hasPermissionsToMutateSystemSettings()) { - return false; - } - - // Verify whether this operation is allowed for the calling package. - if (!isAppOpWriteSettingsAllowedForCallingPackage()) { - return false; + if (!hasWriteSecureSettingsPermission()) { + // If the caller doesn't hold WRITE_SECURE_SETTINGS, we verify whether this + // operation is allowed for the calling package through appops. + if (!Settings.checkAndNoteWriteSettingsOperation(getContext(), + Binder.getCallingUid(), getCallingPackage(), true)) { + return false; + } } // Enforce what the calling package can mutate the system settings. @@ -956,25 +945,13 @@ public class SettingsProvider extends ContentProvider { } } - private boolean hasPermissionsToMutateSystemSettings() { + private boolean hasWriteSecureSettingsPermission() { // Write secure settings is a more protected permission. If caller has it we are good. if (getContext().checkCallingOrSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) == PackageManager.PERMISSION_GRANTED) { return true; } - // The write settings permission gates mutation of system settings. - if (getContext().checkCallingOrSelfPermission(Manifest.permission.WRITE_SETTINGS) - == PackageManager.PERMISSION_GRANTED) { - return true; - } - - // Excpet we let system apps change system settings without the permission. - PackageInfo packageInfo = getCallingPackageInfoOrThrow(); - if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { - return true; - } - return false; } @@ -1102,15 +1079,6 @@ public class SettingsProvider extends ContentProvider { } } - private boolean isAppOpWriteSettingsAllowedForCallingPackage() { - final int callingUid = Binder.getCallingUid(); - - mAppOpsManager.checkPackage(Binder.getCallingUid(), getCallingPackage()); - - return mAppOpsManager.noteOp(AppOpsManager.OP_WRITE_SETTINGS, callingUid, - getCallingPackage()) == AppOpsManager.MODE_ALLOWED; - } - private void enforceWritePermission(String permission) { if (getContext().checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { |