Search in sources :

Example 1 with MockProvider

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

the class LocationManagerService method addTestProvider.

@Override
public void addTestProvider(String name, ProviderProperties properties) {
    checkMockPermissionsSafe();
    if (LocationManager.PASSIVE_PROVIDER.equals(name)) {
        throw new IllegalArgumentException("Cannot mock the passive location provider");
    }
    long identity = Binder.clearCallingIdentity();
    synchronized (mLock) {
        MockProvider provider = new MockProvider(name, this, properties);
        // remove the real provider if we are replacing GPS or network provider
        if (LocationManager.GPS_PROVIDER.equals(name) || LocationManager.NETWORK_PROVIDER.equals(name) || LocationManager.FUSED_PROVIDER.equals(name)) {
            LocationProviderInterface p = mProvidersByName.get(name);
            if (p != null) {
                removeProviderLocked(p);
            }
        }
        if (mProvidersByName.get(name) != null) {
            throw new IllegalArgumentException("Provider \"" + name + "\" already exists");
        }
        mGeoFencerEnabled = false;
        addProviderLocked(provider);
        mMockProviders.put(name, provider);
        mLastLocation.put(name, null);
        mLastLocationCoarseInterval.put(name, null);
        updateProvidersLocked();
    }
    Binder.restoreCallingIdentity(identity);
}
Also used : MockProvider(com.android.server.location.MockProvider) LocationProviderInterface(com.android.server.location.LocationProviderInterface)

Example 2 with MockProvider

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

the class LocationManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump LocationManagerService from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    synchronized (mLock) {
        pw.println("Current Location Manager state:");
        pw.println("  Location Listeners:");
        for (Receiver receiver : mReceivers.values()) {
            pw.println("    " + receiver);
        }
        pw.println("  Records by Provider:");
        for (Map.Entry<String, ArrayList<UpdateRecord>> entry : mRecordsByProvider.entrySet()) {
            pw.println("    " + entry.getKey() + ":");
            for (UpdateRecord record : entry.getValue()) {
                pw.println("      " + record);
            }
        }
        pw.println("  Last Known Locations:");
        for (Map.Entry<String, Location> entry : mLastLocation.entrySet()) {
            String provider = entry.getKey();
            Location location = entry.getValue();
            pw.println("    " + provider + ": " + location);
        }
        pw.println("  Last Known Locations Coarse Intervals:");
        for (Map.Entry<String, Location> entry : mLastLocationCoarseInterval.entrySet()) {
            String provider = entry.getKey();
            Location location = entry.getValue();
            pw.println("    " + provider + ": " + location);
        }
        mGeofenceManager.dump(pw);
        if (mGeoFencer != null && mGeoFencerEnabled) {
            mGeoFencer.dump(pw, "");
        }
        if (mEnabledProviders.size() > 0) {
            pw.println("  Enabled Providers:");
            for (String i : mEnabledProviders) {
                pw.println("    " + i);
            }
        }
        if (mDisabledProviders.size() > 0) {
            pw.println("  Disabled Providers:");
            for (String i : mDisabledProviders) {
                pw.println("    " + i);
            }
        }
        pw.append("  ");
        mBlacklist.dump(pw);
        if (mMockProviders.size() > 0) {
            pw.println("  Mock Providers:");
            for (Map.Entry<String, MockProvider> i : mMockProviders.entrySet()) {
                i.getValue().dump(pw, "      ");
            }
        }
        pw.append("  fudger: ");
        mLocationFudger.dump(fd, pw, args);
        if (args.length > 0 && "short".equals(args[0])) {
            return;
        }
        for (LocationProviderInterface provider : mProviders) {
            pw.print(provider.getName() + " Internal State");
            if (provider instanceof LocationProviderProxy) {
                LocationProviderProxy proxy = (LocationProviderProxy) provider;
                pw.print(" (" + proxy.getConnectedPackageName() + ")");
            }
            pw.println(":");
            provider.dump(fd, pw, args);
        }
    }
}
Also used : LocationProviderProxy(com.android.server.location.LocationProviderProxy) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) MockProvider(com.android.server.location.MockProvider) Map(java.util.Map) HashMap(java.util.HashMap) LocationProviderInterface(com.android.server.location.LocationProviderInterface) Location(android.location.Location)

Example 3 with MockProvider

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

the class LocationManagerService method setTestProviderStatus.

@Override
public void setTestProviderStatus(String provider, int status, Bundle extras, long updateTime) {
    checkMockPermissionsSafe();
    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 4 with MockProvider

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

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)

Example 5 with MockProvider

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

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)

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