大家好,又见面了,我是你们的朋友全栈君。
adb shell dumpsys activity 中的broadcasts信息
通过adb shell dumpsys activity打印中的第二项就是broadcasts信息;
代码语言:javascript复制ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)
Historical broadcasts [foregroun #0: BroadcastRecord{54c39b6 u-1 android.intent.action.CLOSE_SYSTEM_DIALOGS}
act=android.intent.action.CLOSE_SYSTEM_DIALOGS flg=0x50000010 (has extras)
extras: Bundle[{reason=homekey}]1: BroadcastRecord{
7e092c0 u-1 android.hardware.usb.action.USB_STATE}
act=android.hardware.usb.action.USB_STATE flg=0x30000010 (has extras)
extras: Bundle[{connected=true, unlocked=false, adb=true, mass_storage=true, configured=true}]
#2: BroadcastRecord{3ce36b7 u-1 android.hardware.usb.action.USB_STATE}
act=android.hardware.usb.action.USB_STATE flg=0x30000010 (has extras)
extras: Bundle[{connected=true, unlocked=false, adb=true, mass_storage=true, configured=true}]
#3: BroadcastRecord{a0b96a8 u-1 android.hardware.usb.action.USB_STATE}
act=android.hardware.usb.action.USB_STATE flg=0x30000010 (has extras)
extras: Bundle[{connected=true, unlocked=false, adb=true, mass_storage=true, configured=false}]
#4: BroadcastRecord{c033e24 u-1 android.hardware.usb.action.USB_STATE}
act=android.hardware.usb.action.USB_STATE flg=0x30000010 (has extras)
extras: Bundle[{connected=true, unlocked=false, adb=true, mass_storage=true, configured=false}]
#5: BroadcastRecord{e289d8d u0 android.intent.action.SET_PRIMARYCARD_COMPLETE}
act=android.intent.action.SET_PRIMARYCARD_COMPLETE flg=0x10000010
#6: BroadcastRecord{72ee29c u-1 android.media.INTERNAL_RINGER_MODE_CHANGED_ACTION}
act=android.media.INTERNAL_RINGER_MODE_CHANGED_ACTION flg=0x34000010 (has extras)
extras: Bundle[{android.media.EXTRA_RINGER_MODE=2}]
#7: BroadcastRecord{6b8420f u-1 android.media.RINGER_MODE_CHANGED}
act=android.media.RINGER_MODE_CHANGED flg=0x34000010 (has extras)
extras: Bundle[{android.media.EXTRA_RINGER_MODE=2}]
#8: BroadcastRecord{63f4f0a u-1 android.intent.action.TIME_TICK}
act=android.intent.action.TIME_TICK flg=0x50000014 (has extras)
extras: Bundle[{android.intent.extra.ALARM_COUNT=1}]
#9: BroadcastRecord{f5a3b42 u-1 android.media.VOLUME_CHANGED_ACTION}
act=android.media.VOLUME_CHANGED_ACTION flg=0x14000010 (has extras)
extras: Bundle[{android.media.EXTRA_VOLUME_STREAM_TYPE_ALIAS=3, android.media.EXTRA_VOLUME_STREAM_TYPE=9, android.media.EXTRA_VOLUME_STREAM_VALUE=10, android.media.EXTRA_PREV_VOLUME_STREAM_VALUE=12}]
#10: act=android.intent.action.CLOSE_SYSTEM_DIALOGS flg=0x50000010 (has extras)
enq=2017-01-01 08:31:18 disp=2017-01-01 08:31:18 fin=2017-01-01 08:31:18
extras: Bundle[{reason=homekey}]
#11: act=android.hardware.usb.action.USB_STATE flg=0x30000010 (has extras)
enq=2017-01-01 08:31:11 disp=2017-01-01 08:31:11 fin=2017-01-01 08:31:11
extras: Bundle[{connected=true, unlocked=false, adb=true, mass_storage=true, configured=true}]
代码语言:javascript复制 #0: BroadcastRecord{54c39b6 u-1 android.intent.action.CLOSE_SYSTEM_DIALOGS}
act=android.intent.action.CLOSE_SYSTEM_DIALOGS flg=0x50000010 (has extras)
extras: Bundle[{reason=homekey}]
代码语言:javascript复制#10: act=android.intent.action.CLOSE_SYSTEM_DIALOGS flg=0x50000010 (has extras)
enq=2017-01-01 08:31:18 disp=2017-01-01 08:31:18 fin=2017-01-01 08:31:18
extras: Bundle[{reason=homekey}]
从#0 和#10 可以看出CLOSE_SYSTEM_DIALOGS 是成对出现的,#10记录了改广播的处理时间点。
adb shell dumpsys activity broadcasts
打印broadcasts更加具体的信息。包含三项
- ReceiverList//注册的广播接收列表
- Historical broadcasts [foreground]://前台广播的历史记录
- Historical broadcasts [background]://后台广播的历史记录
为了更好的理解打印的具体信息是什么,我自己注册了个广播,发送并接收。
代码语言:javascript复制 IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("wangjicong.broadcast.test");
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(MainActivity.this,"has get broadcast ",Toast.LENGTH_LONG).show();
}
},intentFilter);
Intent intent = new Intent();
intent.setAction("wangjicong.broadcast.test");
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
sendBroadcast(intent);
在运行此界面后,打印 dumpsys activity broadcasts信息。如下:
1.ReceiverList
代码语言:javascript复制 * ReceiverList{
174db8 2601 com.example.administrator.phoneinfo/10086/u0 remote:3f9381b}
app=2601:com.example.administrator.phoneinfo/u0a86 pid=2601 uid=10086 user=0
Filter #0: BroadcastFilter{7ea5791}
Action: "wangjicong.broadcast.test"
AutoVerify=false
这里显示就是注册广播的信息//registerReceiver: pid = 2601 uid=10086 user=0 pkg = com.example.administrator.phonefinfo action = wangjicong.broadcast.test
2.Historical broadcasts [background]:
广播的发送:
代码语言:javascript复制 Historical Broadcast background #0:
BroadcastRecord{
830ac42 u0 wangjicong.broadcast.test} to user 0
Intent { act=wangjicong.broadcast.test flg=0x10 }
caller=com.example.administrator.phoneinfo 2601:com.example.administrator.phoneinfo/u0a86 pid=2601 uid=10086
enqueueClockTime=Sun Jan 01 08:56:00 GMT 08:00 2017 dispatchClockTime=Sun Jan 01 08:56:00 GMT 08:00 2017
dispatchTime=-1s612ms finishTime=-1s612ms
Receiver #0: BroadcastFilter{59f1dd5 u0 ReceiverList{98df28c 2601 com.example.administrator.phoneinfo/10086/u0 remote:e4adbbf}}
这里的信息更加具体,包含了所以得内容,大家都懂得。
总结
我们可以通过dump broadcasts 信息来得到系统发送广播与处理的过程。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/147756.html原文链接:https://javaforall.cn