RK3588 Android13 以太网IP无法保存问题

刚刚接手RK3588 Android13,测试以太网IP设置问题,发现重启设备无法保存,跟踪logcat日志发现,目标目录不存在导致无法写文件,而且写完文件后没有fflush,会概率性出现断电重启数据没有保存。主要集中在仓库:packages/modules/Connectivity

修改一:增加目录和文件创建

diff --git a/service-t/src/com/android/server/net/IpConfigStore.java b/service-t/src/com/android/server/net/IpConfigStore.java
index 3a9a54415..155ea1323 100644
--- a/service-t/src/com/android/server/net/IpConfigStore.java
+++ b/service-t/src/com/android/server/net/IpConfigStore.java
@@ -39,6 +39,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.File;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.util.ArrayList;
@@ -190,6 +191,7 @@ public class IpConfigStore {
     @Deprecated
     public void writeIpAndProxyConfigurationsToFile(String filePath,
                                               final SparseArray<IpConfiguration> networks) {
+        createFilepath(filePath);
         mWriter.write(filePath, out -> {
             out.writeInt(IPCONFIG_FILE_VERSION);
             for (int i = 0; i < networks.size(); i++) {
@@ -203,6 +205,7 @@ public class IpConfigStore {
      */
     public void writeIpConfigurations(String filePath,
                                       ArrayMap<String, IpConfiguration> networks) {
+        createFilepath(filePath);
         mWriter.write(filePath, out -> {
             out.writeInt(IPCONFIG_FILE_VERSION);
             for (int i = 0; i < networks.size(); i++) {
@@ -446,4 +449,20 @@ public class IpConfigStore {
     protected static void log(String s) {
         Log.d(TAG, s);
     }
+
+    private void createFilepath(String filepath){
+        try {
+            String path = filepath.substring(0, filepath.lastIndexOf("/"));
+            File dir = new File(path);
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+
+            File file = new File(filepath);
+            if (!file.exists()) {
+                file.createNewFile();
+            }
+        } catch (Exception e) {
+        }
+    }
 }

修改二:完善文件写机制(写完及时将缓存写到硬盘)

--- a/service/src/com/android/server/net/DelayedDiskWrite.java
+++ b/service/src/com/android/server/net/DelayedDiskWrite.java
@@ -24,6 +24,7 @@ import android.util.Log;
 import java.io.BufferedOutputStream;
 import java.io.DataOutputStream;
 import java.io.FileOutputStream;
+import java.io.FileDescriptor;
 import java.io.IOException;
 
 /**
@@ -81,10 +82,13 @@ public class DelayedDiskWrite {
 
     private void doWrite(String filePath, Writer w, boolean open) {
         DataOutputStream out = null;
+        FileOutputStream  file = null;
+        FileDescriptor fd =null;
         try {
             if (open) {
-                out = new DataOutputStream(new BufferedOutputStream(
-                        new FileOutputStream(filePath)));
+                file = new FileOutputStream(filePath);
+                fd = file.getFD();
+                out = new DataOutputStream(new BufferedOutputStream(file));
             }
             w.onWriteCalled(out);
         } catch (IOException e) {
@@ -92,6 +96,8 @@ public class DelayedDiskWrite {
         } finally {
             if (out != null) {
                 try {
+                    out.flush();
+                    fd.sync();
                     out.close();
                 } catch (Exception e) { }
             }

要在RK3399 Android 10.0设备中设置静态IP,可以按照以下步骤操作: 1. 首先,在设备上找到并打开“设置”应用程序。 2. 在设置界面中,向下滚动直到找到“网络和互联网”选项,并点击进入。 3. 在网络和互联网菜单中,选择“以太网”选项。如果设备没有物理以太网接口,可能显示为“有线连接”或类似选项。 4. 进入以太网设置后,点击右上角的菜单按钮(通常是三个竖排的点或线),然后选择“高级”或“高级选项”。 5. 在高级设置中,寻找一个类似“IP设置”、“IP地址设置”或“连接类型”等选项,点击进入。 6. 在IP设置菜单中,通常默认为“DHCP”(动态IP分配)。如果要切换为静态IP,请选择“静态”或“手动”选项。 7. 在静态IP设置中,输入您想要使用的IP地址、子网掩码、默认网关和DNS服务器。确保这些信息准确无误,一般可以从网络管理员或路由器配置中获取。 8. 输入完毕后,点击“保存”或“应用”按钮,以应用并保存新的静态IP设置。 9. 返回网络设置主菜单,重新启动RK3399设备,以使新的静态IP设置生效。 在完成以上步骤后,您的RK3399 Android 10.0设备将会使用您所提供的静态IP地址进行以太网连接。请注意,静态IP设置通常用于特定网络环境中,如企业网络或技术调试,一般家庭用户使用动态IP更为常见。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值