安全模式:增加修复文件状态以及对应管理接口
authorCaisking <3449750381@qq.com>
Thu, 12 Sep 2024 12:11:25 +0000 (20:11 +0800)
committerCaisking <3449750381@qq.com>
Thu, 12 Sep 2024 12:11:25 +0000 (20:11 +0800)
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp

index 03b6ac0..4a1aadf 100644 (file)
@@ -25,6 +25,7 @@ public:
   void InitLabels(void);
   void InitButtons(void);
   void InitBasicdata(void);
+  void UpdateRepairView(int date);
 
 private:
   UIScrollView *scrollView_{nullptr};
index 294b9a1..0f4e150 100644 (file)
 #include <vector>
 
 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<std::string> &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<std::string> 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
index 84c7ff4..2cd6d40 100644 (file)
@@ -1,3 +1,5 @@
+#include <array>
+#include <cstdint>
 #include <fstream>
 #include <iostream>
 #include <map>
@@ -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_COUNT> 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<int>(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<int>(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<std::string> &
@@ -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