Merge "Restore legacy SecurityException behavior" into rvc-dev am: 0ea91490c5 am: 9942a42bd6 am: 963cc1a02f
Change-Id: I4e646a6085fdb5cbd0feed7b25d25fcbc40e80ec
This commit is contained in:
@@ -102,6 +102,16 @@ public class LocationManager {
|
|||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For apps targeting Android R and above, {@link #getProvider(String)} will no longer throw any
|
||||||
|
* security exceptions.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@ChangeId
|
||||||
|
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
|
||||||
|
private static final long GET_PROVIDER_SECURITY_EXCEPTIONS = 150935354L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For apps targeting Android K and above, supplied {@link PendingIntent}s must be targeted to a
|
* For apps targeting Android K and above, supplied {@link PendingIntent}s must be targeted to a
|
||||||
* specific package.
|
* specific package.
|
||||||
@@ -1401,6 +1411,22 @@ public class LocationManager {
|
|||||||
*/
|
*/
|
||||||
public @Nullable LocationProvider getProvider(@NonNull String provider) {
|
public @Nullable LocationProvider getProvider(@NonNull String provider) {
|
||||||
Preconditions.checkArgument(provider != null, "invalid null provider");
|
Preconditions.checkArgument(provider != null, "invalid null provider");
|
||||||
|
|
||||||
|
if (!Compatibility.isChangeEnabled(GET_PROVIDER_SECURITY_EXCEPTIONS)) {
|
||||||
|
if (NETWORK_PROVIDER.equals(provider) || FUSED_PROVIDER.equals(provider)) {
|
||||||
|
try {
|
||||||
|
mContext.enforcePermission(ACCESS_FINE_LOCATION, Process.myPid(),
|
||||||
|
Process.myUid(), null);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
mContext.enforcePermission(ACCESS_COARSE_LOCATION, Process.myPid(),
|
||||||
|
Process.myUid(), null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mContext.enforcePermission(ACCESS_FINE_LOCATION, Process.myPid(), Process.myUid(),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProviderProperties properties = mService.getProviderProperties(provider);
|
ProviderProperties properties = mService.getProviderProperties(provider);
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user