/**
* Check if Wi-Fi needs to be enabled and start
* if needed
*
* This function is used only at boot time*/
public voidcheckAndStartWifi() {/*Check if wi-fi needs to be enabled*/boolean wifiEnabled=mSettingsStore.isWifiToggleEnabled();
Slog.i(TAG,"WifiService starting up with Wi-Fi" +(wifiEnabled? "enabled" : "disabled"));
registerForScanModeChange();
mContext.registerReceiver(newBroadcastReceiver() {
@Overridepublic voidonReceive(Context context, Intent intent) {if(mSettingsStore.handleAirplaneModeToggled()) {
mWifiController.sendMessage(CMD_AIRPLANE_TOGGLED);
}if(mSettingsStore.isAirplaneModeOn()) {
Log.d(TAG,"resetting country code because Airplane mode is ON");
mWifiStateMachine.resetCountryCode();
}
}
},newIntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));
mContext.registerReceiver(newBroadcastReceiver() {
@Overridepublic voidonReceive(Context context, Intent intent) {
String state=intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);if(state.equals(IccCardConstants.INTENT_VALUE_ICC_ABSENT)) {
Log.d(TAG,"resetting country code because SIM is removed");
mWifiStateMachine.resetCountryCode();
}
}
},newIntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED));//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();
registerForPackageOrUserRemoval();
mInIdleMode=mPowerManager.isDeviceIdleMode();
mWifiController.start();//If we are already disabled (could be due to airplane mode), avoid changing persist//state here
if(wifiEnabled) setWifiEnabled(wifiEnabled);
mWifiWatchdogStateMachine=WifiWatchdogStateMachine.
makeWifiWatchdogStateMachine(mContext, mWifiStateMachine.getMessenger());
}