首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[RK3399/RK3328][Android10.0]Ethernet:以太网设置静态ip,重启后无法获取IP的问题「建议收藏」

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

作者头像
全栈程序员站长
发布2022-09-02 15:52:10
发布2022-09-02 15:52:10
4.2K0
举报

大家好,又见面了,我是你们的朋友全栈君。

测试平台

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次后无问题,提交给到客户

代码语言:javascript
复制
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的时机导致的随机问题)

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139610.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 测试平台
  • 现象
  • 分析解决
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档