添加恢复出厂设置 107/1
authorpenglei <1624952103@qq.com>
Sun, 28 Apr 2024 06:40:22 +0000 (14:40 +0800)
committerpenglei <1624952103@qq.com>
Sun, 28 Apr 2024 06:40:22 +0000 (14:40 +0800)
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 5bca4da..43f5193 100644 (file)
@@ -70,7 +70,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOff fail!");\r
             return nullptr;\r
         }\r
-        FactoryResetButtonCheckOff->SetPosition(240, 320, 130, 130);\r
+        FactoryResetButtonCheckOff->SetPosition(97, 320, 130, 130);\r
         FactoryResetButtonCheckOff->SetViewId(FACTORYRESET_CHECKOFF);\r
         FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
         FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
@@ -85,7 +85,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOn fail!");\r
             return nullptr;\r
         }\r
-        FactoryResetButtonCheckOn->SetPosition(97, 320, 130, 130);\r
+        FactoryResetButtonCheckOn->SetPosition(240, 320, 130, 130);\r
         FactoryResetButtonCheckOn->SetViewId(FACTORYRESET_CHECKON);\r
         FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
         FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
index f32b0af..432e40f 100644 (file)
@@ -175,7 +175,7 @@ namespace OHOS
 \r
         if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON) == 0)\r
         {\r
-            p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW);\r
+            do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING,NULL,0);\r
             return true;\r
         }\r
         else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF) == 0)\r
index 1ba8d74..e1d60e1 100644 (file)
@@ -113,6 +113,12 @@ static void custom_cmd_service_check_task(void const *arg)
                 uapi_callVolumeSet(value);
             }
             break;
+        case CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING:
+            {
+                uapi_delete_files();
+                uapi_reboot_device();
+             }
+             break;
         default:
             PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd);
             break;
@@ -120,7 +126,7 @@ static void custom_cmd_service_check_task(void const *arg)
     }
 }
 #define CUSTOM_CMD_APP_BOARD_MSG_COUNT 10
-#define CUSTOM_CMD_APP_BOARD_TASK_SIZE 0x800
+#define CUSTOM_CMD_APP_BOARD_TASK_SIZE 0x1000
 #define CUSTOM_CMD_BOARD_TASK_PRIO 7
 void create_custom_cmd_queue(void)
 {
index 6131630..a1f9425 100644 (file)
@@ -1410,13 +1410,79 @@ int set_bmp(void)
     return 1;
 }
 
-int enter_recovery(void)
+#include <dirent.h>
+#include <unistd.h>
+
+int removeFilesInFolder(const char *folderPath) 
 {
-    if(set_bmp() == -1)
+    DIR *dir;
+    struct dirent *entry;
+
+    // 打开目录
+    dir = opendir(folderPath);
+    if (dir == NULL) 
     {
-        PRINT("set bmp failed !!! \r\n");
+        PRINT("Unable to open %s\r\n",folderPath);
         return -1;
     }
+
+    // 遍历目录中的文件
+    while ((entry = readdir(dir)) != NULL) 
+    {
+        // 忽略当前目录和父目录
+        if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) 
+        {
+            // 构造文件的完整路径
+            char filePath[64];
+            snprintf(filePath, sizeof(filePath), "%s/%s", folderPath, entry->d_name);
+
+            // 删除文件
+            if (remove(filePath) != 0) 
+            {
+                return -1;
+            }
+        }
+    }
+    // 关闭目录
+    closedir(dir);
+    return 0;
+}
+
+void uapi_delete_files(void)
+{
+    char *filebuf[11] = { "/user/kvstore/","/user/dial/","/user/userdata/health/",
+                            "/user/userdata/sport/","/user/userdata/sport/TrainingData/",
+                            "/user/userdata/sport/Activty/","/user/userdata/callog.bin",
+                            "/user/userdata/alarmclock","/user/userdata/recording/",
+                            "/user/music/","/user/userdata/addressbook.bin"
+                        };
+
+    int ret = 0;
+    for(int i = 0; i < 11 ; i++)
+    {
+        if(access(filebuf[i], F_OK) == -1)
+        {
+            PRINT("%s does not exist !!!\r\n", filebuf[i]);
+            continue;
+        }
+        if(strstr(filebuf[i],".") != NULL)
+            ret = remove(filebuf[i]);
+        else
+            ret = removeFilesInFolder(filebuf[i]);
+        if(ret != 0)
+            PRINT("%s remove failed !!! \r\n",filebuf[i]);
+        else
+            PRINT("%s remove succeed !!! \r\n",filebuf[i]);
+    }
+}
+
+int enter_recovery(void)
+{
+    // if(set_bmp() == -1)
+    // {
+    //     PRINT("set bmp failed !!! \r\n");
+    //     return -1;
+    // }
     return 1;
     //upg_reboot();
 }
index b158a2d..6623aeb 100644 (file)
@@ -150,9 +150,12 @@ uint32_t uapi_calendar_store_date(void);
 #define CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME 0x02
 #define CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME 0x03
 #define CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE 0x04
+#define CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING 0x05
 
 errcode_t uapi_custom_cmd_service_init(void);
 void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen);
+void uapi_delete_files(void);
+
 
 #ifdef __cplusplus
 }