Android12 ethernet和wifi共存

简介: Android12 ethernet和wifi共存

1.修改网络优先走wifi

packages/modules/Connectivity/service/src/com/android/server/connectivity/NetworkRanker.java   
 
@@ -44,7 +44,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.function.Predicate;
-
+import android.util.Log;
 /**
  * A class that knows how to find the best network matching a request out of a list of networks.
  */
@@ -85,7 +85,7 @@ public class NetworkRanker {
     }
 
     // Transport preference order, if it comes down to that.
-    private static final int[] PREFERRED_TRANSPORTS_ORDER = { TRANSPORTETHERNET, TRANSPORTWIFI,
+    private static final int[] PREFERRED_TRANSPORTS_ORDER = { TRANSPORTWIFI,TRANSPORTETHERNET,
             TRANSPORTBLUETOOTH, TRANSPORTCELLULAR };
 
     // Function used to partition a list into two working areas depending on whether they

2.修改NETWORK_SCORE(这一步好像没什么用)

 
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -70,7 +70,9 @@ public class EthernetNetworkFactory extends NetworkFactory {
     private final static String TAG = EthernetNetworkFactory.class.getSimpleName();
     final static boolean DBG = true;
 
-    private final static int NETWORK_SCORE = 70;
+    private final static int NETWORK_SCORE = 30;
 
 
@@ -409,8 +412,10 @@ public class EthernetNetworkFactory extends NetworkFactory {
             sTransports.put(NetworkCapabilities.TRANSPORTWIFIAWARE,
                     new TransportInfo(ConnectivityManager.TYPE_NONE, 1));
             // EthernetNetworkFactory.NETWORK_SCORE
             sTransports.put(NetworkCapabilities.TRANSPORT_ETHERNET,
-                    new TransportInfo(ConnectivityManager.TYPE_ETHERNET, 70));
+                    new TransportInfo(ConnectivityManager.TYPE_ETHERNET, 30));
             // BluetoothTetheringNetworkFactory.NETWORK_SCORE
             sTransports.put(NetworkCapabilities.TRANSPORT_BLUETOOTH,
                     new TransportInfo(ConnectivityManager.TYPE_BLUETOOTH, 69));

3.修改阻止disable eth0

packages\modules\NetworkStack\common\moduleutils\src\android\net\ip\InterfaceController.java

 
--- a/common/moduleutils/src/android/net/ip/InterfaceController.java
+++ b/common/moduleutils/src/android/net/ip/InterfaceController.java
@@ -30,7 +30,7 @@ import android.system.OsConstants;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 
-
+import android.util.Log;
 /**
  * Encapsulates the multiple IP configuration operations performed on an interface.
  *
@@ -102,6 +102,11 @@ public class InterfaceController {
 
     private boolean setEnableIPv6(boolean enabled) {
         try {
+                       if(mIfName.equals("eth0")&& enabled == false)
+                       {
+                               Log.e("setEnableIPv6","eth0 skip disable +++");
+                               return false;
+                       }
             mNetd.interfaceSetEnableIPv6(mIfName, enabled);
         } catch (RemoteException | ServiceSpecificException e) {
             logError("%s IPv6 failed: %s", (enabled ? "enabling" : "disabling"), e);
@@ -197,6 +202,11 @@ public class InterfaceController {
      */
     public boolean clearAllAddresses() {
         try {
+                       if(mIfName.equals("eth0"))
+                       {
+                               Log.e("clearAllAddresses","eth0 skip clear +++");
+                               return false;
+                       }
             mNetd.interfaceClearAddrs(mIfName);
         } catch (Exception e) {
             logError("Failed to clear addresses: %s", e);

4.开机后在rc中自动添加一下路由表配置

路由表设置

ip ru add from all lookup main pref 9000


目录
相关文章
|
6月前
|
Android开发
Android 状态栏WiFi图标的显示逻辑
Android 状态栏WiFi图标的显示逻辑
153 0
|
6月前
|
Android开发
Android获取当前连接的wifi名称
Android获取当前连接的wifi名称
315 6
|
6月前
|
Android开发
android连接指定wifi
android连接指定wifi
101 0
|
6月前
|
Java Android开发
Android 9在连接以太网情况下 还能连接WiFi
Android 9在连接以太网情况下 还能连接WiFi
60 0
|
6月前
|
Java Shell Android开发
Android11 有线网和wifi优先级设置
Android11 有线网和wifi优先级设置
489 0
|
6月前
|
Java Android开发 开发者
rk3399 android以太网和wifi共存
rk3399 android以太网和wifi共存
193 0
|
6月前
|
缓存 Java Android开发
Android 9.0 WiFi 扫描结果上报和获取流程
Android 9.0 WiFi 扫描结果上报和获取流程
280 0
|
6月前
|
Android开发 网络架构
【Android App】检查手机连接WiFi信息以及扫描周围WiFi的讲解及实战(附源码和演示 超详细必看)
【Android App】检查手机连接WiFi信息以及扫描周围WiFi的讲解及实战(附源码和演示 超详细必看)
873 1
|
Android开发
Android获取已连接wifi的热点信息(上位机开发学习之多个界面切换编程)
Android获取已连接wifi的热点信息(上位机开发学习之多个界面切换编程)
247 0
|
物联网 Android开发
Android获取已连接wifi的热点信息
Android获取已连接wifi的热点信息
267 0