From: Caisking <3449750381@qq.com> Date: Thu, 12 Sep 2024 12:11:25 +0000 (+0800) Subject: 安全模式:增加修复文件状态以及对应管理接口 X-Git-Tag: release_V1.2.70_20241020_135402~485^2~5^2~4 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f93c99c158b7c101870f955244769f4f419074b8;p=mirrors%2FFD230.git 安全模式:增加修复文件状态以及对应管理接口 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h index 03b6ac005..4a1aadfa0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h @@ -25,6 +25,7 @@ public: void InitLabels(void); void InitButtons(void); void InitBasicdata(void); + void UpdateRepairView(int date); private: UIScrollView *scrollView_{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h index 294b9a1e1..0f4e15077 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h @@ -17,56 +17,86 @@ #include namespace OHOS { + // 定义状态类型 enum class Safe_State { - BLE_OTA, // bleota - AUTO_OTA, // autoota - FACTORY_RESET, //恢复出厂 - RESOURCE_CHECK //资源检查 + BLE_OTA, // BLE OTA + AUTO_OTA, // Auto OTA + FACTORY_RESET, // 恢复出厂 + RESOURCE_CHECK, // 资源检查 + REPAIR_FILE // 修复 +}; +enum CheckState { + NO_OPERATION = 0, // 未操作 + CHECKING = 1, // 校验中 + CHECK_SUCCESS = 2, // 校验成功 + FILE_NOT_FOUND = 3, // 文件未找到 + FILE_CORRUPTED = 4 // 文件损坏 }; struct SafeStateInfo { Safe_State state; bool active; // 是否激活 }; - +static const int SAFE_STATE_COUNT = 5; // 安全状态数量 class SafeModeManagerModel { public: // 获取单例实例 static SafeModeManagerModel *GetInstance(); - void InitFilenamesListItems(); // 初始化消息列表项 - const ResourceCheckItem *GetFilenamesListItems() const; // 获取消息列表项 - uint16_t GetFilenamesCount() const; // 获取消息数量 // 恢复出厂 bool FactorySet(); + /* ---------------------------------- 校验文件 + * ---------------------------------- */ + // 初始化列表项 + void InitFilenamesListItems(); + // 获取列表项 + const ResourceCheckItem *GetFilenamesListItems() const; + // 获取数量 + uint16_t GetFilenamesCount() const; // 资源检查和读取差异文件 bool ResourceCheck(); bool ReadCheckFile(); - //获取校验状态 + // 获取校验状态 bool GetResourceCheckState() const; void SetResourceCheckState(bool state); // 获取检查文件列表 const std::vector &GetCheckDifferentialFiles() const; size_t GetCheckFileCount() const; + // 更新检查视图 void UpdateCheckView(int date); + /* ---------------------------------- 文件修复 + * ---------------------------------- */ + //获取版本号 + std::string GetVersion() const; + //进行修复开始 + bool RepairStart(); + // 进行修复结束 + bool RepairEnd(); + //更新修复界面 + void UpdateRepairView(int date); + /* ---------------------------------- map管理 + * --------------------------------- */ // 设置状态 void SetState(Safe_State state, bool executeAction); // 获取状态 bool IsState(Safe_State state) const; + // 输出当前状态 + void PrintState() const; private: SafeModeManagerModel() = default; // 默认构造函数 ~SafeModeManagerModel() = default; // 默认析构函数 - SafeModeManagerModel(const SafeModeManagerModel &) = delete; // 禁止拷贝构造 - SafeModeManagerModel & - operator=(const SafeModeManagerModel &) = delete; // 禁止赋值操作 + + // 禁止拷贝构造和赋值操作 + SafeModeManagerModel(const SafeModeManagerModel &) = delete; + SafeModeManagerModel &operator=(const SafeModeManagerModel &) = delete; std::vector resource_check_files; // 存储检查的资源文件列表 - uint16_t numberOfItems; + uint16_t numberOfItems = 0; // 初始化文件项数为 0 static const uint16_t MAX_RESOURCE_CHECK_FILE_NUM = 500; // 列表最大数量 ResourceCheckItem Filenames[MAX_RESOURCE_CHECK_FILE_NUM] = {0, nullptr}; // 列表 - bool resoure_check_state{false}; + bool resource_check_state{false}; // 资源检查状态 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp index 84c7ff468..2cd6d40bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -19,12 +21,60 @@ extern "C" bool resfile_checksum_thread(void); static const char *CHECK_DIFFERENTIAL_FILE = "/system/check_differential.txt"; +// snicker.com.cn 8089 +// http://snicker.com.cn:8089/FD230/V1.1.14_20240706_182936_CT/update.fwpkg +// /user/update.fwpkg get_version_string mgdataTimerCallBack + namespace OHOS { SafeModeManagerModel *SafeModeManagerModel::GetInstance(void) { static SafeModeManagerModel instance; return &instance; } +/* ---------------------------------- map修改 --------------------------------- + */ +/*显示状态map*/ +std::array safestateInfo = {{ + {Safe_State::BLE_OTA, false}, + {Safe_State::AUTO_OTA, false}, + {Safe_State::FACTORY_RESET, false}, + {Safe_State::RESOURCE_CHECK, false}, + {Safe_State::REPAIR_FILE, false}, +}}; +//设置某个配置状态 +void SafeModeManagerModel::SetState(Safe_State state, bool executeAction) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetState: %d", state); + //将状态赋值 + int stateIndex = static_cast(state); + if (stateIndex > 0 && stateIndex < SAFE_STATE_COUNT) { + //检查状态是否一致 + if (safestateInfo[stateIndex].active != executeAction) { + safestateInfo[stateIndex].active = executeAction; + safestateInfo[stateIndex].state = state; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "state is same"); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "state is invalid"); + } +} +//获取某个配置状态 +bool SafeModeManagerModel::IsState(Safe_State state) const { + int stateIndex = static_cast(state); + if (stateIndex > 0 && stateIndex < SAFE_STATE_COUNT) { + return safestateInfo[stateIndex].active; + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "state is invalid"); + return false; + } +} +//打印所有配置状态 +void SafeModeManagerModel::PrintState() const { + for (int i = 0; i < SAFE_STATE_COUNT; i++) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "state[%d]: %d", i, + safestateInfo[i].active); + } +} /* --------------------------------- 恢复出厂相关 * --------------------------------- */ // 恢复出厂 @@ -64,11 +114,11 @@ bool SafeModeManagerModel::ReadCheckFile() { } // 获取校验状态 bool SafeModeManagerModel::GetResourceCheckState() const { - return resoure_check_state; + return resource_check_state; } // 设置校验状态 void SafeModeManagerModel::SetResourceCheckState(bool state) { - resoure_check_state = state; + resource_check_state = state; } // 获取校验数组 const std::vector & @@ -112,10 +162,16 @@ void SafeModeManagerModel::InitFilenamesListItems() { const ResourceCheckItem *SafeModeManagerModel::GetFilenamesListItems() const { return Filenames; } - // 获取消息数量 uint16_t SafeModeManagerModel::GetFilenamesCount() const { return numberOfItems; } +/* ---------------------------------- 下载修复文件 + * ---------------------------------- */ +bool SafeModeManagerModel::RepairStart() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Repair"); + return true; +} + } // namespace OHOS \ No newline at end of file