wifisettings part is not to say, start from wificontroller:
1.WifiController: received CMD_WIFI_TOGGLED, calltransitionTo(mDeviceActiveState)切换状态->DeviceActiveState::mWifiStateMachinePrime.enterClientMode()
2.WifiStateMachinePrime: changeMode(ModeStateMachine.CMD_START_CLIENT_MODE)->ModeStateMachine::ClientModeActiveState::enter::mManager.start()
3. ClientModeManager: mStateMachine.sendMessage(ClientModeStateMachine.CMD_START)->ClientModeStateMachine::IdleState::mWifiNative.setupInterfaceForClientMode(这里做了①startHal②startSupplicant③createStaIface创建wlan0接口④mWifiMonitor.startMonitoring)->transitionTo(mStartedState)->StartedState::processMessage::CMD_INTERFACE_STATUS_CHANGED::onUpChanged(isUp)::mWifiStateMachine.setOperationalMode(WifiStateMachine.CONNECT_MODE, mClientInterfaceName)->updateWifiState(WifiManager.WIFI_STATE_ENABLED, WifiManager.WIFI_STATE_ENABLING)
Here already sent wifi enabled broadcast
4.WifiStateMachine: transitionTo(mDisconnectedState)->先进入父状态ConnectModeState::enter::setupClientMode::p2pSendMessage(WifiStateMachine.CMD_ENABLE_P2P)
Next is the p2p part
wifip2pservice with wifiservice is the same as with the system service starts SystemServer: mSystemServiceManager.startService (WIFI_P2P_SERVICE_CLASS)
in the constructor WifiP2pServiceImpl will start in a P2pStateMachine, in P2pStateMachine constructor initial state setInitialState (mP2pDisabledState), while registered listeners wifi broadcast switching states do two things when the state acquired wifi WifiManager.WIFI_STATE_ENABLED:
1. checkAndReEnableP2p->sendMessage(ENABLE_P2P)->P2pStateMachine::P2pDisabledState::mWifiNative.setupInterface(这里调用mIWifiP2pIface = mHalDeviceManager.createP2pIface(mInterfaceDestroyedListener, handler)创建p2p0接口)->mNwService.setInterfaceUp(mInterfaceName)将这个接口拉起来->registerForWifiMonitorEvents
this is the call mWifiMonitor.startMonitoring (mInterfaceName) -> transitionTo ( mInactiveState) and then switches to wait for subsequent messaging InactiveState
2 .checkAndSendP2pStateChangedBroadcast->sendP2pStateChangedBroadcast(mIsWifiEnabled && mIsInterfaceAvailable)
, the p2p step in the transmission WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION broadcast after port available and carry WifiP2pManager.WIFI_P2P_STATE_ENABLED state.