From 108aa4d44ffaee982e5817de27e64db5ec62100e Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 15:35:51 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E6=AD=BB=E6=9C=BA=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E5=88=97?= =?utf8?q?=E8=A1=A8=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../debug_output_notification.h | 1 + .../debug_output_notification.cpp | 36 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) 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