Search in sources :

Example 61 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project platform_frameworks_base by android.

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

Example 62 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project platform_frameworks_base by android.

the class LocationManagerService method requestLocationUpdatesLocked.

private void requestLocationUpdatesLocked(LocationRequest request, Receiver receiver, int pid, int uid, String packageName) {
    // use the fused provider
    if (request == null)
        request = DEFAULT_LOCATION_REQUEST;
    String name = request.getProvider();
    if (name == null) {
        throw new IllegalArgumentException("provider name must not be null");
    }
    if (D)
        Log.d(TAG, "request " + Integer.toHexString(System.identityHashCode(receiver)) + " " + name + " " + request + " from " + packageName + "(" + uid + ")");
    LocationProviderInterface provider = mProvidersByName.get(name);
    if (provider == null) {
        throw new IllegalArgumentException("provider doesn't exist: " + name);
    }
    UpdateRecord record = new UpdateRecord(name, request, receiver);
    UpdateRecord oldRecord = receiver.mUpdateRecords.put(name, record);
    if (oldRecord != null) {
        oldRecord.disposeLocked(false);
    }
    boolean isProviderEnabled = isAllowedByUserSettingsLocked(name, uid);
    if (isProviderEnabled) {
        applyRequirementsLocked(name);
    } else {
        // Notify the listener that updates are currently disabled
        receiver.callProviderEnabledLocked(name, false);
    }
    // Update the monitoring here just in case multiple location requests were added to the
    // same receiver (this request may be high power and the initial might not have been).
    receiver.updateMonitoring(true);
}
Also used : LocationProviderInterface(com.android.server.location.LocationProviderInterface)

Example 63 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project platform_frameworks_base by android.

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 64 with LocationProviderInterface

use of com.android.server.location.LocationProviderInterface in project platform_frameworks_base by android.

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 65 with LocationProviderInterface

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

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 (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
                if (checkLocationAccess(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 (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
                    LocationRequest locationRequest = record.mRequest;
                    if (locationRequest.getInterval() <= thresholdInterval) {
                        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

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