Android检测注册的broadcast receiver
检查系统的注册的广播接收器有两个路径
静态注册检测
静态注册的广播接收:getPackageManager().queryBroadcastReceivers()
系统有现成的东西
动态注册检测
动态注册就有点麻烦,我们先看下动态注册系统到底是怎么走的?
动态注册有一下几个方法,最后都是到
//android.app.ContextImpl.classprivate Intent registerReceiverInternal(BroadcastReceiver receiver, int userId,IntentFilter filter, String broadcastPermission,Handler scheduler, Context context, int flags)
//com.android.server.am.ActivityManagerService.class
public Intent registerReceiver(IApplicationThread caller, String callerPackage,IIntentReceiver receiver, IntentFilter filter, String permission, int userId,int flags)
具体代码其实就是:
//新建立的ReceiverList(代表BroadcastReceiver),放入AMS中已经注册的mRegisteredReceivers//(相当于在AMS中动态注册的所有BroadcastReceiver),这个是注册的角度的变量,用来通过这个寻找广播的接收者。mRegisteredReceivers.put(receiver.asBinder(), rl);
所以获取动态注册的广播关键就是在mRegisteredReceivers。
然后发现ams里面的dump会把这个部分给dump出来。
//com.android.server.am.ActivityManagerService.class
dumpBroadcastsLocked()
套路来了:dumpsys activity broadcasts
ReceiverList{20cf1c3 10919 com.android.settings/1000/u0 remote:d6c0972}app=10919:com.android.settings/1000 pid=10919 uid=1000 user=0Filter #0: BroadcastFilter{fe8a40}Action: "android.bluetooth.adapter.action.STATE_CHANGED"Action: "android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED"Action: "android.bluetooth.adapter.action.DISCOVERY_STARTED"Action: "android.bluetooth.adapter.action.DISCOVERY_FINISHED"Action: "android.bluetooth.device.action.FOUND"Action: "android.bluetooth.device.action.DISAPPEARED"Action: "android.bluetooth.device.action.NAME_CHANGED"Action: "android.bluetooth.device.action.ALIAS_CHANGED"Action: "android.bluetooth.device.action.BOND_STATE_CHANGED"Action: "android.bluetooth.device.action.PAIRING_CANCEL"Action: "android.bluetooth.device.action.CLASS_CHANGED"Action: "android.bluetooth.device.action.UUID"Action: "android.intent.action.DOCK_EVENT"AutoVerify=false
这样就知道动态注册了啥了。。。
才疏学浅,敬请指教。谢谢。