[RK3399/RK3328][Android10.0]Ethernet:以太网设置静态ip,重启后无法获取IP的问题

测试平台

Platform: RK3399/RK3328
OS: Android 10.0

现象

设置中设置以太网为静态ip,设置后使用ifconfig查看ip显示正常。然后重启,极大概率出现开机后设备没有获取到ip.

分析解决

测试后发现了几点规律:

  1. 设置静态ip会开机获取不到ip,但是设置动态ip无问题
  2. 没有获取到ip时,使用ifconfig查看,发现网卡设备连接正常。此时拔插网线,或者使用ifconfig eth0 down + ifconfig eth0 up 来开关一次设备后,就能正常获取到ip

根据测试结果采取了如下的解决方案,在开机的时候在Ethernet服务中进行一次ifconfig eth0 down + ifconfig eth0 up的操作来解决.

修改补丁如下,测试20次后无问题,提交给到客户

diff --git a/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java b/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java
index 308e328..919edc6 100644
--- a/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java
+++ b/frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java
@@ -252,12 +254,41 @@ final class EthernetTracker {
         }
     }
 
-    private void maybeTrackInterface(String iface) {
+    private boolean maybeTrackInterface(String iface) {
         if (DBG) Log.i(TAG, "maybeTrackInterface " + iface);
         // If we don't already track this interface, and if this interface matches
         // our regex, start tracking it.
         if (!iface.matches(mIfaceMatch) || mFactory.hasInterface(iface)) {
-            return;
+            return false;
         }
 
         if (mIpConfigForDefaultInterface != null) {
@@ -266,13 +297,31 @@ final class EthernetTracker {
         }
 
         addInterface(iface);
+        return true;
     }
 
     private void trackAvailableInterfaces() {
         try {
             final String[] ifaces = mNMService.listInterfaces();
             for (String iface : ifaces) {
-                maybeTrackInterface(iface);
+               if (maybeTrackInterface(iface)) {
+                    String mIfaceTmp = iface;
+                    new Thread(new Runnable() {
+                        public void run() {
+                            // carrier is always 1 when kernel boot up no matter RJ45 plugin or not,
+                            // sleep a little time to wait kernel's correct carrier status
+                            try {
+                                Thread.sleep(3000);
+                            } catch (InterruptedException ignore) {
+                            }
+							if(isEthernetInterfaceActive()){
+                                IpConfiguration config = getIpConfiguration(mIfaceTmp);
+                                if(config != null && IpAssignment.STATIC == config.getIpAssignment())
+                                {
+                                    updateInterfaceState(mIfaceTmp, false);
+                                    updateInterfaceState(mIfaceTmp, true);
+                                }
+                            }else{
+                                 updateInterfaceState(mIfaceTmp, false);
+                             }
+                        }
+                    }).start();
+                    break;
+                }
             }
         } catch (RemoteException | IllegalStateException e) {
             Log.e(TAG, "Could not get list of interfaces " + e);


注:其实这是种治标不治本的解决办法,但是由于客户追的比较紧先采取这种解决方案,后续有时间再去查一下根本所在(根据测试log等,我猜想这是个由于加载顺序和获取ip的时机导致的随机问题)

你可能感兴趣的:(Android10,Android,Ethernet)