Search in sources :

Example 6 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class FusionEngine method updateFusedLocation.

private void updateFusedLocation() {
    // may the best location win!
    if (isBetterThan(mGpsLocation, mNetworkLocation)) {
        mFusedLocation = new Location(mGpsLocation);
    } else {
        mFusedLocation = new Location(mNetworkLocation);
    }
    mFusedLocation.setProvider(FUSED);
    if (mNetworkLocation != null) {
        // copy NO_GPS_LOCATION extra from mNetworkLocation into mFusedLocation
        Bundle srcExtras = mNetworkLocation.getExtras();
        if (srcExtras != null) {
            Parcelable srcParcelable = srcExtras.getParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION);
            if (srcParcelable instanceof Location) {
                Bundle dstExtras = mFusedLocation.getExtras();
                if (dstExtras == null) {
                    dstExtras = new Bundle();
                    mFusedLocation.setExtras(dstExtras);
                }
                dstExtras.putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION, (Location) srcParcelable);
            }
        }
    }
    if (mCallback != null) {
        mCallback.reportLocation(mFusedLocation);
    } else {
        Log.w(TAG, "Location updates received while fusion engine not started");
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) Location(android.location.Location)

Example 7 with Location

use of android.location.Location 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 8 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class LocationManagerService method handleLocationChanged.

private void handleLocationChanged(Location location, boolean passive) {
    // create a working copy of the incoming Location so that the service can modify it without
    // disturbing the caller's copy
    Location myLocation = new Location(location);
    String provider = myLocation.getProvider();
    // forward locations from mock providers, and should not grant them legitimacy in doing so.
    if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
        myLocation.setIsFromMockProvider(true);
    }
    synchronized (mLock) {
        if (isAllowedByCurrentUserSettingsLocked(provider)) {
            if (!passive) {
                // notify passive provider of the new location
                mPassiveProvider.updateLocation(myLocation);
            }
            handleLocationChangedLocked(myLocation, passive);
        }
    }
}
Also used : Location(android.location.Location)

Example 9 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class LocationFudger method createCoarseLocked.

/**
     * Create a coarse location.
     *
     * <p>Two techniques are used: random offsets and snap-to-grid.
     *
     * <p>First we add a random offset. This mitigates against detecting
     * grid transitions. Without a random offset it is possible to detect
     * a users position very accurately when they cross a grid boundary.
     * The random offset changes very slowly over time, to mitigate against
     * taking many location samples and averaging them out.
     *
     * <p>Second we snap-to-grid (quantize). This has the nice property of
     * producing stable results, and mitigating against taking many samples
     * to average out a random offset.
     */
private Location createCoarseLocked(Location fine) {
    Location coarse = new Location(fine);
    // clean all the optional information off the location, because
    // this can leak detailed location information
    coarse.removeBearing();
    coarse.removeSpeed();
    coarse.removeAltitude();
    coarse.setExtras(null);
    double lat = coarse.getLatitude();
    double lon = coarse.getLongitude();
    // wrap
    lat = wrapLatitude(lat);
    lon = wrapLongitude(lon);
    // Step 1) apply a random offset
    //
    // The goal of the random offset is to prevent the application
    // from determining that the device is on a grid boundary
    // when it crosses from one grid to the next.
    //
    // We apply the offset even if the location already claims to be
    // inaccurate, because it may be more accurate than claimed.
    updateRandomOffsetLocked();
    // perform lon first whilst lat is still within bounds
    lon += metersToDegreesLongitude(mOffsetLongitudeMeters, lat);
    lat += metersToDegreesLatitude(mOffsetLatitudeMeters);
    if (D)
        Log.d(TAG, String.format("applied offset of %.0f, %.0f (meters)", mOffsetLongitudeMeters, mOffsetLatitudeMeters));
    // wrap
    lat = wrapLatitude(lat);
    lon = wrapLongitude(lon);
    // Step 2) Snap-to-grid (quantize)
    //
    // This is the primary means of obfuscation. It gives nice consistent
    // results and is very effective at hiding the true location
    // (as long as you are not sitting on a grid boundary, which
    // step 1 mitigates).
    //
    // Note we quantize the latitude first, since the longitude
    // quantization depends on the latitude value and so leaks information
    // about the latitude
    double latGranularity = metersToDegreesLatitude(mGridSizeInMeters);
    lat = Math.round(lat / latGranularity) * latGranularity;
    double lonGranularity = metersToDegreesLongitude(mGridSizeInMeters, lat);
    lon = Math.round(lon / lonGranularity) * lonGranularity;
    // wrap again
    lat = wrapLatitude(lat);
    lon = wrapLongitude(lon);
    // apply
    coarse.setLatitude(lat);
    coarse.setLongitude(lon);
    coarse.setAccuracy(Math.max(mAccuracyInMeters, coarse.getAccuracy()));
    if (D)
        Log.d(TAG, "fudged " + fine + " to " + coarse);
    return coarse;
}
Also used : Location(android.location.Location)

Example 10 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class LocationBasedCountryDetector method getLastKnownLocation.

/**
     * @return the last known location from all providers
     */
protected Location getLastKnownLocation() {
    List<String> providers = mLocationManager.getAllProviders();
    Location bestLocation = null;
    for (String provider : providers) {
        Location lastKnownLocation = mLocationManager.getLastKnownLocation(provider);
        if (lastKnownLocation != null) {
            if (bestLocation == null || bestLocation.getElapsedRealtimeNanos() < lastKnownLocation.getElapsedRealtimeNanos()) {
                bestLocation = lastKnownLocation;
            }
        }
    }
    return bestLocation;
}
Also used : Location(android.location.Location)

Aggregations

Location (android.location.Location)284 Bundle (android.os.Bundle)48 LocationListener (android.location.LocationListener)36 LocationManager (android.location.LocationManager)31 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)19 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6