From 512999efd1cc8e8c4d982a0c04aa452395f1b450 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 5 Nov 2024 16:47:43 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E7=9D=A1=E7=9C=A0=E6=96=87=E4=BB=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../debug_output_notification.cpp | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) 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 6fedbaa32..4af0518bc 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 @@ -136,7 +136,7 @@ namespace OHOS // 死机文件列表 debugOutputItemInfo[index++] = {index, "shutdown_file_list"}; // 睡眠数据 - debugOutputItemInfo[index++] = {index, "sleep_time"}; + debugOutputItemInfo[index++] = {index, "sleep_data"}; // 系统空闲内存 debugOutputItemInfo[index++] = {index, "system_free_memory"}; // nextday执行日志 @@ -400,18 +400,54 @@ namespace OHOS return oss.str(); // 返回以换行符分隔的文件名字符串 } - // 获取睡眠时间戳 - std::string DebugOutputViewEventListener::get_sleep_time(void) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_sleep_time"); - do_custom_fileoperate_service_check_msg( - CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, nullptr, 0); - LOS_Msleep(100); - std::string result = "asleep_time:" + get_sleep_asleep_time_str() + " "; - result += "wake_time:" + get_sleep_wake_time_str() + " "; - return result; - } + // 获取睡眠数据 + static const char *SLEEP_DATA_PATH = "/user/userdata/sleep"; + // 获取睡眠数据 + std::string DebugOutputViewEventListener::get_sleep_time(void) { + std::string result; + uint8_t falg = 0; + result += "--------------------\n"; + // 进行文件读取 + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, nullptr, 0); + LOS_Msleep(100); // 等待文件系统准备 + // 打开目录 + DIR *dir = opendir(SLEEP_DATA_PATH); + if (dir == NULL) { + // 如果失败,打印错误信息 + perror("Error opening directory"); + return "目前无睡眠数据"; + } + + struct dirent *entry; // 结构体用于存放目录项信息 + while ((entry = readdir(dir)) != NULL) { + // 忽略当前目录和父目录 + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { + // 检查文件类型是否为普通文件 + if (entry->d_type == DT_REG) { + // 获取文件名并添加到结果中 + result += entry->d_name; + result += "\n"; // 添加换行符以分隔文件名 + falg = 1; + } + } + } + + // 关闭目录 + closedir(dir); + if(falg == 0) { + result += "目录没有文件\n"; + } + + result += "--------------------\n"; + + // 获取当天最新的入睡与醒来时间 + result += "asleep_time: " + get_sleep_asleep_time_str() + " "; + result += "wake_time: " + get_sleep_wake_time_str() + " "; + + return result; // 返回结果字符串 + } // 获取系统free内存 std::string DebugOutputViewEventListener::get_free_memory() { @@ -574,6 +610,7 @@ namespace OHOS get_vote_status(buf); return std::string(buf); } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); -- 2.17.1