-
Notifications
You must be signed in to change notification settings - Fork 187
/
VABroadcast.puml
211 lines (173 loc) · 8.37 KB
/
VABroadcast.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
@startuml
box "ClientSender" #LightBlue
participant Context
participant ContextImpl
participant ActivityManagerNative
participant BroadcastIntent #ff0000
end box
box "system_server" #LightGreen
participant ActivityManagerService
participant BroadcastQueue
participant IApplicationThread
participant ApplicationThreadProxy
end box
box "VA server process" #LightBlue
participant StaticBroadcastReceiver #ff0000
participant VActivityManagerService #ff0000
participant IApplicationThreadKitkat #ff0000
end box
box "ClientReceiver process" #Gray
participant ApplicationThreadNative
participant ApplicationThread
participant BroadcastReceiver
participant ReceiverData
end box
note left of Context
VA中应用发送广播到广播被接收的处理过程
主要描述静态广播接收器
endnote
note left of Context
在VA中安装应用时,已经解析应用的AndroidManifests.xml
中所有receiver,分别注册到VA应用中,并修改了ACTION。
因此对应的广播发送程序也需要安装到VA中。
本图做如下说明:
ClientSender,广播发送应用
ClientReceiver,广播接收应用
其中红色类表示VA的类
endnote
[-> Context : sendBroadcast
activate Context
Context -> ContextImpl : sendBroadcast
activate ContextImpl
ContextImpl -> ActivityManagerNative : sendBroadcast
activate ActivityManagerNative
ActivityManagerNative -> BroadcastIntent : broadcastIntent
activate BroadcastIntent
note over BroadcastIntent
在这里对client发送的广播Intent进行拦截,替换ACTION等,
替换后的Intent将会被VA应用接收到(安装能接收该广播的应用时,
其静态广播已经VA解析并注册相应的动态广播到VA应用本身,且也
替换了IntentFilter的ACTION)。
这样处理之后,client发送的广播将会被VA程序接收到
endnote
BroadcastIntent -> BroadcastIntent : onHook
activate BroadcastIntent
BroadcastIntent -> BroadcastIntent : handleIntent
activate BroadcastIntent
deactivate BroadcastIntent
deactivate BroadcastIntent
deactivate BroadcastIntent
BroadcastIntent -> 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
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 -> StaticBroadcastReceiver
deactivate BroadcastQueue
...
StaticBroadcastReceiver -> StaticBroadcastReceiver : onReceive
activate StaticBroadcastReceiver
StaticBroadcastReceiver -> VActivityManagerService : handleStaticBroadcast
activate VActivityManagerService
VActivityManagerService -> VActivityManagerService : handleStaticBroadcastAsUser
activate VActivityManagerService
VActivityManagerService -> VActivityManagerService : startProcessIfNeedLocked
activate VActivityManagerService
note over VActivityManagerService
当前VA在这里有宏开关控制,接收器进程不存在时是否启动进程
控制变量为BROADCAST_NOT_STARTED_PKG
endnote
deactivate VActivityManagerService
VActivityManagerService -> VActivityManagerService : handleBroadcastIntent
activate VActivityManagerService
VActivityManagerService -> IApplicationThreadKitkat : scheduleReceiver
activate IApplicationThreadKitkat
note over IApplicationThreadKitkat
这里VA的设计很精巧,利用java的Method Reference语法,
配合注解和反射,执行IApplicationThread.scheduleReceiver,
因为安卓不同版本SDK该方法的参数不一样,所以VA设计了这个方式
兼容多个SDK版本。
endnote
IApplicationThreadKitkat -> ApplicationThreadNative : scheduleReceiver
activate ApplicationThreadNative
deactivate ApplicationThreadNative
deactivate IApplicationThreadKitkat
deactivate VActivityManagerService
deactivate VActivityManagerService
deactivate VActivityManagerService
deactivate StaticBroadcastReceiver
...
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