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博客

相关推荐
建群新人小猿2 分钟前
陀螺匠企业助手-我的日程
android·大数据·运维·开发语言·容器
_李小白3 分钟前
【Android FrameWork】第三十九天:DeviceStorageManagerService
android
不急不躁1231 小时前
Android16 给应用默认获取权限
android·java
用户41659673693551 小时前
拒绝 Race Condition:深入理解 StateFlow 的取值与更新
android
青莲8432 小时前
Kotlin Flow 深度探索与实践指南——上部:基础与核心篇
android·前端
恋猫de小郭2 小时前
2025 年终醒悟,AI 让我误以为自己很强,未来程序员的转型之路
android·前端·flutter
2501_915918412 小时前
iOS 开发中证书创建与管理中的常见问题
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张3 小时前
IOScer 开发环境证书包括哪些,证书、描述文件与 App ID 的协同管理实践
android·ios·小程序·https·uni-app·iphone·webview
aningxiaoxixi4 小时前
android AV 之 SimpleC2Component
android
TAEHENGV4 小时前
导入导出模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库