Search in sources :

Example 6 with ProviderRequest

use of com.android.internal.location.ProviderRequest in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : LocationRequest(android.location.LocationRequest) WorkSource(android.os.WorkSource) LocationProviderInterface(com.android.server.location.LocationProviderInterface) ProviderRequest(com.android.internal.location.ProviderRequest)

Aggregations

LocationRequest (android.location.LocationRequest)6 WorkSource (android.os.WorkSource)6 ProviderRequest (com.android.internal.location.ProviderRequest)6 LocationProviderInterface (com.android.server.location.LocationProviderInterface)6