Search in sources :

Example 81 with LocationProviderInterface

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

Example 82 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.

the class LocationManagerService method getProviderProperties.

/**
     * @return null if the provider does not exist
     * @throws SecurityException if the provider is not allowed to be
     * accessed by the caller
     */
@Override
public ProviderProperties getProviderProperties(String provider) {
    if (mProvidersByName.get(provider) == null) {
        return null;
    }
    checkResolutionLevelIsSufficientForProviderUse(getCallerAllowedResolutionLevel(), provider);
    LocationProviderInterface p;
    synchronized (mLock) {
        p = mProvidersByName.get(provider);
    }
    if (p == null)
        return null;
    return p.getProperties();
}
Also used : LocationProviderInterface(com.android.server.location.LocationProviderInterface)

Example 83 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by DirtyUnicorns.

the class LocationManagerService method isProviderEnabled.

@Override
public boolean isProviderEnabled(String provider) {
    // so we discourage its use
    if (LocationManager.FUSED_PROVIDER.equals(provider))
        return false;
    int uid = Binder.getCallingUid();
    long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            LocationProviderInterface p = mProvidersByName.get(provider);
            if (p == null)
                return false;
            return isAllowedByUserSettingsLocked(provider, uid);
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : LocationProviderInterface(com.android.server.location.LocationProviderInterface)

Example 84 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ResurrectionRemix.

the class LocationManagerService method updateProviderListenersLocked.

private void updateProviderListenersLocked(String provider, boolean enabled) {
    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 (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) {
                // 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();
    }
}
Also used : BroadcastReceiver(android.content.BroadcastReceiver) LocationProviderInterface(com.android.server.location.LocationProviderInterface)

Example 85 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project android_frameworks_base by ResurrectionRemix.

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

Aggregations

LocationProviderInterface (com.android.server.location.LocationProviderInterface)95 BroadcastReceiver (android.content.BroadcastReceiver)18 Location (android.location.Location)18 MockProvider (com.android.server.location.MockProvider)13 PendingIntent (android.app.PendingIntent)6 Intent (android.content.Intent)6 LocationRequest (android.location.LocationRequest)6 Bundle (android.os.Bundle)6 WorkSource (android.os.WorkSource)6 ProviderRequest (com.android.internal.location.ProviderRequest)6 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 FlpHardwareProvider (com.android.server.location.FlpHardwareProvider)5 PackageProviderKey (com.android.server.location.LocationRequestStatistics.PackageProviderKey)5 PackageStatistics (com.android.server.location.LocationRequestStatistics.PackageStatistics)5