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

相关推荐
txh05076 小时前
如何使用示波器
嵌入式硬件·硬件工程
我命由我123457 小时前
Android 开发 - 广播组件(标准广播、有序广播、静态注册广播、分钟到达广播、网络变更广播...)
android·java·开发语言·网络·java-ee·android studio·android-studio
A富得流油的咸鸭蛋7 小时前
安卓鸿蒙面试
android·面试·harmonyos
LCG元8 小时前
STM32 多总线传感器采集系统:I2C + SPI + ADC + UART 协同实战(FreeRTOS 调度)
stm32·单片机·嵌入式硬件
Coffeeee8 小时前
AGP9.0的主要变更项,给Gradle来一次大变样
android·前端·gradle
hongmai6668888 小时前
ESP32-C5-WROOM-1-N16R8:双频Wi-Fi 6与多协议融合,重新定义物联网连接新标准
笔记·嵌入式硬件·物联网·智能路由器·risc-v
小孔龙8 小时前
Android GPU 渲染管线:一帧画面如何走上屏幕
android·性能优化·gpu
米码收割机8 小时前
【Android】Android 书澜图书馆信息管理系统(源码+文档)【独一无二】
android
恋猫de小郭8 小时前
KotlinLLM 开源 ,一个可以在运行时自己生成永久 Kotlin 代码的 Agent 库
android·前端·人工智能
m0_547486668 小时前
《Arm Cortex-M4嵌入式系统-STM32G4系列微控制器的原理架构与开发》全套PPT课件
arm开发·stm32·嵌入式硬件