From 579f327609a9782026d9f48e771971ffc11d8a59 Mon Sep 17 00:00:00 2001
From: lin <lin@kickpi.com>
Date: Tue, 18 Feb 2025 07:30:00 +0000
Subject: [PATCH] fix(battery): fixed the problem of abnormal battery power display

---
 android/system/core/healthd/BatteryMonitor.cpp |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/android/system/core/healthd/BatteryMonitor.cpp b/android/system/core/healthd/BatteryMonitor.cpp
index c88e90d..4f85b5e 100644
--- a/android/system/core/healthd/BatteryMonitor.cpp
+++ b/android/system/core/healthd/BatteryMonitor.cpp
@@ -72,7 +72,7 @@
     props->batteryStatus = BATTERY_STATUS_UNKNOWN;
     props->batteryHealth = BATTERY_HEALTH_UNKNOWN;
     props->batteryPresent = false;
-    props->batteryLevel = 100;
+    props->batteryLevel = 0;
     props->batteryVoltage = 0;
     props->batteryTemperature = 0;
     props->batteryCurrent = 0;
@@ -210,10 +210,14 @@
     else
         props.batteryPresent = mBatteryDevicePresent;
 
-    //props.batteryLevel = mBatteryFixedCapacity ?
-    //    mBatteryFixedCapacity :
-    //    getIntField(mHealthdConfig->batteryCapacityPath);
-     props.batteryLevel = 100;
+    if (!props.batteryPresent) {
+         props.batteryLevel = 100;}
+    else {
+    props.batteryLevel = mBatteryFixedCapacity ?
+        mBatteryFixedCapacity :
+        getIntField(mHealthdConfig->batteryCapacityPath);
+    }
+
     props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
 
     if (!mHealthdConfig->batteryCurrentNowPath.isEmpty())

--
Gitblit v1.6.2