public Location toSysLocation() { Location location = new Location(LocationManager.GPS_PROVIDER); location.setAccuracy(8f); Bundle extraBundle = new Bundle(); location.setBearing(bearing); Reflect.on(location).call("setIsFromMockProvider", false); location.setLatitude(latitude); location.setLongitude(longitude); location.setSpeed(speed); location.setTime(System.currentTimeMillis()); location.setExtras(extraBundle); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { location.setElapsedRealtimeNanos(277000000); } int svCount = VirtualGPSSatalines.get().getSvCount(); extraBundle.putInt("satellites", svCount); extraBundle.putInt("satellitesvalue", svCount); return location; } }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanFastestInterval() throws Exception { TestLocationListener listener = new TestLocationListener(); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 2000, 0, listener); long time = System.currentTimeMillis(); Location location1 = new Location(GPS_PROVIDER); location1.setTime(time); Location location2 = new Location(GPS_PROVIDER); location2.setTime(time + 1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getTime()).isEqualTo(location1.getTime()); }
private Location copyOf(Location location) { if (location == null) return null; Location copy = new Location(location); copy.setAccuracy(location.getAccuracy()); copy.setAltitude(location.getAltitude()); copy.setBearing(location.getBearing()); copy.setExtras(location.getExtras()); copy.setLatitude(location.getLatitude()); copy.setLongitude(location.getLongitude()); copy.setProvider(location.getProvider()); copy.setSpeed(location.getSpeed()); copy.setTime(location.getTime()); return copy; }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener); Location location1 = new Location(GPS_PROVIDER); location1.setLatitude(1); location1.setLongitude(2); location1.setTime(0); Location location2 = new Location(GPS_PROVIDER); location2.setLatitude(1.5); location2.setLongitude(2.5); location2.setTime(1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getLatitude()).isEqualTo(1.0d); assertThat(listener.location.getLongitude()).isEqualTo(2.0d); }
Location mockLocation = new Location(mocLocationProvider); // a string mockLocation.setLatitude(location.getLatitude()); // double mockLocation.setLongitude(location.getLongitude()); mockLocation.setAltitude(location.getAltitude()); mockLocation.setTime(System.currentTimeMillis()); locationManager.setTestProviderLocation( mocLocationProvider, mockLocation);
public static Location create(String source) { Location l = new Location(source); l.setTime(System.currentTimeMillis()); return l; }
public static Location create(String source, long time) { Location location = create(source); location.setTime(time); return location; }
Location mockLocation = new Location(mocLocationProvider); // a string mockLocation.setLatitude(location.getLatitude()); // double mockLocation.setLongitude(location.getLongitude()); mockLocation.setAltitude(location.getAltitude()); mockLocation.setTime(System.currentTimeMillis()); locationManager.setTestProviderLocation( mocLocationProvider, mockLocation);
locationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, true, 0, 5); locationManager.setTestProviderEnabled(mocLocationProvider, true); Location mockLocation = new Location(mocLocationProvider); // a string mockLocation.setLatitude(location.getLatitude()); // double mockLocation.setLongitude(location.getLongitude()); mockLocation.setAltitude(location.getAltitude()); mockLocation.setTime(System.currentTimeMillis()); locationManager.setTestProviderLocation( mocLocationProvider, mockLocation); <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION">
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location fix) { fix.setTime(fix.getTime() + timeZoneOffset); //Add Timezone offset if needed //here you have a fresh new location in fix... //You can set the value of any class level field from here } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } };
Location loc = new Location(LocationManager.GPS_PROVIDER); loc.setLatitude(37.422); loc.setLongitude(-122.084); loc.setAltitude(0); loc.setTime(System.currentTimeMillis()); loc.setAccuracy(10); if (android.os.Build.VERSION.SDK_INT >= 17) loc.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
public Location create(String source, double latitude, double longitude, float accuracy) { Location location = new Location(source); location.setTime(System.currentTimeMillis()); location.setLatitude(latitude); location.setLongitude(longitude); location.setAccuracy(accuracy); return location; }
public Location createLocation(double lat, double lng, float accuracy) { // Create a new Location Location newLocation = new Location(LocationManager.GPS_PROVIDER); newLocation.setLatitude(lat); newLocation.setLongitude(lng); newLocation.setProvider(LocationManager.GPS_PROVIDER); newLocation.setAccuracy(1); newLocation.setTime(new Date().getTime()); newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); return newLocation; }
Location location = new Location(LocationManager.GPS_PROVIDER); location.setLatitude(48.446743); location.setLongitude(52.44672); location.setAccuracy(4.0f); location.setElapsedRealtimeNanos(elapsedTimeNanos); location.setTime(currentTime); LocationServices.FusedLocationApi.setMockLocation(mGoogleApiClient, location);
public static Location a(double d, double d2) { Location location = new Location("gps"); location.setLatitude(d); location.setLongitude(d2); location.setAccuracy(100.0f); location.setTime(System.currentTimeMillis()); if (VERSION.SDK_INT >= 17) { location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); } return location; }
public void setLocation(Location loc) { android.location.Location location = new android.location.Location(locationProvider); location.setLatitude(loc.getLatitude()); location.setLongitude(loc.getLongitude()); location.setAltitude(loc.getAltitude()); // set the time so it's not ignored! location.setTime(System.currentTimeMillis()); locManagerSupplier.get().setTestProviderLocation(locationProvider, location); }
public static Location makeLocation(double latitude, double longitude) { Location location = new Location("gps"); location.setLatitude(latitude); location.setLongitude(longitude); location.setAccuracy(100.0F); location.setTime(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); } return location; }
@Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Location l = new Location(LocationManager.GPS_PROVIDER); l.setLatitude(latitude); l.setLongitude(longtitude); l.setAccuracy(100f); l.setTime(0); /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); }*/ param.setResult(l); } });
@Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Location l = new Location(LocationManager.GPS_PROVIDER); l.setLatitude(latitude); l.setLongitude(longtitude); l.setAccuracy(100f); l.setTime(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); } param.setResult(l); } });
@Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { Location l = new Location(LocationManager.GPS_PROVIDER); l.setLatitude(latitude); l.setLongitude(longtitude); l.setAccuracy(100f); l.setTime(0); /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { l.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); }*/ param.setResult(l); } });