Merge "[SettingsProvider] allow test_only apps access @hide keys w/o @Readable" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7027b32e9e
@@ -2790,13 +2790,12 @@ public final class Settings {
|
|||||||
// Settings.Global and is not annotated as @Readable.
|
// Settings.Global and is not annotated as @Readable.
|
||||||
// Notice that a key string that is not defined in any of the Settings.* classes will
|
// Notice that a key string that is not defined in any of the Settings.* classes will
|
||||||
// still be regarded as readable.
|
// still be regarded as readable.
|
||||||
// TODO(b/175024829): provide a register method.
|
if (!isCallerExemptFromReadableRestriction()
|
||||||
if (!Settings.isInSystemServer() && !isSystemOrPrivilegedApp()
|
|
||||||
&& mAllFields.contains(name) && !mReadableFields.contains(name)) {
|
&& mAllFields.contains(name) && !mReadableFields.contains(name)) {
|
||||||
throw new SecurityException(
|
throw new SecurityException(
|
||||||
"Settings key: <" + name + "> is not readable. From S+, new public "
|
"Settings key: <" + name + "> is not readable. From S+, settings keys "
|
||||||
+ "settings keys need to be annotated with @Readable unless they are "
|
+ "annotated with @hide are restricted to system_server and system "
|
||||||
+ "annotated with @hide.");
|
+ "apps only, unless they are annotated with @Readable.");
|
||||||
}
|
}
|
||||||
final boolean isSelf = (userHandle == UserHandle.myUserId());
|
final boolean isSelf = (userHandle == UserHandle.myUserId());
|
||||||
int currentGeneration = -1;
|
int currentGeneration = -1;
|
||||||
@@ -2972,7 +2971,10 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSystemOrPrivilegedApp() {
|
private static boolean isCallerExemptFromReadableRestriction() {
|
||||||
|
if (Settings.isInSystemServer()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (UserHandle.getAppId(Binder.getCallingUid()) < Process.FIRST_APPLICATION_UID) {
|
if (UserHandle.getAppId(Binder.getCallingUid()) < Process.FIRST_APPLICATION_UID) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2981,7 +2983,9 @@ public final class Settings {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ApplicationInfo applicationInfo = application.getApplicationInfo();
|
final ApplicationInfo applicationInfo = application.getApplicationInfo();
|
||||||
return applicationInfo.isSystemApp() || applicationInfo.isPrivilegedApp()
|
final boolean isTestOnly =
|
||||||
|
(applicationInfo.flags & ApplicationInfo.FLAG_TEST_ONLY) != 0;
|
||||||
|
return isTestOnly || applicationInfo.isSystemApp() || applicationInfo.isPrivilegedApp()
|
||||||
|| applicationInfo.isSignedWithPlatformKey();
|
|| applicationInfo.isSignedWithPlatformKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1941,7 +1941,10 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
if (ai.isSystemApp() || ai.isSignedWithPlatformKey()) {
|
if (ai.isSystemApp() || ai.isSignedWithPlatformKey()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkReadableAnnotation(settingsType, settingName);
|
if ((ai.flags & ApplicationInfo.FLAG_TEST_ONLY) == 0) {
|
||||||
|
// Skip checking readable annotations for test_only apps
|
||||||
|
checkReadableAnnotation(settingsType, settingName);
|
||||||
|
}
|
||||||
if (!ai.isInstantApp()) {
|
if (!ai.isInstantApp()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1983,9 +1986,9 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
|
|
||||||
if (allFields.contains(settingName) && !readableFields.contains(settingName)) {
|
if (allFields.contains(settingName) && !readableFields.contains(settingName)) {
|
||||||
throw new SecurityException(
|
throw new SecurityException(
|
||||||
"Settings key: <" + settingName + "> is not readable. From S+, new public "
|
"Settings key: <" + settingName + "> is not readable. From S+, settings keys "
|
||||||
+ "settings keys need to be annotated with @Readable unless they are "
|
+ "annotated with @hide are restricted to system_server and system "
|
||||||
+ "annotated with @hide.");
|
+ "apps only, unless they are annotated with @Readable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user