Search in sources :

Example 81 with Location

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

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)

Example 82 with Location

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

the class DeviceIdleController method receivedGpsLocationLocked.

void receivedGpsLocationLocked(Location location) {
    if (mState != STATE_LOCATING) {
        cancelLocatingLocked();
        return;
    }
    if (DEBUG)
        Slog.d(TAG, "GPS location: " + location);
    mLastGpsLocation = new Location(location);
    if (location.getAccuracy() > mConstants.LOCATION_ACCURACY) {
        return;
    }
    mLocated = true;
    if (mNotMoving) {
        stepIdleStateLocked("s:gps");
    }
}
Also used : Location(android.location.Location)

Example 83 with Location

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

the class DeviceIdleController method receivedGenericLocationLocked.

void receivedGenericLocationLocked(Location location) {
    if (mState != STATE_LOCATING) {
        cancelLocatingLocked();
        return;
    }
    if (DEBUG)
        Slog.d(TAG, "Generic location: " + location);
    mLastGenericLocation = new Location(location);
    if (location.getAccuracy() > mConstants.LOCATION_ACCURACY && mHasGps) {
        return;
    }
    mLocated = true;
    if (mNotMoving) {
        stepIdleStateLocked("s:location");
    }
}
Also used : Location(android.location.Location)

Example 84 with Location

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

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 85 with Location

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

the class LocationBasedCountryDetector method getLastKnownLocation.

/**
     * @return the last known location from all providers
     */
protected Location getLastKnownLocation() {
    final long bid = Binder.clearCallingIdentity();
    try {
        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;
    } finally {
        Binder.restoreCallingIdentity(bid);
    }
}
Also used : 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