Search in sources :

Example 16 with MockProvider

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

the class LocationManagerService method clearTestProviderLocation.

@Override
public void clearTestProviderLocation(String provider, String opPackageName) {
    if (!canCallerAccessMockLocation(opPackageName)) {
        return;
    }
    synchronized (mLock) {
        MockProvider mockProvider = mMockProviders.get(provider);
        if (mockProvider == null) {
            throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
        }
        mockProvider.clearLocation();
    }
}
Also used : MockProvider(com.android.server.location.MockProvider)

Example 17 with MockProvider

use of com.android.server.location.MockProvider in project android_frameworks_base by crdroidandroid.

the class LocationManagerService method setTestProviderLocation.

@Override
public void setTestProviderLocation(String provider, Location loc, String opPackageName) {
    if (!canCallerAccessMockLocation(opPackageName)) {
        return;
    }
    synchronized (mLock) {
        MockProvider mockProvider = mMockProviders.get(provider);
        if (mockProvider == null) {
            throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
        }
        // Ensure that the location is marked as being mock. There's some logic to do this in
        // handleLocationChanged(), but it fails if loc has the wrong provider (bug 33091107).
        Location mock = new Location(loc);
        mock.setIsFromMockProvider(true);
        if (!TextUtils.isEmpty(loc.getProvider()) && !provider.equals(loc.getProvider())) {
            // The location has an explicit provider that is different from the mock provider
            // name. The caller may be trying to fool us via bug 33091107.
            EventLog.writeEvent(0x534e4554, "33091107", Binder.getCallingUid(), provider + "!=" + loc.getProvider());
        }
        // clear calling identity so INSTALL_LOCATION_PROVIDER permission is not required
        long identity = Binder.clearCallingIdentity();
        mockProvider.setLocation(mock);
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : MockProvider(com.android.server.location.MockProvider) Location(android.location.Location)

Example 18 with MockProvider

use of com.android.server.location.MockProvider in project android_frameworks_base by crdroidandroid.

the class LocationManagerService method setTestProviderStatus.

@Override
public void setTestProviderStatus(String provider, int status, Bundle extras, long updateTime, String opPackageName) {
    if (!canCallerAccessMockLocation(opPackageName)) {
        return;
    }
    synchronized (mLock) {
        MockProvider mockProvider = mMockProviders.get(provider);
        if (mockProvider == null) {
            throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
        }
        mockProvider.setStatus(status, extras, updateTime);
    }
}
Also used : MockProvider(com.android.server.location.MockProvider)

Example 19 with MockProvider

use of com.android.server.location.MockProvider in project android_frameworks_base by crdroidandroid.

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 20 with MockProvider

use of com.android.server.location.MockProvider in project android_frameworks_base by crdroidandroid.

the class LocationManagerService method clearTestProviderEnabled.

@Override
public void clearTestProviderEnabled(String provider, String opPackageName) {
    if (!canCallerAccessMockLocation(opPackageName)) {
        return;
    }
    synchronized (mLock) {
        MockProvider mockProvider = mMockProviders.get(provider);
        if (mockProvider == null) {
            throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
        }
        long identity = Binder.clearCallingIdentity();
        mEnabledProviders.remove(provider);
        mDisabledProviders.remove(provider);
        updateProvidersLocked();
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : MockProvider(com.android.server.location.MockProvider)

Aggregations

MockProvider (com.android.server.location.MockProvider)54 LocationProviderInterface (com.android.server.location.LocationProviderInterface)13 Location (android.location.Location)9 BroadcastReceiver (android.content.BroadcastReceiver)6 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 PackageProviderKey (com.android.server.location.LocationRequestStatistics.PackageProviderKey)5 PackageStatistics (com.android.server.location.LocationRequestStatistics.PackageStatistics)5