From: Caisking <3449750381@qq.com> Date: Tue, 5 Nov 2024 08:47:43 +0000 (+0800) Subject: 系统:增加睡眠文件显示 X-Git-Tag: fd230_release_V1.3.102~29^2~49^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F1344%2F1;p=mirrors%2FFD230.git 系统:增加睡眠文件显示 --- 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();