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(),有两处。