summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Wu <wjack@google.com>2020-06-17 02:24:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-17 02:24:19 +0000
commitc8ff73dd17c11c3b702c482f3e2467bfbac92680 (patch)
treecd99c7c13817a613bc24ce3baba99e4542a349f8
parent88584a8bc3d65d435d74945be314761ba778157f (diff)
parent282b3e3c9b5d54029c3615d38f32e264c912aed7 (diff)
downloaddevice_google_wahoo-c8ff73dd17c11c3b702c482f3e2467bfbac92680.tar.gz
device_google_wahoo-c8ff73dd17c11c3b702c482f3e2467bfbac92680.tar.bz2
device_google_wahoo-c8ff73dd17c11c3b702c482f3e2467bfbac92680.zip
healthd: fix the over estimated battery capacity am: 282b3e3c9b
Original change: https://googleplex-android-review.googlesource.com/c/device/google/wahoo/+/11865856 Change-Id: I72f7ed1242d8a2dd0bfb6b57698d6ccc172236e1
-rw-r--r--health/LearnedCapacityBackupRestore.cpp25
-rw-r--r--health/LearnedCapacityBackupRestore.h2
2 files changed, 24 insertions, 3 deletions
diff --git a/health/LearnedCapacityBackupRestore.cpp b/health/LearnedCapacityBackupRestore.cpp
index cf8de8d3..a3111d38 100644
--- a/health/LearnedCapacityBackupRestore.cpp
+++ b/health/LearnedCapacityBackupRestore.cpp
@@ -21,6 +21,7 @@ namespace google {
namespace wahoo {
namespace health {
+static constexpr char kChgFullDesignFile[] = "sys/class/power_supply/bms/charge_full_design";
static constexpr char kChgFullFile[] = "sys/class/power_supply/bms/charge_full";
static constexpr char kSysCFPersistFile[] = "/persist/battery/qcom_charge_full";
static constexpr int kBuffSize = 256;
@@ -29,13 +30,15 @@ LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() : sw_cap_(0), hw_ca
void LearnedCapacityBackupRestore::Restore() {
ReadFromStorage();
+ ReadNominalCapacity();
ReadFromSRAM();
if (sw_cap_ == 0) {
// First backup
sw_cap_ = hw_cap_;
SaveToStorage();
- } else {
- // Always restore backup value
+ } else if (hw_cap_ == nom_cap_) {
+ // Restore backup value when capacity is reset to nominal
+ hw_cap_ = sw_cap_;
SaveToSRAM();
}
}
@@ -74,11 +77,27 @@ void LearnedCapacityBackupRestore::SaveToStorage() {
LOG(ERROR) << "Write file error: " << strerror(errno);
}
+void LearnedCapacityBackupRestore::ReadNominalCapacity() {
+ std::string buffer;
+
+ if (!android::base::ReadFileToString(std::string(kChgFullDesignFile), &buffer)) {
+ LOG(ERROR) << "Read nominal capacity error: " << strerror(errno);
+ return;
+ }
+
+ buffer = android::base::Trim(buffer);
+
+ if (sscanf(buffer.c_str(), "%d", &nom_cap_) < 1)
+ LOG(ERROR) << "Failed to parse nominal capacity: " << buffer;
+ else
+ LOG(INFO) << "nominal capacity: " << buffer;
+}
+
void LearnedCapacityBackupRestore::ReadFromSRAM() {
std::string buffer;
if (!android::base::ReadFileToString(std::string(kChgFullFile), &buffer)) {
- LOG(ERROR) << "Read cycle counter error: " << strerror(errno);
+ LOG(ERROR) << "Read capacity error: " << strerror(errno);
return;
}
diff --git a/health/LearnedCapacityBackupRestore.h b/health/LearnedCapacityBackupRestore.h
index da9e5643..b35396d5 100644
--- a/health/LearnedCapacityBackupRestore.h
+++ b/health/LearnedCapacityBackupRestore.h
@@ -36,9 +36,11 @@ class LearnedCapacityBackupRestore {
private:
int sw_cap_;
int hw_cap_;
+ int nom_cap_;
void ReadFromStorage();
void SaveToStorage();
+ void ReadNominalCapacity();
void ReadFromSRAM();
void SaveToSRAM();
};