Android13 WifiService创建流程

WifiService由SystemServer创建,在WifiService的构造函数中会创建WifiServiceImpl实例:

//packages/modules/Wifi/service/java/com/android/server/wifi/WifiService.java
public final class WifiService extends SystemService {


    private static final String TAG = "WifiService";
    // Notification channels used by the wifi service.
    public static final String NOTIFICATION_NETWORK_STATUS = "NETWORK_STATUS";
    public static final String NOTIFICATION_NETWORK_ALERTS = "NETWORK_ALERTS";
    public static final String NOTIFICATION_NETWORK_AVAILABLE = "NETWORK_AVAILABLE";


    private final WifiServiceImpl mImpl;
    private final WifiContext mWifiContext;


    public WifiService(Context contextBase) {
        super(contextBase);
        mWifiContext = new WifiContext(contextBase); //创建WifiContext对象
        WifiInjector injector = new WifiInjector(mWifiContext); //创建WifiInjector对象
        mImpl = new WifiServiceImpl(mWifiContext, injector); //创建WifiServiceImpl对象
    }


    @Override
    public void onStart() {
        Log.i(TAG, "Registering " + Context.WIFI_SERVICE);
        publishBinderService(Context.WIFI_SERVICE, mImpl);
    }


    @Override
    public void onBootPhase(int phase) {
        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
            mImpl.checkAndStartWifi();
        } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
            mImpl.handleBootCompleted();
        }
    }


    @Override
    public void onUserSwitching(TargetUser from, TargetUser to) {
        mImpl.handleUserSwitch(to.getUserHandle().getIdentifier());
    }


    @Override
    public void onUserUnlocking(TargetUser user) {
        mImpl.handleUserUnlock(user.getUserHandle().getIdentifier());
    }


    @Override
    public void onUserStopping(TargetUser user) {
        mImpl.handleUserStop(user.getUserHandle().getIdentifier());
    }
}

在WifiServiceImpl的构造函数中会通过WifiInjector获取Wifi相关实例:

//packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java
public class WifiServiceImpl extends BaseWifiService {
    public WifiServiceImpl(WifiContext context, WifiInjector wifiInjector) {
        mContext = context;
        mWifiInjector = wifiInjector;
        mClock = wifiInjector.getClock();


        mFacade = mWifiInjector.getFrameworkFacade();
        mWifiMetrics = mWifiInjector.getWifiMetrics();
        mWifiTrafficPoller = mWifiInjector.getWifiTrafficPoller();
        mUserManager = mWifiInjector.getUserManager();
        mCountryCode = mWifiInjector.getWifiCountryCode();
        mActiveModeWarden = mWifiInjector.getActiveModeWarden();
        mScanRequestProxy = mWifiInjector.getScanRequestProxy();
        mSettingsStore = mWifiInjector.getWifiSettingsStore();
        mPowerManager = mContext.getSystemService(PowerManager.class);
        mAppOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        mWifiLockManager = mWifiInjector.getWifiLockManager();
        mWifiMulticastLockManager = mWifiInjector.getWifiMulticastLockManager();
        mWifiBackupRestore = mWifiInjector.getWifiBackupRestore();
        mSoftApBackupRestore = mWifiInjector.getSoftApBackupRestore();
        mWifiApConfigStore = mWifiInjector.getWifiApConfigStore();
        mWifiPermissionsUtil = mWifiInjector.getWifiPermissionsUtil();
        mLog = mWifiInjector.makeLog(TAG);
        mFrameworkFacade = wifiInjector.getFrameworkFacade();
        mTetheredSoftApTracker = new TetheredSoftApTracker();
        mActiveModeWarden.registerSoftApCallback(mTetheredSoftApTracker);
        mLohsSoftApTracker = new LohsSoftApTracker();
        mActiveModeWarden.registerLohsCallback(mLohsSoftApTracker);
        mWifiNetworkSuggestionsManager = mWifiInjector.getWifiNetworkSuggestionsManager();
        mDppManager = mWifiInjector.getDppManager();
        mWifiThreadRunner = mWifiInjector.getWifiThreadRunner();
        mWifiHandlerThread = mWifiInjector.getWifiHandlerThread();
        mWifiConfigManager = mWifiInjector.getWifiConfigManager();
        mHalDeviceManager = mWifiInjector.getHalDeviceManager();
        mWifiBlocklistMonitor = mWifiInjector.getWifiBlocklistMonitor();
        mPasspointManager = mWifiInjector.getPasspointManager();
        mWifiScoreCard = mWifiInjector.getWifiScoreCard();
        mWifiHealthMonitor = wifiInjector.getWifiHealthMonitor();
        mMemoryStoreImpl = new MemoryStoreImpl(mContext, mWifiInjector,
                mWifiScoreCard,  mWifiHealthMonitor);
        mWifiConnectivityManager = wifiInjector.getWifiConnectivityManager();
        mWifiDataStall = wifiInjector.getWifiDataStall();
        mWifiNative = wifiInjector.getWifiNative();
        mCoexManager = wifiInjector.getCoexManager();
        mConnectHelper = wifiInjector.getConnectHelper();
        mWifiGlobals = wifiInjector.getWifiGlobals();
        mSimRequiredNotifier = wifiInjector.getSimRequiredNotifier();
        mWifiCarrierInfoManager = wifiInjector.getWifiCarrierInfoManager();
        mMakeBeforeBreakManager = mWifiInjector.getMakeBeforeBreakManager();
        mLastCallerInfoManager = mWifiInjector.getLastCallerInfoManager();
        mWifiDialogManager = mWifiInjector.getWifiDialogManager();
        mBuildProperties = mWifiInjector.getBuildProperties();
        mDefaultClientModeManager = mWifiInjector.getDefaultClientModeManager();
        mCountryCodeTracker = new CountryCodeTracker();
        mWifiTetheringDisallowed = false;
        mMultiInternetManager = mWifiInjector.getMultiInternetManager();
    }
}

checkAndStartWifi流程

在系统启动过程中,SystemService会调用WifiService的onBootPhase回调,通知系统启动阶段,在接收到phase 为PHASE_SYSTEM_SERVICES_READY时调用WifiServiceImpl的checkAndStartWifi方法:

WifiServiceImpl的checkAndStartWifi方法:

//packages/modules/Wifi/service/java/com/android/server/wifi/WifiService.java
public class WifiServiceImpl extends BaseWifiService {
    private final ActiveModeWarden mActiveModeWarden;
    private final WifiConfigManager mWifiConfigManager;
    private final WifiThreadRunner mWifiThreadRunner;
    private final WifiSettingsStore mSettingsStore;
    private final WifiGlobals mWifiGlobals;
    private final WifiInjector mWifiInjector;


    public void checkAndStartWifi() {
        mWifiThreadRunner.post(() -> {
            if (!mWifiConfigManager.loadFromStore()) {
                Log.e(TAG, "Failed to load from config store");
            }
            if (!mWifiGlobals.isInsecureEnterpriseConfigurationAllowed()) {
                mWifiConfigManager.updateTrustOnFirstUseFlag(isTrustOnFirstUseSupported());
            }
            mWifiConfigManager.incrementNumRebootsSinceLastUse();
            // config store is read, check if verbose logging is enabled.
            enableVerboseLoggingInternal(
                    mWifiInjector.getSettingsConfigStore().get(WIFI_VERBOSE_LOGGING_ENABLED)
                    ? 1 : 0);
            // Check if wi-fi needs to be enabled
            boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled();
            Log.i(TAG,
                    "WifiService starting up with Wi-Fi " + (wifiEnabled ? "enabled" : "disabled"));


            mWifiInjector.getWifiScanAlwaysAvailableSettingsCompatibility().initialize();
            mWifiInjector.getWifiNotificationManager().createNotificationChannels();


    //注册ACTION_SIM_CARD_STATE_CHANGED广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            int state = intent.getIntExtra(TelephonyManager.EXTRA_SIM_STATE,
                                    TelephonyManager.SIM_STATE_UNKNOWN);
                            if (TelephonyManager.SIM_STATE_ABSENT == state) {
                                Log.d(TAG, "resetting networks because SIM was removed");
                                resetCarrierNetworks(RESET_SIM_REASON_SIM_REMOVED);
                            }
                        }
                    },
                    new IntentFilter(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));
    
     //注册RESET_SIM_REASON_SIM_INSERTED广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            int state = intent.getIntExtra(TelephonyManager.EXTRA_SIM_STATE,
                                    TelephonyManager.SIM_STATE_UNKNOWN);
                            if (TelephonyManager.SIM_STATE_LOADED == state) {
                                Log.d(TAG, "resetting networks because SIM was loaded");
                                resetCarrierNetworks(RESET_SIM_REASON_SIM_INSERTED);
                            }
                        }
                    },
                    new IntentFilter(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));


            //注册ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        private int mLastSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            final int subId = intent.getIntExtra("subscription",
                                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);
                            if (subId != mLastSubId) {
                                Log.d(TAG, "resetting networks as default data SIM is changed");
                                resetCarrierNetworks(RESET_SIM_REASON_DEFAULT_DATA_SIM_CHANGED);
                                mLastSubId = subId;
                                mWifiDataStall.resetPhoneStateListener();
                            }
                        }
                    },
                    new IntentFilter(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));


            //注册ACTION_NETWORK_COUNTRY_CHANGED广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            String countryCode = intent.getStringExtra(
                                    TelephonyManager.EXTRA_NETWORK_COUNTRY);
                            Log.d(TAG, "Country code changed to :" + countryCode);
                            mCountryCode.setTelephonyCountryCodeAndUpdate(countryCode);
                        }
                    },
                    new IntentFilter(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));


            //注册ACTION_LOCALE_CHANGED广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            Log.d(TAG, "locale changed");
                            resetNotificationManager();
                        }
                    },
                    new IntentFilter(Intent.ACTION_LOCALE_CHANGED),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));


            //注册MODE_CHANGED_ACTION广播
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            if (isVerboseLoggingEnabled()) {
                                Log.v(TAG, "onReceive: MODE_CHANGED_ACTION: intent=" + intent);
                            }
                            updateLocationMode();
                        }
                    },
                    new IntentFilter(LocationManager.MODE_CHANGED_ACTION),
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));
            updateLocationMode(); //更新本地模式


            if (SdkLevel.isAtLeastT()) {
                //注册ACTION_USER_RESTRICTIONS_CHANGED广播
                mContext.registerReceiver(
                        new BroadcastReceiver() {
                            @Override
                            public void onReceive(Context context, Intent intent) {
                                Log.d(TAG, "user restrictions changed");
                                onUserRestrictionsChanged();
                            }
                        },
                        new IntentFilter(UserManager.ACTION_USER_RESTRICTIONS_CHANGED),
                        null,
                        new Handler(mWifiHandlerThread.getLooper()));
                mWifiTetheringDisallowed = mUserManager.getUserRestrictions()
                        .getBoolean(UserManager.DISALLOW_WIFI_TETHERING);
            }


            // Adding optimizations of only receiving broadcasts when wifi is enabled
            // can result in race conditions when apps toggle wifi in the background
            // without active user involvement. Always receive broadcasts.
            registerForBroadcasts(); //注册package相关广播
            mInIdleMode = mPowerManager.isDeviceIdleMode();


            mActiveModeWarden.start(); //调用ActiveModeWarden的start方法
            registerForCarrierConfigChange(); //注册运营商配置更改
            mWifiInjector.getAdaptiveConnectivityEnabledSettingObserver().initialize();
            mIsWifiServiceStarted = true;
        });
    }


    private void updateLocationMode() {
        mIsLocationModeEnabled = mWifiPermissionsUtil.isLocationModeEnabled();
        mWifiConnectivityManager.setLocationModeEnabled(mIsLocationModeEnabled);
    }


    private void registerForBroadcasts() { 
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
        intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        intentFilter.addDataScheme("package");
        mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
                        Uri uri = intent.getData();
                        if (uid == -1 || uri == null) {
                            Log.e(TAG, "Uid or Uri is missing for action:" + intent.getAction());
                            return;
                        }
                        String pkgName = uri.getSchemeSpecificPart();
                        PackageManager pm = context.getPackageManager();
                        PackageInfo packageInfo = null;
                        try {
                            packageInfo = pm.getPackageInfo(pkgName, 0);
                        } catch (PackageManager.NameNotFoundException e) {
                            Log.w(TAG, "Couldn't get PackageInfo for package:" + pkgName);
                        }
                        // If package is not removed or disabled, just ignore.
                        if (packageInfo != null
                                && packageInfo.applicationInfo != null
                                && packageInfo.applicationInfo.enabled) {
                            return;
                        }
                        Log.d(TAG, "Remove settings for package:" + pkgName);
                        removeAppStateInternal(uid, pkgName);
                    }
                },
                intentFilter,
                null,
                new Handler(mWifiHandlerThread.getLooper()));
    }


    private void registerForCarrierConfigChange() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        final int subId = SubscriptionManager.getActiveDataSubscriptionId();
                        Log.d(TAG, "ACTION_CARRIER_CONFIG_CHANGED, active subId: " + subId);
                        // Tether mode only since carrier requirement only for tethered SoftAp.
                        mTetheredSoftApTracker
                                .updateSoftApCapabilityWhenCarrierConfigChanged(subId);
                        mActiveModeWarden.updateSoftApCapability(
                                mTetheredSoftApTracker.getSoftApCapability(),
                                WifiManager.IFACE_IP_MODE_TETHERED);
                    }
                },
                filter,
                null,
                new Handler(mWifiHandlerThread.getLooper()));


        WifiPhoneStateListener phoneStateListener = new WifiPhoneStateListener(
                mWifiHandlerThread.getLooper());


        mContext.getSystemService(TelephonyManager.class).listen(
                phoneStateListener, PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
    }
}

调用ActiveModeWarden的start方法:

//packages/modules/Wifi/service/java/com/android/server/wifi/util/ActiveModeWarden.java
public class ActiveModeWarden {
    private final WifiController mWifiController;
    public void start() {
        //监听MODE_CHANGED_ACTION广播
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // Location mode has been toggled...  trigger with the scan change
                // update to make sure we are in the correct mode
                scanAlwaysModeChanged();
            }
        }, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));


        //监听ACTION_AIRPLANE_MODE_CHANGED广播
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                boolean airplaneModeUpdated = mSettingsStore.updateAirplaneModeTracker();
                boolean userRestrictionSet =
                        SdkLevel.isAtLeastT() && mUserManager.hasUserRestrictionForUser(
                                UserManager.DISALLOW_CHANGE_WIFI_STATE,
                                UserHandle.getUserHandleForUid(Process.SYSTEM_UID));
                if (!userRestrictionSet && airplaneModeUpdated) {
                    mSettingsStore.handleAirplaneModeToggled();
                    airplaneModeToggled();
                }
            }
        }, new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
        
        //监听ACTION_EMERGENCY_CALLBACK_MODE_CHANGED广播
        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                boolean emergencyMode =
                        intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false);
                emergencyCallbackModeChanged(emergencyMode);
            }
        }, new IntentFilter(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED));


        boolean trackEmergencyCallState = mContext.getResources().getBoolean(
                R.bool.config_wifi_turn_off_during_emergency_call);
        if (trackEmergencyCallState) {
            //监听ACTION_EMERGENCY_CALL_STATE_CHANGED广播
            mContext.registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    boolean inCall = intent.getBooleanExtra(
                            TelephonyManager.EXTRA_PHONE_IN_EMERGENCY_CALL, false);
                    emergencyCallStateChanged(inCall);
                }
            }, new IntentFilter(TelephonyManager.ACTION_EMERGENCY_CALL_STATE_CHANGED));
        }


        mWifiController.start(); //调用WifiController的start方法
    }
}

调用ActiveModeWarden内部类WifiController的start方法:

//packages/modules/Wifi/service/java/com/android/server/wifi/util/ActiveModeWarden.java
public class ActiveModeWarden {
    private final WifiNative mWifiNative;
    private class WifiController extends StateMachine {
        public void start() {
            boolean isAirplaneModeOn = mSettingsStore.isAirplaneModeOn();
            boolean isWifiEnabled = mSettingsStore.isWifiToggleEnabled();
            boolean isScanningAlwaysAvailable = mSettingsStore.isScanAlwaysAvailable();
            boolean isLocationModeActive = mWifiPermissionsUtil.isLocationModeEnabled();


            log("isAirplaneModeOn = " + isAirplaneModeOn
                    + ", isWifiEnabled = " + isWifiEnabled
                    + ", isScanningAvailable = " + isScanningAlwaysAvailable
                    + ", isLocationModeActive = " + isLocationModeActive);


            // Initialize these values at bootup to defaults, will be overridden by API calls
            // for further toggles.
            mLastPrimaryClientModeManagerRequestorWs = mFacade.getSettingsWorkSource(mContext);
            mLastScanOnlyClientModeManagerRequestorWs = INTERNAL_REQUESTOR_WS;
            ActiveModeManager.ClientRole role = getRoleForPrimaryOrScanOnlyClientModeManager();
            if (role == ROLE_CLIENT_PRIMARY) {
                startPrimaryClientModeManager(mLastPrimaryClientModeManagerRequestorWs);
                setInitialState(mEnabledState);
            } else if (role == ROLE_CLIENT_SCAN_ONLY) {
                startScanOnlyClientModeManager(mLastScanOnlyClientModeManagerRequestorWs);
                setInitialState(mEnabledState);
            } else {
                setInitialState(mDisabledState);
            }
            mWifiMetrics.noteWifiEnabledDuringBoot(mSettingsStore.isWifiToggleEnabled());


            // Initialize the lower layers before we start.
            mWifiNative.initialize(); //初始化WifiNative
            super.start(); //调用父类的start方法,启动状态机
        }
}

handleBootCompleted流程

在系统启动过程中,SystemService会调用WifiService的onBootPhase回调,通知系统启动阶段,在接收到phase为PHASE_BOOT_COMPLETED时调用WifiServiceImpl的handleBootCompleted方法:

WifiServiceImpl的handleBootCompleted方法:

//packages/modules/Wifi/service/java/com/android/server/wifi/WifiService.java
public class WifiServiceImpl extends BaseWifiService {
    private final MemoryStoreImpl mMemoryStoreImpl;
    private final PasspointManager mPasspointManager;
    private final TetheredSoftApTracker mTetheredSoftApTracker;
    private final LohsSoftApTracker mLohsSoftApTracker;
    public void handleBootCompleted() {
        mWifiThreadRunner.post(() -> {
            Log.d(TAG, "Handle boot completed");


            // Register for system broadcasts.
     //注册系统广播。
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(Intent.ACTION_USER_REMOVED);
            intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
            intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
            intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
            intentFilter.addAction(Intent.ACTION_SHUTDOWN);
            mContext.registerReceiver(
                    new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            String action = intent.getAction();
                            if (Intent.ACTION_USER_REMOVED.equals(action)) {
                                UserHandle userHandle =
                                        intent.getParcelableExtra(Intent.EXTRA_USER);
                                if (userHandle == null) {
                                    Log.e(TAG,
                                            "User removed broadcast received with no user handle");
                                    return;
                                }
                                mWifiConfigManager
                                        .removeNetworksForUser(userHandle.getIdentifier());
                            } else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED
                                    .equals(action)) {
                                int state = intent.getIntExtra(
                                        BluetoothAdapter.EXTRA_CONNECTION_STATE,
                                        BluetoothAdapter.STATE_DISCONNECTED);
                                boolean isConnected =
                                        state != BluetoothAdapter.STATE_DISCONNECTED;
                                mWifiGlobals.setBluetoothConnected(isConnected);
                                for (ClientModeManager cmm :
                                        mActiveModeWarden.getClientModeManagers()) {
                                    cmm.onBluetoothConnectionStateChanged();
                                }
                            } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                        BluetoothAdapter.STATE_OFF);
                                boolean isEnabled = state != BluetoothAdapter.STATE_OFF;
                                mWifiGlobals.setBluetoothEnabled(isEnabled);
                                for (ClientModeManager cmm :
                                        mActiveModeWarden.getClientModeManagers()) {
                                    cmm.onBluetoothConnectionStateChanged();
                                }
                            } else if (PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED
                                    .equals(action)) {
                                handleIdleModeChanged();
                            } else if (Intent.ACTION_SHUTDOWN.equals(action)) {
                                handleShutDown();
                            }
                        }
                    },
                    intentFilter,
                    null,
                    new Handler(mWifiHandlerThread.getLooper()));
            mMemoryStoreImpl.start();
            mPasspointManager.initializeProvisioner(
                    mWifiInjector.getPasspointProvisionerHandlerThread().getLooper());
            mWifiInjector.getWifiNetworkFactory().register(); //调用WifiNetworkFactory的register方法
            mWifiInjector.getUntrustedWifiNetworkFactory().register();  //调用UntrustedWifiNetworkFactory的register方法
            mWifiInjector.getRestrictedWifiNetworkFactory().register(); //调用RestrictedWifiNetworkFactory的register方法
            mWifiInjector.getOemWifiNetworkFactory().register();   //调用OemWifiNetworkFactory的register方法
            mWifiInjector.getMultiInternetWifiNetworkFactory().register();  //调用MultiInternetWifiNetworkFactory的register方法
            mWifiInjector.getWifiP2pConnection().handleBootCompleted();
            // Start to listen country code change to avoid query supported channels causes boot
            // time increased.
            mCountryCode.registerListener(mCountryCodeTracker);  
            mTetheredSoftApTracker.handleBootCompleted();
            mLohsSoftApTracker.handleBootCompleted();
            mWifiInjector.getSarManager().handleBootCompleted();
            mIsBootComplete = true;
        });
    }
}
  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Android 11的WiFi打开函数调用流程图如下: 1. 点击设备的“设置”按钮,进入系统设置界面。 2. 在设置界面中找到“网络和互联网”的选项,点击进入。 3. 在网络和互联网界面中,找到并点击“WiFi”选项。 4. 进入WiFi设置界面后,点击“开启WiFi”按钮。 5. 设备调用系统的WiFi管理模块,开始执行WiFi打开的流程。 6. WiFi管理模块首先检查设备的WiFi芯片状态,如果芯片已经关闭,则需要先打开WiFi芯片。 7. 如果WiFi芯片已经打开,则WiFi管理模块开始搜索可用的WiFi网络。 8. 当找到可用的WiFi网络时,WiFi管理模块会尝试连接到该网络。 9. 连接到WiFi网络后,设备会获取该网络的IP地址和其他网络相关信息。 10. 设备将WiFi连接状态设置为已连接,并通知系统和应用程序。 11. 如果WiFi连接失败或者没有可用的WiFi网络,WiFi管理模块将会关闭WiFi芯片并返回WiFi打开失败的信息。 以上就是Android 11的WiFi打开函数调用流程图。在实际执行中,可能还会有一些其他细节和错误处理逻辑,但总体而言,这个流程可以帮助用户打开设备的WiFi功能并连接到可用的WiFi网络。 ### 回答2: Android 11中的WiFi打开函数调用流程图如下: 1. 首先,应用程序通过调用WiFiManager类的getSystemService()方法获取系统的WiFi服务实例。 2. 接下来,应用程序通过调用WiFiManager类的setWifiEnabled()方法来打开WiFi功能。 3. WiFiManager类会将该请求传递给系统服务,即WifiService类。 4. WifiService类会通过调用WifiController类的方法来处理WiFi打开请求。 5. WifiController类会检查当前设备的权限和状态,以确定是否允许打开WiFi。 6. 如果设备具有足够的权限并且当前设备处于正确状态,则WifiController类会继续处理打开WiFi请求。 7. WifiController类会与驱动程序进行通信,以控制硬件设备的操作,从而打开WiFi。 8. 一旦WiFi硬件设备成功打开,WifiController类会通知WifiService类。 9. WifiService类随后会通知应用程序,指示WiFi已成功打开。 10. 最后,应用程序可以进一步使用WiFi功能,如连接到可用的WiFi网络。 请注意,Android 11中的WiFi打开函数调用流程可能会因设备和系统定制而有所不同。上述流程图仅为概述,具体实现可能会有所差异。 ### 回答3: Android 11中的Wi-Fi打开函数调用流程图如下: 1. 应用程序调用Wi-Fi Manager类的`setWifiEnabled(true)`方法,用于打开Wi-Fi功能。 2. Wi-Fi Manager类将此请求发送给系统服务。 3. 系统服务接收到请求后,检查当前设备是否具有足够的权限来打开Wi-Fi。如果权限不足,服务将拒绝请求,并向应用程序返回相应的错误代码。 4. 如果应用程序具有足够的权限,系统服务将检查与Wi-Fi硬件驱动程序的通信是否正常。如果存在通信问题,服务将返回相应的错误代码。 5. 如果无任何问题,系统服务将向Wi-Fi硬件驱动程序发送打开Wi-Fi的指令。 6. Wi-Fi硬件驱动程序接收到指令后,控制Wi-Fi芯片打开相应的电路和无线射频器。 7. 一旦Wi-Fi硬件处于打开状态,驱动程序将返回成功的消息给系统服务。 8. 系统服务收到成功消息后,将其传递给Wi-Fi Manager类。 9. Wi-Fi Manager类会更新其内部状态,表示Wi-Fi已成功打开。 10. Wi-Fi Manager类将成功的消息返回给应用程序,通知其Wi-Fi已成功打开。 11. 应用程序可以通过检查Wi-Fi Manager类的状态来确认Wi-Fi是否已打开。 总的来说,Android 11中的Wi-Fi打开函数调用流程主要涉及应用程序调用Wi-Fi Manager类的方法,将请求传递给系统服务,然后由系统服务与Wi-Fi硬件驱动程序进行通信以打开Wi-Fi。最后,成功的消息将传递回应用程序,并更新Wi-Fi Manager类的内部状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值