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

相关推荐
LcGero21 小时前
Cocos Creator 业务与原生通信详解
android·ios·cocos creator·游戏开发·jsb
fundoit21 小时前
MySQL插入数据遇到唯一键已存在怎么办?
android·数据库·mysql
ameyume21 小时前
基于原生Android 16设置音量调用流程
android·audio
ii_best21 小时前
lua语言开发脚本基础、mql命令库开发、安卓/ios基础开发教程,按键精灵新手工具
android·ios·自动化·编辑器
BoomHe2 天前
Android AOSP13 原生 Launcher3 壁纸获取方式
android
Digitally2 天前
如何将联系人从 Android 转移到 Android
android
李小枫2 天前
webflux接收application/x-www-form-urlencoded参数
android·java·开发语言
爱丽_2 天前
MySQL `EXPLAIN`:看懂执行计划、判断索引是否生效与排错套路
android·数据库·mysql
NPE~2 天前
[App逆向]环境搭建下篇 — — 逆向源码+hook实战
android·javascript·python·教程·逆向·hook·逆向分析
yewq-cn2 天前
AOSP 下载
android