Merge "Remove settings to relax device ID access restrictions" into qt-dev
am: 692a68133b
Change-Id: I54d5aba18bc6925273668b3a9b940445d6a2a4ca
This commit is contained in:
@@ -13568,39 +13568,6 @@ public final class Settings {
|
|||||||
public static final String LOCATION_GLOBAL_KILL_SWITCH =
|
public static final String LOCATION_GLOBAL_KILL_SWITCH =
|
||||||
"location_global_kill_switch";
|
"location_global_kill_switch";
|
||||||
|
|
||||||
/**
|
|
||||||
* 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_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 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_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 privileged apps.
|
|
||||||
*
|
|
||||||
* STOPSHIP: Remove this once we ship with the new device identifier check enabled.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
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
|
* If set to 1, SettingsProvider's restoreAnyVersion="true" attribute will be ignored
|
||||||
* and restoring to lower version of platform API will be skipped.
|
* and restoring to lower version of platform API will be skipped.
|
||||||
|
|||||||
@@ -397,9 +397,6 @@ public class SettingsBackupTest {
|
|||||||
Settings.Global.POWER_MANAGER_CONSTANTS,
|
Settings.Global.POWER_MANAGER_CONSTANTS,
|
||||||
Settings.Global.PREFERRED_NETWORK_MODE,
|
Settings.Global.PREFERRED_NETWORK_MODE,
|
||||||
Settings.Global.PRIVATE_DNS_DEFAULT_MODE,
|
Settings.Global.PRIVATE_DNS_DEFAULT_MODE,
|
||||||
Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED,
|
|
||||||
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.PROVISIONING_APN_ALARM_DELAY_IN_MS,
|
||||||
Settings.Global.RADIO_BLUETOOTH,
|
Settings.Global.RADIO_BLUETOOTH,
|
||||||
Settings.Global.RADIO_CELL,
|
Settings.Global.RADIO_CELL,
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ import android.os.Process;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.telephony.Rlog;
|
import android.telephony.Rlog;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -364,23 +362,8 @@ public final class TelephonyPermissions {
|
|||||||
*/
|
*/
|
||||||
private static boolean reportAccessDeniedToReadIdentifiers(Context context, int subId, int pid,
|
private static boolean reportAccessDeniedToReadIdentifiers(Context context, int subId, int pid,
|
||||||
int uid, String callingPackage, String message) {
|
int uid, String callingPackage, String message) {
|
||||||
// Check if the application is not preinstalled; if not then a separate setting is required
|
|
||||||
// to relax the check to begin flagging problems with non-preinstalled apps early.
|
|
||||||
boolean relax3PDeviceIdentifierCheck = Settings.Global.getInt(context.getContentResolver(),
|
|
||||||
Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED, 0) == 1;
|
|
||||||
boolean isPreinstalled = false;
|
boolean isPreinstalled = false;
|
||||||
// Also check if the application is a preloaded non-privileged app; if so there is a
|
|
||||||
// separate setting to relax the check for these apps to ensure users can relax the check
|
|
||||||
// for non-preinstalled or non-priv apps as needed while continuing to test the other.
|
|
||||||
boolean relaxNonPrivDeviceIdentifierCheck = Settings.Global.getInt(
|
|
||||||
context.getContentResolver(),
|
|
||||||
Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED, 0) == 1;
|
|
||||||
boolean isPrivApp = false;
|
boolean isPrivApp = false;
|
||||||
// Similar to above support relaxing the check for privileged apps while still enforcing it
|
|
||||||
// for non-privileged and non-preinstalled apps.
|
|
||||||
boolean relaxPrivDeviceIdentifierCheck = Settings.Global.getInt(
|
|
||||||
context.getContentResolver(),
|
|
||||||
Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED, 0) == 1;
|
|
||||||
ApplicationInfo callingPackageInfo = null;
|
ApplicationInfo callingPackageInfo = null;
|
||||||
try {
|
try {
|
||||||
callingPackageInfo = context.getPackageManager().getApplicationInfoAsUser(
|
callingPackageInfo = context.getPackageManager().getApplicationInfoAsUser(
|
||||||
@@ -399,58 +382,40 @@ public final class TelephonyPermissions {
|
|||||||
Log.e(LOG_TAG, "Exception caught obtaining package info for package " + callingPackage,
|
Log.e(LOG_TAG, "Exception caught obtaining package info for package " + callingPackage,
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
// The new Q restrictions for device identifier access will be enforced for all apps with
|
// The current package should only be reported in StatsLog if it has not previously been
|
||||||
// settings to individually disable the new restrictions for privileged, preloaded
|
// reported for the currently invoked device identifier method.
|
||||||
// non-privileged, and non-preinstalled apps.
|
boolean packageReported = sReportedDeviceIDPackages.containsKey(callingPackage);
|
||||||
if (!isIdentifierCheckDisabled() && (
|
if (!packageReported || !sReportedDeviceIDPackages.get(callingPackage).contains(
|
||||||
(isPrivApp && !relaxPrivDeviceIdentifierCheck)
|
message)) {
|
||||||
|| (!isPreinstalled && !relax3PDeviceIdentifierCheck)
|
Set invokedMethods;
|
||||||
|| (isPreinstalled && !isPrivApp && !relaxNonPrivDeviceIdentifierCheck))) {
|
if (!packageReported) {
|
||||||
// The current package should only be reported in StatsLog if it has not previously been
|
invokedMethods = new HashSet<String>();
|
||||||
// reported for the currently invoked device identifier method.
|
sReportedDeviceIDPackages.put(callingPackage, invokedMethods);
|
||||||
boolean packageReported = sReportedDeviceIDPackages.containsKey(callingPackage);
|
} else {
|
||||||
if (!packageReported || !sReportedDeviceIDPackages.get(callingPackage).contains(
|
invokedMethods = sReportedDeviceIDPackages.get(callingPackage);
|
||||||
message)) {
|
|
||||||
Set invokedMethods;
|
|
||||||
if (!packageReported) {
|
|
||||||
invokedMethods = new HashSet<String>();
|
|
||||||
sReportedDeviceIDPackages.put(callingPackage, invokedMethods);
|
|
||||||
} else {
|
|
||||||
invokedMethods = sReportedDeviceIDPackages.get(callingPackage);
|
|
||||||
}
|
|
||||||
invokedMethods.add(message);
|
|
||||||
StatsLog.write(StatsLog.DEVICE_IDENTIFIER_ACCESS_DENIED, callingPackage, message,
|
|
||||||
isPreinstalled, isPrivApp);
|
|
||||||
}
|
}
|
||||||
Log.w(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message
|
invokedMethods.add(message);
|
||||||
+ ":isPreinstalled=" + isPreinstalled + ":isPrivApp=" + isPrivApp);
|
StatsLog.write(StatsLog.DEVICE_IDENTIFIER_ACCESS_DENIED, callingPackage, message,
|
||||||
// if the target SDK is pre-Q then check if the calling package would have previously
|
isPreinstalled, isPrivApp);
|
||||||
// had access to device identifiers.
|
|
||||||
if (callingPackageInfo != null && (
|
|
||||||
callingPackageInfo.targetSdkVersion < Build.VERSION_CODES.Q)) {
|
|
||||||
if (context.checkPermission(
|
|
||||||
android.Manifest.permission.READ_PHONE_STATE,
|
|
||||||
pid,
|
|
||||||
uid) == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (checkCarrierPrivilegeForSubId(subId)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new SecurityException(message + ": The user " + uid
|
|
||||||
+ " does not meet the requirements to access device identifiers.");
|
|
||||||
} else {
|
|
||||||
return checkReadPhoneState(context, subId, pid, uid, callingPackage, message);
|
|
||||||
}
|
}
|
||||||
}
|
Log.w(LOG_TAG, "reportAccessDeniedToReadIdentifiers:" + callingPackage + ":" + message
|
||||||
|
+ ":isPreinstalled=" + isPreinstalled + ":isPrivApp=" + isPrivApp);
|
||||||
/**
|
// if the target SDK is pre-Q then check if the calling package would have previously
|
||||||
* Returns true if the new device identifier access restrictions are disabled.
|
// had access to device identifiers.
|
||||||
*/
|
if (callingPackageInfo != null && (
|
||||||
private static boolean isIdentifierCheckDisabled() {
|
callingPackageInfo.targetSdkVersion < Build.VERSION_CODES.Q)) {
|
||||||
return DeviceConfig.getInt(DeviceConfig.NAMESPACE_PRIVACY,
|
if (context.checkPermission(
|
||||||
PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED, 0) == 1;
|
android.Manifest.permission.READ_PHONE_STATE,
|
||||||
|
pid,
|
||||||
|
uid) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (checkCarrierPrivilegeForSubId(subId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new SecurityException(message + ": The user " + uid
|
||||||
|
+ " does not meet the requirements to access device identifiers.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user