I am trying to trace the wifi settings code. My intention is to know the flow from application to kernel layer after toggling the WIFI button OFF to ON.
While we go to Settings page in Android, toggle the WLAN(WIFI) button, then
your wifi should be enabled.
-
I found that this page corresponds to
WifiSettings.java. In this file, while you toggle the button from OFF to ON:private void updateWifiState(int state) { getActivity().invalidateOptionsMenu(); switch (state) { case WifiManager.WIFI_STATE_ENABLING: addMessagePreference(R.string.wifi_starting); break; } mLastInfo = null; mLastState = null; mScanner.pause(); }This function will be called.
-
I then go to check
WifiManager.java. I found:/** * Wi-Fi is currently being enabled. The state will change to {@link#WIFI_STATE_ENABLED} if it finishes successfully. * * @see #WIFI_STATE_CHANGED_ACTION * @see #getWifiState() */ public static final int WIFI_STATE_ENABLING = 2;
However, after this, I did not really understand how to dig deeper in tracing the flow.
You should look at
WifiEnabler.java, since the code you mentioned just shows some string.In
WifiEnabler::onCheckChanged(), you can see thatmWifiManager.setWifiEnabled()is called.After that, you may look at
WifiManager.javaand other related files in that directory. There is a state machine and you should trace the state transitions.Generally, Android is using
wpa_supplicant, which is nearly the same as Linux. The configuration file is at/data/misc/wifi/wpa_supplicant.conf, and is generated by Android. After you toggle the wifi switch, Android startswpa_supplicantand communicates with it. Thewpa_supplicantis in charge of scanning and connecting to wifi station.