If you have access to an Android 11 device, there are new data access APIs available that you can tap into to find out what in your app is using dangerous
permissions like this.
In this sample project (profiled in this book), I have some code to record stack traces from all dangerous
permission uses:
getSystemService(AppOpsManager::class.java)
?.setOnOpNotedCallback(executor, object : AppOpsManager.OnOpNotedCallback() {
override fun onNoted(op: SyncNotedAppOp) {
Log.d(TAG, "onNoted: ${op.toDebugString()}")
RuntimeException().printStackTrace(System.out)
}
override fun onSelfNoted(op: SyncNotedAppOp) {
Log.d(TAG, "onSelfNoted: ${op.toDebugString()}")
RuntimeException().printStackTrace(System.out)
}
override fun onAsyncNoted(op: AsyncNotedAppOp) {
Log.d(TAG, "onAsyncNoted: ${op.toDebugString()}")
RuntimeException().printStackTrace(System.out)
}
})
(as part of other code in a custom Application
subclass)
In the context of that sample, it will record the fact that the app is obtaining the location from its viewmodel. But, that's just based on the sample — in a larger app, it would record the permission uses from anything, including your ad network library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…