From: Caisking <3449750381@qq.com> Date: Mon, 9 Sep 2024 13:25:10 +0000 (+0800) Subject: 增加安全模式->资源校验 X-Git-Tag: release_V1.2.70_20241020_135402~519 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=5374b7ecc6d1c41e0e3b562806dbda519121bf0b;p=mirrors%2FFD230.git 增加安全模式->资源校验 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 06c9715fc..38d112fd6 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -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 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 82779db3e..e5fcd4eb2 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -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(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index dc359c294..b08252dfb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -28,6 +28,7 @@ #include "ConfigModel.h" #include "heartrate/include/HeartModel.h" #include "sleep/include/SleepModel.h" +#include "safemodemanager/include/SafeModeManagerModel.h" #include "cat1_server_hal.h" #include "custom_runtime.h" #include "uiservice/include/ui_service.h" @@ -76,10 +77,10 @@ extern "C" static int sleep_notify_time_min = 0; static int sleep_notify_time_hour = 0; -// #define SEDENTARY_TIME_RANGE (((curTime.tm_hour > sedentary_start_hour) || (curTime.tm_hour == sedentary_start_hour && curTime.tm_min >= sedentary_start_min)) && \ + // #define SEDENTARY_TIME_RANGE (((curTime.tm_hour > sedentary_start_hour) || (curTime.tm_hour == sedentary_start_hour && curTime.tm_min >= sedentary_start_min)) && \ // ((curTime.tm_hour < sedentary_stop_hour) || (curTime.tm_hour == sedentary_stop_hour && curTime.tm_min < sedentary_stop_min))) -// #define WAKE_TIME_RANGE (((wake_time_hour < sleep_time_hour) && \ + // #define WAKE_TIME_RANGE (((wake_time_hour < sleep_time_hour) && \ // ((curTime.tm_hour > wake_time_hour) || \ // (curTime.tm_hour == wake_time_hour && curTime.tm_min >= wake_time_min)) && \ // ((curTime.tm_hour < sleep_time_hour) || \ @@ -152,11 +153,11 @@ extern "C" } } - static bool is_time_range(struct tm &curTime,int start_time_hour,int start_time_min,int end_time_hour,int end_time_min) + static bool is_time_range(struct tm &curTime, int start_time_hour, int start_time_min, int end_time_hour, int end_time_min) { - int start_min = start_time_hour * 60 + start_time_min; /* 开始时间的分钟数 */ - int end_min = end_time_hour * 60 + end_time_min; /* 结束时间的分钟数 */ - int cur_time_min = curTime.tm_hour * 60 + curTime.tm_min; /* 当前时间的分钟数 */ + int start_min = start_time_hour * 60 + start_time_min; /* 开始时间的分钟数 */ + int end_min = end_time_hour * 60 + end_time_min; /* 结束时间的分钟数 */ + int cur_time_min = curTime.tm_hour * 60 + curTime.tm_min; /* 当前时间的分钟数 */ // 处理非跨天的情况 if (end_min > start_min) @@ -383,7 +384,19 @@ extern "C" g_alarmCtrB.callback(); } } - + // 开始校验文件 + if (uapi_dev_runtime_get_checkres_status() == 1) + { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::SafeModeManagerModel::updatecheckview,OHOS::SafeModeManagerModel::GetInstance(), curTime.tm_sec)); + } + // 校验成功 + else if (uapi_dev_runtime_get_checkres_status() == 2) + { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::SafeModeManagerModel::updatecheckview, OHOS::SafeModeManagerModel::GetInstance(), 61)); + uapi_dev_runtime_set_checkres_status(0); + } // 未绑定状态下,以下操作不进行 if (OHOS::ConfigModel::GetInstance()->get_configData_bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_FIRSTTIMESTART)) return; @@ -412,12 +425,12 @@ extern "C" } } // 退出睡眠检测模式并进入小睡检测模式 - 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)) + 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)) { // uapi_dev_runtime_set_sleep_status(0); // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); - 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); + 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); if (curTime.tm_hour == wake_time_hour && curTime.tm_min == wake_time_min && curTime.tm_sec == 0) { @@ -433,26 +446,26 @@ extern "C" if (uapi_dev_runtime_get_sleep_status() == 0) { // 设置状态为小睡 - uapi_dev_runtime_set_nap_status(0); // 清零小睡状态 + uapi_dev_runtime_set_nap_status(0); // 清零小睡状态 uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态 uapi_dev_runtime_set_nap_monitoring_status(1); uapi_dev_runtime_set_sleep_monitoring_status(0); OHOS::SleepModel::GetInstance().ReInitData(); // 更新睡眠数据 - set_keep_in_wear_det_mode(1); //开启小睡佩戴监测 + set_keep_in_wear_det_mode(1); // 开启小睡佩戴监测 SendMsgToUIService(UI_UPDATE_SLEEP_DATA, 0, nullptr, 0); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); // 算法底层切换小睡监测模式 } } // 进入睡眠检测模式并退出小睡检测模式 - 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)) + 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)) { int cmd = 1; - uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态 + uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态 uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态 - OHOS::clean_sleep_data(); // 清零睡眠文件存储数据 + OHOS::clean_sleep_data(); // 清零睡眠文件存储数据 uapi_dev_runtime_set_sleep_monitoring_status(1); uapi_dev_runtime_set_nap_monitoring_status(0); - set_keep_in_wear_det_mode(0); //关闭小睡佩戴监测 + set_keep_in_wear_det_mode(0); // 关闭小睡佩戴监测 do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); // 强制获取小睡数据,结束小睡 // 睡眠弹窗 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "要睡觉啦!"); @@ -472,12 +485,12 @@ extern "C" // 久坐提醒 if (sedentary_switch) { - if (is_time_range(curTime,sedentary_start_hour,sedentary_start_min,sedentary_stop_hour,sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 0)) + if (is_time_range(curTime, sedentary_start_hour, sedentary_start_min, sedentary_stop_hour, sedentary_stop_min) && (uapi_dev_runtime_get_sedentary_status() == 0)) { uapi_dev_runtime_set_sedentary_status(1); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_SEDENTARY, NULL); } - 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)) + 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)) { uapi_dev_runtime_set_sedentary_status(0); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_SEDENTARY, NULL); @@ -501,7 +514,7 @@ extern "C" else if (drinkreminder_switch == 2) { // 判断当前时间是否在提醒时间段内 - if (is_time_range(curTime,drinkreminder_start_hour,drinkreminder_start_min,drinkreminder_end_hour,drinkreminder_end_min)) + if (is_time_range(curTime, drinkreminder_start_hour, drinkreminder_start_min, drinkreminder_end_hour, drinkreminder_end_min)) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " curTime.tm_sec = %d", curTime.tm_sec); double interval_time = (drinkreminder_freq == 0) ? 0.5 : drinkreminder_freq; // 频率设置 @@ -535,7 +548,7 @@ extern "C" } } } - 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) + 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) { uapi_dev_runtime_set_drinkremind_status(0); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index 5f0a7d645..027102b55 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -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 index 000000000..dddc9efad --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/ResourceCheckView.h @@ -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 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 476963174..726c6088a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h @@ -10,21 +10,44 @@ #include #include +#include +#include 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 &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 resource_check_files; // 存储检查的资源文件列表 + + // 初始化状态与操作的映射 + void InitializeStateActions(); }; -} + +} // namespace OHOS #endif // SAFE_MODE_MANAGER_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h index 0de6463bf..4af100635 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h @@ -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 { 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 index 000000000..1ad3d94d9 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/ResourceCheckView.cpp @@ -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(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 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 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 d491231c3..8c033bf18 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp @@ -2,13 +2,24 @@ #include #include #include +#include +#include + #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 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(state); + if (index < stateActions.size()) { + stateActions[index] = executeAction; + } + } + + // 获取指定类状态 + bool SafeModeManagerModel::IsState(Safe_State state) const { + auto index = static_cast(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 &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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp index 722d09715..614b3bcd7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerPresenter.cpp @@ -11,25 +11,25 @@ #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) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp index 130955dfd..e9d65a42f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp @@ -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_); } diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp index 601d64e79..f49a60e60 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/NativeAbility.cpp @@ -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 diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index 4081cd793..0fd459f3e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -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; diff --git a/code/sdk/drivers/peripheral/utils/custom_resfile_check.c b/code/sdk/drivers/peripheral/utils/custom_resfile_check.c index 761f207c1..64a720ba5 100644 --- a/code/sdk/drivers/peripheral/utils/custom_resfile_check.c +++ b/code/sdk/drivers/peripheral/utils/custom_resfile_check.c @@ -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 diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index eaf42f095..7bba0bfa6 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -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) { diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 35416d87e..8d2880b1b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -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); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 54ec4014e..b1b44ede0 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -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,