From: penglei <1624952103@qq.com> Date: Sun, 28 Apr 2024 06:40:22 +0000 (+0800) Subject: 添加恢复出厂设置 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~42^2~5 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=refs%2Fchanges%2F107%2F1;p=mirrors%2FFD230.git 添加恢复出厂设置 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp index 5bca4daf8..43f5193c6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp @@ -70,7 +70,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOff fail!"); return nullptr; } - FactoryResetButtonCheckOff->SetPosition(240, 320, 130, 130); + FactoryResetButtonCheckOff->SetPosition(97, 320, 130, 130); FactoryResetButtonCheckOff->SetViewId(FACTORYRESET_CHECKOFF); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00); @@ -85,7 +85,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOn fail!"); return nullptr; } - FactoryResetButtonCheckOn->SetPosition(97, 320, 130, 130); + FactoryResetButtonCheckOn->SetPosition(240, 320, 130, 130); FactoryResetButtonCheckOn->SetViewId(FACTORYRESET_CHECKON); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00); diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp index f32b0afeb..432e40f03 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp @@ -175,7 +175,7 @@ namespace OHOS if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON) == 0) { - p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING,NULL,0); return true; } else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF) == 0) diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index 1ba8d7486..e1d60e1e4 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -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) { diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 613163084..a1f9425ce 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -1410,13 +1410,79 @@ int set_bmp(void) return 1; } -int enter_recovery(void) +#include +#include + +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(); } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index b158a2df9..6623aebac 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -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 }