我们公司上架的app被打回来了。信通院那边出了个报告,说定频获取了位置信息
直接上代码
import android.content.Context;
import android.location.LocationManager;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class HookHelper {
public static final String TAG = “LocationHook”;
private static final Set
}
public class ILocationManagerProxy implements InvocationHandler {
private Object mLocationManager;
public ILocationManagerProxy(Object locationManager) {
this.mLocationManager = locationManager;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Log.d("ILocationManagerProxy",method.getName());
if (TextUtils.equals("requestLocationUpdates", method.getName())
||TextUtils.equals("getLastKnownLocation", method.getName())
||TextUtils.equals("getLastLocation", method.getName())) {
//获取当前函数调用栈
Log.d("getStackTraceString",Log.getStackTraceString(new Throwable("ILocationManagerProxy")));
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (stackTrace == null || stackTrace.length == 3) {
return null;
}
StackTraceElement log = stackTrace[2];
String invoker = null;
boolean foundLocationManager = false;
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement e = stackTrace[i];
if (TextUtils.equals(e.getClassName(), "android.location.LocationManager")) {
foundLocationManager = true;
continue;
}
//找到LocationManager外层的调用者
if (foundLocationManager && !TextUtils.equals(e.getClassName(), "android.location.LocationManager")) {
invoker = e.getClassName() + "." + e.getMethodName();
//此处可将定位接口的调用者信息根据自己的需求进行记录,这里我将调用类、函数名、以及参数打印出来
Log.d("LocationTest", "invoker is " + invoker + "(" + args + ")");
break;
}
}
}
return method.invoke(mLocationManager, args);
}
}
import android.location.LocationManager;
import android.text.TextUtils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class LMCachedServiceFetcherProxy implements InvocationHandler {
private Object mLMCachedServiceFetcher;
public LMCachedServiceFetcherProxy(Object LMCachedServiceFetcher) {
this.mLMCachedServiceFetcher = LMCachedServiceFetcher;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//为什么拦截getService,而不是createService?
if(TextUtils.equals(method.getName(), "getService")){
Object result = method.invoke(mLMCachedServiceFetcher, args);
if(result instanceof LocationManager){
//在这里hook LocationManager
HookHelper.hookLocationManager((LocationManager)result);
}
return result;
}
return method.invoke(mLMCachedServiceFetcher, args);
}
}



