系统:增加死机文件名称列表的日志
authorCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 07:35:51 +0000 (15:35 +0800)
committerCaisking <3449750381@qq.com>
Tue, 8 Oct 2024 07:35:51 +0000 (15:35 +0800)
code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp

index 0d270bc..b7f828a 100644 (file)
@@ -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();
index 71a1fb3..b82b3de 100644 (file)
 #include "vibrator_service.h"
 #include "wearable_log.h"
 #include <array>
+
 #include <cmsis_os2.h>
 #include <cstdint>
 #include <custom_runtime.h>
 #include <custom_utils.h>
+#include <dirent.h>
 #include <fstream>
 #include <iomanip>
 #include <iostream>
@@ -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;