use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method providerMeetsCriteria.
@Override
public boolean providerMeetsCriteria(String provider, Criteria criteria) {
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null) {
throw new IllegalArgumentException("provider=" + provider);
}
boolean result = LocationProvider.propertiesMeetCriteria(p.getName(), p.getProperties(), criteria);
if (D)
Log.d(TAG, "providerMeetsCriteria(" + provider + ", " + criteria + ")=" + result);
return result;
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method getProviders.
/**
* Return all providers by name, that match criteria and are optionally
* enabled.
* Can return passive provider, but never returns fused provider.
*/
@Override
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
int allowedResolutionLevel = getCallerAllowedResolutionLevel();
ArrayList<String> out;
int uid = Binder.getCallingUid();
;
long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
out = new ArrayList<String>(mProviders.size());
for (LocationProviderInterface provider : mProviders) {
String name = provider.getName();
if (LocationManager.FUSED_PROVIDER.equals(name)) {
continue;
}
if (allowedResolutionLevel >= getMinimumResolutionLevelForProviderUse(name)) {
if (enabledOnly && !isAllowedByUserSettingsLocked(name, uid)) {
continue;
}
if (criteria != null && !LocationProvider.propertiesMeetCriteria(name, provider.getProperties(), criteria)) {
continue;
}
out.add(name);
}
}
}
} finally {
Binder.restoreCallingIdentity(identity);
}
if (D)
Log.d(TAG, "getProviders()=" + out);
return out;
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method updateProviderListenersLocked.
private void updateProviderListenersLocked(String provider, boolean enabled, int userId) {
int listeners = 0;
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null)
return;
ArrayList<Receiver> deadReceivers = null;
ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider);
if (records != null) {
final int N = records.size();
for (int i = 0; i < N; i++) {
UpdateRecord record = records.get(i);
if (UserHandle.getUserId(record.mReceiver.mUid) == userId) {
// Sends a notification message to the receiver
if (!record.mReceiver.callProviderEnabledLocked(provider, enabled)) {
if (deadReceivers == null) {
deadReceivers = new ArrayList<Receiver>();
}
deadReceivers.add(record.mReceiver);
}
listeners++;
}
}
}
if (deadReceivers != null) {
for (int i = deadReceivers.size() - 1; i >= 0; i--) {
removeUpdatesLocked(deadReceivers.get(i));
}
}
if (enabled) {
p.enable();
if (listeners > 0) {
applyRequirementsLocked(provider);
}
} else {
p.disable();
}
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method removeTestProvider.
@Override
public void removeTestProvider(String provider) {
checkMockPermissionsSafe();
synchronized (mLock) {
MockProvider mockProvider = mMockProviders.remove(provider);
if (mockProvider == null) {
throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
}
long identity = Binder.clearCallingIdentity();
removeProviderLocked(mProvidersByName.get(provider));
if (mGeoFencer != null) {
mGeoFencerEnabled = true;
}
// 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);
}
}
use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.
the class LocationManagerService method applyRequirementsLocked.
private void applyRequirementsLocked(String provider) {
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null)
return;
ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider);
WorkSource worksource = new WorkSource();
ProviderRequest providerRequest = new ProviderRequest();
if (records != null) {
for (UpdateRecord record : records) {
if (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) {
if (checkLocationAccess(record.mReceiver.mPid, record.mReceiver.mUid, record.mReceiver.mPackageName, record.mReceiver.mAllowedResolutionLevel)) {
LocationRequest locationRequest = record.mRequest;
providerRequest.locationRequests.add(locationRequest);
if (locationRequest.getInterval() < providerRequest.interval) {
providerRequest.reportLocation = true;
providerRequest.interval = locationRequest.getInterval();
}
}
}
}
if (providerRequest.reportLocation) {
// calculate who to blame for power
// This is somewhat arbitrary. We pick a threshold interval
// that is slightly higher that the minimum interval, and
// spread the blame across all applications with a request
// under that threshold.
long thresholdInterval = (providerRequest.interval + 1000) * 3 / 2;
for (UpdateRecord record : records) {
if (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) {
LocationRequest locationRequest = record.mRequest;
// client has no permission to receive location data.
if (!providerRequest.locationRequests.contains(locationRequest)) {
continue;
}
if (locationRequest.getInterval() <= thresholdInterval) {
if (record.mReceiver.mWorkSource != null && record.mReceiver.mWorkSource.size() > 0 && record.mReceiver.mWorkSource.getName(0) != null) {
// Assign blame to another work source.
// Can only assign blame if the WorkSource contains names.
worksource.add(record.mReceiver.mWorkSource);
} else {
// Assign blame to caller.
worksource.add(record.mReceiver.mUid, record.mReceiver.mPackageName);
}
}
}
}
}
}
if (D)
Log.d(TAG, "provider request: " + provider + " " + providerRequest);
p.setRequest(providerRequest, worksource);
}
Aggregations