summaryrefslogtreecommitdiff
path: root/health
diff options
context:
space:
mode:
authorJack Wu <wjack@google.com>2019-03-31 19:42:59 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-03-31 19:42:59 -0700
commit55e21c3eb91b971fd47cf3817768e5ef055a41eb (patch)
tree8b6f36764727b64f6bc71300227c0e3215d896f5 /health
parentdf169566fa1dee4fe73a4bdaa2e8d1d620a90e6c (diff)
parente9ba88595309422896a2fe07f93c5b7995408f70 (diff)
downloadbonito-55e21c3eb91b971fd47cf3817768e5ef055a41eb.tar.gz
healthd: battery: backup/restore capacity to/from persist data am: 1649c84346
am: e9ba885953 Change-Id: I0887227b1cd2b5384c0f994efe2cf01daf3895a7
Diffstat (limited to 'health')
-rw-r--r--health/LearnedCapacityBackupRestore.cpp39
-rw-r--r--health/LearnedCapacityBackupRestore.h6
2 files changed, 33 insertions, 12 deletions
diff --git a/health/LearnedCapacityBackupRestore.cpp b/health/LearnedCapacityBackupRestore.cpp
index 9ce12e65..cfea5c04 100644
--- a/health/LearnedCapacityBackupRestore.cpp
+++ b/health/LearnedCapacityBackupRestore.cpp
@@ -21,6 +21,7 @@ namespace google {
namespace bonito {
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;
@@ -28,17 +29,18 @@ static constexpr int kBuffSize = 256;
LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() {}
void LearnedCapacityBackupRestore::Restore() {
- ReadFromStorage();
- ReadFromSRAM();
+ ReadPersistData();
+ ReadNominalCapacity();
+ ReadCapacity();
UpdateAndSave();
}
void LearnedCapacityBackupRestore::Backup() {
- ReadFromSRAM();
+ ReadCapacity();
UpdateAndSave();
}
-void LearnedCapacityBackupRestore::ReadFromStorage() {
+void LearnedCapacityBackupRestore::ReadPersistData() {
std::string buffer;
if (!android::base::ReadFileToString(std::string(kSysCFPersistFile), &buffer)) {
@@ -63,20 +65,36 @@ void LearnedCapacityBackupRestore::SaveToStorage() {
LOG(ERROR) << "Write file error: " << strerror(errno);
}
-void LearnedCapacityBackupRestore::ReadFromSRAM() {
+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::ReadCapacity() {
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;
}
buffer = android::base::Trim(buffer);
if (sscanf(buffer.c_str(), "%d", &hw_cap_) < 1)
- LOG(ERROR) << "Failed to parse SRAM bins: " << buffer;
+ LOG(ERROR) << "Failed to parse capacity: " << buffer;
else
- LOG(INFO) << "SRAM data: " << buffer;
+ LOG(INFO) << "capacity: " << buffer;
}
void LearnedCapacityBackupRestore::SaveToSRAM() {
@@ -94,10 +112,11 @@ void LearnedCapacityBackupRestore::UpdateAndSave() {
bool backup = false;
bool restore = false;
if (hw_cap_) {
- if ((hw_cap_ < sw_cap_) || (sw_cap_ == 0)) {
+ if (((hw_cap_ != sw_cap_) && (hw_cap_ != nom_cap_)) ||
+ (sw_cap_ == 0)) {
sw_cap_ = hw_cap_;
backup = true;
- } else if (hw_cap_ > sw_cap_) {
+ } else if ((sw_cap_ > 0) && (hw_cap_ == nom_cap_)) {
hw_cap_ = sw_cap_;
restore = true;
}
diff --git a/health/LearnedCapacityBackupRestore.h b/health/LearnedCapacityBackupRestore.h
index 4024fda5..b96385ec 100644
--- a/health/LearnedCapacityBackupRestore.h
+++ b/health/LearnedCapacityBackupRestore.h
@@ -36,10 +36,12 @@ class LearnedCapacityBackupRestore {
private:
int sw_cap_;
int hw_cap_;
+ int nom_cap_;
- void ReadFromStorage();
+ void ReadPersistData();
void SaveToStorage();
- void ReadFromSRAM();
+ void ReadNominalCapacity();
+ void ReadCapacity();
void SaveToSRAM();
void UpdateAndSave();
};