-
Notifications
You must be signed in to change notification settings - Fork 187
/
Broadcast.puml
168 lines (141 loc) · 6.64 KB
/
Broadcast.puml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@startuml
box "ClientSender" #LightBlue
participant Context
participant ContextImpl
participant ActivityManagerNative
end box
box "system_server" #LightGreen
participant ActivityManagerService
participant BroadcastQueue
participant IApplicationThread
participant ApplicationThreadProxy
end box
box "ClientReceiver process" #Gray
participant ApplicationThreadNative
participant ApplicationThread
participant BroadcastReceiver
participant ReceiverData
end box
note left of Context
本图为Android系统中,应用发送广播到广播被接收的处理过程
endnote
note left of Context
在VA中安装应用时,已经解析应用的AndroidManifests.xml
中所有receiver,分别注册到VA应用中,并修改了ACTION。
因此对应的广播发送程序也需要安装到VA中。
本图做如下说明:
ClientSender,广播发送应用
ClientReceiver,广播接收应用
endnote
[-> Context : sendBroadcast
activate Context
Context -> ContextImpl : sendBroadcast
activate ContextImpl
ContextImpl -> ActivityManagerNative : sendBroadcast
activate ActivityManagerNative
ActivityManagerNative -> ActivityManagerService : broadcastIntent
activate ActivityManagerService
ActivityManagerService -> ActivityManagerService : broadcastIntentLocked
activate ActivityManagerService
ActivityManagerService -> BroadcastQueue : scheduleBroadcastsLocked
activate BroadcastQueue
BroadcastQueue -> BroadcastQueue : sendMessage(BROADCAST_INTENT_MSG)
activate BroadcastQueue
deactivate BroadcastQueue
deactivate BroadcastQueue
deactivate ActivityManagerService
deactivate ActivityManagerService
deactivate ActivityManagerNative
deactivate ContextImpl
[<- Context
deactivate Context
...
BroadcastQueue -> BroadcastQueue : handleMessage
activate BroadcastQueue
BroadcastQueue -> BroadcastQueue : processNextBroadcast
activate BroadcastQueue
note over BroadcastQueue : 动态receiver
BroadcastQueue -> BroadcastQueue : deliverToRegisteredReceiverLocked
activate BroadcastQueue
BroadcastQueue -> BroadcastQueue : performReceiveLocked
activate BroadcastQueue
BroadcastQueue -> IApplicationThread : scheduleRegisteredReceiver
activate IApplicationThread
IApplicationThread -> ApplicationThreadProxy : scheduleRegisteredReceiver
activate ApplicationThreadProxy
ApplicationThreadProxy -> ApplicationThreadNative : scheduleRegisteredReceiver
activate ApplicationThreadNative
note over ApplicationThreadProxy
这里使用了ONEWAY关键字,因此这条binder调用是异步执行的
endnote
deactivate ApplicationThreadNative
deactivate ApplicationThreadProxy
deactivate IApplicationThread
deactivate BroadcastQueue
deactivate BroadcastQueue
...
ApplicationThreadNative -> ApplicationThreadNative : scheduleRegisteredReceiver
activate ApplicationThreadNative
ApplicationThreadNative -> ApplicationThread : scheduleRegisteredReceiver
activate ApplicationThread
deactivate ApplicationThread
deactivate ApplicationThreadNative
note over BroadcastQueue : 静态receiver,所属进程已创建
BroadcastQueue -> BroadcastQueue : processCurBroadcastLocked
activate BroadcastQueue
BroadcastQueue -> IApplicationThread : scheduleReceiver
activate IApplicationThread
IApplicationThread -> ApplicationThreadProxy : scheduleRegisteredReceiver
activate ApplicationThreadProxy
ApplicationThreadProxy -> ApplicationThreadNative : scheduleRegisteredReceiver
activate ApplicationThreadNative
note over ApplicationThreadProxy
这里使用了ONEWAY关键字,因此这条binder调用是异步执行的
endnote
deactivate ApplicationThreadNative
deactivate ApplicationThreadProxy
deactivate IApplicationThread
deactivate IApplicationThread
deactivate BroadcastQueue
...
ApplicationThreadNative -> ApplicationThreadNative : scheduleReceiver
activate ApplicationThreadNative
ApplicationThreadNative -> ApplicationThread : scheduleReceiver
activate ApplicationThread
ApplicationThread -> ApplicationThread : sendMessage(RECEIVER)
deactivate ApplicationThread
deactivate ApplicationThreadNative
...
ApplicationThread -> ApplicationThread : handleMessage(RECEIVER)
activate ApplicationThread
ApplicationThread -> ApplicationThread : handleReceiver
activate ApplicationThread
ApplicationThread <-- BroadcastReceiver : 反射创建receiver
activate BroadcastReceiver
deactivate BroadcastReceiver
note over ApplicationThread
在这里处理使用反射创建xml中定义的的静态receiver类,
并回调onReceive方法
endnote
ApplicationThread -> BroadcastReceiver : onReceive
activate BroadcastReceiver
deactivate BroadcastReceiver
ApplicationThread -> ReceiverData : finish
activate ReceiverData
ReceiverData -> ActivityManagerService : finishReceiver
activate ActivityManagerService
note over ActivityManagerService
这里继续调用r.queue.processNextBroadcast(false);
处理下一条广播
endnote
deactivate ActivityManagerService
deactivate ReceiverData
deactivate ApplicationThread
deactivate ApplicationThread
note over BroadcastQueue : 静态receiver,所属进程未创建
BroadcastQueue -> BroadcastQueue : processCurBroadcastLocked
activate BroadcastQueue
deactivate BroadcastQueue
deactivate BroadcastQueue
deactivate BroadcastQueue
@enduml