android上ethernet和wifi共存

Android12配置WiFi网络优先以实现与Ethernet共存-开发者社区-阿里云

  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. 禁止down eth0的ip地址

    --- 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);

【android 12】【网络】wifi与以太网共存操作_android 以太网和wifi共存-CSDN博客

Android WiFi和Ethernet共存_android 以太网和wifi共存-CSDN博客

相关推荐
fengci.1 小时前
BUUCTF(困难部分)
android·开发语言·前端·学习·php
传奇开心果3 小时前
【Compose Multiplatform跨端声明式UI实用技术】第9课:跨平台 ViewModel 与状态架构
android·kotlin
用户69371750013843 小时前
当你向领导申请 AI 编程工具预算时,如果领导追问“能提效多少,有量化数据吗”,你该怎么回答?
android·后端·ios
hunterandroid4 小时前
WorkManager 后台任务调度实战:从一次性任务到周期执行
android
事圆则缓4 小时前
Android 屏幕适配的前世今生
android
andyweike5 小时前
kotlin dsl library工程怎么配置
android·开发语言·kotlin
啵啵啵鱼5 小时前
九、JDBC 操作 MySQL 数据库
android·数据库·mysql
用户69371750013845 小时前
当我说 Claude 搭配 GLM-5.3-Flash 太好用了,同事却提醒我:你可能正在失去对代码的掌控
android·后端·ios
张小姐的猫5 小时前
【MySQL】数据类型
android·linux·数据库·c++·mysql·adb·php
2501_916008895 小时前
马甲包过审卡在哪?Ipa Guard 能做的和做不到的
android·小程序·https·uni-app·iphone·webview