From 4f61199ea83aa3a45f6f49e50d13aa4e2e9bbdcc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Tue, 8 Oct 2024 08:13:21 +0000 Subject: [PATCH] Merge #1125 into sdk602patch0626 from refs/changes/1125/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/1125/head: (3 commits squashed) - 系统:安全模式增加手表蓝牙名称,版本号,固件版本等相关信息 - 系统:增加死机文件名称列表的日志 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1125 --- .../include/SafeModeManagerModel.h | 5 + .../include/SafeModeManagerView.h | 44 ++++- .../src/SafeModeManagerModel.cpp | 42 ++++- .../src/SafeModeManagerView.cpp | 158 ++++++++---------- .../debug_output_notification.h | 1 + .../debug_output_notification.cpp | 36 +++- 6 files changed, 187 insertions(+), 99 deletions(-) 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 663967e7a..ea7b45279 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h @@ -100,6 +100,11 @@ public: // 输出当前状态 void PrintState() const; + /* ---------------------------------- 手表信息 + * ---------------------------------- */ + std::string get_voltage_and_version_string(); + std::string get_bluetooth_name(); + private: SafeModeManagerModel() = default; // 默认构造函数 ~SafeModeManagerModel() = default; // 默认析构函数 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 3a9617033..7c926bc56 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h @@ -28,6 +28,37 @@ typedef enum { MAX_VIEW_ID, // Maximum View ID } SafeViewID; +// 定义结构体用于位置设置 +struct Position { + int x; + int y; +}; + +// 初始化背景项及其位置 +struct BackgroundItem { + UIImageView *background; + Position position; +}; +// 定义按钮 +struct ButtonItem { + UIToggleButton *button; + Position position; + const char *viewId; +}; + +// 定义功能状态标签 +struct StatusLabelItem { + UILabel *label; + std::string text; + Position position; +}; + +struct SafeViewItem { + BackgroundItem background; + ButtonItem button; + StatusLabelItem statusLabel; +}; + class SafeModeManagerPresenter; class ResourceCheckView; @@ -71,7 +102,8 @@ private: SafeModeManagerView &operator=(SafeModeManagerView &&) = delete; // UI Components - UILabelExt labelTitle_; // Title Label + UILabel labelTitle_; // Title Label + UILabel labelInfo_; // Background Images for Features UIImageView backgroundBLE_; // BLE OTA Background Image @@ -88,11 +120,11 @@ private: UIToggleButton btnRestart_; // Restart Toggle Button // Status Labels - UILabelExt labelBLEStatus_; // BLE OTA Status Label - UILabelExt labelAutoOTAStatus_; // Auto OTA Status Label - UILabelExt labelFactoryResetStatus_; // Factory Reset Status Label - UILabelExt labelResourceCheckStatus_; // Resource Check Status Label - UILabelExt labelRestart_; // Restart Status Label + UILabel labelBLEStatus_; // BLE OTA Status Label + UILabel labelAutoOTAStatus_; // Auto OTA Status Label + UILabel labelFactoryResetStatus_; // Factory Reset Status Label + UILabel labelResourceCheckStatus_; // Resource Check Status Label + UILabel labelRestart_; // Restart Status Label UIScrollView *SafeModeScrollView[MAX_VIEW_ID]{nullptr}; }; 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 cf361c63b..2c2fb8948 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp @@ -19,16 +19,29 @@ #include "custom_runtime.h" #include "custom_utils.h" #include "graphic_service.h" +#include "iostream" #include "lwip/apps/http_client.h" +#include "string" #include "tcxo.h" #include "thread_adapter.h" #include "thread_init.h" +#include "ui_resource_string.h" #include "wearable_log.h" +#include +#include +#include +#include -extern "C" bool resfile_checksum_thread(void); extern "C" { #include "build_version.h" const char *get_version_string(void); + +#include "battery_hal.h" +#include "build_version.h" +extern uint8_t battery_get_voltage(float *voltage); +const char *get_version_string(void); + +bool resfile_checksum_thread(void); } static const char *CHECK_DIFFERENTIAL_FILE = "/system/check_differential.txt"; @@ -410,4 +423,31 @@ void SafeModeManagerModel::UpdateSginOperate() { } } } + +//手表信息 +std::string SafeModeManagerModel::get_voltage_and_version_string(void) { + // 电量 + float voltage = 0.0F; + uint8_t value = battery_get_voltage(&voltage); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value); + + // 版本号 + std::string version_string = + std::string("V") + get_version_string(); // 修正字符串拼接 + + // 拼接字符串 + std::ostringstream oss; + oss << "bat: " << static_cast(value) << "% " << version_string; + + return oss.str(); +} + +// 蓝牙名称 +std::string SafeModeManagerModel::get_bluetooth_name(void) { + uint8_t ble_name[30] = {0}; + uint32_t ble_name_len = sizeof(ble_name); + errcode_t ret = uapi_get_nv_btname(ble_name, &ble_name_len); + + return std::string(reinterpret_cast(ble_name)); +} } // namespace OHOS \ No newline at end of file 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 60b4f27ca..fb2c4ce06 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp @@ -54,11 +54,12 @@ SafeModeManagerView *SafeModeManagerView::GetInstance() { } void SafeModeManagerView::InitView() { + // 初始化 SafeModeScrollView if (SafeModeScrollView[VIEW_SAFE_LIST] == nullptr) { SafeModeScrollView[VIEW_SAFE_LIST] = new UIScrollView(); if (SafeModeScrollView[VIEW_SAFE_LIST] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "SafeModeScrollView[VIEW_SAFE_LIST] new fail"); + "SafeModeScrollView[VIEW_SAFE_LIST] new fail"); return; } SafeModeScrollView[VIEW_SAFE_LIST]->SetScrollBlankSize(35); @@ -70,104 +71,83 @@ void SafeModeManagerView::InitView() { SafeModeScrollView[VIEW_SAFE_LIST]->SetOnDragListener(presenter_); SafeModeScrollView[VIEW_SAFE_LIST]->SetTouchable(true); SafeModeScrollView[VIEW_SAFE_LIST]->SetDraggable(true); - SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_COLOR, - BACK_GROUND_COLOR); SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); } - // 初始化背景图和按钮的位置 - backgroundBLE_.SetPosition(43, 120, 380, 100); // BLE OTA 背景 - backgroundBLE_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundBLE_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundBLE_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundBLE_); - - backgroundAutoOTA_.SetPosition(43, 240, 380, 100); // Auto OTA 背景 - backgroundAutoOTA_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundAutoOTA_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundAutoOTA_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundAutoOTA_); - - backgroundFactoryReset_.SetPosition(43, 360, 380, 100); // 恢复出厂设置背景 - backgroundFactoryReset_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundFactoryReset_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundFactoryReset_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundFactoryReset_); - - backgroundResourceCheck_.SetPosition(43, 480, 380, 100); // 资源校验背景 - backgroundResourceCheck_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundResourceCheck_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundResourceCheck_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundResourceCheck_); - - backgroundRestart_.SetPosition(43, 600, 380, 100); // 资源校验背景 - backgroundRestart_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundRestart_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundRestart_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundRestart_); - + // 初始化标题 labelTitle_.SetPosition(83, 50, 300, 60); labelTitle_.SetFont(GILROY_BOLD_FONT, 30); labelTitle_.SetText("Safe Mode"); - labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); // 居中 + labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); labelTitle_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelTitle_); - // 设置四个功能状态标签 - labelBLEStatus_.SetPosition(90, 153, 200, 60); - labelBLEStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelBLEStatus_.SetText("BLE OTA"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelBLEStatus_); - - labelAutoOTAStatus_.SetPosition(90, 273, 200, 60); - labelAutoOTAStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelAutoOTAStatus_.SetText("Auto OTA"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelAutoOTAStatus_); - - labelFactoryResetStatus_.SetPosition(90, 393, 200, 60); - labelFactoryResetStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelFactoryResetStatus_.SetText("Factory Reset"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelFactoryResetStatus_); - - labelResourceCheckStatus_.SetPosition(90, 513, 200, 60); - labelResourceCheckStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelResourceCheckStatus_.SetText("Resource Check"); - labelResourceCheckStatus_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - labelResourceCheckStatus_.SetAlign(TEXT_ALIGNMENT_CENTER); - labelResourceCheckStatus_.SetRollSpeed(30); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelResourceCheckStatus_); - - labelRestart_.SetPosition(90, 633, 200, 60); - labelRestart_.SetFont(GILROY_BOLD_FONT, 30); - labelRestart_.SetText("Restart"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelRestart_); - - // 设置四个切换按钮 - btnBLE_.SetPosition(245, 120, 200, 100); // BLE OTA 切换按钮 - btnBLE_.SetViewId(BLE_OTA); // 设置按钮的ViewId - btnBLE_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnBLE_); - - btnAutoOTA_.SetPosition(245, 240, 200, 100); // Auto OTA 切换按钮 - btnAutoOTA_.SetViewId(AUTO_OTA); // 设置按钮的ViewId - btnAutoOTA_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnAutoOTA_); - - btnFactoryReset_.SetPosition(245, 360, 200, 100); // 恢复出厂设置切换按钮 - btnFactoryReset_.SetViewId(FACTORY_RESET_SAFE); // 设置按钮的ViewId - btnFactoryReset_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnFactoryReset_); - - btnResourceCheck_.SetPosition(245, 480, 200, 100); // 资源校验切换按钮 - btnResourceCheck_.SetViewId(RESOURCE_CHECK); // 设置按钮的ViewId - btnResourceCheck_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnResourceCheck_); - - btnRestart_.SetPosition(245, 600, 200, 100); // 资源校验切换按钮 - btnRestart_.SetViewId(RE_START); // 设置按钮的ViewId - btnRestart_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnRestart_); + // 初始化信息标签 + std::string infostr = + SafeModeManagerModel::GetInstance()->get_voltage_and_version_string() + + "\n" + SafeModeManagerModel::GetInstance()->get_bluetooth_name(); + labelInfo_.SetPosition(43, 100, 380, 60); + labelInfo_.SetFont(GILROY_BOLD_FONT, 26); + labelInfo_.SetText(infostr.c_str()); + labelInfo_.SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelInfo_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelInfo_); + + // 定义安全视图项 + SafeViewItem safeItems[] = { + {{&backgroundBLE_, {43, 120}}, + {&btnBLE_, {245, 120}, BLE_OTA}, + {&labelBLEStatus_, "BLE OTA", {90, 153}}}, + {{&backgroundAutoOTA_, {43, 0}}, + {&btnAutoOTA_, {245, 0}, AUTO_OTA}, + {&labelAutoOTAStatus_, "Auto OTA", {90, 0}}}, + {{&backgroundFactoryReset_, {43, 0}}, + {&btnFactoryReset_, {245, 0}, FACTORY_RESET_SAFE}, + {&labelFactoryResetStatus_, "Factory Reset", {90, 0}}}, + {{&backgroundResourceCheck_, {43, 0}}, + {&btnResourceCheck_, {245, 0}, RESOURCE_CHECK}, + {&labelResourceCheckStatus_, "Resource Check", {90, 0}}}, + {{&backgroundRestart_, {43, 0}}, + {&btnRestart_, {245, 0}, RE_START}, + {&labelRestart_, "Restart", {90, 0}}}}; + + // 初始 Y 坐标 + int initialY = 180; + int itemHeight = 120; // 每个 item 的高度,包括背景和按钮的高度 + + // 遍历安全视图项并设置UI元素 + for (const auto &item : safeItems) { + // 设置背景 + item.background.background->SetPosition(item.background.position.x, + initialY, 380, 100); + item.background.background->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + item.background.background->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + item.background.background->SetStyle(STYLE_BORDER_RADIUS, 100); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.background.background); + + // 设置状态标签 + item.statusLabel.label->SetPosition(item.statusLabel.position.x, + initialY + 33, 200, 60); + item.statusLabel.label->SetFont(GILROY_BOLD_FONT, 30); + item.statusLabel.label->SetText(item.statusLabel.text.c_str()); + if (item.statusLabel.text == "Resource Check") { + item.statusLabel.label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + item.statusLabel.label->SetAlign(TEXT_ALIGNMENT_CENTER); + item.statusLabel.label->SetRollSpeed(30); + } + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.statusLabel.label); + + // 设置按钮 + item.button.button->SetPosition(item.button.position.x, initialY, 200, 100); + item.button.button->SetViewId(item.button.viewId); + item.button.button->SetOnClickListener(presenter_); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.button.button); + + // 更新 Y 坐标 + initialY += itemHeight; + } } /* -------------------------------------------------------------------------- */ // 主视图 diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index 0d270bc7f..b7f828a25 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -38,6 +38,7 @@ namespace OHOS std::string get_runtime_status_t(void); std::string get_system_log(void); std::string get_battery_info(void); + std::string get_shutdown_info(void); private: DebugOutputViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 71a1fb3f0..b82b3de92 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -27,10 +27,12 @@ #include "vibrator_service.h" #include "wearable_log.h" #include + #include #include #include #include +#include #include #include #include @@ -77,6 +79,8 @@ namespace OHOS debugOutputItemInfo[index++] = {4, "system_log"}; //电池服务 debugOutputItemInfo[index++] = {5, "battery_service"}; + //死机文件列表 + debugOutputItemInfo[index++] = {6, "shutdown_file_list"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -247,10 +251,9 @@ namespace OHOS str << "[" << timestr << "] "<< "\n"; // 拼接日志内容 } - return str.str(); // 返回拼接后的字符串 + return str.str(); // 返回拼接后的字符串 } - - + // 获取电池相关信息 std::string DebugOutputViewEventListener::get_battery_info() { // 获取电池温度 @@ -281,6 +284,30 @@ namespace OHOS return oss.str(); } + + // 死机文件名称列表 + static const char *SHUTDOWN_PATH = "/user/tar"; + std::string DebugOutputViewEventListener::get_shutdown_info() { + std::ostringstream oss; + + // 打开目录 + DIR *dir = opendir(SHUTDOWN_PATH); + if (dir == nullptr) { + return "死机目录不存在或者目录下不存在文件"; + } + + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) { + // 跳过. 和 .. + if (entry->d_name[0] != '.') { + oss << entry->d_name << "\n"; // 逐行添加 + } + } + + closedir(dir); // 关闭目录 + return oss.str(); // 返回以换行符分隔的文件名字符串 + } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); @@ -331,6 +358,9 @@ namespace OHOS case 5: str = get_battery_info(); break; + case 6: + str = get_shutdown_info(); + break; default: str = "--"; break; -- 2.17.1