Search in sources :

Example 46 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 47 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)

Example 48 with Location

use of android.location.Location in project Parse-SDK-Android by ParsePlatform.

the class LocationNotifier method getCurrentLocationAsync.

/**
   * Asynchronously gets the current location of the device.
   *
   * This will request location updates from the best provider that match the given criteria
   * and return the first location received.
   *
   * You can customize the criteria to meet your specific needs.
   * * For higher accuracy, you can set {@link Criteria#setAccuracy(int)}, however result in longer
   *   times for a fix.
   * * For better battery efficiency and faster location fixes, you can set
   *   {@link Criteria#setPowerRequirement(int)}, however, this will result in lower accuracy.
   *
   * @param context
   *          The context used to request location updates.
   * @param timeout
   *          The number of milliseconds to allow before timing out.
   * @param criteria
   *          The application criteria for selecting a location provider.
   *
   * @see android.location.LocationManager#getBestProvider(android.location.Criteria, boolean)
   * @see android.location.LocationManager#requestLocationUpdates(String, long, float, android.location.LocationListener)
   */
/* package */
static Task<Location> getCurrentLocationAsync(Context context, long timeout, Criteria criteria) {
    final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>();
    final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<ScheduledFuture<?>>();
    final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    final LocationListener listener = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
            if (location == null) {
                return;
            }
            timeoutFuture.get().cancel(true);
            tcs.trySetResult(location);
            manager.removeUpdates(this);
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    };
    timeoutFuture.set(ParseExecutors.scheduled().schedule(new Runnable() {

        @Override
        public void run() {
            tcs.trySetError(new ParseException(ParseException.TIMEOUT, "Location fetch timed out."));
            manager.removeUpdates(listener);
        }
    }, timeout, TimeUnit.MILLISECONDS));
    String provider = manager.getBestProvider(criteria, true);
    if (provider != null) {
        manager.requestLocationUpdates(provider, /* minTime */
        0, /* minDistance */
        0.0f, listener);
    }
    if (fakeLocation != null) {
        listener.onLocationChanged(fakeLocation);
    }
    return tcs.getTask();
}
Also used : LocationManager(android.location.LocationManager) TaskCompletionSource(bolts.TaskCompletionSource) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Capture(bolts.Capture) ScheduledFuture(java.util.concurrent.ScheduledFuture) Location(android.location.Location)

Example 49 with Location

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

the class GeofenceHardwareImpl method reportGpsGeofenceStatus.

/**
     * called from GpsLocationProvider to report GPS status change.
     */
public void reportGpsGeofenceStatus(int status, int flags, double latitude, double longitude, double altitude, float speed, float bearing, float accuracy, long timestamp) {
    Location location = getLocation(flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp);
    boolean available = false;
    if (status == GeofenceHardware.GPS_GEOFENCE_AVAILABLE)
        available = true;
    int val = (available ? GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE : GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE);
    setMonitorAvailability(GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, val);
    acquireWakeLock();
    Message m = mCallbacksHandler.obtainMessage(GPS_GEOFENCE_STATUS, location);
    m.arg1 = val;
    mCallbacksHandler.sendMessage(m);
}
Also used : Message(android.os.Message) Location(android.location.Location)

Example 50 with Location

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

the class ExternalSharedPermsDiffKeyTest method testRunBluetoothAndFineLocation.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunBluetoothAndFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
    fail("this app was signed by a different cert and should crash/fail to run by now");
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 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 Intent (android.content.Intent)8 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