[RK3399][Android7.1.1] Ethernet:异常断电导致ip设置没有保存的问题
程序员文章站
2022-03-30 10:17:28
/data/misc/ethernet/ipconfig.txtdiff --git a/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java b/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.javaindex d8718a2…3c1750a 100644— a/frameworks/base/servi...
测试平台
Platform: RK3399
OS: Android 7.1.1
现象
在设置-以太网中设置ip地址(如dhcp->static或static ip修改),生效后,立刻断电,重新上电开机后发现ip状态恢复到设置前.
分析
查看了一下以太网的ip设置是以文件方式保存的,怀疑是因为文件存在缓存中没有真正保存导致的。
保存地址:/data/misc/ethernet/ipconfig.txt
再次测试,在设置后运行命令adb shell sync :/data/misc/ethernet/ipconfig.txt 之后再断电,重新上电开机后发现ip状态正确.所以写入文件后sync是可以解决问题的。
解决方案
diff --git a/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java b/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java
index d8718a2..3c1750a 100644
--- a/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java
+++ b/frameworks/base/services/core/java/com/android/server/net/IpConfigStore.java
@@ -38,6 +38,13 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.Inet4Address;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
public class IpConfigStore {
private static final String TAG = "IpConfigStore";
private static final boolean DBG = false;
@@ -167,6 +174,7 @@ public class IpConfigStore {
}
out.writeUTF(EOS);
+ out.flush();
return written;
}
@@ -178,10 +186,33 @@ public class IpConfigStore {
for(int i = 0; i < networks.size(); i++) {
writeConfig(out, networks.keyAt(i), networks.valueAt(i));
}
+ Log.v("sjfe","2 writeIpAndProxyConfigurations");
+ try{
+ sync(filePath);
+ }catch (IOException e){
+ Log.v("sjfe","2 sync error:"+e.toString());
+ }
+
}
});
}
+ public void sync(String filepath) throws IOException {
+ File f = new File(filepath);
+ RandomAccessFile raf = null;
+
+ try {
+ raf = new RandomAccessFile(f, "r");
+ FileDescriptor fd = raf.getFD();
+ fd.sync();
+
+ } finally {
+ if (raf != null) {
+ raf.close();
+ }
+ }
+ }
+
public SparseArray<IpConfiguration> readIpAndProxyConfigurations(String filePath) {
SparseArray<IpConfiguration> networks = new SparseArray<IpConfiguration>();
本文地址:https://blog.csdn.net/weixin_39966398/article/details/107205967
上一篇: 荐 MySQL6天笔记——day06
下一篇: java学习第一周