美文网首页
安卓如何查看app哪些地方频繁调用了位置信息

安卓如何查看app哪些地方频繁调用了位置信息

作者: 不思进取的码农 | 来源:发表于2021-09-16 11:03 被阅读0次

前言

最近网信办下发了整改通知,其中有一个问题是在启动后 频繁调去了位置信息40次

想到除自身代码外,可能有其他的sdk调用

想通过hook技术查看一下问题都有哪些地方调用了

直接放代码,有疑问可以在评论区留言

object LocationDetector {
    fun changeLocationServiceInstance(context: Context) {
        if (BuildConfig.DEBUG) {
            smartLog {
                "changeLocationServiceInstance"
            }
            val wifiManager = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager
            wifiManager ?: return
            val serviceInstance = Reflect.on(wifiManager).field("mService").get<Any>()
            val handler = DynamicInvocationHandler()
            handler.setOriginal(serviceInstance)
            val newServiceInstance = Proxy.newProxyInstance(serviceInstance::class.java.classLoader, arrayOf(Class.forName("android.location.ILocationManager")), handler)
            Reflect.on(wifiManager).set("mService", newServiceInstance)
        }
    }

}
public class DynamicInvocationHandler implements InvocationHandler {
    private Object original;
    @Override
    public Object invoke(Object proxy, Method method, Object[] objects) throws Throwable {
        Object result = method.invoke(original, objects);
        new Throwable("Issue").printStackTrace();
        Log.i("printMessage", "method.name=" + method.getName());
        return result;

    }

    public void setOriginal(Object original) {
        this.original = original;
    }
}

在Application中的onCreate方法添加

LocationDetector.INSTANCE.changeLocationServiceInstance(this);

对上述做一下简单说明

DynamicInvocationHandler 这个动态代理 里面的
Log.i("printMessage", "method.name=" + method.getName());
只能看出被调用了,但是打印的方法并不是真正的你要找的调用方法
所以加了
new Throwable("Issue").printStackTrace();
通过这个异常 ,我们可以查看出具体调用的完整路径

相关文章

网友评论

      本文标题:安卓如何查看app哪些地方频繁调用了位置信息

      本文链接:https://www.haomeiwen.com/subject/bklrgltx.html