NetworkManagementService.create -> SystemServer.java
create -> //socket name 是NETD_SOCKET_NAME,即netd
new NetworkManagementService ->
new NativeDaemonConnector -> //NativeDaemonConnector.java 参数有个new NetdCallbackReceiver,当此类和netd建立socket通信时,会调用此callback
new Thread //把NativeDaemonConnector放到thread中去跑
run ->
new Handler //会用到其消息机制
listenToSocket ->
new LocalSocket
socket.connect
mCallbacks.onDaemonConnected //socket建立后就调用它
onDaemonConnected //NetworkManagementService.java
inputStream.read //循环监听socket netd过来的事件,有事件就读取
mCallbackHandler.sendMessage ->
handleMessage -> //NativeDaemonConnector.java
mCallbacks.onEvent ->
onEvent //NetworkManagementService.java处理各种事件
比如拿stopAccessPoint为例:
stopAccessPoint -> //NetworkManagementService.java
mConnector.execute -> //cmd为softap stopap
execute -> //NativeDaemonConnector.java
mOutputStream.write -> //mOutputStream在上面提到的listenToSocket建立,也是基于netd socket的,所以会触发netd socket接收事件
SocketListener::startListener -> //注意这里已经在另一个进程了
listen
pthread_create //创建线程,执行SocketListener::threadStart
me->runListener ->
select
accept
onDataAvailable ->
FrameworkListener::onDataAvailable ->
dispatchCommand ->
c->runCommand ->
CommandListener::SoftapCmd::runCommand ->
sSoftapCtrl->stopSoftap ->
kill