当前位置:   article > 正文

Android adb shell dumpsys activity broadcasts分析

dumpsys activity broadcasts

adb shell dumpsys activity 中的broadcasts信息

通过adb shell dumpsys activity打印中的第二项就是broadcasts信息;

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}]

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  #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
  • 2
  • 3
  • 4
  • 5
  • 6
#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}]
  • 1
  • 2
  • 3
  • 4
  • 5

从#0 和#10 可以看出CLOSE_SYSTEM_DIALOGS 是成对出现的,#10记录了改广播的处理时间点。

adb shell dumpsys activity broadcasts

打印broadcasts更加具体的信息。包含三项

  1. ReceiverList//注册的广播接收列表
  2. Historical broadcasts [foreground]://前台广播的历史记录
  3. Historical broadcasts [background]://后台广播的历史记录

为了更好的理解打印的具体信息是什么,我自己注册了个广播,发送并接收。

        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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在运行此界面后,打印 dumpsys activity broadcasts信息。如下:

1.ReceiverList

  * 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这里显示就是注册广播的信息//registerReceiver:
pid = 2601 uid=10086 user=0
pkg = com.example.administrator.phonefinfo
action = wangjicong.broadcast.test

2.Historical broadcasts [background]:

广播的发送:

  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}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

这里的信息更加具体,包含了所以得内容,大家都懂得。

总结

我们可以通过dump broadcasts 信息来得到系统发送广播与处理的过程。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/865976
推荐阅读
相关标签
  

闽ICP备14008679号