private static String leftZeroPad(int num, int size) { return leftZeroPad(String.valueOf(num), size); }
super.onBindMethods(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { addMethodProxy(new ReplaceLastPkgMethodProxy("addTestProvider")); addMethodProxy(new ReplaceLastPkgMethodProxy("removeTestProvider")); addMethodProxy(new ReplaceLastPkgMethodProxy("setTestProviderLocation")); addMethodProxy(new ReplaceLastPkgMethodProxy("clearTestProviderLocation")); addMethodProxy(new ReplaceLastPkgMethodProxy("setTestProviderEnabled")); addMethodProxy(new ReplaceLastPkgMethodProxy("clearTestProviderEnabled")); addMethodProxy(new ReplaceLastPkgMethodProxy("setTestProviderStatus")); addMethodProxy(new ReplaceLastPkgMethodProxy("clearTestProviderStatus")); addMethodProxy(new FakeReplaceLastPkgMethodProxy("addGpsMeasurementsListener", true)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("addGpsNavigationMessageListener", true)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("removeGpsMeasurementListener", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("removeGpsNavigationMessageListener", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("requestGeofence", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("removeGeofence", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("addProximityAlert", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("addNmeaListener", 0)); addMethodProxy(new FakeReplaceLastPkgMethodProxy("removeNmeaListener", 0));
@Override public Object call(final Object who, Method method, Object... args) throws Throwable { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { LocationRequest request = (LocationRequest) args[0]; fixLocationRequest(request); } if (isFakeLocationEnable()) { Object transport = ArrayUtils.getFirst(args, mirror.android.location.LocationManager.ListenerTransport.TYPE); if (transport != null) { Object locationManager = mirror.android.location.LocationManager.ListenerTransport.this$0.get(transport); MockLocationHelper.setGpsStatus(locationManager); GPSListenerThread.get().addListenerTransport(locationManager); } return 0; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { Object transport = ArrayUtils.getFirst(args, mirror.android.location.LocationManager.GpsStatusListenerTransport.TYPE); Object locationManager = mirror.android.location.LocationManager.GpsStatusListenerTransport.this$0.get(transport); mirror.android.location.LocationManager.GpsStatusListenerTransport.onGpsStarted.call(transport); mirror.android.location.LocationManager.GpsStatusListenerTransport.onFirstFix.call(transport, 0); if (mirror.android.location.LocationManager.GpsStatusListenerTransport.mListener.get(transport) != null) { MockLocationHelper.invokeSvStatusChanged(transport); } else { MockLocationHelper.invokeNmeaReceived(transport); } GPSListenerThread.get().addListenerTransport(locationManager); return true; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (!isFakeLocationEnable()) { return super.call(who, method, args); } Object transport = ArrayUtils.getFirst(args, mirror.android.location.LocationManager.GnssStatusListenerTransport.TYPE); if (transport != null) { mirror.android.location.LocationManager.GnssStatusListenerTransport.onGnssStarted.call(transport, new Object[0]); if (mirror.android.location.LocationManager.GnssStatusListenerTransport.mGpsListener.get(transport) != null) { MockLocationHelper.invokeSvStatusChanged(transport); } else { MockLocationHelper.invokeNmeaReceived(transport); } mirror.android.location.LocationManager.GnssStatusListenerTransport.onFirstFix.call(transport, Integer.valueOf(0)); Object locationManager = mirror.android.location.LocationManager.GnssStatusListenerTransport.this$0.get(transport); GPSListenerThread.get().addListenerTransport(locationManager); } return true; } }
if (location != null) { String date = new SimpleDateFormat("HHmmss:SS", Locale.US).format(new Date()); String lat = getGPSLat(location.latitude); String lon = getGPSLat(location.longitude); String latNW = getNorthWest(location); String lonSE = getSouthEast(location); String $GPGGA = checksum(String.format("$GPGGA,%s,%s,%s,%s,%s,1,%s,692,.00,M,.00,M,,,", date, lat, latNW, lon, lonSE, satalines.getSvCount())); String $GPRMC = checksum(String.format("$GPRMC,%s,A,%s,%s,%s,%s,0,0,260717,,,A,", date, lat, latNW, lon, lonSE)); if (LocationManager.GnssStatusListenerTransport.onNmeaReceived != null) { LocationManager.GnssStatusListenerTransport.onNmeaReceived.call(listener, System.currentTimeMillis(), "$GPGSV,1,1,04,12,05,159,36,15,41,087,15,19,38,262,30,31,56,146,19,*73");
if (VERSION.SDK_INT >= 24) { Map nmeaListeners = LocationManager.mGnssNmeaListeners.get(transport); notifyGPSStatus(LocationManager.mGnssStatusListeners.get(transport)); notifyMNmeaListener(nmeaListeners); gpsStatusListeners = LocationManager.mGpsStatusListeners.get(transport); notifyGPSStatus(gpsStatusListeners); notifyMNmeaListener(LocationManager.mGpsNmeaListeners.get(transport)); } else { gpsStatusListeners = LocationManager.mGpsStatusListeners.get(transport); notifyGPSStatus(gpsStatusListeners); notifyMNmeaListener(LocationManager.mNmeaListeners.get(transport)); notifyLocation(listeners);
public void run() { if (!listeners.isEmpty()) { for (Entry entry : listeners.entrySet()) { try { Object transport = entry.getKey(); MockLocationHelper.invokeSvStatusChanged(transport); MockLocationHelper.invokeNmeaReceived(transport); } catch (Throwable e) { e.printStackTrace(); } } } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { return mDefValue; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { // TODO return 0; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { return LocationManager.GPS_PROVIDER; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { return true; } return super.call(who, method, args); } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { return true; } return super.call(who, method, args); }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { return 0; } return super.call(who, method, args); } }
private void notifyMNmeaListener(Map listeners) { if (listeners != null && !listeners.isEmpty()) { //noinspection unchecked Set<Map.Entry> entries = listeners.entrySet(); for (Map.Entry entry : entries) { try { Object value = entry.getValue(); if (value != null) { MockLocationHelper.invokeNmeaReceived(value); } } catch (Exception e) { e.printStackTrace(); } } } }
private void notifyGPSStatus(Map listeners) { if (listeners != null && !listeners.isEmpty()) { //noinspection unchecked Set<Map.Entry> entries = listeners.entrySet(); for (Map.Entry entry : entries) { try { Object value = entry.getValue(); if (value != null) { MockLocationHelper.invokeSvStatusChanged(value); } } catch (Throwable e) { e.printStackTrace(); } } } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (isFakeLocationEnable()) { String provider = (String) args[0]; if (LocationManager.PASSIVE_PROVIDER.equals(provider)) { return true; } if (LocationManager.GPS_PROVIDER.equals(provider)) { return true; } if (LocationManager.NETWORK_PROVIDER.equals(provider)) { return true; } return false; } return super.call(who, method, args); } }
@Override public Object afterCall(Object who, Method method, Object[] args, Object result) throws Throwable { if (isFakeLocationEnable()) { return super.afterCall(who, method, args, result); } try { Reflect.on(result).set("mRequiresNetwork", false); Reflect.on(result).set("mRequiresCell", false); } catch (Throwable e) { e.printStackTrace(); } return result; } }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { if (!(args[0] instanceof String)) { LocationRequest request = (LocationRequest) args[0]; fixLocationRequest(request); } if (isFakeLocationEnable()) { VLocation loc = VirtualLocationManager.get().getLocation(); if (loc != null) { return loc.toSysLocation(); } else { return null; } } return super.call(who, method, args); } }
public static String getGPSLat(double v) { int du = (int) v; double fen = (v - (double) du) * 60.0d; return du + leftZeroPad((int) fen, 2) + ":" + String.valueOf(fen).substring(2); }