From: luozheng <1732036298@qq.com> Date: Sat, 19 Oct 2024 03:03:38 +0000 (+0800) Subject: #1042 手表,增加部分弹窗的状态监控 X-Git-Tag: release_V1.2.70_20241020_135402~5^2~8 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=661c4545e1fb82f7285c38268e0328ade10aa24b;p=mirrors%2FFD230.git #1042 手表,增加部分弹窗的状态监控 --- diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 4a88ed348..04c93af49 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -581,6 +581,8 @@ namespace OHOS SystemLogModel::GetInstance()->saveLog(systemlog); // 读取nextday日志 SystemLogModel::GetInstance()->load_nextday_log(); + // 读取popup_windows日志 + SystemLogModel::GetInstance()->load_popup_windows_log(); } void NativeLauncher::InitAllNativeSlices(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h index b063fabab..4b7147b4c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h @@ -22,6 +22,17 @@ struct SystemLogData { uint32_t timestamp; // 时间戳 }; +enum class popup_windows_type // 弹窗类型 +{ + MOTION_RECOGNITION = 0, // 运动识别 + DRINK_WATER_REMINDER, // 喝水提醒 + SEDENTARY_REMINDER, // 久坐提醒 +}; + +struct popup_windows_log_data { + popup_windows_type type; // 弹窗类型 + uint32_t timestamp; // 时间戳 +}; class SystemLogModel { public: // 获取单例实例 @@ -40,6 +51,14 @@ public: bool load_nextday_log(); // 加载nextday日志 const std::deque &get_nextday_log() const; // 获取nextday日志记录(常量引用) size_t get_nextday_log_size() const;//获取日志大小 + /* ------------------------------ popup_windows 日志记录----------------------------- */ + bool save_popup_windows_log(popup_windows_log_data data); // 保存popup_windows日志 + bool load_popup_windows_log(); // 加载popup_windows日志 + const std::deque &get_popup_windows_log() const; // 获取popup_windows日志记录(常量引用) + size_t get_popup_windows_log_size() const; // 获取日志大小 + void clear_popup_windows_log(); // 清空popup_windows日志记录 + + private: SystemLogModel() = default; // 私有构造函数 ~SystemLogModel() = default; // 默认析构函数 @@ -50,6 +69,7 @@ private: std::deque logData; // 存储日志数据 std::deque nextday_log; // 存储nextday时间戳 + std::deque popup_windows_log; // 存储popup_windows时间戳 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h index 48a9e15ca..ef40e5481 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h @@ -13,6 +13,7 @@ void stop_report_log(void); void resume_report_log(void); void update_version_report_log(void); void start_report_nextday_log(void); +void nextday_clear_popup_windows_log(void); #ifdef __cplusplus diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp index 6602fcd8e..e3ef04476 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp @@ -25,6 +25,7 @@ #define SYSTEM_LOG_FILE_PATH "/system/system_log.txt" #define SYSTEM_LOG_FILE_PATH_NEXTDAY "/system/system_log_nextday.txt" +#define SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS "/system/popup_windows_log.txt" extern "C" { // 通用日志记录功能 @@ -56,6 +57,10 @@ void start_report_nextday_log(void) { uint32_t timestamp = OHOS::SystemLogModel::GetInstance()->GetCurrentTime(); OHOS::SystemLogModel::GetInstance()->save_nextday_log(timestamp); } +// 清空popup_windows日志 +void nextday_clear_popup_windows_log(void) { + OHOS::SystemLogModel::GetInstance()->clear_popup_windows_log(); +} } namespace OHOS { @@ -226,4 +231,70 @@ size_t SystemLogModel::get_nextday_log_size() const { return nextday_log.size(); } +// 保存popup_windows日志 +bool SystemLogModel::save_popup_windows_log(popup_windows_log_data data) +{ + // 保存新日志 + popup_windows_log.push_back(data); + + // 将日志写入文件 + std::ofstream outFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS, std::ios::app); + if (!outFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for writing"); + return false; // 文件打开失败 + } + + // 将结构体中的数据转换为字符串格式写入文件 + outFile << static_cast(data.type) << " " << data.timestamp << std::endl; + outFile.close(); + return true; +} + +bool SystemLogModel::load_popup_windows_log() +{ + std::ifstream inFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS); + if (!inFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for reading"); + return false; // 无法打开文件 + } + + std::string line; + while (std::getline(inFile, line)) { + std::istringstream ss(line); + popup_windows_log_data data; + int typeInt; + if (ss >> typeInt >> data.timestamp) { + data.type = static_cast(typeInt); + popup_windows_log.push_back(data); + } + } + + inFile.close(); + return true; +} +// 获取popup_windows日志记录(常量引用) +const std::deque &SystemLogModel::get_popup_windows_log() const +{ + return popup_windows_log; +} +// 获取日志大小 +size_t SystemLogModel::get_popup_windows_log_size() const +{ + return popup_windows_log.size(); +} + +void SystemLogModel::clear_popup_windows_log() +{ + // 清空当前的日志 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clear_popup_windows_log"); + popup_windows_log.clear(); + + std::ofstream outFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS, std::ios::trunc); + if (!outFile) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open log file for writing"); + return; + } + outFile<<""; + outFile.close(); +} } // namespace OHOS 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 821a4d392..7d4eaefe0 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 @@ -1,8 +1,8 @@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-10-02 14:12:12 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-10-08 16:29:19 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-18 18:45:48 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification.h */ #ifndef DEBUG_OUTPUT_NOTIFICATION_H @@ -42,6 +42,7 @@ namespace OHOS std::string get_sleep_time(void); std::string get_free_memory(void); std::string get_nextday_log(void); + std::string get_popup_windows_log(void); private: DebugOutputViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/drinkReminder_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/drinkReminder_notification.h index f9c7bd019..f22fa7c49 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/drinkReminder_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/drinkReminder_notification.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-18 11:46:35 + * @LastEditTime: 2024-10-18 20:23:42 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/drinkReminder_notification.h */ #ifndef DRINKREMINDER_NOTIFICATION @@ -24,6 +24,8 @@ namespace OHOS void set_screen_on_and_vibration(void); + void record_drink_reminder_log(void); + private: DrinkReminderViewEventListener(); ~DrinkReminderViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/motion_recognition_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/motion_recognition_notification.h index 02c9d2e41..788526307 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/motion_recognition_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/motion_recognition_notification.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-17 16:43:46 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-19 11:00:50 + * @LastEditTime: 2024-10-18 20:25:34 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/motion_recognition_notification.h */ @@ -29,6 +29,8 @@ namespace OHOS int GetMotionType(void); UIResourceTextId GetMotionTypeTextId(void); + void record_motion_recognition_log(void); + private: MotionRecognitionViewEventListener(); ~MotionRecognitionViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h index b8e680b83..a0ec8e2b4 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-29 11:15:23 + * @LastEditTime: 2024-10-18 20:29:35 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h */ #ifndef SEDENTARYREMINDER_NOTIFICATION @@ -24,6 +24,8 @@ namespace OHOS bool OnDragEnd(UIView &view, const DragEvent &event) override; void SetSedentaryReminderNoteIntervalTime(int interval); int GetIntervalTime(); + + void record_sedentary_reminder_log(void); private: SedentaryReminderViewEventListener(); ~SedentaryReminderViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 11c08bf7b..139cc4896 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -603,6 +603,8 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) // 存储nextday执行日志 start_report_nextday_log(); + // 清除popup_windows日志 + nextday_clear_popup_windows_log(); printf("******nextday is end******\r\n"); #endif @@ -1247,6 +1249,7 @@ void MsgCenterNotifyDrinkReminderProc(const Topic topic, Request *req) unused(req); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyDrinkReminderProc !"); // DrinkReminderViewEventListener::GetInstance().set_screen_on_and_vibration(); + DrinkReminderViewEventListener::GetInstance().record_drink_reminder_log(); if (CheckPriority(topic)) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); @@ -1351,6 +1354,7 @@ void MsgCenterNotifyArAlertProc(const Topic topic, Request* req) { uint8_t* motionType=(uint8_t*)req->data; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyArAlertProc,motionType = %d !",*motionType); + MotionRecognitionViewEventListener::GetInstance().record_motion_recognition_log(); if(*motionType > 5 || *motionType <1) //未知运动不弹窗 { return; @@ -1404,6 +1408,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) case INACTIVITY_MODE_SEDENTARY_OUTPUT: if(cywee_Inactivity_Info->status == 1) { + SedentaryReminderViewEventListener::GetInstance().record_sedentary_reminder_log(); if (CheckPriority(topic)) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); 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 134d2c358..299c9969b 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 @@ -76,22 +76,24 @@ namespace OHOS void DebugOutputViewEventListener::InitDebugOutputItem() { int index = 0; - debugOutputItemInfo[index++] = {0, "exit"}; // 标题:设置() - debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"}; - debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"}; - debugOutputItemInfo[index++] = {3, "runtime_status_t"}; - //系统日志 - debugOutputItemInfo[index++] = {4, "system_log"}; - //电池服务 - debugOutputItemInfo[index++] = {5, "battery_service"}; - //死机文件列表 - debugOutputItemInfo[index++] = {6, "shutdown_file_list"}; - //睡眠数据 - debugOutputItemInfo[index++] = {7, "sleep_time"}; - //系统空闲内存 - debugOutputItemInfo[index++] = {8, "system_free_memory"}; + debugOutputItemInfo[index++] = {index, "exit"}; // 标题:设置() + debugOutputItemInfo[index++] = {index, "bt_ble_connectstat"}; + debugOutputItemInfo[index++] = {index, "cat1_runtime_status_t"}; + debugOutputItemInfo[index++] = {index, "runtime_status_t"}; + // 系统日志 + debugOutputItemInfo[index++] = {index, "system_log"}; + // 电池服务 + debugOutputItemInfo[index++] = {index, "battery_service"}; + // 死机文件列表 + debugOutputItemInfo[index++] = {index, "shutdown_file_list"}; + // 睡眠数据 + debugOutputItemInfo[index++] = {index, "sleep_time"}; + // 系统空闲内存 + debugOutputItemInfo[index++] = {index, "system_free_memory"}; // nextday执行日志 - debugOutputItemInfo[index++] = {9, "nextday_log"}; + debugOutputItemInfo[index++] = {index, "nextday_log"}; + // 弹窗日志 + debugOutputItemInfo[index++] = {index, "popup_windows_log"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -123,7 +125,7 @@ namespace OHOS char *buf_btaddr = (char *)malloc(32); if (buf_btaddr == NULL) return ""; - memset_s(buf_btaddr,32,0,32); + memset_s(buf_btaddr, 32, 0, 32); uint8_t ret = uapi_get_btaddr((uint8_t *)buf_btaddr, &len); std::string str = std::string(buf_btaddr); printf("%s | %s \n", buf_btaddr, str.c_str()); @@ -131,17 +133,16 @@ namespace OHOS return (str); } - static std::string getCurrentWatchadvdata() + static std::string getCurrentWatchadvdata() { uint32_t len = 64; char *buf_advdata = (char *)malloc(len); if (buf_advdata == NULL) return ""; - memset_s(buf_advdata,64,0,64); + memset_s(buf_advdata, 64, 0, 64); get_adv_data(buf_advdata); - std::string str = std::string(buf_advdata); printf("%s | %s \n", buf_advdata, str.c_str()); @@ -149,8 +150,6 @@ namespace OHOS return (str); } - - std::string DebugOutputViewEventListener::get_bt_runtime_status_t(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_bt_runtime_status_t"); @@ -160,7 +159,7 @@ namespace OHOS result += "bt_earphone_connectstat:" + std::to_string(uapi_dev_runtime_get_earphone_connect_stat()) + " "; result += "android_app_connected:" + std::to_string(get_ble_pair()) + " "; result += "localAddress:" + (getCurrentWatchMacAddress()) + " "; -result += "advdata:" + (getCurrentWatchadvdata()) + " "; + result += "advdata:" + (getCurrentWatchadvdata()) + " "; result += "ble广播状态:" + std::to_string(get_ble_adv_status()); // 蓝牙ble广播开关,基础信息如,地址,广播状态 @@ -214,150 +213,156 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; result += "lock_flag_training:" + std::to_string(uapi_dev_runtime_get_train_storage_status()) + " "; result += "lock_flag_heartrate:" + std::to_string(uapi_dev_runtime_get_heartrate_storage_status()) + " "; result += "lock_flag_blood:" + std::to_string(uapi_dev_runtime_get_bloodoxygen_storage_status()) + " "; - result += "lock_flag_sleep:" + std::to_string(uapi_dev_runtime_get_sleep_storage_status()) + " ";; - result += "nap_monitoring_status:" + std::to_string(uapi_dev_runtime_get_nap_monitoring_status()) + " ";; - result += "nap_status:" + std::to_string(uapi_dev_runtime_get_nap_status()) + " ";; - result += "sleep_monitoring_status:" + std::to_string(uapi_dev_runtime_get_sleep_monitoring_status()) + " ";; - result += "sleep_status:" + std::to_string(uapi_dev_runtime_get_sleep_status()) + " ";; - result += "lock_flag_goal:" + std::to_string(uapi_dev_runtime_get_goal_storage_status()) + " ";; - result += "respiratory_training_status:" + std::to_string(uapi_dev_runtime_get_respiratory_training_status()) + " ";; - result += "heartrate_detect_status:" + std::to_string(uapi_dev_runtime_get_heartrate_detect_status()) + " ";; - result += "factory_test_status:" + std::to_string(uapi_dev_runtime_get_factory_test_status_flag()) + " ";; - result += "screen_always_on_status:" + std::to_string(uapi_dev_runtime_get_screen_always_on_status()) + " ";; + result += "lock_flag_sleep:" + std::to_string(uapi_dev_runtime_get_sleep_storage_status()) + " "; + result += "nap_monitoring_status:" + std::to_string(uapi_dev_runtime_get_nap_monitoring_status()) + " "; + result += "nap_status:" + std::to_string(uapi_dev_runtime_get_nap_status()) + " "; + result += "sleep_monitoring_status:" + std::to_string(uapi_dev_runtime_get_sleep_monitoring_status()) + " "; + result += "sleep_status:" + std::to_string(uapi_dev_runtime_get_sleep_status()) + " "; + result += "lock_flag_goal:" + std::to_string(uapi_dev_runtime_get_goal_storage_status()) + " "; + result += "respiratory_training_status:" + std::to_string(uapi_dev_runtime_get_respiratory_training_status()) + " "; + result += "heartrate_detect_status:" + std::to_string(uapi_dev_runtime_get_heartrate_detect_status()) + " "; + result += "factory_test_status:" + std::to_string(uapi_dev_runtime_get_factory_test_status_flag()) + " "; + result += "screen_always_on_status:" + std::to_string(uapi_dev_runtime_get_screen_always_on_status()) + " "; return result; } // 日志服务 - std::string DebugOutputViewEventListener::get_system_log() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log"); - - // 获取系统日志实例 - auto logModel = SystemLogModel::GetInstance(); - uint8_t logSize = logModel->getLogSize(); - if (logSize == 0) - { - return "目前没有日志"; - } - - std::deque systemlogs = logModel->getLogData(); - std::ostringstream str; - - for (int i = 0; i < logSize; i++) - { - // 处理日志类型 - switch (systemlogs[i].type) - { - case SystemLogType::POWER_ON: - str << "开机:"; - break; - case SystemLogType::POWER_OFF: - str << "关机:"; - break; - case SystemLogType::RESTART: - str << "重启:"; - break; - case SystemLogType::FACTORY_RESET: - str << "恢复出厂设置:"; - break; - case SystemLogType::SOFTWARE_UPDATE: - str << "软件更新:"; - break; - default: - str << "UNKNOWN:"; - break; - } - - // 格式化时间 - char labelTime[20]; - std::string timestr; - if (uapi_get_TIME_STR(systemlogs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) - { - timestr = "--"; - } - else - { - timestr = labelTime; - } - - str << "[" << timestr << "] "<< "\n"; // 拼接日志内容 - } + std::string DebugOutputViewEventListener::get_system_log() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log"); + + // 获取系统日志实例 + auto logModel = SystemLogModel::GetInstance(); + uint8_t logSize = logModel->getLogSize(); + if (logSize == 0) + { + return "目前没有日志"; + } + + std::deque systemlogs = logModel->getLogData(); + std::ostringstream str; + + for (int i = 0; i < logSize; i++) + { + // 处理日志类型 + switch (systemlogs[i].type) + { + case SystemLogType::POWER_ON: + str << "开机:"; + break; + case SystemLogType::POWER_OFF: + str << "关机:"; + break; + case SystemLogType::RESTART: + str << "重启:"; + break; + case SystemLogType::FACTORY_RESET: + str << "恢复出厂设置:"; + break; + case SystemLogType::SOFTWARE_UPDATE: + str << "软件更新:"; + break; + default: + str << "UNKNOWN:"; + break; + } + + // 格式化时间 + char labelTime[20]; + std::string timestr; + if (uapi_get_TIME_STR(systemlogs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + + str << "[" << timestr << "] " << "\n"; // 拼接日志内容 + } return str.str(); // 返回拼接后的字符串 } - + // 获取电池相关信息 - std::string DebugOutputViewEventListener::get_battery_info() { - // 获取电池温度 - float bat_temp = 0.0f; - batteryservice_get_battery_temp(&bat_temp); - - // 获取 PCB 温度 - float pcb_temp = 0.0f; - batteryservice_get_pcb_temp(&pcb_temp); - - // 获取电量 - float voltage = 0.0f; - uint8_t percent = batteryservice_get_voltage(&voltage); - - // 获取充电状态 - bool isCharging = get_charge_stat(); - - // 拼接字符串,并简化为保留两位小数 - std::ostringstream oss; - oss << std::fixed - << std::setprecision(2) // 设置为固定小数位,保留两位小数 - << "Bat Temp: " << bat_temp << " °C\n" - << "PCB Temp: " << pcb_temp << " °C\n" - << "Voltage: " << voltage << " V\n" - << "Percent: " << static_cast(percent) - << " %\n" - << "Charge: " << (isCharging ? "Yes" : "No"); - - return oss.str(); + std::string DebugOutputViewEventListener::get_battery_info() + { + // 获取电池温度 + float bat_temp = 0.0f; + batteryservice_get_battery_temp(&bat_temp); + + // 获取 PCB 温度 + float pcb_temp = 0.0f; + batteryservice_get_pcb_temp(&pcb_temp); + + // 获取电量 + float voltage = 0.0f; + uint8_t percent = batteryservice_get_voltage(&voltage); + + // 获取充电状态 + bool isCharging = get_charge_stat(); + + // 拼接字符串,并简化为保留两位小数 + std::ostringstream oss; + oss << std::fixed + << std::setprecision(2) // 设置为固定小数位,保留两位小数 + << "Bat Temp: " << bat_temp << " °C\n" + << "PCB Temp: " << pcb_temp << " °C\n" + << "Voltage: " << voltage << " V\n" + << "Percent: " << static_cast(percent) + << " %\n" + << "Charge: " << (isCharging ? "Yes" : "No"); + + return oss.str(); } - //获取死机列表 - static const char *SHUTDOWN_PATH = "/user/tar"; - std::string DebugOutputViewEventListener::get_shutdown_info() { - std::ostringstream oss; + // 获取死机列表 + 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 "死机目录不存在: " + std::string(strerror(errno)); - } + // 打开目录 + DIR *dir = opendir(SHUTDOWN_PATH); + if (dir == nullptr) + { + return "死机目录不存在: " + std::string(strerror(errno)); + } - struct dirent *entry; - while ((entry = readdir(dir)) != nullptr) { - // 跳过. 和 .. - if (entry->d_name[0] != '.') { - oss << entry->d_name << "\n"; // 逐行添加 - } - } + struct dirent *entry; + while ((entry = readdir(dir)) != nullptr) + { + // 跳过. 和 .. + if (entry->d_name[0] != '.') + { + oss << entry->d_name << "\n"; // 逐行添加 + } + } - closedir(dir); // 关闭目录 + closedir(dir); // 关闭目录 - if (oss.str().empty()) { - return "无死机文件"; - } + if (oss.str().empty()) + { + return "无死机文件"; + } - return oss.str(); // 返回以换行符分隔的文件名字符串 + 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); + 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; } - //获取系统free内存 + // 获取系统free内存 std::string DebugOutputViewEventListener::get_free_memory() { auto logModel = SystemLogModel::GetInstance(); @@ -365,31 +370,84 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; return result; } + std::string DebugOutputViewEventListener::get_nextday_log() + { + std::ostringstream result; + result << "nextday_log:\n"; // 添加标题 + + auto logModel = SystemLogModel::GetInstance(); + const auto &nextday_logs = logModel->get_nextday_log(); + + // 遍历日志并拼接到结果字符串 + for (const auto &log : nextday_logs) + { + // 格式化时间 + char labelTime[20]; + std::string timestr; - std::string DebugOutputViewEventListener::get_nextday_log() { - std::ostringstream result; - result << "nextday_log:\n"; // 添加标题 - - auto logModel = SystemLogModel::GetInstance(); - const auto& nextday_logs = logModel->get_nextday_log(); - - // 遍历日志并拼接到结果字符串 - for (const auto &log : nextday_logs) { - // 格式化时间 - char labelTime[20]; - std::string timestr; - - // 调用时间格式化函数 - if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { - timestr = "--"; // 如果获取时间失败,使用默认值 - } else { - timestr = labelTime; // 成功获取时间 - } - - result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 - } - - return result.str(); + // 调用时间格式化函数 + if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; // 如果获取时间失败,使用默认值 + } + else + { + timestr = labelTime; // 成功获取时间 + } + + result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 + } + + return result.str(); + } + + std::string DebugOutputViewEventListener::get_popup_windows_log(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_popup_windows_log"); + // 获取系统日志实例 + auto logModel = SystemLogModel::GetInstance(); + uint8_t logSize = logModel->get_popup_windows_log_size(); + if (logSize == 0) + { + return "目前没有日志"; + } + + std::deque popup_windows_logs = logModel->get_popup_windows_log(); + std::ostringstream str; + + for (int i = 0; i < logSize; i++) + { + // 处理日志类型 + switch (popup_windows_logs[i].type) + { + case popup_windows_type::MOTION_RECOGNITION: + str << "运动识别:"; + break; + case popup_windows_type::DRINK_WATER_REMINDER: + str << "喝水提醒:"; + break; + case popup_windows_type::SEDENTARY_REMINDER: + str << "久坐提醒:"; + break; + default: + str << "UNKNOWN:"; + break; + } + str << "\n"; + // 格式化时间 + char labelTime[20]; + std::string timestr; + if (uapi_get_TIME_STR(popup_windows_logs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + str << "[" << timestr << "] " << "\n"; // 拼接日志内容 + } + return str.str(); // 返回拼接后的字符串 } bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) @@ -401,7 +459,7 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; { // if (BluetoothModel::GetInstance()->GetAdvStartState() == false) // 如果广播是关的就去开启广播 // BleAdvStart(); - + svr_ble_adv_start(); return true; } @@ -456,22 +514,24 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; case 9: str = get_nextday_log(); break; + case 10: + str = get_popup_windows_log(); + break; default: str = "--"; break; - } + } - GraphicService::GetInstance()->PostGraphicEvent(std::bind( - &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(),str)); + GraphicService::GetInstance()->PostGraphicEvent(std::bind( + &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(), str)); return true; } - - //获取视图 - void DebugOutputViewEventListener::UpdateView(std::string str) + // 获取视图 + void DebugOutputViewEventListener::UpdateView(std::string str) { - if(debugOutputLabel != nullptr) + if (debugOutputLabel != nullptr) { debugOutputLabel->SetText(str.c_str()); } diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/drinkReminder_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/drinkReminder_notification.cpp index 973dc7b7e..06ed68efa 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/drinkReminder_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/drinkReminder_notification.cpp @@ -19,6 +19,7 @@ #include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" #include #include "../../../../../../drivers/peripheral/vibrator/service/vibrator_service.h" +#include "system/include/SystemLogModel.h" namespace OHOS { @@ -102,6 +103,15 @@ namespace OHOS } } + //记录喝水提醒日志 + void DrinkReminderViewEventListener::record_drink_reminder_log(void) + { + popup_windows_log_data systemlog; + systemlog.type = popup_windows_type::DRINK_WATER_REMINDER; + systemlog.timestamp = SystemLogModel::GetInstance()->GetCurrentTime(); + SystemLogModel::GetInstance()->save_popup_windows_log(systemlog); + } + /*创建喝水提醒视图*/ UIViewGroup *CreateDrinkReminderView(void) { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/motion_recognition_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/motion_recognition_notification.cpp index f77ec5a8e..c9f2fcd02 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/motion_recognition_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/motion_recognition_notification.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-17 16:44:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-17 11:21:57 + * @LastEditTime: 2024-10-18 20:25:43 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/motion_recognition_notification.cpp */ #include "notification_manager.h" @@ -22,6 +22,7 @@ #include "ui_service.h" #include "vibrator_service.h" #include "custom_runtime.h" +#include "system/include/SystemLogModel.h" namespace OHOS { @@ -158,6 +159,15 @@ namespace OHOS return motionTypeTextId; } + // 记录运动识别日志 + void MotionRecognitionViewEventListener::record_motion_recognition_log(void) + { + popup_windows_log_data systemlog; + systemlog.timestamp = SystemLogModel::GetInstance()->GetCurrentTime(); + systemlog.type = popup_windows_type::MOTION_RECOGNITION; + SystemLogModel::GetInstance()->save_popup_windows_log(systemlog); + } + static std::string UpdateNoteLabelText(UILabelExt *&label, const std::string &newText, int id) { if (label == nullptr) @@ -333,7 +343,7 @@ namespace OHOS MotionRecognitionGroupView->Add(MotionRecognitionScrollView); } /* -------------------------------------------------------------------------- */ - ScreenTurnOn(10*1000);//显示时长10s + ScreenTurnOn(10 * 1000); // 显示时长10s // 震动一次 if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp index 969ed2e27..3aa4f697b 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp @@ -16,6 +16,7 @@ #include #include "vibrator_service.h" #include "custom_runtime.h" +#include "system/include/SystemLogModel.h" namespace OHOS { @@ -89,6 +90,15 @@ namespace OHOS return true; } + // 记录久坐提醒日志 + void SedentaryReminderViewEventListener::record_sedentary_reminder_log(void) + { + popup_windows_log_data systemlog; + systemlog.timestamp = SystemLogModel::GetInstance()->GetCurrentTime(); + systemlog.type = popup_windows_type::SEDENTARY_REMINDER; + SystemLogModel::GetInstance()->save_popup_windows_log(systemlog); + } + static std::string UpdateNoteLabelText(UILabelExt *&label, const std::string &newText, int id) { if (label == nullptr) @@ -307,7 +317,7 @@ namespace OHOS delete SedentaryReminderLabel; SedentaryReminderLabel = nullptr; - + SedentaryReminderScrollView->ClearFocus(); delete SedentaryReminderScrollView; SedentaryReminderScrollView = nullptr;