am 3f840c8c: Merge "fix crashing apps" into jb-mr1-dev
* commit '3f840c8c3c1c53f046f6d187b2d3c4120b8d8afe': fix crashing apps
This commit is contained in:
@@ -609,10 +609,9 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw SecurityException if caller has neither COARSE or FINE.
|
* Returns the best permission available to the caller.
|
||||||
* Otherwise, return the best permission.
|
|
||||||
*/
|
*/
|
||||||
private String checkPermission() {
|
private String getBestCallingPermission() {
|
||||||
if (mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION) ==
|
if (mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION) ==
|
||||||
PackageManager.PERMISSION_GRANTED) {
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
return ACCESS_FINE_LOCATION;
|
return ACCESS_FINE_LOCATION;
|
||||||
@@ -620,9 +619,20 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
PackageManager.PERMISSION_GRANTED) {
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
return ACCESS_COARSE_LOCATION;
|
return ACCESS_COARSE_LOCATION;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
throw new SecurityException("Location requires either ACCESS_COARSE_LOCATION or" +
|
/**
|
||||||
" ACCESS_FINE_LOCATION permission");
|
* Throw SecurityException if caller has neither COARSE or FINE.
|
||||||
|
* Otherwise, return the best permission.
|
||||||
|
*/
|
||||||
|
private String checkPermission() {
|
||||||
|
String perm = getBestCallingPermission();
|
||||||
|
if (perm == null) {
|
||||||
|
throw new SecurityException("Location requires either ACCESS_COARSE_LOCATION or" +
|
||||||
|
" ACCESS_FINE_LOCATION permission");
|
||||||
|
}
|
||||||
|
return perm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -635,19 +645,15 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAllowedProviderSafe(String provider) {
|
private String getMinimumPermissionForProvider(String provider) {
|
||||||
if (LocationManager.GPS_PROVIDER.equals(provider) ||
|
if (LocationManager.GPS_PROVIDER.equals(provider) ||
|
||||||
LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
||||||
// gps and passive providers require FINE permission
|
// gps and passive providers require FINE permission
|
||||||
return mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION)
|
return ACCESS_FINE_LOCATION;
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
} else if (LocationManager.NETWORK_PROVIDER.equals(provider) ||
|
} else if (LocationManager.NETWORK_PROVIDER.equals(provider) ||
|
||||||
LocationManager.FUSED_PROVIDER.equals(provider)) {
|
LocationManager.FUSED_PROVIDER.equals(provider)) {
|
||||||
// network and fused providers are ok with COARSE or FINE
|
// network and fused providers are ok with COARSE or FINE
|
||||||
return (mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION)
|
return ACCESS_COARSE_LOCATION;
|
||||||
== PackageManager.PERMISSION_GRANTED) ||
|
|
||||||
(mContext.checkCallingOrSelfPermission(ACCESS_COARSE_LOCATION)
|
|
||||||
== PackageManager.PERMISSION_GRANTED);
|
|
||||||
} else {
|
} else {
|
||||||
// mock providers
|
// mock providers
|
||||||
LocationProviderInterface lp = mMockProviders.get(provider);
|
LocationProviderInterface lp = mMockProviders.get(provider);
|
||||||
@@ -656,20 +662,43 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
if (properties.mRequiresSatellite) {
|
if (properties.mRequiresSatellite) {
|
||||||
// provider requiring satellites require FINE permission
|
// provider requiring satellites require FINE permission
|
||||||
return mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION)
|
return ACCESS_FINE_LOCATION;
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
} else if (properties.mRequiresNetwork || properties.mRequiresCell) {
|
} else if (properties.mRequiresNetwork || properties.mRequiresCell) {
|
||||||
// provider requiring network and or cell require COARSE or FINE
|
// provider requiring network and or cell require COARSE or FINE
|
||||||
return (mContext.checkCallingOrSelfPermission(ACCESS_FINE_LOCATION)
|
return ACCESS_COARSE_LOCATION;
|
||||||
== PackageManager.PERMISSION_GRANTED) ||
|
|
||||||
(mContext.checkCallingOrSelfPermission(ACCESS_COARSE_LOCATION)
|
|
||||||
== PackageManager.PERMISSION_GRANTED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPermissionSufficient(String perm, String minPerm) {
|
||||||
|
if (ACCESS_FINE_LOCATION.equals(minPerm)) {
|
||||||
|
return ACCESS_FINE_LOCATION.equals(perm);
|
||||||
|
} else if (ACCESS_COARSE_LOCATION.equals(minPerm)) {
|
||||||
|
return ACCESS_FINE_LOCATION.equals(perm) ||
|
||||||
|
ACCESS_COARSE_LOCATION.equals(perm);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPermissionForProvider(String perm, String provider) {
|
||||||
|
String minPerm = getMinimumPermissionForProvider(provider);
|
||||||
|
if (!isPermissionSufficient(perm, minPerm)) {
|
||||||
|
if (ACCESS_FINE_LOCATION.equals(minPerm)) {
|
||||||
|
throw new SecurityException("Location provider \"" + provider +
|
||||||
|
"\" requires ACCESS_FINE_LOCATION permission.");
|
||||||
|
} else if (ACCESS_COARSE_LOCATION.equals(minPerm)) {
|
||||||
|
throw new SecurityException("Location provider \"" + provider +
|
||||||
|
"\" requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.");
|
||||||
|
} else {
|
||||||
|
throw new SecurityException("Insufficient permission for location provider \"" +
|
||||||
|
provider + "\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -703,6 +732,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
|
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
|
||||||
ArrayList<String> out;
|
ArrayList<String> out;
|
||||||
|
String perm = getBestCallingPermission();
|
||||||
int callingUserId = UserHandle.getCallingUserId();
|
int callingUserId = UserHandle.getCallingUserId();
|
||||||
long identity = Binder.clearCallingIdentity();
|
long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -713,7 +743,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
if (LocationManager.FUSED_PROVIDER.equals(name)) {
|
if (LocationManager.FUSED_PROVIDER.equals(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isAllowedProviderSafe(name)) {
|
if (isPermissionSufficient(perm, getMinimumPermissionForProvider(name))) {
|
||||||
if (enabledOnly && !isAllowedBySettingsLocked(name, callingUserId)) {
|
if (enabledOnly && !isAllowedBySettingsLocked(name, callingUserId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -980,26 +1010,12 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
return receiver;
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProviderAllowedByCoarsePermission(String provider) {
|
|
||||||
if (LocationManager.FUSED_PROVIDER.equals(provider)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (LocationManager.PASSIVE_PROVIDER.equals(provider)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String checkPermissionAndRequest(LocationRequest request) {
|
private String checkPermissionAndRequest(LocationRequest request) {
|
||||||
String perm = checkPermission();
|
String perm = getBestCallingPermission();
|
||||||
|
String provider = request.getProvider();
|
||||||
|
checkPermissionForProvider(perm, provider);
|
||||||
|
|
||||||
if (ACCESS_COARSE_LOCATION.equals(perm)) {
|
if (ACCESS_COARSE_LOCATION.equals(perm)) {
|
||||||
if (!isProviderAllowedByCoarsePermission(request.getProvider())) {
|
|
||||||
throw new SecurityException("Requires ACCESS_FINE_LOCATION permission");
|
|
||||||
}
|
|
||||||
switch (request.getQuality()) {
|
switch (request.getQuality()) {
|
||||||
case LocationRequest.ACCURACY_FINE:
|
case LocationRequest.ACCURACY_FINE:
|
||||||
request.setQuality(LocationRequest.ACCURACY_BLOCK);
|
request.setQuality(LocationRequest.ACCURACY_BLOCK);
|
||||||
@@ -1324,7 +1340,7 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ProviderProperties getProviderProperties(String provider) {
|
public ProviderProperties getProviderProperties(String provider) {
|
||||||
checkPermission();
|
checkPermissionForProvider(getBestCallingPermission(), provider);
|
||||||
|
|
||||||
LocationProviderInterface p;
|
LocationProviderInterface p;
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -1337,13 +1353,8 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isProviderEnabled(String provider) {
|
public boolean isProviderEnabled(String provider) {
|
||||||
String perms = checkPermission();
|
checkPermissionForProvider(getBestCallingPermission(), provider);
|
||||||
if (LocationManager.FUSED_PROVIDER.equals(provider)) return false;
|
if (LocationManager.FUSED_PROVIDER.equals(provider)) return false;
|
||||||
if (ACCESS_COARSE_LOCATION.equals(perms) &&
|
|
||||||
!isProviderAllowedByCoarsePermission(provider)) {
|
|
||||||
throw new SecurityException("The \"" + provider +
|
|
||||||
"\" provider requires ACCESS_FINE_LOCATION permission");
|
|
||||||
}
|
|
||||||
|
|
||||||
long identity = Binder.clearCallingIdentity();
|
long identity = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user