1、mNotificationTask- mContext.sendOrderedBroadcast(mScreenOnIntent, null, mScreenOnBroadcastDone, mHandler, 0, null, null);4. Wifi Service will receive the SCREEN_ON intent, will enable Rssi polling, then call updateWifiState. if (action.equals(Intent.ACTION_SCREEN_ON) Log.d(TAG, ACTION_SCREEN_ON); mA
2、larmManager.cancel(mIdleIntent); mDeviceIdle = false; mScreenOff = false; mWifiStateTracker.enableRssiPolling(true);5. updateWifiState will send start driver message: MESSAGE_START_WIFI to Wifi Service itself.if (wifiShouldBeEnabled) if (wifiShouldBeStarted) sWakeLock.acquire(); sendEnableMessage(tr
3、ue, false, mLastEnableUid); sendStartMessage(strongestLockMode = WifiManager.WIFI_MODE_SCAN_ONLY); 6. HandleMessage will call restart of WifiStateTracker public void handleMessage(Message msg) switch (msg.what) case MESSAGE_START_WIFI: mWifiStateTracker.setScanOnlyMode(msg.arg1 != 0); mWifiStateTrac
4、ker.restart(); sWakeLock.release(); break;7. restart of WifiStateTracker will reset interface, call WifiNative.startDriverCommand public synchronized boolean restart() if (mRunState = RUN_STATE_STOPPED) mRunState = RUN_STATE_STARTING; resetInterface(true); return WifiNative.startDriverCommand(); els
5、e if (mRunState = RUN_STATE_STOPPING) return true;8. resetInterface will clear wifi ip address, reset Connections and stop DHCP. /* * Resets the Wi-Fi interface by clearing any state, resetting any sockets * using the interface, stopping DHCP, and disabling the interface. */ public void resetInterfa
6、ce(boolean reenable) mHaveIpAddress = false; mObtainingIpAddress = false; mWifiInfo.setIpAddress(0); /* * Reset connection depends on both the interface and the IP assigned, * so it should be done before any chance of the IP being lost. NetworkUtils.resetConnections(mInterfaceName); / Stop DHCP if (
7、mDhcpTarget != null) mDhcpTarget.setCancelCallback(true); mDhcpTarget.removeMessages(EVENT_DHCP_START); if (!NetworkUtils.stopDhcp(mInterfaceName) Log.e(TAG, Could not stop DHCP/Marvell:cant disableInterface here as the driver wont turn it on automatically/ NetworkUtils.disableInterface(mInterfaceNa
8、me); / we no longer net to start the interface (driver does this for us) / and it led to problems - removed. * The supplicant is reporting that we are disconnected from the current * access point. Often, however, a disconnect will be followed very shortly * by a reconnect to the same access point. T
9、herefore, we delay resetting * the connections IP state for a bit.8. WifiNative.startDriverCommand send start driver event to wpa_suppliant9. Wpa_supplicant call wext to handle start driver event, wpa_supplicant_run eloop_run(void) tmp-handler(tmp-eloop_data, tmp-user_data); -wpa_supplicant_ctrl_ifa
10、ce_receive wpa_supplicant_ctrl_iface_process-wpa_supplicant_driver_cmd wpa_drv_driver_cmd-wpa_s-driver-driver_cmd(wpa_s-drv_priv, cmd, buf, buf_len);10. Wext will call ioctl to send command to Wlan kernel driver11. Wlan kernel driver will handle start driver command (now not support yet)1.3 Screen o
11、ff1. When Android is in running mode , if the power key is pressed, Thread InputDeviceReader will be created and process the key event. Send a message to Windows manager.3. Power manager Service will call setPowerState to set power state, call sendNotificationLocked to notify power on event. will ca
12、ll screenTurnedOff of KeyguardViewMediator to turn off screen, call goingToSleep() of ActivityManagerService to pause activity, broadcast intent, Intent(Intent.ACTION_SCREEN_OFF), send broadcast message:4. Wifi Service will receive the SCREEN_OFF intent, will disable Rssi polling, Set an alarm timer
13、 to send ACTION_DEVICE_IDLE else if (action.equals(Intent.ACTION_SCREEN_OFF) ACTION_SCREEN_OFF mScreenOff = true; mWifiStateTracker.enableRssiPolling(false); * Set a timer to put Wi-Fi to sleep, but only if the screen is off * AND the stay on while plugged in setting doesnt match the * current power
14、 conditions (i.e, not plugged in, plugged in to USB, * or plugged in to AC).shouldWifiStayAwake(stayAwakeConditions, mPluggedType) WifiInfo info = mWifiStateTracker.requestConnectionInfo(); if (info.getSupplicantState() != SupplicantState.COMPLETED) / we used to go to sleep immediately, but this cau
15、sed some race conditions / we dont have time to track down for this release. Delay instead, but not / as long as we would if connected (below) / TODO - fix the race conditions and switch back to the immediate turn-off long triggerTime = System.currentTimeMillis() + (2*60*1000); / 2 minsetting ACTION
16、_DEVICE_IDLE timer for 120,000 ms mAlarmManager.set(AlarmManager.RTC_WAKEUP, triggerTime, mIdleIntent); / / do not keep Wifi awake when screen is off if Wifi is not associated / mDeviceIdle = true; / updateWifiState(); else long triggerTime = System.currentTimeMillis() + idleMillis;setting ACTION_DE
17、VICE_IDLE timer for + idleMillis + ms MESSAGE_STOP_WIFI to Wifi Service itself.sDriverStopWakeLock.acquire();mWifiHandler.sendEmptyMessage(MESSAGE_STOP_WIFI); mWifiHandler.sendEmptyMessageDelayed(MESSAGE_RELEASE_WAKELOCK, wakeLockTimeout); 6. HandleMessage will call disconnectAndStop of WifiStateTra
18、cker case MESSAGE_STOP_WIFI: mWifiStateTracker.disconnectAndStop(); / dont release wakelock7. disconnectAndStop of WifiStateTracker call WifiNative.disconnectCommand first to disconnect the wifi network. /* * We want to stop the driver, but if were connected to a network, * we first want to disconne
19、ct, so that the supplicant is always in * a known state (DISCONNECTED) when the driver is stopped. * return code true if the operation succeeds, which means that the * disconnect or stop command was initiated. public synchronized boolean disconnectAndStop() if (mRunState != RUN_STATE_STOPPING & mRun
20、State != RUN_STATE_STOPPED) / Take down any open network notifications setNotificationVisible(false, 0, false, 0); mRunState = RUN_STATE_STOPPING; if (mWifiInfo.getSupplicantState() = SupplicantState.DORMANT) return WifiNative.stopDriverCommand(); return WifiNative.disconnectCommand(); * The driver-
21、stop wake lock normally is released from the * connectivity manager after the mobile data connection has * been established, or after a timeout period, if that never * happens. Because WifiService.updateWifiState() can get called * multiple times, we can end up acquiring the wake lock and calling *
22、disconnectAndStop() even when a disconnect or stop operation * is already in progress. In that case, we want to ignore the * disconnectAndStop request and release the (ref-counted) wake * lock, so that eventually, when the mobile data connection is * established, the ref count will drop to zero. rel
23、easeWakeLock();8. wpa_supplicant_ctrl_iface_process of handles “DISCONNECT” command, will call wpa_supplicant_disassociate, then call wpa_drv_disassociatevoid wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s, int reason_code) u8 *addr = NULL; if (os_memcmp(wpa_s-bssid, x00x00x00x00x00x00, ET
24、H_ALEN) != 0) if (wpa_s-use_client_mlme) ieee80211_sta_disassociate(wpa_s, reason_code); else wpa_drv_disassociate(wpa_s, wpa_s-bssid, reason_code); addr = wpa_s-bssid; wpa_clear_keys(wpa_s, addr); wpa_supplicant_mark_disassoc(wpa_s); wpa_s-current_ssid = NULL; wpa_sm_set_config(wpa_s-wpa, NULL);9.
25、wpa_drv_disassociate will call wpa_driver_wext_disassociatestatic int wpa_driver_wext_disassociate(void *priv, const u8 *addr, int reason_code) struct wpa_driver_wext_data *drv = priv; wpa_printf(MSG_DEBUG, %s, _FUNCTION_); return wpa_driver_wext_mlme(drv, addr, IW_MLME_DISASSOC, reason_code);10. wpa_driver_wext_disassociate call wpa_driver_wext
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1