android wifi 初始化失败,android P wifi模块分析之wifi初始化

/**

* Check if we are ready to start wifi.

*

* First check if we will be restarting system services to decrypt the device. If the device is

* not encrypted, check if Wi-Fi needs to be enabled and start if needed

*

* This function is used only at boot time.

*/

public void checkAndStartWifi(){

// First check if we will end up restarting WifiService

if (mFrameworkFacade.inStorageManagerCryptKeeperBounce()) {

Log.d(TAG, "Device still encrypted. Need to restart SystemServer. Do not start wifi.");

return;

}

// 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(

new BroadcastReceiver() {

public void onReceive(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");

mCountryCode.airplaneModeEnabled();

}

}

},

new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));

mContext.registerReceiver(

new BroadcastReceiver() {

public void onReceive(Context context, Intent intent){

String state = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);

if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(state)) {

Log.d(TAG, "resetting networks because SIM was removed");

mWifiStateMachine.resetSimAuthNetworks(false);

} else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(state)) {

Log.d(TAG, "resetting networks because SIM was loaded");

mWifiStateMachine.resetSimAuthNetworks(true);

}

}

},

new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED));

mContext.registerReceiver(

new BroadcastReceiver() {

public void onReceive(Context context, Intent intent){

final int currState = intent.getIntExtra(EXTRA_WIFI_AP_STATE,

WIFI_AP_STATE_DISABLED);

final int prevState = intent.getIntExtra(EXTRA_PREVIOUS_WIFI_AP_STATE,

WIFI_AP_STATE_DISABLED);

final int errorCode = intent.getIntExtra(EXTRA_WIFI_AP_FAILURE_REASON,

HOTSPOT_NO_ERROR);

final String ifaceName =

intent.getStringExtra(EXTRA_WIFI_AP_INTERFACE_NAME);

final int mode = intent.getIntExtra(EXTRA_WIFI_AP_MODE,

WifiManager.IFACE_IP_MODE_UNSPECIFIED);

handleWifiApStateChange(currState, prevState, errorCode, ifaceName, mode);

}

},

new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION));

// 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();

mInIdleMode = mPowerManager.isDeviceIdleMode();

if (!mWifiStateMachine.syncInitialize(mWifiStateMachineChannel)) {

Log.wtf(TAG, "Failed to initialize WifiStateMachine");

}

mWifiController.start();

// If we are already disabled (could be due to airplane mode), avoid changing persist

// state here

if (wifiEnabled) {

try {

setWifiEnabled(mContext.getPackageName(), wifiEnabled);

} catch (RemoteException e) {

/* ignore - local call */

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值