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

相关推荐
深圳市恒锐丰科技杨生9 分钟前
LTK118 2‑7V 单通道 H 桥直流有刷电机驱动芯片|集成 MOS 低压消费类驱动方案
嵌入式硬件·硬件工程
星河单片机17 分钟前
STM32读取电阻式土壤湿度模块+OLED显示完整教程
stm32·单片机·嵌入式硬件·土壤湿度
basketball61617 分钟前
AI Infra 推理部署技术总结:2. vLLM 内核——PagedAttention 与调度器原理
android·人工智能·vllm·ai infra
szxinmai主板定制专家1 小时前
基于 RK3576 的智能割草机器人解决方案,从样机到量产
人工智能·嵌入式硬件·计算机视觉·fpga开发·机器人·rk3588+fpga·割草机器人
I'mChloe1 小时前
群晖部署 image-matting:把人像去背景做成一个随开随用的 Web 工具
android·前端
千里马-horse1 小时前
第 61 章:设备策略与 Android 企业版
android·aosp
单片机仿真设计1 小时前
【proteus仿真】基于单片机的水肥一体化智能监控系统(仿真图+程序)
stm32·单片机·嵌入式硬件·proteus
2501_915106321 小时前
Flutter iOS混淆打包详细教程与步骤
android·flutter·ios·小程序·uni-app·iphone·webview
三少爷的鞋2 小时前
Android 架构演进:从生命周期事件到结构化任务
android
国科安芯2 小时前
基于抗辐射MCU的卫星分布式控制系统CANFD总线架构研究
网络·人工智能·分布式·单片机·嵌入式硬件·架构·抗辐射