增加低电量打点,充电打点 3271/1 3271/head 3279/target/1 3281/target/1
authorCaisking <Casiking@zhihuishixun.com>
Fri, 13 Mar 2026 06:46:58 +0000 (14:46 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 13 Mar 2026 06:46:58 +0000 (14:46 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModel.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/include/SystemLogModelC.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/system/src/SystemLogModel.cpp
code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp
code/sdk/application/wearable/fd272/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/zhihui/services/battery/service/battery_service.cpp

index b4dec42..c94e54f 100644 (file)
 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 {  
index cbcbc4b..f1090a8 100644 (file)
@@ -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);
index dcbab5a..04294f7 100644 (file)
@@ -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;
index 6d8128f..3202387 100644 (file)
@@ -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 <service/graphic_service.h>
 
@@ -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(); // 关机 
     }
 
index 94b7bba..9362834 100644 (file)
@@ -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;
index 80c122d..f3d5fe7 100644 (file)
@@ -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();