之前一直想着把后续写下的,事情太多给搞忘了,这几天有几个人加我 QQ 问我有没解决,我才想起来
以下是我这边经过修改可以达到预期效果的方法,仅供参考! 思路是:先保证系统多个网卡能同时获取到 IP ,然后设置路由表分配什么流量走什么网卡
=============================================
当以太网连接后 Wi-Fi 仍可连
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java
private void setScanResults() {
...
if (getCurrentState() == mRoamingState
|| getCurrentState() == mObtainingIpState
|| getCurrentState() == mScanModeState
|| getCurrentState() == mDisconnectingState
|| (getCurrentState() == mConnectedState
&& !mWifiConfigStore.enableAutoJoinWhenAssociated)
|| linkDebouncing
|| state == SupplicantState.ASSOCIATING
|| state == SupplicantState.AUTHENTICATING
|| state == SupplicantState.FOUR_WAY_HANDSHAKE
|| state == SupplicantState.GROUP_HANDSHAKE
|| (/* keep autojoin enabled if user has manually selected a wifi network,
so as to make sure we reliably remain connected to this network */
mConnectionRequests == 0 && selection == null)) {
// Dont attempt auto-joining again while we are already attempting to join
// and/or obtaining Ip address
attemptAutoJoin = false;
}
//add by a_bin for blzn network
if(SystemProperties.getBoolean("ro.zwqx.blzn_network",false)){
attemptAutoJoin = true;
}
...
}
连接高优先级的网络,低优先级的不断开
frameworks/base/services/core/java/com/android/server/ConnectivityService.java
private void teardownUnneededNetwork(NetworkAgentInfo nai) {
//add by a_bin for blzn network
if(SystemProperties.getBoolean("ro.zwqx.blzn_network",false)){
return;
}
}
最后就是路由表的设置了,这里需要 root 权限
frameworks/base/services/core/java/com/android/server/ConnectivityService.java
private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties oldLp){
...
if(networkAgent.linkProperties.getInterfaceName().equals("wlan0")){
java.lang.Process pro = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(pro.getOutputStream());
outputStream.writeBytes("ip route flush table 3\n");
outputStream.writeBytes("ip route add dev wlan0 table 3\n");
outputStream.writeBytes("ip rule add to 10.1.0.0/16 table 3\n");
outputStream.writeBytes("ip route flush cache\n");
outputStream.writeBytes("exit\n");
outputStream.flush();
outputStream.close();
pro.waitFor();
}else if(networkAgent.linkProperties.getInterfaceName().equals("eth0")){
java.lang.Process pro = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(pro.getOutputStream());
outputStream.writeBytes("ip route flush table 1\n");
outputStream.writeBytes("ip route add dev eth0 table 1\n");
outputStream.writeBytes("ip rule add to 192.168.0.0/16 table 1\n");
outputStream.writeBytes("ip route flush cache\n");
outputStream.writeBytes("exit\n");
outputStream.flush();
outputStream.close();
pro.waitFor(); ok::updateLinkProperties()");
}
...
}
1
csrbot 2017-05-28 17:42:45 +08:00
非常感谢楼主的分享。
但是我路由配置那里需要将 16 该成 24 才能 ping 通。 |
2
csrbot 2017-07-15 14:46:33 +08:00
楼主,android5.1 里面如何修改这个 wifi 和以太网的优先级,我想把 wifi 的优先级高于以太网,但是没有成功。
|