增加安全模式->资源校验
authorCaisking <3449750381@qq.com>
Mon, 9 Sep 2024 13:25:10 +0000 (21:25 +0800)
committerCaisking <3449750381@qq.com>
Mon, 9 Sep 2024 13:25:10 +0000 (21:25 +0800)
17 files changed:
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/ResourceCheckView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/ResourceCheckView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp
code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_resfile_check.c
code/sdk/drivers/peripheral/utils/custom_runtime.c
code/sdk/drivers/peripheral/utils/custom_runtime.h
code/sdk/drivers/peripheral/utils/custom_utils.h

index 06c9715..38d112f 100644 (file)
@@ -704,6 +704,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/safemodemanager/src/SafeModeManagerView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/safemodemanager/src/SafeModeManagerModel.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/safemodemanager/src/ResourceCheckView.cpp
 
 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneCallView.cpp
index 82779db..e5fcd4e 100644 (file)
@@ -466,15 +466,15 @@ namespace OHOS
         {
             GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::NEW_FONT_DIR, GILROY_BOLD_FONT); // 注册字体
             set_current_global_font_name(GILROY_BOLD_FONT);
+            if (language::GetInstance()->InitLangues() == false)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLangues error");
+            }
             /*加载安全模式Slice*/
-            (this->*(SLICE_MAPPER[VIEW_SAFE_MODE].func))();
+            InitSafeModeSlice();
             NativeAbility::GetInstance().SetDefaultSliceId(VIEW_SAFE_MODE);
-            InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化
-            CallerLogModel::GetInstance()->InitPhoneService();
             PresenterTask::GetInstance()->Init();
-            PlayersModel::GetInstance()->AudioInit();
-            ScreenModels::GetInstance()->InitKvStorage();
-            BluetoothModel::GetInstance()->Init();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "safe_mode is enter!");
         }
         else if (mode == LaunchMode::NORMAL_MODE)
         {
@@ -525,7 +525,6 @@ namespace OHOS
             }
             /*开机读取天气历史数据*/
             read_jsonHistory_weather();
-
             C_ScheduleDataReadFromFile();
             mmi_sleep_mode_switch_read();
         }
index dc359c2..b08252d 100644 (file)
@@ -28,6 +28,7 @@
 #include "ConfigModel.h"\r
 #include "heartrate/include/HeartModel.h"\r
 #include "sleep/include/SleepModel.h"\r
+#include "safemodemanager/include/SafeModeManagerModel.h"\r
 #include "cat1_server_hal.h"\r
 #include "custom_runtime.h"\r
 #include "uiservice/include/ui_service.h"\r
@@ -76,10 +77,10 @@ extern "C"
     static int sleep_notify_time_min = 0;\r
     static int sleep_notify_time_hour = 0;\r
 \r
-// #define SEDENTARY_TIME_RANGE (((curTime.tm_hour > sedentary_start_hour) || (curTime.tm_hour == sedentary_start_hour && curTime.tm_min >= sedentary_start_min)) && \\r
+    // #define SEDENTARY_TIME_RANGE (((curTime.tm_hour > sedentary_start_hour) || (curTime.tm_hour == sedentary_start_hour && curTime.tm_min >= sedentary_start_min)) && \\r
 //                               ((curTime.tm_hour < sedentary_stop_hour) || (curTime.tm_hour == sedentary_stop_hour && curTime.tm_min < sedentary_stop_min)))\r
 \r
-// #define WAKE_TIME_RANGE (((wake_time_hour < sleep_time_hour) &&                                              \\r
+    // #define WAKE_TIME_RANGE (((wake_time_hour < sleep_time_hour) &&                                              \\r
 //                           ((curTime.tm_hour > wake_time_hour) ||                                             \\r
 //                            (curTime.tm_hour == wake_time_hour && curTime.tm_min >= wake_time_min)) &&        \\r
 //                           ((curTime.tm_hour < sleep_time_hour) ||                                            \\r
@@ -152,11 +153,11 @@ extern "C"
         }\r
     }\r
 \r
-    static bool is_time_range(struct tm &curTime,int start_time_hour,int start_time_min,int end_time_hour,int end_time_min)\r
+    static bool is_time_range(struct tm &curTime, int start_time_hour, int start_time_min, int end_time_hour, int end_time_min)\r
     {\r
-        int start_min = start_time_hour * 60 + start_time_min; /* 开始时间的分钟数 */\r
-        int end_min = end_time_hour * 60 + end_time_min;       /* 结束时间的分钟数 */\r
-        int cur_time_min = curTime.tm_hour * 60 + curTime.tm_min;                                   /* 当前时间的分钟数 */\r
+        int start_min = start_time_hour * 60 + start_time_min;    /* 开始时间的分钟数 */\r
+        int end_min = end_time_hour * 60 + end_time_min;          /* 结束时间的分钟数 */\r
+        int cur_time_min = curTime.tm_hour * 60 + curTime.tm_min; /* 当前时间的分钟数 */\r
 \r
         // 处理非跨天的情况\r
         if (end_min > start_min)\r
@@ -383,7 +384,19 @@ extern "C"
                 g_alarmCtrB.callback();\r
             }\r
         }\r
-\r
+        // 开始校验文件\r
+        if (uapi_dev_runtime_get_checkres_status() == 1)\r
+        {\r
+            GraphicService::GetInstance()->PostGraphicEvent(\r
+                std::bind(&OHOS::SafeModeManagerModel::updatecheckview,OHOS::SafeModeManagerModel::GetInstance(), curTime.tm_sec));\r
+        }\r
+        // 校验成功\r
+        else if (uapi_dev_runtime_get_checkres_status() == 2)\r
+        {\r
+            GraphicService::GetInstance()->PostGraphicEvent(\r
+                std::bind(&OHOS::SafeModeManagerModel::updatecheckview, OHOS::SafeModeManagerModel::GetInstance(), 61));\r
+            uapi_dev_runtime_set_checkres_status(0);\r
+        }\r
         // 未绑定状态下,以下操作不进行\r
         if (OHOS::ConfigModel::GetInstance()->get_configData_bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_FIRSTTIMESTART))\r
             return;\r
@@ -412,12 +425,12 @@ extern "C"
                 }\r
             }\r
             // 退出睡眠检测模式并进入小睡检测模式\r
-            if (!is_time_range(curTime,sleep_time_hour,sleep_time_min,wake_time_hour,wake_time_min) && (uapi_dev_runtime_get_nap_monitoring_status() == 0))\r
+            if (!is_time_range(curTime, sleep_time_hour, sleep_time_min, wake_time_hour, wake_time_min) && (uapi_dev_runtime_get_nap_monitoring_status() == 0))\r
             {\r
                 // uapi_dev_runtime_set_sleep_status(0);\r
                 //  do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL);\r
 \r
-                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "起床啦! curTime.tm_hour:%d  curTime.tm_min:%d curTime.tm_sec:%d ",curTime.tm_hour,curTime.tm_min,curTime.tm_sec);\r
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "起床啦! curTime.tm_hour:%d  curTime.tm_min:%d curTime.tm_sec:%d ", curTime.tm_hour, curTime.tm_min, curTime.tm_sec);\r
 \r
                 if (curTime.tm_hour == wake_time_hour && curTime.tm_min == wake_time_min && curTime.tm_sec == 0)\r
                 {\r
@@ -433,26 +446,26 @@ extern "C"
                 if (uapi_dev_runtime_get_sleep_status() == 0)\r
                 {\r
                     // 设置状态为小睡\r
-                    uapi_dev_runtime_set_nap_status(0); // 清零小睡状态\r
+                    uapi_dev_runtime_set_nap_status(0);             // 清零小睡状态\r
                     uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态\r
                     uapi_dev_runtime_set_nap_monitoring_status(1);\r
                     uapi_dev_runtime_set_sleep_monitoring_status(0);\r
                     OHOS::SleepModel::GetInstance().ReInitData(); // 更新睡眠数据\r
-                    set_keep_in_wear_det_mode(1); //开启小睡佩戴监测\r
+                    set_keep_in_wear_det_mode(1);                 // 开启小睡佩戴监测\r
                     SendMsgToUIService(UI_UPDATE_SLEEP_DATA, 0, nullptr, 0);\r
                     do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); // 算法底层切换小睡监测模式\r
                 }\r
             }\r
             // 进入睡眠检测模式并退出小睡检测模式\r
-            else if (is_time_range(curTime,sleep_time_hour,sleep_time_min,wake_time_hour,wake_time_min) && (uapi_dev_runtime_get_sleep_monitoring_status() == 0))\r
+            else if (is_time_range(curTime, sleep_time_hour, sleep_time_min, wake_time_hour, wake_time_min) && (uapi_dev_runtime_get_sleep_monitoring_status() == 0))\r
             {\r
                 int cmd = 1;\r
-                uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态\r
+                uapi_dev_runtime_set_sleep_status(0);           // 清零睡眠状态\r
                 uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态\r
-                OHOS::clean_sleep_data(); // 清零睡眠文件存储数据\r
+                OHOS::clean_sleep_data();                       // 清零睡眠文件存储数据\r
                 uapi_dev_runtime_set_sleep_monitoring_status(1);\r
                 uapi_dev_runtime_set_nap_monitoring_status(0);\r
-                set_keep_in_wear_det_mode(0); //关闭小睡佩戴监测\r
+                set_keep_in_wear_det_mode(0);                                       // 关闭小睡佩戴监测\r
                 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); // 强制获取小睡数据,结束小睡\r
                 // 睡眠弹窗\r
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "要睡觉啦!");\r
@@ -472,12 +485,12 @@ extern "C"
         // 久坐提醒\r
         if (sedentary_switch)\r
         {\r
-            if (is_time_range(curTime,sedentary_start_hour,sedentary_start_min,sedentary_stop_hour,sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 0))\r
+            if (is_time_range(curTime, sedentary_start_hour, sedentary_start_min, sedentary_stop_hour, sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 0))\r
             {\r
                 uapi_dev_runtime_set_sedentary_status(1);\r
                 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_SEDENTARY, NULL);\r
             }\r
-            else if (!is_time_range(curTime,sedentary_start_hour,sedentary_start_min,sedentary_stop_hour,sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 1))\r
+            else if (!is_time_range(curTime, sedentary_start_hour, sedentary_start_min, sedentary_stop_hour, sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 1))\r
             {\r
                 uapi_dev_runtime_set_sedentary_status(0);\r
                 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_SEDENTARY, NULL);\r
@@ -501,7 +514,7 @@ extern "C"
             else if (drinkreminder_switch == 2)\r
             {\r
                 // 判断当前时间是否在提醒时间段内\r
-                if (is_time_range(curTime,drinkreminder_start_hour,drinkreminder_start_min,drinkreminder_end_hour,drinkreminder_end_min))\r
+                if (is_time_range(curTime, drinkreminder_start_hour, drinkreminder_start_min, drinkreminder_end_hour, drinkreminder_end_min))\r
                 {\r
                     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " curTime.tm_sec = %d", curTime.tm_sec);\r
                     double interval_time = (drinkreminder_freq == 0) ? 0.5 : drinkreminder_freq;             // 频率设置\r
@@ -535,7 +548,7 @@ extern "C"
                         }\r
                     }\r
                 }\r
-                else if (!is_time_range(curTime,drinkreminder_start_hour,drinkreminder_start_min,drinkreminder_end_hour,drinkreminder_end_min) && uapi_dev_runtime_get_drinkremind_status() == 1)\r
+                else if (!is_time_range(curTime, drinkreminder_start_hour, drinkreminder_start_min, drinkreminder_end_hour, drinkreminder_end_min) && uapi_dev_runtime_get_drinkremind_status() == 1)\r
                 {\r
                     uapi_dev_runtime_set_drinkremind_status(0);\r
                 }\r
index 5f0a7d6..027102b 100644 (file)
@@ -21,6 +21,8 @@
 #include "ui_service.h"
 #include "dial_sos_c.h"
 
+#define SAVEMODE 0
+
 extern "C" uint8_t uapi_dev_runtime_get_lock_status(void);
 namespace OHOS
 {
@@ -540,6 +542,8 @@ namespace OHOS
         RegisterFuncKeyLongPressEvent();
         // RegisterFuncKeyClickEvent();
         RegisterFuncKeyDoubleClickEvent();
+#if SAVEMODE
         RegisterPowerAndFuncKeyPressEvent();
+#endif
     }
 }
diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/ResourceCheckView.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/ResourceCheckView.h
new file mode 100644 (file)
index 0000000..dddc9ef
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-01-29 15:37:44
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-05-07 09:39:01
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/system/include/ResourceCheckView.h
+ */
+#ifndef ResourceCheck_VIEW_H
+#define ResourceCheck_VIEW_H
+
+#include "BaseView.h"
+#include "View.h"
+
+#include "components/ui_image_view.h"
+#include "components/ui_button.h"
+#include "components/ui_scroll_view.h"
+#include "components/ui_label_ext.h"
+namespace OHOS
+{
+    class ResourceCheckView
+    {
+
+    public:
+        ResourceCheckView();
+        virtual ~ResourceCheckView();
+        static ResourceCheckView *GetInstance(void);
+
+        UIScrollView *ResourceCheckViewInit(void);
+        void ClearAll(void);
+
+        void UpdateView(int date);
+        void UpdateView();
+
+    private:
+        UIScrollView *scrollView{nullptr};
+        UILabelExt *notelabel{nullptr};
+        bool initViewStatus{false};
+    };
+} // namespace OHOS
+#endif
\ No newline at end of file
index 4769631..726c608 100644 (file)
 
 #include <string>
 #include <vector>
+#include <map>
+#include <functional>
 
 namespace OHOS
 {
+    // 定义状态类型
+    enum class Safe_State
+    {
+        BLE_OTA,
+        AUTO_OTA,
+        FACTORY_RESET,
+        RESOURCE_CHECK
+    };
+    struct SafeStateInfo
+    {
+        Safe_State state;
+        bool active; // 是否激活
+    };
+
     class SafeModeManagerModel
     {
     public:
         // 获取单例实例
         static SafeModeManagerModel *GetInstance();
-
+        // 恢复出厂
+        bool FactorySet();
         // 资源检查和读取差异文件
         bool ResourceCheck();
         bool ReadCheckFile();
         // 获取检查文件列表
         const std::vector<std::string> &GetCheckDifferentialFiles() const;
         size_t GetCheckFileCount() const;
+        void updatecheckview(int date);
+
+        // 设置状态
+        void SetState(Safe_State state, bool executeAction);
+        // 获取状态
+        bool IsState(Safe_State state) const;
 
     private:
         SafeModeManagerModel() = default;                                       // 默认构造函数
@@ -33,7 +56,11 @@ namespace OHOS
         SafeModeManagerModel &operator=(const SafeModeManagerModel &) = delete; // 禁止赋值操作
 
         std::vector<std::string> resource_check_files; // 存储检查的资源文件列表
+
+        // 初始化状态与操作的映射
+        void InitializeStateActions();
     };
-}
+
+} // namespace OHOS
 
 #endif // SAFE_MODE_MANAGER_MODEL_H
\ No newline at end of file
index 0de6463..4af1006 100644 (file)
@@ -13,7 +13,7 @@
 #include "components/ui_toggle_button.h"
 
 #include "SafeModeManagerPresenter.h"
-
+#include "safemodemanager/include/ResourceCheckView.h"
 namespace OHOS
 {
     typedef enum
@@ -27,6 +27,7 @@ namespace OHOS
     } SafeViewID;
 
     class SafeModeManagerPresenter;
+    class ResourceCheckView;
     class SafeModeManagerView : public View<SafeModeManagerPresenter>
     {
     public:
@@ -50,12 +51,13 @@ namespace OHOS
         bool ChangeToAutoOTAView(int16_t thisView);
         bool ChangeToFactoryView(int16_t thisView);
         bool ChangeToResourceCheckView(int16_t thisView);
+        UIScrollView *GetSafeScrollView(int ViewId);
 
     private:
-        SafeModeManagerView *p_BleOTAView{nullptr};        // BleOTA
-        SafeModeManagerView *p_AutoOTAView{nullptr};       // 自动OTA
-        SafeModeManagerView *p_FactoryView{nullptr};       // 恢复出厂
-        SafeModeManagerView *p_ResourceCheckView{nullptr}; // 资源校验
+        SafeModeManagerView *p_BleOTAView{nullptr};      // BleOTA
+        SafeModeManagerView *p_AutoOTAView{nullptr};     // 自动OTA
+        SafeModeManagerView *p_FactoryView{nullptr};     // 恢复出厂
+        ResourceCheckView *p_ResourceCheckView{nullptr}; // 资源校验
 
     private:
         SafeModeManagerView(SafeModeManagerView &&) = delete;
diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/ResourceCheckView.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/ResourceCheckView.cpp
new file mode 100644 (file)
index 0000000..1ad3d94
--- /dev/null
@@ -0,0 +1,156 @@
+/***
+ * @Date: 2024-09-09 17:47:36
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-09-09 18:56:07
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/ResourceCheckView.cpp
+ */
+#include "safemodemanager/include/ResourceCheckView.h"
+#include "safemodemanager/include/SafeModeManagerPresenter.h"
+#include "safemodemanager/include/SafeModeManagerModel.h"
+
+#include "wearable_log.h"
+#include "UiConfig.h"
+#include "ui_resource_string.h"
+
+namespace OHOS
+{
+
+    static ResourceCheckView *g_pResourceCheckView{nullptr};
+
+    ResourceCheckView::ResourceCheckView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResourceCheckView::ResourceCheckView");
+        g_pResourceCheckView = this;
+    }
+
+    ResourceCheckView::~ResourceCheckView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResourceCheckView::~ResourceCheckView");
+        ClearAll();
+        g_pResourceCheckView = nullptr;
+    }
+
+    ResourceCheckView *ResourceCheckView::GetInstance()
+    {
+        return g_pResourceCheckView;
+    }
+
+    void ResourceCheckView::ClearAll()
+    {
+        delete scrollView;
+        scrollView = nullptr;
+        delete notelabel;
+        notelabel = nullptr;
+        g_pResourceCheckView = nullptr;
+    }
+
+    UIScrollView *ResourceCheckView::ResourceCheckViewInit(void)
+    {
+        scrollView = new UIScrollView();
+        if (scrollView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResourceCheckView::new scrollView fail!");
+            return nullptr;
+        }
+        scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        scrollView->SetStyle(STYLE_BORDER_RADIUS, 100);
+        scrollView->SetScrollBlankSize(50);
+        scrollView->SetReboundSize(35);
+        scrollView->SetMaxScrollDistance(1000);
+        scrollView->SetThrowDrag(true);
+        scrollView->RequestFocus();
+        scrollView->SetRotateFactor(2);
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(SafeModeManagerPresenter::GetInstance());
+        if (dragListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::GetInstance fail!!");
+            return nullptr;
+        }
+        scrollView->SetOnDragListener(dragListener);
+
+        notelabel = new UILabelExt();
+        if (notelabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResourceCheckView::new Title fail!");
+            return nullptr;
+        }
+        notelabel->SetPosition(83, 217);
+        notelabel->Resize(300, 60);
+        notelabel->SetViewId("label4");
+        notelabel->SetStyle(STYLE_TEXT_FONT, 30);
+
+        notelabel->SetText("正在进行文件校对。。。");
+        notelabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+        notelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        notelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+        scrollView->Add(notelabel);
+        return scrollView;
+    }
+    void ResourceCheckView::UpdateView(int date)
+    {
+        std::string display = "文件校对中";
+
+        if (date == -1)
+        {
+            notelabel->SetText("文件校对失败。。。");
+            return;
+        }
+        else if (date >= 0 && date <= 60)
+        {
+            int progress = date % 5;
+
+            // 添加进度点
+            for (int i = 0; i < progress; ++i)
+            {
+                display += "。";
+            }
+        }
+        else if (date == 61)
+        {
+            notelabel->SetText("文件校对成功。。。");
+            return;
+        }
+        else
+        {
+            notelabel->SetText("无效的输入。。。");
+            return;
+        }
+
+        // 更新标签文本
+        notelabel->SetText(display.c_str());
+    }
+    void ResourceCheckView::UpdateView()
+    {
+        printf("开始显示校验结果\r\n");
+        // 进行文件读取
+        if (SafeModeManagerModel::GetInstance()->ReadCheckFile())
+        {
+            // 读取数组
+            std::vector<std::string> filenames = SafeModeManagerModel::GetInstance()->GetCheckDifferentialFiles();
+            // 清空 notelabel 的文本
+            std::string allFilenames;
+        #if 0
+            // 更新 notelabel 的文本为文件名列表
+            for (const auto &filename : filenames)
+            {
+                allFilenames += filename + "\n"; // 逐行添加文件名
+            }
+            printf("allFilenames %s\r\n", allFilenames.c_str());
+            notelabel->SetText(allFilenames.c_str()); // 一次性设置文本
+        #endif
+            int num = SafeModeManagerModel::GetInstance()->GetCheckFileCount();
+            allFilenames = "本次校验结果校验成功:校验文件:"+ std::to_string(num) ;
+            notelabel->SetText(allFilenames.c_str()); // 一次性设置文本
+            printf("本次校验结果校验成功:校验文件%d\r\n", num);
+        }
+        else
+        {
+            notelabel->SetText("无法读取差异文件。。。");
+            printf("校验结果校验失败\r\n");
+        }
+        printf("校验结果校验完成\r\n");
+    }
+
+}
\ No newline at end of file
index d491231..8c033bf 100644 (file)
@@ -2,13 +2,24 @@
 #include <fstream>
 #include <string>
 #include <vector>
+#include <map>
+#include <functional>
+
 #include "safemodemanager/include/SafeModeManagerModel.h"
+#include "safemodemanager/include/SafeModeManagerView.h"
+#include "safemodemanager/include/ResourceCheckView.h"
+
 #include "custom_utils.h"
 #include "wearable_log.h"
+#include "thread_adapter.h"
+#include "graphic_service.h"
+#include "broadcast_service.h"
+#include "broadcast_feature.h"
 
 extern "C" bool resfile_checksum_thread(void);
 
 static const char *CHECK_DIFFERENTIAL_FILE = "/system/check_differential.txt";
+
 namespace OHOS
 {
     SafeModeManagerModel *SafeModeManagerModel::GetInstance(void)
@@ -16,22 +27,44 @@ namespace OHOS
         static SafeModeManagerModel instance;
         return &instance;
     }
+/* ---------------------------------安全模式 map状态相关 -------------------------------- */
+#if 0
+    /*状态map*/
+    std::array<SafeStateInfo, 4> stateActions = {{
+        {Safe_State::BLE_OTA, false},
+        {Safe_State::AUTO_OTA, false},
+        {Safe_State::FACTORY_RESET, false},
+        {Safe_State::RESOURCE_CHECK, false},
+    }};
+
+    // 设置状态
+    void SafeModeManagerModel::SetState(Safe_State state, bool executeAction) {
+        auto index = static_cast<size_t>(state);
+        if (index < stateActions.size()) {
+            stateActions[index] = executeAction;
+        }
+    }
+
+    // 获取指定类状态
+    bool SafeModeManagerModel::IsState(Safe_State state) const {
+        auto index = static_cast<size_t>(state);
+        return stateActions[index];
+    }
+#endif
+    /* --------------------------------- 恢复出厂相关 --------------------------------- */
+    bool SafeModeManagerModel::FactorySet()
+    {
+        do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING, NULL, 0);
+        return true;
+    }
 
     /*-----------------------------资源校验相关-----------------------------*/
     bool SafeModeManagerModel::ResourceCheck()
     {
-        bool checkstate{false};
-        if (resfile_checksum_thread())
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "文件校验成功");
-            checkstate = true;
-        }
-        else
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "文件校验失败");
-        }
-        return checkstate;
+        do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CHECK_RES, NULL, 0);
+        return true;
     }
+
     // 进行文件读取
     bool SafeModeManagerModel::ReadCheckFile()
     {
@@ -52,18 +85,38 @@ namespace OHOS
                 resource_check_files.push_back(filename); // 将文件名添加到向量中
             }
         }
-        
+
         infile.close(); // 关闭文件
         return true;
     }
+
     // 获取校验数组
     const std::vector<std::string> &SafeModeManagerModel::GetCheckDifferentialFiles() const // 返回常量引用以避免复制
     {
         return resource_check_files; // 返回资源检查文件列表
     }
+
     // 获取文件个数
     size_t SafeModeManagerModel::GetCheckFileCount() const
     {
         return resource_check_files.size(); // 返回文件个数
     }
+
+    // 更新文件校对界面
+    void SafeModeManagerModel::updatecheckview(int date)
+    {
+        if (SafeModeManagerView::GetInstance() != nullptr)
+        {
+            if (SafeModeManagerView::GetInstance()->GetSafeScrollView(VIEW_RESOURCE_CHECK) != nullptr)
+            {
+                ResourceCheckView::GetInstance()->UpdateView(date);
+                if (date == 61)
+                {
+                    // LOS_Msleep(1); // 暂停1秒
+                    ResourceCheckView::GetInstance()->UpdateView();
+                }
+            }
+        }
+    }
+
 }
\ No newline at end of file
index 722d097..614b3bc 100644 (file)
 #include "safemodemanager/include/SafeModeManagerModel.h"
 #include "gfx_utils/mem_check.h"
 #include "custom_utils.h"
+#include "broadcast_service.h"
+#include "graphic_service.h"
 namespace OHOS
 {
 
     // 当前Presenter属性实例化的内存指针
     static SafeModeManagerPresenter *g_pSafeModeManagerPresenter = nullptr;
-
     SafeModeManagerPresenter::SafeModeManagerPresenter()
     {
-#ifdef MEM_CHECK
-        MemCheck::GetInstance()->EnableLeakCheck(true);
-#endif
+        // 设置常亮
+        ScreenAlwaysOnCtr(0);
+        ScreenAlwaysOnCtr(1);
+
         g_pSafeModeManagerPresenter = this;
     }
 
     SafeModeManagerPresenter::~SafeModeManagerPresenter()
     {
-#ifdef MEM_CHECK
-        MemCheck::GetInstance()->EnableLeakCheck(false);
-#endif
+
         g_pSafeModeManagerPresenter = nullptr;
     }
 
@@ -65,17 +65,34 @@ namespace OHOS
 
     bool SafeModeManagerPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::OnClick");
+        SafeModeManagerView *p_SafeModeManagerView = SafeModeManagerView::GetInstance();
+        if (p_SafeModeManagerView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SafeModeManagerView::GetInstance fail!");
+            return false;
+        }
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
             (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
-            // NativeAbility::GetInstance().Back();
+            if (&view == p_SafeModeManagerView->GetSafeScrollView(VIEW_RESOURCE_CHECK))
+            {
+                p_SafeModeManagerView->ChangeView(VIEW_RESOURCE_CHECK, VIEW_SAFE_LIST);
+            }
         }
-        UNUSED(view);
         return true;
     }
 
     bool SafeModeManagerPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SafeModeManagerPresenter::OnClick");
+        SafeModeManagerView *p_SafeModeManagerView = SafeModeManagerView::GetInstance();
+        if (p_SafeModeManagerView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SafeModeManagerView::GetInstance fail!");
+            return false;
+        }
+
         if (strcmp(view.GetViewId(), BLE_OTA) == 0)
         {
             /*蓝牙ota*/
@@ -87,12 +104,13 @@ namespace OHOS
         if (strcmp(view.GetViewId(), FACTORY_RESET_SAFE) == 0)
         {
             /*恢复出厂*/
+            SafeModeManagerModel::GetInstance()->FactorySet();
         }
         if (strcmp(view.GetViewId(), RESOURCE_CHECK) == 0)
         {
             /*资源校验*/
-            GraphicService::GetInstance()->PostGraphicEvent(std::bind(&SafeModeManagerModel::ResourceCheck,
-                                                                      SafeModeManagerModel::GetInstance()));
+            p_SafeModeManagerView->ChangeView(VIEW_SAFE_LIST, VIEW_RESOURCE_CHECK);
+            SafeModeManagerModel::GetInstance()->ResourceCheck();
         }
         if (strcmp(view.GetViewId(), RE_START) == 0)
         {
index 130955d..e9d65a4 100644 (file)
@@ -1,5 +1,6 @@
 #include "safemodemanager/include/SafeModeManagerView.h"
 #include "safemodemanager/include/SafeModeManagerPresenter.h"
+#include "safemodemanager/include/ResourceCheckView.h"
 
 #include "common/image_cache_manager.h"
 #include "UiConfig.h"
@@ -9,7 +10,10 @@
 #include "uicomponents/UIComponents.h"
 #include "ui_resource_string.h"
 #include "components/ui_scroll_view.h"
+#include "custom_utils.h"
 
+extern "C" bool resfile_checksum_thread(void);
+extern "C" void uapi_enter_power_saving_mode(void);
 namespace OHOS
 {
 
@@ -18,6 +22,8 @@ namespace OHOS
 
     SafeModeManagerView::SafeModeManagerView()
     {
+        /*开启省电模式*/
+        uapi_enter_power_saving_mode();
         g_pSafeModeManagerView = this;
     }
 
@@ -239,17 +245,15 @@ namespace OHOS
     {
         if (SafeModeScrollView[thisView] == nullptr)
         {
-#if 0
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SafeModeManagerView::ChangeToResourceCheckView");
-            p_ResourceCheckView = new SystemShutdown();
+            p_ResourceCheckView = new ResourceCheckView();
             if (p_ResourceCheckView == nullptr)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SafeModeManagerView:: new scrollView[%d] fail", thisView);
                 return false;
             }
-            SafeModeScrollView[thisView] = p_ResourceCheckView->SystemShutdownViewInit();
+            SafeModeScrollView[thisView] = p_ResourceCheckView->ResourceCheckViewInit();
             container_->Add(SafeModeScrollView[thisView]);
-#endif
         }
         return true;
     }
@@ -318,6 +322,14 @@ namespace OHOS
         SafeModeScrollView[showView]->SetVisible(true);
         Draw();
     }
+    UIScrollView *SafeModeManagerView::GetSafeScrollView(int ViewId)
+    {
+        if (SafeModeScrollView[ViewId] == nullptr)
+        {
+            return nullptr;
+        }
+        return SafeModeScrollView[ViewId];
+    }
     /* -------------------------------------------------------------------------- */
     void SafeModeManagerView::OnStart()
     {
@@ -329,9 +341,9 @@ namespace OHOS
             return;
         }
         container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        
+
         InitView();
-        
+
         // SetContainerView(container_);
         // RootView::GetInstance()->SetOnKeyActListener(presenter_);
     }
index 601d64e..f49a60e 100755 (executable)
@@ -1,7 +1,7 @@
 /*** 
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-09-09 15:48:54
+ * @LastEditTime: 2024-09-09 18:03:42
  * @FilePath: /FD230/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp
  */
 /*
@@ -29,6 +29,8 @@
 #include "graphic_config.h"
 #include "dfx/fps_task.h"
 #include "notification_manager.h"
+#include "custom_runtime.h"
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -57,7 +59,15 @@ void NativeAbility::InstallAbility(void)
     InstallNativeAbility(nullptr, this);
 
     // 初始化Launcher
-    NativeLauncher::GetInstance().InitNativeLauncher(LaunchMode::NORMAL_MODE);
+    if(uapi_dev_runtime_get_safemode_flag())
+    {
+        NativeLauncher::GetInstance().InitNativeLauncher(LaunchMode::SAFE_MODE);
+    }
+    else
+    {   
+        NativeLauncher::GetInstance().InitNativeLauncher(LaunchMode::NORMAL_MODE);
+    }
+
     return;
 }
 #endif
index 4081cd7..0fd459f 100644 (file)
@@ -250,7 +250,9 @@ static void custom_cmd_service_check_task(void const *arg)
                     break;
             }
             break;
-
+        case CUSTOM_CMD_MSG_CHECK_RES:
+            resfile_checksum_thread();
+            break;
         default:
             PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd);
             break;
index 761f207..64a720b 100644 (file)
@@ -180,13 +180,22 @@ freebuf:
     return false;
 }
 
+/*
+    校验状态
+    0 未校验
+    1 校验中
+    2 校验成功
+    3 校验失败
+*/
 bool resfile_checksum_thread(void)
 {
+    uapi_dev_runtime_set_checkres_status(1);
     printf("resfile start check\r\n");
     char *readbuf = malloc(MAX_FILE_CHECKSUM_STR_LEN);
     if (readbuf == NULL)
     {
         printf("malloc fail, skip resfile check\r\n");
+        uapi_dev_runtime_set_checkres_status(3);
         return false;
     }
     char *filename = malloc(MAX_FILE_NAME_LEN);
@@ -194,6 +203,7 @@ bool resfile_checksum_thread(void)
     {
         free(readbuf);
         printf("malloc fail, skip resfile check\r\n");
+        uapi_dev_runtime_set_checkres_status(3);
         return false;
     }
     FILE *file = fopen(RESFILE_CHECKSUM_FILE, "rb");
@@ -202,19 +212,21 @@ bool resfile_checksum_thread(void)
         printf("checksum list file %s not exist, skip resfile check\r\n", RESFILE_CHECKSUM_FILE);
         free(readbuf);
         free(filename);
+        uapi_dev_runtime_set_checkres_status(3);
         return false;
     }
 
     memset(readbuf, 0, MAX_FILE_CHECKSUM_STR_LEN);
     char tmp;
     int i = 0;
-    FILE *diff_file = fopen(CHECK_DIFFERENTER_FILE, "a");
+    FILE *diff_file = fopen(CHECK_DIFFERENTER_FILE, "w");
     if (diff_file == NULL)
     {
         printf("Failed to open differential file %s\r\n", CHECK_DIFFERENTER_FILE);
         fclose(file);
         free(readbuf);
         free(filename);
+        uapi_dev_runtime_set_checkres_status(3);
         return false;
     }
 
@@ -260,6 +272,8 @@ bool resfile_checksum_thread(void)
     fclose(file);
     free(readbuf);
     free(filename);
+    uapi_dev_runtime_set_checkres_status(2);
     printf("resfile check done\r\n");
+
     return true;
 }
\ No newline at end of file
index eaf42f0..7bba0bf 100644 (file)
@@ -82,6 +82,7 @@ typedef struct
     uint8_t motion_recognition_status;//运动识别开关状态
     uint8_t sleep_mode_flag; // sleep mode flag
     uint8_t absolute_static_state; // 绝对静止状态
+    uint8_t checkres_status;//校验文件状态
 } runtime_status_t;
 
 
@@ -374,6 +375,15 @@ uint8_t uapi_dev_runtime_get_lock_status(void)
 {
     return g_runtime.lock_status;
 }
+/*设置校验状态*/
+void uapi_dev_runtime_set_checkres_status(uint8_t status)
+{
+    g_runtime.checkres_status = status;
+}
+uint8_t uapi_dev_runtime_get_checkres_status(void)
+{
+    return g_runtime.checkres_status;
+}
 /*设置运动识别状态*/
 void uapi_dev_runtime_set_motion_recognition_status(uint8_t status)
 {
index 35416d8..8d2880b 100644 (file)
@@ -89,6 +89,16 @@ uint8_t uapi_dev_runtime_get_saveele_status(void);
 void uapi_dev_runtime_set_lock_status(uint8_t status);
 uint8_t uapi_dev_runtime_get_lock_status(void);
 
+/*
+    校验状态
+    0 未校验
+    1 校验中
+    2 校验成功
+    3 校验失败
+*/
+void uapi_dev_runtime_set_checkres_status(uint8_t status);
+uint8_t uapi_dev_runtime_get_checkres_status(void);
+
 
 /*运动识别*/
 void uapi_dev_runtime_set_motion_recognition_status(uint8_t status);
index 54ec401..b1b44ed 100644 (file)
@@ -216,6 +216,7 @@ uint32_t uapi_calendar_store_date(void);
 
 #define CUSTOM_CMD_MSG_BR_CONNECT 0x0C
 
+#define CUSTOM_CMD_MSG_CHECK_RES 0x0D
 typedef enum {
     BR_HFP_CONNECT=1,
     BR_HFP_DISCONNECT,