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");
}
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");
}
}
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");
}
}
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;
}
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);
}
}
Aggregations