需求
系统起来之后,如果有线(ETH)插入和WIFI 打开的情况下,优先使用哪种连接方式。
实现
NetworkAgentInfo 中getCurrentScore 函数直接返回最大的Score 即可。
有线优先
frameworks/base/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java private int getCurrentScore(boolean pretendValidated) { + //Begin add for ETH higher priority + if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) { + return ConnectivityConstants.EXPLICITLY_SELECTED_NETWORK_SCORE; + } + //End add for ETH higher priority }
无线优先
frameworks/base/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java private int getCurrentScore(boolean pretendValidated) { + //Begin add for ETH higher priority + if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + return MAXIMUM_NETWORK_SCORE; + } + //End add for ETH higher priority }
参考:
framework中的连接管理机制
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)