Android 12 WiFi开启流程

 /*                                           ActiveModeWarden
 *                                      /                        \
 *                                     /                          \
 *                        ConcreteClientModeManager         DefaultClientModeManager
 *                      (Client Mode + Scan Only Mode)            (Wifi off)
 *                             /            \
 *                           /               \
 *                     ClientModeImpl       ScanOnlyModeImpl
 */
一、startHal
packages/apps/Settings/src/com/android/settings/wifi/WifiEnabler.java
frameworks/base/wifi/java/android/net/wifi/WifiManager.java
packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java
packages/modules/Wifi/service/java/com/android/server/wifi/ActiveModeWarden.java
packages/modules/Wifi/service/java/com/android/server/wifi/ConcreteClientModeManager.java
packages/modules/Wifi/service/java/com/android/server/wifi/WifiNative.java
packages/modules/Wifi/service/java/com/android/server/wifi/WifiVendorHal.java
packages/modules/Wifi/service/java/com/android/server/wifi/HalDeviceManager.java

WifiEnabler.java ->mWifiManager.setWifiEnabled(isChecked)
---->WifiManager.java =>setWifiEnabled(boolean enabled)
--------->WifiServiceImpl.java =>setWifiEnabled(String packageName, boolean enable): mActiveModeWarden.wifiToggled(new WorkSource(Binder.getCallingUid(), packageName));
-------------->ActiveModeWarden.java =>wifiToggled(WorkSource requestorWs): mWifiController.sendMessage(WifiController.CMD_WIFI_TOGGLED, requestorWs);//发送CMD_WIFI_TOGGLED消息到EnabledState中
                                      -->ActiveModeWarden$DisabledState
                                         ->processMessageFiltered(Message msg)
                                           -->case CMD_WIFI_TOGGLED
                                              handleStaToggleChangeInDisabledState((WorkSource) msg.obj);;//接收到CMD_WIFI_TOGGLED消息
                                      -->handleStaToggleChangeInDisabledState((WorkSource) msg.obj):
                                         startPrimaryOrScanOnlyClientModeManager(requestorWs);
                                         transitionTo(mEnabledState);//将状态切换到EnabledState
                                      -->startPrimaryOrScanOnlyClientModeManager(WorkSource requestorWs):
                                         ->if (role == ROLE_CLIENT_PRIMARY)
                                           return startPrimaryClientModeManager(requestorWs);
                                         ->else if
                                           return startScanOnlyClientModeManager(requestorWs);
                                         ->else
                                           return false;
                                      -->startPrimaryClientModeManager(WorkSource requestorWs):
                                         ConcreteClientModeManager manager = mWifiInjector.makeClientModeManager(new ClientListener(), requestorWs, ROLE_CLIENT_PRIMARY, mVerboseLoggingEnabled);//创建对象
                                         mClientModeManagers.add(manager);//加入到ConcreteClientModeManager列表集合中
------------------->ConcreteClientModeManager.java =>mStateMachine.sendMessage(ClientModeStateMachine.CMD_START, mTargetRoleChangeInfo);//在构造方法里发送CMD_START消息
                                                -->ConcreteClientModeManager$IdleState->processMessage(Message message)
                                                   --->case CMD_START//接收CMD_START消息
                                                       mClientInterfaceName = mWifiNative.setupInterfaceForClientInScanMode( mWifiNativeInterfaceCallback, roleChangeInfo.requestorWs);
----------------------->WifiNative.java =>setupInterfaceForClientInScanMode(@NonNull InterfaceCallback interfaceCallback, @NonNull WorkSource requestorWs):startHal()
                                          ->startHal():mWifiVendorHal.startVendorHal()//开启vendor Hal
--------------------------->WifiVendorHal.java =>startVendorHal():mHalDeviceManager.start()
------------------------------->HalDeviceManager.java =>start():startWifi()
                                                        -->startWifi():
                                                           -> WifiStatus status = mWifi.start();//启动实际加载WiFi动作的调用,涉及HIDL机制调用

hardware/interfaces/wifi/1.5/IWifi.hal//编译的时候会生成IWifi.java中间文件,通过Binder调用到wifi.cpp中
hardware/interfaces/wifi/1.5/default/wifi.cpp
hardware/interfaces/wifi/1.5/default/wifi_mode_controller.cpp
frameworks/opt/net/wifi/libwifi_hal/driver_tool.cpp
frameworks/opt/net/wifi/libwifi_hal/wifi_hal_common.cpp

wifi.cpp =>Return Wifi::start(start_cb hidl_status_cb) => return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN,&Wifi::startInternal, hidl_status_cb);
           ==> WifiStatus Wifi::startInternal() => WifiStatus wifi_status = initializeModeControllerAndLegacyHal();
              ==> WifiStatus Wifi::initializeModeControllerAndLegacyHal() => legacy_hal::wifi_error legacy_status = hal->initialize()
---->wifi_mode_controller.cpp =>bool WifiModeController::initialize() => driver_tool_->LoadDriver()
-------->driver_tool.cpp => bool DriverTool::LoadDriver()//加载wifi驱动
------------->wifi_hal_common.cpp => int wifi_load_driver() =>insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG)//处理完成CMD_START消息,状态机将执行IdleState.exit()->StartedState.enter()->StartedState.exit()->ScanOnlyModeState.enter()

二、启动supplicant

-------------->ActiveModeWarden.java =>ActiveModeWarden$EnabledState
                                       -->processMessageFiltered(Message msg)
                                          ->case CMD_WIFI_TOGGLED
                                            handleStaToggleChangeInEnabledState((WorkSource) msg.obj);
                                       -->handleStaToggleChangeInEnabledState(WorkSource requestorWs):
                                          ->if (shouldEnableSta())
                                            -->if (hasAnyClientModeManager())
                                               switchAllPrimaryOrScanOnlyClientModeManagers();
                                            -->else
                                               startPrimaryOrScanOnlyClientModeManager(requestorWs);
                                          ->else
                                            stopAllClientModeManagers();
                                       -->switchAllPrimaryOrScanOnlyClientModeManagers():switchPrimaryOrScanOnlyClientModeManagerRole(clientModeManager)
                                       -->switchPrimaryOrScanOnlyClientModeManagerRole(@NonNull ConcreteClientModeManager modeManager):
                                          ->modeManager.setRole(role, lastRequestorWs);
------------------>ConcreteClientModeManager.java =>setRole(@NonNull ClientRole role, @NonNull WorkSource requestorWs):setRole(role, requestorWs, null);
                                                    ->setRole(@NonNull ClientRole role, @NonNull WorkSource requestorWs,@Nullable Listener modeListener):
                                                      -->if (role == ROLE_CLIENT_SCAN_ONLY)
                                                         mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_SCAN_ONLY_MODE);
                                                      -->else
                                                         mStateMachine.sendMessage(ClientModeStateMachine.CMD_SWITCH_TO_CONNECT_MODE,mTargetRoleChangeInfo);
                                       -->ConcreteClientModeManager$StartedState->processMessage(Message message):
                                          ->case CMD_SWITCH_TO_CONNECT_MODE
                                            mWifiNative.switchClientInterfaceToConnectivityMode(mClientInterfaceName, roleChangeInfo.requestorWs);
                                            transitionTo(mConnectModeState);//将状态切换到connectmodestate
---------------------->WifiNative.java =>switchClientInterfaceToConnectivityMode(@NonNull String ifaceName,@NonNull WorkSource requestorWs):startSupplicant()
                                         -->startSupplicant():startAndWaitForSupplicantConnection()
                                         -->startAndWaitForSupplicantConnection():
                                            mSupplicantStaIfaceHal.initialize();
                                            mSupplicantStaIfaceHal.startDaemon();
-------------------------->SupplicantStaIfaceHal.java => startDaemon():
                                                         -->if (isV1_1())
                                                            Log.i(TAG, "Starting supplicant using HIDL");
                                                            return startDaemon_V1_1();
                                                         -->else
                                                            Log.i(TAG, "Starting supplicant using init");
                                                            return mFrameworkFacade.startSupplicant();
                                                         -->startDaemon_V1_1():getSupplicantMockableV1_1();
                                                         -->getSupplicantMockableV1_1()//通过HIDL来打开supplicant
//注册wpa_supplicant:main.c ==> wpa_supplicant.c->wpa_supplicant_init() ==> notify.c->wpas_notify_supplicant_initialized() ==> hidl.cpp->wpas_hidl_init() ==> Hidl_manager.cpp->registerHidlService()

你可能感兴趣的:(Android,Wifi,模块,android,framework)