Use platform-compat-fw to separate enforce location change
The location permission check enforcement introduced in b/182384053
is separated with CompatChanges#isChangeEnabled to keep better
compatibility.
Bug: 191911306
Test: atest ServiceStateProviderTest
Change-Id: I3d9b24e05e86cbcd7f64d9c0969171d7db1c8756
diff --git a/src/com/android/phone/ServiceStateProvider.java b/src/com/android/phone/ServiceStateProvider.java
index 56786f9..6f5fcf5 100644
--- a/src/com/android/phone/ServiceStateProvider.java
+++ b/src/com/android/phone/ServiceStateProvider.java
@@ -28,6 +28,9 @@
import static android.provider.Telephony.ServiceStateTable.getUriForSubscriptionIdAndField;
import android.Manifest;
+import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledAfter;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
@@ -230,6 +233,15 @@
*/
public static final String OPERATOR_ALPHA_SHORT_RAW = "operator_alpha_short_raw";
+ /**
+ * If the change Id is enabled, location permission is required to access location sensitive
+ * columns in the ServiceStateTable.
+ */
+ @ChangeId
+ @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
+ @VisibleForTesting
+ /* package */ static final long ENFORCE_LOCATION_PERMISSION_CHECK = 191911306;
+
private final HashMap<Integer, ServiceState> mServiceStates = new HashMap<>();
@VisibleForTesting
@@ -398,7 +410,8 @@
return null;
}
- // TODO(b/182384053): replace targetSdk check with CompatChanges#isChangeEnabled
+ final boolean enforceLocationPermission =
+ CompatChanges.isChangeEnabled(ENFORCE_LOCATION_PERMISSION_CHECK);
final boolean targetingAtLeastS = TelephonyPermissions.getTargetSdk(getContext(),
getCallingPackage()) >= Build.VERSION_CODES.S;
final boolean canReadPrivilegedPhoneState = getContext().checkCallingOrSelfPermission(
@@ -406,7 +419,7 @@
final String[] availableColumns;
final ServiceState ss;
- if (targetingAtLeastS && !canReadPrivilegedPhoneState) {
+ if (enforceLocationPermission && targetingAtLeastS && !canReadPrivilegedPhoneState) {
// targetSdkVersion S+ without read privileged phone state permission can only
// access public columns which have no location sensitive info.
availableColumns = PUBLIC_COLUMNS;
@@ -415,9 +428,9 @@
availableColumns = ALL_COLUMNS;
final boolean hasLocationPermission = hasLocationPermission();
- if (hasLocationPermission) {
+ if (!enforceLocationPermission || hasLocationPermission) {
// No matter the targetSdkVersion, return unredacted ServiceState if caller does
- // have location permission.
+ // have location permission or location permission enforcement is not introduced
ss = unredactedServiceState;
} else {
// The caller has targetSdkVersion S+ but no location permission. It explicitly