现在安卓玩pokemongo,虚拟定位比较常用的欺骗方法是将fake gps软件弄为系统app,用其他普通的方法模拟定位会被检测出来。不过之前不明白是什么原理,所以到github上找了找,找到了xiangtailiang/FakeGPS: FakeGPS is a GPS device simulator, GPS location signal keep output according to the coordinates. By the direction keys on the joystick, the user can simulate walking on the map. (github.com)
实现就是依靠反射得到LocationManager对象的ILocationManager这个对象,调用其reportLocation方法上传坐标,需要INSTALL_LOCATION_PROVIDER权限。ILocationManager是一个AIDL接口,所以还需要创建android.location.ILocationManager.aidl文件
private static ILocationManager mILocationManager;
private void mock(){
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Field declaredField = null;
try {
declaredField = Class.forName(mLocationManager.getClass().getName()).getDeclaredField("mService");
declaredField.setAccessible(true);
mILocationManager = (ILocationManager) declaredField.get(mLocationManager);
} catch (Exception e) {
e.printStackTrace();
}
new Thread(new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
Location location = new Location(LocationManager.GPS_PROVIDER);
try {
location.setLatitude(35.6925);
location.setLongitude(139.7564);
location.setAltitude(5);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
location.setAccuracy(10);
location.setSpeed(0);
location.setTime(System.currentTimeMillis());
mILocationManager.reportLocation(location, false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
这个只上报了gps provider。所以用的时候需要手机定位模式设为only gps。
此方法不需要打开模拟位置开关也不需要手机root,所以能够避免被pokemongo检测到,只需要有个能够解锁BL刷TWRP或者其他的recovery包,用他们的文件管理器功能移动这个加入了上面代码的应用到/system/priv-app目录中即可。也可以用现成的应用,我目前用的是theappninjas的gpsjoystick这个应用,这个应用里面有隐私模式能够下载生成一个app的副本,将这个副本移动到/system/priv-app然后卸载掉原来的app即可。
其次这个方法:只是往系统的API中增加了一个GPS Provider,并没有改变原来GPS的读取。如果真实的GPS也定位成功,一个真信号一个假信号会交替出现,就会发生瞬移的现象。
所以为了屏蔽真实的gps信号,买个gps屏蔽器就行了,某宝50元就能买到,自己去搜索,如果某宝买不到,那么就到搜不到gps信号的地方比如地下停车场或者房子内远离窗户的地方,或者用锡纸包住手机周围不让手机的GPS接收器接收到GPS即可。