当前位置: 首页 > news >正文

Android13 以太网(YT8531)

一、基本调试

按照正常驱动调试基本流程移植驱动后(移植过程可查看前面linux调试以太网部分),启动网卡出现以下错误

Error: Could not connect to phy ethernet-phy

GMAC无法扫描到PHY设备,一般怀疑为硬件问题。

解决办法

  • 供电:PHY一般无需单独的供电,GMAC的PIN BANK在某些平台上需要单独供电,检查PIN的供电是否正常

  • 时钟:主要检查PHY的25M时钟,如果是外部晶振,用示波器量晶振频率是否在25Mhz左右,每款PHY对晶振的精确度要求不一致(PHY的datasheet上会有相关说明);如果是内部SOC25M时钟供电,查看SOC25M对应的是哪个PIN,用示波器量下PIN输出的时钟频率是否在25M左右

  • PHY-RST:确保对PHY在进行MDIO读写操作时需要10ms左右rst拉低以及150ms左右rst拉高操作(每款PHY的要求不一致,此处为典型值)

具体原因:使用外部晶振,25M时钟未焊接导致

修改phy地址

重新测试后正常:

正确识别ID:

联网测试:(需判断速率是否达标)

  1. 判断以太网网线插拔状态,1 为插上,0 为拔掉。

cat /sys/class/net/eth0/carrier

二、双网卡使用(双YT8531)

Android_双网口时无法关闭以太网功能

1、从 logcat 中看,点击 Settings 以太网开关,都只是对 eth0 进行了操作。

EthernetServiceImpl: enableInterface called with: iface=eth0 
EthernetServiceImpl: disableInterface called with: iface=eth0

eth1 无法被关闭,当然也就会导致以太网功能始终是可以被使用的状态。

控制网口的开关,是 Settings 负责的,如果 Settings 不去关闭 eth1,那么 eth1 肯定就无法被关闭。

解决办法:在Settings 部分增加了对多网口处理判断的逻辑

路径:packages/apps/Settings/src/com/android/settings/ethernet

(1)EthernetSettings.java

diff --git a/src/com/android/settings/ethernet/EthernetSettings.java b/src/com/android/settings/ethernet/EthernetSettings.java
index 90c757146bd..15e7b9800a4 100644
--- a/src/com/android/settings/ethernet/EthernetSettings.java
+++ b/src/com/android/settings/ethernet/EthernetSettings.java
@@ -43,7 +43,6 @@ public class EthernetSettings extends DashboardFragment implementsprivate static final String KEY_TOGGLE_ETHERNET = "main_toggle_ethernet";public static final String SHARED_PREFERENCES_NAME = "ethernet_prefs";public static final String ETHERNET_SETTINGS_CONFIG = "ethernet_settings_config";
-    public static final String ETHERNET_IFACE = "eth0";private static EthernetSwitchPreferenceController mEthernetUIController = null;

(2)EthernetSettingsManager.java

通过动态获取以太网接口列表,取代了原先 eth0 接口名称的方式

diff --git a/src/com/android/settings/ethernet/EthernetSettingsManager.java b/src/com/android/settings/ethernet/EthernetSettingsManager.java
index 55fb790a94c..fa8a65d3827 100644
--- a/src/com/android/settings/ethernet/EthernetSettingsManager.java
+++ b/src/com/android/settings/ethernet/EthernetSettingsManager.java
@@ -16,8 +16,6 @@package com.android.settings.ethernet;-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
-import android.content.Context;import android.net.ConnectivityManager;import android.net.EthernetManager;
@@ -39,6 +37,7 @@ import java.net.Inet4Address;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.ArrayList;
+import java.util.List;public class EthernetSettingsManager {private final static String TAG = "EthernetSettingsManager";
@@ -103,7 +102,15 @@ public class EthernetSettingsManager {final EthernetNetworkUpdateRequest request = new EthernetNetworkUpdateRequest.Builder().setIpConfiguration(mIpConfiguration).build();
-        mEthManager.updateConfiguration(ETHERNET_IFACE, request, r -> r.run(), null);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (!interfaces.isEmpty()) {
+            // When there are two interfaces, only the interface configuration of the first access device will be modified
+            Log.d(TAG, "update Ethernet Configuration : " + interfaces.get(0));
+            mEthManager.updateConfiguration(interfaces.get(0), request, r -> r.run(), null);
+        } else {
+            Log.w(TAG, "Ethernet Interfaces is null");
+        }}public Network getFirstNetwork() {

(3)EthernetSwitchPreferenceController.java

  1. 通过 NetworkInfo.State 更灵活地处理网络状态,替代了 ETHERNET_IFACE 的硬编码。

  2. 新增了 getDefaultNetwork()方法,通过 NetworkInfo 检查当前活跃的以太网网络。

  3. tryEthNode()替换为 haveEthernetInterface() 方法,直接使用以太网管理器来查询接口。

  4. 可以处理所有以太网接口的状态,而不仅仅是一个。

diff --git a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
index d39d0e70b45..dac9efb1235 100644
--- a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
+++ b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
@@ -17,7 +17,7 @@package com.android.settings.ethernet;import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
+import static android.net.NetworkInfo.State;import android.app.Activity;import android.content.Context;
@@ -28,6 +28,7 @@ import android.net.EthernetNetworkUpdateRequest;import android.net.IpConfiguration;import android.net.Network;import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;import android.net.NetworkRequest;import android.net.wifi.WifiManager;import android.util.Log;
@@ -46,6 +47,7 @@ import com.android.settings.R;import com.android.settingslib.core.AbstractPreferenceController;import java.io.IOException;
+import java.util.List;/*** This controller helps to manage the state of wifi switch preference.*/
@@ -100,13 +102,32 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceContro@Overridepublic void onLost(@NonNull Network network) {
-                updatePreferenceStatus(false);
-                Log.w(TAG, "onLost setChecked");
+                if (getDefaultNetwork() == null) {
+                    Log.d(TAG, "There is no Ethernet interface, setChecked false");
+                    updatePreferenceStatus(false);
+                }}};Log.w(TAG, "initNetworkCallback");}+    private Network getDefaultNetwork() {
+        final Network[] networks = mConnectivityManager.getAllNetworks();
+        for (final Network network : networks) {
+            NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
+            Log.w(TAG, "getDefaultNetwork, networkInfo:" + networkInfo);
+            if (networkInfo != null
+                    && (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
+                Log.w(TAG, "getDefaultNetwork, type is ethernet:" + network);
+                if (networkInfo.getState() == State.DISCONNECTED) {
+                    continue;
+                }
+                return network;
+            }
+        }
+        return null;
+    }
+private void updatePreferenceStatus(boolean isChecked) {if (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();
@@ -144,8 +165,7 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControLog.w(TAG, "mPreference is null: " + (mPreference == null));boolean checked = mPrefs.getBoolean(KEY, false);Log.w(TAG, "mPreference is checked: " + checked);
-        updatePreferenceStatus(tryEthNode() && checked && mIsCheckEthernet);
-//        showEthernetSettings(checked);
+        updatePreferenceStatus(haveEthernetInterface() && checked && mIsCheckEthernet);}private void showEthernetSettings(boolean show) {
@@ -162,24 +182,21 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControreturn true;}-    // TODO: We need to change to no longer use nodes here
-    private boolean tryEthNode() {
-        try {
-            Process p = Runtime.getRuntime().exec("ls sys/class/net/eth0");
-            int tmp = p.waitFor();
-            Log.w(TAG, "tryEthNode tmp: " + tmp);
-            return tmp == 0;
-        } catch (IOException | InterruptedException e) {
-            Log.w(TAG, "access /proc/net/dev failed!");
+    private boolean haveEthernetInterface() {
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (interfaces.isEmpty()) {
+            return false;
+        } else {
+            Log.v(TAG, "Ethernet Interfaces = " + interfaces);
+            return true;}
-        return false;}@Overridepublic boolean onPreferenceChange(Preference preference, Object newValue) {boolean isChecked = (Boolean) newValue;Log.w(TAG, "onPreferenceChange: " + isChecked);
-        if (!tryEthNode()) {
+        if (!haveEthernetInterface()) {Toast.makeText(mContext, mContext.getString(R.string.not_support_eth), Toast.LENGTH_LONG).show();return false;}
@@ -188,7 +205,11 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControif (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();}
-        setIfaceState(ETHERNET_IFACE, isChecked);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        for (int i = 0; i < interfaces.size(); i++) {
+            setIfaceState(interfaces.get(i), isChecked);
+        }return true;}

完整补丁:

diff --git a/src/com/android/settings/ethernet/EthernetSettings.java b/src/com/android/settings/ethernet/EthernetSettings.java
index 90c757146bd..15e7b9800a4 100644
--- a/src/com/android/settings/ethernet/EthernetSettings.java
+++ b/src/com/android/settings/ethernet/EthernetSettings.java
@@ -43,7 +43,6 @@ public class EthernetSettings extends DashboardFragment implementsprivate static final String KEY_TOGGLE_ETHERNET = "main_toggle_ethernet";public static final String SHARED_PREFERENCES_NAME = "ethernet_prefs";public static final String ETHERNET_SETTINGS_CONFIG = "ethernet_settings_config";
-    public static final String ETHERNET_IFACE = "eth0";private static EthernetSwitchPreferenceController mEthernetUIController = null;@Override
diff --git a/src/com/android/settings/ethernet/EthernetSettingsManager.java b/src/com/android/settings/ethernet/EthernetSettingsManager.java
index 55fb790a94c..fa8a65d3827 100644
--- a/src/com/android/settings/ethernet/EthernetSettingsManager.java
+++ b/src/com/android/settings/ethernet/EthernetSettingsManager.java
@@ -16,8 +16,6 @@package com.android.settings.ethernet;-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
-import android.content.Context;import android.net.ConnectivityManager;import android.net.EthernetManager;
@@ -39,6 +37,7 @@ import java.net.Inet4Address;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.ArrayList;
+import java.util.List;public class EthernetSettingsManager {private final static String TAG = "EthernetSettingsManager";
@@ -103,7 +102,15 @@ public class EthernetSettingsManager {final EthernetNetworkUpdateRequest request = new EthernetNetworkUpdateRequest.Builder().setIpConfiguration(mIpConfiguration).build();
-        mEthManager.updateConfiguration(ETHERNET_IFACE, request, r -> r.run(), null);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (!interfaces.isEmpty()) {
+            // When there are two interfaces, only the interface configuration of the first access device will be modified
+            Log.d(TAG, "update Ethernet Configuration : " + interfaces.get(0));
+            mEthManager.updateConfiguration(interfaces.get(0), request, r -> r.run(), null);
+        } else {
+            Log.w(TAG, "Ethernet Interfaces is null");
+        }}public Network getFirstNetwork() {
diff --git a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
index d39d0e70b45..dac9efb1235 100644
--- a/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
+++ b/src/com/android/settings/ethernet/EthernetSwitchPreferenceController.java
@@ -17,7 +17,7 @@package com.android.settings.ethernet;import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
-import static com.android.settings.ethernet.EthernetSettings.ETHERNET_IFACE;
+import static android.net.NetworkInfo.State;import android.app.Activity;import android.content.Context;
@@ -28,6 +28,7 @@ import android.net.EthernetNetworkUpdateRequest;import android.net.IpConfiguration;import android.net.Network;import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;import android.net.NetworkRequest;import android.net.wifi.WifiManager;import android.util.Log;
@@ -46,6 +47,7 @@ import com.android.settings.R;import com.android.settingslib.core.AbstractPreferenceController;import java.io.IOException;
+import java.util.List;/*** This controller helps to manage the state of wifi switch preference.*/
@@ -100,13 +102,32 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceContro@Overridepublic void onLost(@NonNull Network network) {
-                updatePreferenceStatus(false);
-                Log.w(TAG, "onLost setChecked");
+                if (getDefaultNetwork() == null) {
+                    Log.d(TAG, "There is no Ethernet interface, setChecked false");
+                    updatePreferenceStatus(false);
+                }}};Log.w(TAG, "initNetworkCallback");}+    private Network getDefaultNetwork() {
+        final Network[] networks = mConnectivityManager.getAllNetworks();
+        for (final Network network : networks) {
+            NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
+            Log.w(TAG, "getDefaultNetwork, networkInfo:" + networkInfo);
+            if (networkInfo != null
+                    && (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
+                Log.w(TAG, "getDefaultNetwork, type is ethernet:" + network);
+                if (networkInfo.getState() == State.DISCONNECTED) {
+                    continue;
+                }
+                return network;
+            }
+        }
+        return null;
+    }
+private void updatePreferenceStatus(boolean isChecked) {if (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();
@@ -144,8 +165,7 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControLog.w(TAG, "mPreference is null: " + (mPreference == null));boolean checked = mPrefs.getBoolean(KEY, false);Log.w(TAG, "mPreference is checked: " + checked);
-        updatePreferenceStatus(tryEthNode() && checked && mIsCheckEthernet);
-//        showEthernetSettings(checked);
+        updatePreferenceStatus(haveEthernetInterface() && checked && mIsCheckEthernet);}private void showEthernetSettings(boolean show) {
@@ -162,24 +182,21 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControreturn true;}-    // TODO: We need to change to no longer use nodes here
-    private boolean tryEthNode() {
-        try {
-            Process p = Runtime.getRuntime().exec("ls sys/class/net/eth0");
-            int tmp = p.waitFor();
-            Log.w(TAG, "tryEthNode tmp: " + tmp);
-            return tmp == 0;
-        } catch (IOException | InterruptedException e) {
-            Log.w(TAG, "access /proc/net/dev failed!");
+    private boolean haveEthernetInterface() {
+        List<String> interfaces = mEthManager.getInterfaceList();
+        if (interfaces.isEmpty()) {
+            return false;
+        } else {
+            Log.v(TAG, "Ethernet Interfaces = " + interfaces);
+            return true;}
-        return false;}@Overridepublic boolean onPreferenceChange(Preference preference, Object newValue) {boolean isChecked = (Boolean) newValue;Log.w(TAG, "onPreferenceChange: " + isChecked);
-        if (!tryEthNode()) {
+        if (!haveEthernetInterface()) {Toast.makeText(mContext, mContext.getString(R.string.not_support_eth), Toast.LENGTH_LONG).show();return false;}
@@ -188,7 +205,11 @@ public class EthernetSwitchPreferenceController extends AbstractPreferenceControif (mPrefs != null) {mPrefs.edit().putBoolean(KEY, isChecked).apply();}
-        setIfaceState(ETHERNET_IFACE, isChecked);
+
+        List<String> interfaces = mEthManager.getInterfaceList();
+        for (int i = 0; i < interfaces.size(); i++) {
+            setIfaceState(interfaces.get(i), isChecked);
+        }return true;}

相关文章:

  • MetaERP:开启企业数字化管理新时代
  • 2025年渗透测试面试题总结-各厂商二面试题01(题目+回答)
  • 智能呼叫中心系统的功能
  • 设计模式-面试题
  • 用Caffeine和自定义注解+AOP优雅实现本地防抖接口限流
  • 基于RT-Thread的STM32F4开发第五讲——软件模拟I2C
  • spring boot 注解 @bean
  • 解决 uv run 时 ModuleNotFoundError: No module named ‘anthropic‘ 的完整指南
  • HTTPS、SSL证书是啥?网站“安全小锁”的入门科普
  • megatron——EP并行
  • 【idea 报错:java: 非法字符: ‘\ufeff‘】
  • Node.js 实战八:服务部署方案对比与实践
  • [IMX] 05.串口 - UART
  • 数据可视化热图工具:Python实现CSV/XLS导入与EXE打包
  • Python在自动驾驶数据清洗中的应用
  • 路由器实战操作
  • Vue百日学习计划Day36-42天详细计划-Gemini版
  • mysql的安装方式
  • Lambda大数据架构
  • Linux基础开发工具三(git,gdb/cgdb)
  • 再囤三个月库存!美国客户抢付尾款,外贸企业发货订单排到7月
  • 证监会副主席李明:支持符合条件的外资机构申请新业务、设立新产品
  • 发射后失联,印度地球观测卫星发射任务宣告失败
  • 网文书单|推荐4本网文,可以当作《绍宋》代餐
  • 嫩黑线货物列车脱轨致1名路外人员死亡,3人被采取刑事强制措施
  • 小雨伞保险经纪母公司手回集团通过港交所聆讯