Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7027b32e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[SettingsProvider] allow test_only apps access @hide keys w/o @Readable" into sc-dev

parents 65cadbe0 3a4059f7
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -2790,13 +2790,12 @@ public final class Settings {
            // Settings.Global and is not annotated as @Readable.
            // Notice that a key string that is not defined in any of the Settings.* classes will
            // still be regarded as readable.
            // TODO(b/175024829): provide a register method.
            if (!Settings.isInSystemServer() && !isSystemOrPrivilegedApp()
            if (!isCallerExemptFromReadableRestriction()
                    && mAllFields.contains(name) && !mReadableFields.contains(name)) {
                throw new SecurityException(
                        "Settings key: <" + name + "> is not readable. From S+, new public "
                        + "settings keys need to be annotated with @Readable unless they are "
                        + "annotated with @hide.");
                        "Settings key: <" + name + "> is not readable. From S+, settings keys "
                                + "annotated with @hide are restricted to system_server and system "
                                + "apps only, unless they are annotated with @Readable.");
            }
            final boolean isSelf = (userHandle == UserHandle.myUserId());
            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) {
                return true;
            }
@@ -2981,7 +2983,9 @@ public final class Settings {
                return false;
            }
            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();
        }
+7 −4
Original line number Diff line number Diff line
@@ -1941,7 +1941,10 @@ public class SettingsProvider extends ContentProvider {
        if (ai.isSystemApp() || ai.isSignedWithPlatformKey()) {
            return;
        }
        if ((ai.flags & ApplicationInfo.FLAG_TEST_ONLY) == 0) {
            // Skip checking readable annotations for test_only apps
            checkReadableAnnotation(settingsType, settingName);
        }
        if (!ai.isInstantApp()) {
            return;
        }
@@ -1983,9 +1986,9 @@ public class SettingsProvider extends ContentProvider {

        if (allFields.contains(settingName) && !readableFields.contains(settingName)) {
            throw new SecurityException(
                    "Settings key: <" + settingName + "> is not readable. From S+, new public "
                            + "settings keys need to be annotated with @Readable unless they are "
                            + "annotated with @hide.");
                    "Settings key: <" + settingName + "> is not readable. From S+, settings keys "
                            + "annotated with @hide are restricted to system_server and system "
                            + "apps only, unless they are annotated with @Readable.");
        }
    }