Android11 有线网和WiFi同时使用

Android11 实现有线网络和wifi共存_android 以太网和wifi共存-CSDN博客

        可以查看上面文章中的方法,去掉了网络释放。按照上面文章中所列出来的代码设置后,只有先开启WiFi然后再接有线网时是有效的,如果先接有线网再连接WiFi则WiFi无法打开,原因是因为默认有线网的优先级是高于WiFi的,所以打开有线网后,再打开WiFi时不会执行。其实在上面的文章中方法2里面已经给出了方法,让方法2中的第一步强制返回true,就可以了。

再把代码记录一下:

        1)、frameworks/libs/net/common/src_servicescommon/android/net/NetworkFactory.java 中注释掉释放网络:releaseNetworkFor,shouldNeedNetworkFor强制返回true;


private void evalRequest(NetworkRequestInfo n) {
        if (VDBG) {
            log("evalRequest");
            log(" n.requests = " + n.requested);
            log(" n.score = " + n.score);
            log(" mScore = " + mScore);
            log(" request.providerId = " + n.providerId);
            log(" mProvider.id = " + mProvider.getProviderId());
        }
        if (shouldNeedNetworkFor(n)) {
            if (VDBG) log("  needNetworkFor");
            needNetworkFor(n.request, n.score);
            n.requested = true;
        } else if (shouldReleaseNetworkFor(n)) {
            if (VDBG) log("  releaseNetworkFor");
            
            //releaseNetworkFor(n.request);
            //n.requested = false;
        } else {
            if (VDBG) log("  done");
        }
    }

private boolean shouldNeedNetworkFor(NetworkRequestInfo n) {
        
        return true;
       // // If this request is already tracked, it doesn't qualify for need
       // return !n.requested
       //     // If the score of this request is higher or equal to that of this factory and some
       //     // other factory is responsible for it, then this factory should not track the request
       //     // because it has no hope of satisfying it.
       //     && (n.score < mScore || n.providerId == mProvider.getProviderId())
       //     // If this factory can't satisfy the capability needs of this request, then it
       //     // should not be tracked.
       //     && n.request.canBeSatisfiedBy(mCapabilityFilter)
       //     // Finally if the concrete implementation of the factory rejects the request, then
       //     // don't track it.
       //     && acceptRequest(n.request, n.score);
    }


     2)、frameworks/base/services/core/java/com/android/server/ConnectivityService.java中注释掉nai.asyncChannel.disconnect(),有两处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值