android web认证失败,Android Wi-Fi 自动连接至需要网页认证AP失败

测试机打开Wi-Fi,连接至Test,关闭Wi-Fi再打开后不能自动重连至Test(其他open AP可以自动重连)

1 测试步骤

测试机打开Wi-Fi,连接至Test(为需要网页认证才能够使用的Wi-Fi)测试机在保持Test连接情况下,关闭Wi-Fi再打开

2 测试结果

步骤2中,测试机不能自动重连至Test

3 预期结果

步骤2中,测试机可以自动重连至Test

4 调查过程

4.1 NetworkMonitor.java::private class EvaluatingState extends State

......

int httpResponseCode = isCaptivePortal();

if (httpResponseCode == 204) {

transitionTo(mValidatedState);

} else if (httpResponseCode >= 200 && httpResponseCode <= 399) {

transitionTo(mCaptivePortalState);

}

......

4.2 NetworkMonitor.java::protected int isCaptivePortal()

......

validationLog("isCaptivePortal: ret=" + httpResponseCode +

" headers=" + urlConnection.getHeaderFields());

......

如上打印如下的log

11-28 19:22:06.682 3474 7290 D NetworkMonitor/NetworkAgentInfo [WIFI () - 101]: isCaptivePortal: ret=200 headers={null=[HTTP/1.1 200 OK], Content-Length=[488],Content-Type=[text/html], Location=[https://sprdwlc.spreadtrum.com/fs/customwebauth/login.html ? switch_url=https://sprdwlc.spreadtrum.com/login.html&ap_mac=64:f6:9d:66:3c:20&client_mac=40:45:da:c1:87:2c&wlan=Test&redirect=connectivitycheck.gstatic.com/generate_204], X-Android-Received-Millis=[1480332126681], X-Android-Response-Source=[NETWORK 200], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1480332126662]}

4.3 NetworkMonitor.java::private class CaptivePortalState extends State

......

public void enter() {

mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,

NETWORK_TEST_RESULT_INVALID, 0, mNetworkAgentInfo));

......

4.4 ConnectivityService.java::case NetworkMonitor.EVENT_NETWORK_TESTED:

......

final boolean valid =

(msg.arg1 == NetworkMonitor.NETWORK_TEST_RESULT_VALID);

......

// Let the NetworkAgent know the state of its network

nai.asyncChannel.sendMessage(

android.net.NetworkA从如下的log开始:gent.CMD_REPORT_NETWORK_STATUS,

(valid ? NetworkAgent.VALID_NETWORK : NetworkAgent.INVALID_NETWORK),

0, null);

......

4.5 WifiStateMachine.java::protected void networkStatus()

.....

mIsCaptivePortalCheckEnabled = Settings.Global.getInt(mContext.getContentResolver(),

Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 0) == 1;

if (status == NetworkAgent.INVALID_NETWORK) {

if (DBG) log("WifiNetworkAgent -> Wifi networkStatus invalid, score="

+ Integer.toString(mWifiInfo.score));

unwantedNetwork(NETWORK_STATUS_UNWANTED_VALIDATION_FAILED);

}

.....

4.6 WifiStateMachine.java:void unwantedNetwork()

......

sendMessage(CMD_UNWANTED_NETWORK, reason);

......

4.7 WifiStateMachine.java::case CMD_UNWANTED_NETWORK:

......

} else if (message.arg1 == NETWORK_STATUS_UNWANTED_DISABLE_AUTOJOIN ||

message.arg1 == NETWORK_STATUS_UNWANTED_VALIDATION_FAILED) {

config = getCurrentWifiConfiguration();

if (config != null) {

// Disable autojoin

if (message.arg1 == NETWORK_STATUS_UNWANTED_DISABLE_AUTOJOIN) {

config.validatedInternetAccess = false;

// Clear last-selected status, as being last-selected also avoids

// disabling auto-join.

if (mWifiConfigStore.isLastSelectedConfiguration(config)) {

mWifiConfigStore.setLastSelectedConfiguration(

WifiConfiguration.INVALID_NETWORK_ID);

}

}

config.numNoInternetAccessReports += 1;

config.dirty = true;

mWifiConfigStore.writeKnownNetworkHistory(false);

}

}

.....

4.8 WifiAutoJoinController.java ::boolean attemptAutoJoin()

最终在AutoConnet的时候在如下的地方被退出.没有进行AutoConnect.

// NOTE: If this condition is updated, update NETWORK_STATUS_UNWANTED_DISABLE_AUTOJOIN.

if (config.numNoInternetAccessReports > 0

&& !isLastSelected

&& !config.validatedInternetAccess) {

// Avoid autoJoining this network because last time we used it, it didn't

// have internet access, and we never manage to validate internet access on this

// network configuration

if (DBG) {

logDbg("attemptAutoJoin skip candidate due to no InternetAccess "

+ config.configKey(true)

+ " num reports " + config.numNoInternetAccessReports);

}

continue;

}

如上打印出如下的log:11-28 19:22:28.378 3474 5227 D WifiAutoJoinController : attemptAutoJoin() num recent config 1 ---> suppNetId=-1

11-28 19:22:28.378 3474 5227 D WifiAutoJoinController : attemptAutoJoin good candidate seen, bumped hard -> status="Test"NONE status=0

11-28 19:22:28.378 3474 5227 D WifiAutoJoinController : attemptAutoJoin skip candidate due to no InternetAccess "Test"NONE num reports 1

11-28 19:22:28.378 3474 5227 D WifiAutoJoinController : attemptRoam not associated

5 解决方案

如果需要关闭网络可用性检测.请修改"captive_portal_detection_enabled"的默认值为0.

NetworkMonitor.java :: public NetworkMonitor()

mIsCaptivePortalCheckEnabled = Settings.Global.getInt(mContext.getContentResolver(),

Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED, 0) == 1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值