android NetworkMonitor和ConnectivityService记录

一、NetworkMonitor

packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java

网络上都叫网络可用性校验,在WIFI和数据(以太网切换中使用)

有多个状态机

方法:isCaptivePortal

11-03 12:01:17.885  2535  4681 D NetworkMonitor/100: isCaptivePortal: isSuccessful()=false isPortal()=false RedirectUrl=null isPartialConnectivity()=false Time=23029ms

类 EvaluationState下的reportEvaluationResult

----------------------------------------------------------------------------------------------------------------------

父类下的notifyNetworkTested,会将校验结果发送给ConnectivityService

private final INetworkMonitorCallbacks mCallback;
private void notifyNetworkTested(NetworkTestResultParcelable result) {
    mCallback.notifyNetworkTestedWithExtras(result);
}

ConnectivityService.java里有个子类NetworkMonitorCallbacks 重写了notifyNetworkTestedWithExtras

NetworkMonitorCallbacks是在registerNetworkAgent里注册的

mDeps.getNetworkStack().makeNetworkMonitor(
		nai.network, name, new NetworkMonitorCallbacks(nai));

-----------------------------------------------------------------------------------------------------------------------

二、NetworkMonitor与ConnectivityService的回调

class EvaluationState 应该是上报数据给ConnectivityService的 

reportEvaluationResult

        notifyNetworkTested

                mCallback.notifyNetworkTestedWithExtras

isCaptivePortal

        else if (mUseHttps && httpsUrls.length == 1 && httpUrls.length == 1)

        sendHttpAndHttpsParallelWithFallbackProbes

                reportHttpProbeResult(NETWORK_VALIDATION_PROBE_FALLBACK) (16)

                reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTPS) (32)

packages/modules/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java

sendDnsProbe

        sendDnsProbeWithTimeout    //这个是阻塞执行

                DnsUtils.getAllByName

11-28 10:57:11.770  2414  4178 D NetworkMonitor/100: PROBE_DNS connectivitycheck.gstatic.com 12508ms FAIL in type ADDRCONFIG Timeout

这个日志一直没找到在哪儿打印,后来发现是在这儿

    protected InetAddress[] sendDnsProbeWithTimeout(String host, int timeoutMs)
                throws UnknownHostException {
        return DnsUtils.getAllByName(mDependencies.getDnsResolver(), mCleartextDnsNetwork, host,
                TYPE_ADDRCONFIG, FLAG_EMPTY, timeoutMs,
                str -> validationLog(ValidationProbeEvent.PROBE_DNS, host, str));
    }

    private void validationLog(int probeType, Object url, String msg) {
        String probeName = ValidationProbeEvent.getProbeName(probeType);
        //自己加的日志    
        Log.i(TAG, "validationLog, probeName = " + probeName + " url = " + url.toString());
        validationLog(String.format("%s %s %s", probeName, url, msg));
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值