From f8398976b57653019f0e5a1f0146277109062370 Mon Sep 17 00:00:00 2001 From: Caisking Date: Fri, 13 Mar 2026 14:46:58 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E4=BD=8E=E7=94=B5=E9=87=8F?= =?utf8?q?=E6=89=93=E7=82=B9=EF=BC=8C=E5=85=85=E7=94=B5=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/system/include/SystemLogModel.h | 11 +++++----- .../nativeui/system/include/SystemLogModelC.h | 1 + .../nativeui/system/src/SystemLogModel.cpp | 22 ++++++++++++++++++- .../src/notify/charge_notification.cpp | 7 ++++++ .../debug_output_notification.cpp | 3 +++ .../battery/service/battery_service.cpp | 4 ++++ 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModel.h index b4dec424c..c94e54fef 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModel.h @@ -44,11 +44,12 @@ namespace OHOS { enum class SystemLogType { - POWER_ON = 0, // 开机 - POWER_OFF, // 关机 - RESTART, // 重启 - FACTORY_RESET, // 恢复出厂设置 - SOFTWARE_UPDATE, // 更新 + POWER_ON = 0, // 开机 + POWER_OFF, // 关机 + POWER_OFF_LOW_BATTERY, // 低电量关机 + RESTART, // 重启 + FACTORY_RESET, // 恢复出厂设置 + SOFTWARE_UPDATE, // 更新 }; struct SystemLogData { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModelC.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModelC.h index cbcbc4bb2..f1090a869 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModelC.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModelC.h @@ -12,6 +12,7 @@ void start_report_log(void); void stop_report_log(void); void resume_report_log(void); void update_version_report_log(void); +void set_low_battery_shutdown_flag(bool enable); void start_report_nextday_log_start(void); void start_report_nextday_log_end(void); void nextday_clear_popup_windows_log(void); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemLogModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemLogModel.cpp index dcbab5a9d..04294f71f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemLogModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemLogModel.cpp @@ -47,8 +47,24 @@ void report_log(OHOS::SystemLogType type) { OHOS::SystemLogModel::GetInstance()->saveLog(systemlog); } +// 低电量关机标志,由业务在触发关机前设置 +static bool g_low_battery_shutdown = false; + +void set_low_battery_shutdown_flag(bool enable) +{ + g_low_battery_shutdown = enable; +} + // 关机保存 -void start_report_log(void) { report_log(OHOS::SystemLogType::POWER_OFF); } +void start_report_log(void) +{ + if (g_low_battery_shutdown) { + report_log(OHOS::SystemLogType::POWER_OFF_LOW_BATTERY); + g_low_battery_shutdown = false; + } else { + report_log(OHOS::SystemLogType::POWER_OFF); + } +} // 重启保存 void stop_report_log(void) { report_log(OHOS::SystemLogType::RESTART); } @@ -118,6 +134,10 @@ bool SystemLogModel::saveLog(SystemLogData data) { case SystemLogType::POWER_OFF: uapi_save_runtime_log(RUNTIME_LOG_POWER_OFF);//TOOD* break; + case SystemLogType::POWER_OFF_LOW_BATTERY: + // 运行时日志沿用关机码,只在 SystemLogType 上区分“低电量关机” + uapi_save_runtime_log(RUNTIME_LOG_POWER_OFF); + break; case SystemLogType::RESTART: uapi_save_runtime_log(RUNTIME_LOG_REBOOT);//TOOD* break; diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp index 6d8128f80..320238772 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp @@ -16,6 +16,7 @@ #include "linux/delay.h" #include "components/ui_circle_progress.h" #include "uicomponents/UIComponents.h" +#include "system/include/SystemLogModelC.h" #include "charge_notification.h" #include @@ -587,9 +588,15 @@ namespace OHOS msleep(500); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxxxxxxOnAnimatorStop"); if(battery_falg==4) + { shutdown_reboot_prejobs(REBOOT_TYPE); + } else + { + // 低电量触发的关机,标记为“低电量关机”日志 + ::set_low_battery_shutdown_flag(true); shutdown_reboot_prejobs(SHUTDOWN_TYPE); + } // uapi_poweroff_device(); // 关机 } diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 94b7bbafc..9362834e5 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -357,6 +357,9 @@ namespace OHOS case SystemLogType::POWER_OFF: str << "关机:"; break; + case SystemLogType::POWER_OFF_LOW_BATTERY: + str << "低电量关机:"; + break; case SystemLogType::RESTART: str << "重启:"; break; diff --git a/code/sdk/zhihui/services/battery/service/battery_service.cpp b/code/sdk/zhihui/services/battery/service/battery_service.cpp index 80c122d1e..f3d5fe7f0 100644 --- a/code/sdk/zhihui/services/battery/service/battery_service.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_service.cpp @@ -624,6 +624,8 @@ static void battery_check_task(void *arg) #endif battery_check_chargement(); charger_plug_event_ui_sendmsg_toUI(1); + // 记录一次充电线插入时刻的电池数据,用于后续统计充电时间 + battery_save_data(); }else if (mail.comm.event == BATTERY_CMD_CHARGE_UNPLUG) { // PRINT("[battery][service] charger_plug_event_ui_sendmsg_toUI unplugged \n"); oncharging_status = 0; @@ -634,6 +636,8 @@ static void battery_check_task(void *arg) disable_charge(); #endif charger_plug_event_ui_sendmsg_toUI(0); + // 记录一次充电线拔出时刻的电池数据,用于后续统计充电时间 + battery_save_data(); }else if(mail.comm.event == BATTERY_CMD_FIRST_CHECK) { battery_check_chargement(); -- 2.17.1