use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method getAllProviders.
/**
* Returns all providers by name, including passive, but excluding
* fused, also including ones that are not permitted to
* be accessed by the calling activity or are currently disabled.
*/
@Override
public List<String> getAllProviders() {
ArrayList<String> out;
synchronized (mLock) {
out = new ArrayList<String>(mProviders.size());
for (LocationProviderInterface provider : mProviders) {
String name = provider.getName();
if (LocationManager.FUSED_PROVIDER.equals(name)) {
continue;
}
out.add(name);
}
}
if (D)
Log.d(TAG, "getAllProviders()=" + out);
return out;
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method addTestProvider.
@Override
public void addTestProvider(String name, ProviderProperties properties, String opPackageName) {
if (!canCallerAccessMockLocation(opPackageName)) {
return;
}
if (LocationManager.PASSIVE_PROVIDER.equals(name)) {
throw new IllegalArgumentException("Cannot mock the passive location provider");
}
long identity = Binder.clearCallingIdentity();
synchronized (mLock) {
// remove the real provider if we are replacing GPS or network provider
if (LocationManager.GPS_PROVIDER.equals(name) || LocationManager.NETWORK_PROVIDER.equals(name) || LocationManager.FUSED_PROVIDER.equals(name)) {
LocationProviderInterface p = mProvidersByName.get(name);
if (p != null) {
removeProviderLocked(p);
}
}
addTestProviderLocked(name, properties);
updateProvidersLocked();
}
Binder.restoreCallingIdentity(identity);
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method getLastLocation.
@Override
public Location getLastLocation(LocationRequest request, String packageName) {
if (D)
Log.d(TAG, "getLastLocation: " + request);
if (request == null)
request = DEFAULT_LOCATION_REQUEST;
int allowedResolutionLevel = getCallerAllowedResolutionLevel();
checkPackageName(packageName);
checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, request.getProvider());
// no need to sanitize this request, as only the provider name is used
final int pid = Binder.getCallingPid();
final int uid = Binder.getCallingUid();
final long identity = Binder.clearCallingIdentity();
try {
if (mBlacklist.isBlacklisted(packageName)) {
if (D)
Log.d(TAG, "not returning last loc for blacklisted app: " + packageName);
return null;
}
if (!reportLocationAccessNoThrow(pid, uid, packageName, allowedResolutionLevel)) {
if (D)
Log.d(TAG, "not returning last loc for no op app: " + packageName);
return null;
}
synchronized (mLock) {
// Figure out the provider. Either its explicitly request (deprecated API's),
// or use the fused provider
String name = request.getProvider();
if (name == null)
name = LocationManager.FUSED_PROVIDER;
LocationProviderInterface provider = mProvidersByName.get(name);
if (provider == null)
return null;
if (!isAllowedByUserSettingsLocked(name, uid))
return null;
Location location;
if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) {
// Make sure that an app with coarse permissions can't get frequent location
// updates by calling LocationManager.getLastKnownLocation repeatedly.
location = mLastLocationCoarseInterval.get(name);
} else {
location = mLastLocation.get(name);
}
if (location == null) {
return null;
}
if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) {
Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION);
if (noGPSLocation != null) {
return new Location(mLocationFudger.getOrCreate(noGPSLocation));
}
} else {
return new Location(location);
}
}
return null;
} finally {
Binder.restoreCallingIdentity(identity);
}
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method shutdownComponents.
/**
* Provides a way for components held by the {@link LocationManagerService} to clean-up
* gracefully on system's shutdown.
*
* NOTES:
* 1) Only provides a chance to clean-up on an opt-in basis. This guarantees back-compat
* support for components that do not wish to handle such event.
*/
private void shutdownComponents() {
if (D)
Log.d(TAG, "Shutting down components...");
LocationProviderInterface gpsProvider = mProvidersByName.get(LocationManager.GPS_PROVIDER);
if (gpsProvider != null && gpsProvider.isEnabled()) {
gpsProvider.disable();
}
// avoids an exception to be thrown by the singleton factory method
if (FlpHardwareProvider.isSupported()) {
FlpHardwareProvider flpHardwareProvider = FlpHardwareProvider.getInstance(mContext);
flpHardwareProvider.cleanup();
}
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method removeTestProvider.
@Override
public void removeTestProvider(String provider, String opPackageName) {
if (!canCallerAccessMockLocation(opPackageName)) {
return;
}
synchronized (mLock) {
// These methods can't be called after removing the test provider, so first make sure
// we don't leave anything dangling.
clearTestProviderEnabled(provider, opPackageName);
clearTestProviderLocation(provider, opPackageName);
clearTestProviderStatus(provider, opPackageName);
MockProvider mockProvider = mMockProviders.remove(provider);
if (mockProvider == null) {
throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
}
long identity = Binder.clearCallingIdentity();
removeProviderLocked(mProvidersByName.get(provider));
// reinstate real provider if available
LocationProviderInterface realProvider = mRealProviders.get(provider);
if (realProvider != null) {
addProviderLocked(realProvider);
}
mLastLocation.put(provider, null);
mLastLocationCoarseInterval.put(provider, null);
updateProvidersLocked();
Binder.restoreCallingIdentity(identity);
}
}
Aggregations