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

RK3328][Android10.0]Ethernet-以太网设置静态ip,重启后无法获取IP的问题「建议收藏」测试平台 Platform RK3399 RK3328 OS Android 10 0 现象 设置中设置以太网为静态 ip 设置后使用 ifconfig 查看 ip 显示正常 然后重启 极大概率出现开机后设备没有获取到 ip 分析解决 测试后发现了几点规律 设置静态 ip 会开机获取不到 ip 但是设置动态 ip 无问题 没有获取到 ip 时 使用 ifconfig 查看 发现网卡设备连接正常 此时拔插网线

测试平台

Platform: RK3399/RK3328
OS: Android 10.0

现象

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

分析解决

测试后发现了几点规律:

设置静态ip会开机获取不到ip,但是设置动态ip无问题

没有获取到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的时机导致的随机问题)

编程小号
上一篇 2025-01-28 12:21
下一篇 2025-02-09 21:27

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/110148.html