From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 07:35:51 +0000 (+0800) Subject: 系统:增加死机文件名称列表的日志 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=108aa4d44ffaee982e5817de27e64db5ec62100e;p=mirrors%2FFD230.git 系统:增加死机文件名称列表的日志 --- 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;