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
如对本文有疑问, 点击进行留言回复!!
解决idea中出现“illegal character U+200B” 问题
荐 为什么加了@Transactional注解,事务没有回滚?
Attribute ‘sklearn.linear_model._logistic.LogisticRegression.multi_class‘ must be explicitly set to
Java/Python实现 LeetCode剑指Offer 14-I.剪绳子(动态规划)
网友评论