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

Commit b9dd251e authored by Michael Groover's avatar Michael Groover Committed by Android (Google) Code Review
Browse files

Merge "Enable device identifier check for priv apps"

parents e9c836ef efca4772
Loading
Loading
Loading
Loading
+10 −21
Original line number Diff line number Diff line
@@ -13018,48 +13018,37 @@ public final class Settings {
                "sms_access_restriction_enabled";
        /**
         * If set to 1, an app must have the READ_PRIVILEGED_PHONE_STATE permission (or be a device
         * / profile owner with the READ_PHONE_STATE permission) to access device identifiers.
         *
         * STOPSHIP: Remove this once we ship with the new device identifier check enabled.
         *
         * @hide
         */
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_CHECK_ENABLED =
                "privileged_device_identifier_check_enabled";
        /**
         * If set to 1, an app that is targeting Q and does not meet the new requirements to access
         * device identifiers will receive a SecurityException.
         * If set to 1, the device identifier check will be relaxed to the previous READ_PHONE_STATE
         * permission check for 3P apps.
         *
         * STOPSHIP: Remove this once we ship with the new device identifier check enabled.
         *
         * @hide
         */
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_TARGET_Q_BEHAVIOR_ENABLED =
                "privileged_device_identifier_target_q_behavior_enabled";
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED =
                "privileged_device_identifier_3p_check_relaxed";
        /**
         * If set to 1, the device identifier check will be relaxed to the previous READ_PHONE_STATE
         * permission check for 3P apps.
         * permission check for preloaded non-privileged apps.
         *
         * STOPSHIP: Remove this once we ship with the new device identifier check enabled.
         *
         * @hide
         */
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED =
                "privileged_device_identifier_3p_check_relaxed";
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED =
                "privileged_device_identifier_non_priv_check_relaxed";
        /**
         * If set to 1, the device identifier check will be relaxed to the previous READ_PHONE_STATE
         * permission check for preloaded non-privileged apps.
         * permission check for preloaded privileged apps.
         *
         * STOPSHIP: Remove this once we ship with the new device identifier check enabled.
         *
         * @hide
         */
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED =
                "privileged_device_identifier_non_priv_check_relaxed";
        public static final String PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED =
                "privileged_device_identifier_priv_check_relaxed";
        /**
         * If set to 1, SettingsProvider's restoreAnyVersion="true" attribute will be ignored
+1 −2
Original line number Diff line number Diff line
@@ -390,9 +390,8 @@ public class SettingsBackupTest {
                    Settings.Global.POWER_MANAGER_CONSTANTS,
                    Settings.Global.PREFERRED_NETWORK_MODE,
                    Settings.Global.PRIVATE_DNS_DEFAULT_MODE,
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_CHECK_ENABLED,
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED,
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_TARGET_Q_BEHAVIOR_ENABLED,
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED,
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED,
                    Settings.Global.PROVISIONING_APN_ALARM_DELAY_IN_MS,
                    Settings.Global.RADIO_BLUETOOTH,
+25 −33
Original line number Diff line number Diff line
@@ -284,10 +284,6 @@ public final class TelephonyPermissions {
     */
    private static boolean reportAccessDeniedToReadIdentifiers(Context context, int subId, int pid,
            int uid, String callingPackage, String message) {
        // If the device identifier check is enabled then enforce the new access requirements for
        // both 1P and 3P apps.
        boolean enableDeviceIdentifierCheck = Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_CHECK_ENABLED, 0) == 1;
        // Check if the application is a 3P app; if so then a separate setting is required to relax
        // the check to begin flagging problems with 3P apps early.
        boolean relax3PDeviceIdentifierCheck = Settings.Global.getInt(context.getContentResolver(),
@@ -300,6 +296,11 @@ public final class TelephonyPermissions {
                context.getContentResolver(),
                Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED, 0) == 1;
        boolean isNonPrivApp = false;
        // Similar to above support relaxing the check for privileged apps while still enforcing it
        // for non-privileged and 3P apps.
        boolean relaxPrivDeviceIdentifierCheck = Settings.Global.getInt(
                context.getContentResolver(),
                Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED, 0) == 1;
        ApplicationInfo callingPackageInfo = null;
        try {
            callingPackageInfo = context.getPackageManager().getApplicationInfo(callingPackage, 0);
@@ -315,26 +316,18 @@ public final class TelephonyPermissions {
            Log.e(LOG_TAG, "Exception caught obtaining package info for package " + callingPackage,
                    e);
        }
        Log.wtf(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message
                + ":is3PApp=" + is3PApp + ":isNonPrivApp=" + isNonPrivApp);
        // The new Q restrictions for device identifier access will be enforced if any of the
        // following are true:
        // - The PRIVILEGED_DEVICE_IDENTIFIER_CHECK_ENABLED setting has been set.
        // - The app requesting a device identifier is not a preloaded app (3P), and the
        //   PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED setting has not been set.
        // - The app requesting a device identifier is a preloaded app but is not a privileged app,
        //   and the PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED setting has not been set.
        if (enableDeviceIdentifierCheck
        // The new Q restrictions for device identifier access will be enforced for all apps with
        // settings to individually disable the new restrictions for privileged, preloaded
        // non-privileged, and 3P apps.
        if ((!is3PApp && !isNonPrivApp && !relaxPrivDeviceIdentifierCheck)
                || (is3PApp && !relax3PDeviceIdentifierCheck)
                || (isNonPrivApp && !relaxNonPrivDeviceIdentifierCheck)) {
            boolean targetQBehaviorDisabled = Settings.Global.getInt(context.getContentResolver(),
                    Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_TARGET_Q_BEHAVIOR_ENABLED, 0) == 0;
            if (callingPackage != null) {
                // if the target SDK is pre-Q or the target Q behavior is disabled then check if
                // the calling package would have previously had access to device identifiers.
            Log.wtf(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message
                    + ":is3PApp=" + is3PApp + ":isNonPrivApp=" + isNonPrivApp);
            // if the target SDK is pre-Q then check if the calling package would have previously
            // had access to device identifiers.
            if (callingPackageInfo != null && (
                        callingPackageInfo.targetSdkVersion < Build.VERSION_CODES.Q
                                || targetQBehaviorDisabled)) {
                    callingPackageInfo.targetSdkVersion < Build.VERSION_CODES.Q)) {
                if (context.checkPermission(
                        android.Manifest.permission.READ_PHONE_STATE,
                        pid,
@@ -347,7 +340,6 @@ public final class TelephonyPermissions {
                    return false;
                }
            }
            }
            throw new SecurityException(message + ": The user " + uid
                    + " does not meet the requirements to access device identifiers.");
        } else {