作者:爱到最后还是分离_851 | 来源:互联网 | 2023-07-26 16:33
Wifi框架中WifiMonitor负责上报wpa_supplicant的消息给WifiStateMachine,WifiNative负责将WifiStateMachine的消息下发给wpa_supp
Wifi框架中WifiMonitor负责上报wpa_supplicant的消息给WifiStateMachine,WifiNative负责将WifiStateMachine的消息下发给wpa_supplicant执行.
本文先来简单介绍WifiMonitor如何处理事件以及怎么分发事件。(未完待续)
(1)
在WifiStateMachine中InitialState状态收到CMD_START_SUPPLICANT消息时候
if (mWifiNative.startSupplicant(mP2pSupported)) {
setWifiState(WIFI_STATE_ENABLING);
if (DBG) log("Supplicant start successful");
mWifiMonitor.startMonitoring(mInterfaceName);
transitionTo(mSupplicantStartingState);
} else {……}
(2)
startMonitoring这是一个同步函数
![](https://img1.php1.cn/3cd4a/24ed6/9f3/521108c6bd15cd72.jpeg)
(3)
关注ensureConnectedLocked函数
![](https://img1.php1.cn/3cd4a/24ed6/9f3/1a6f031b9acd1b04.jpeg)
(4)
一个跟踪的线程类MonitorThread
private class MonitorThread extends Thread {
private final LocalLog mLocalLog = mWifiNative.getLocalLog();
public MonitorThread() {
super("WifiMonitor");
}
public void run() {
if (DBG) {
Log.d(TAG, "MonitorThread start with mCOnnected=" + mConnected);
}
//noinspection InfiniteLoopStatement
for (;;) {
if (!mConnected) {
if (DBG) Log.d(TAG, "MonitorThread exit because mConnected is false");
break;
}
String eventStr = mWifiNative.waitForEvent();
// Skip logging the common but mostly uninteresting events
if (!eventStr.contains(BSS_ADDED_STR) && !eventStr.contains(BSS_REMOVED_STR)) {
if (DBG) Log.d(TAG, "Event [" + eventStr + "]");
mLocalLog.log("Event [" + eventStr + "]");
}
if (dispatchEvent(eventStr)) {
if (DBG) Log.d(TAG, "Disconnecting from the supplicant, no more events");
break;
}
}
}
}
(5)
然后事件被dispatchEvent函数分发。
ispatchEvent函数有两个,一个是一个参数,一个是两个参数的。
1 private boolean dispatchEvent(String eventStr, String iface)
2 private synchronized boolean dispatchEvent(String eventStr)
(版权所有,转载请告知)