charger: Add API to replace ro.charger.enable_suspend

The system property is set by vendor partition but owned by platform,
hence vendor domains can't read this value. Add an API in
ChargerConfigurationInterface so that HAL implementations can override
its value.

Other ro.charger.* sysprops are unused, hence no APIs are created for
them.

Test: manual
Bug: 203246116

Change-Id: I583c21e58ed3d912b156e253d6a4b46a0378f11e
diff --git a/healthd/Android.bp b/healthd/Android.bp
index 020a744..15f009e 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -167,6 +167,7 @@
 
     static_libs: [
         "android.hardware.health@1.0-convert",
+        "libcharger_sysprop",
         "libhealth2impl",
         "libhealthd_charger_ui",
     ],
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index 645ac41..aac719b 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -254,15 +254,18 @@
     LOGW("************* END LAST KMSG *************\n");
 }
 
-static int request_suspend(bool enable) {
-    if (!android::sysprop::ChargerProperties::enable_suspend().value_or(false)) {
+int Charger::RequestEnableSuspend() {
+    if (!configuration_->ChargerEnableSuspend()) {
         return 0;
     }
+    return autosuspend_enable();
+}
 
-    if (enable)
-        return autosuspend_enable();
-    else
-        return autosuspend_disable();
+int Charger::RequestDisableSuspend() {
+    if (!configuration_->ChargerEnableSuspend()) {
+        return 0;
+    }
+    return autosuspend_disable();
 }
 
 static void kick_animation(animation* anim) {
@@ -302,7 +305,7 @@
                 batt_anim_.run = false;
                 next_screen_transition_ = -1;
                 if (configuration_->ChargerIsOnline()) {
-                    request_suspend(true);
+                    RequestEnableSuspend();
                 }
                 return;
             }
@@ -325,7 +328,7 @@
         screen_blanked_ = true;
         LOGV("[%" PRId64 "] animation done\n", now);
         if (configuration_->ChargerIsOnline()) {
-            request_suspend(true);
+            RequestEnableSuspend();
         }
         return;
     }
@@ -481,13 +484,13 @@
                  * rather than on key release
                  */
                 kick_animation(&batt_anim_);
-                request_suspend(false);
+                RequestDisableSuspend();
             }
         } else {
             /* if the power key got released, force screen state cycle */
             if (key->pending) {
                 kick_animation(&batt_anim_);
-                request_suspend(false);
+                RequestDisableSuspend();
             }
         }
     }
@@ -506,7 +509,7 @@
     if (!have_battery_state_) return;
 
     if (!configuration_->ChargerIsOnline()) {
-        request_suspend(false);
+        RequestDisableSuspend();
         if (next_pwr_check_ == -1) {
             /* Last cycle would have stopped at the extreme top of battery-icon
              * Need to show the correct level corresponding to capacity.
@@ -536,7 +539,7 @@
              * Reset & kick animation to show complete animation cycles
              * when charger connected again.
              */
-            request_suspend(false);
+            RequestDisableSuspend();
             next_screen_transition_ = now - 1;
             reset_animation(&batt_anim_);
             kick_animation(&batt_anim_);
@@ -563,7 +566,7 @@
     if (!have_battery_state_) {
         have_battery_state_ = true;
         next_screen_transition_ = curr_time_ms() - 1;
-        request_suspend(false);
+        RequestDisableSuspend();
         reset_animation(&batt_anim_);
         kick_animation(&batt_anim_);
     }
diff --git a/healthd/healthd_mode_charger_hidl.cpp b/healthd/healthd_mode_charger_hidl.cpp
index ae46b23..3a33c02 100644
--- a/healthd/healthd_mode_charger_hidl.cpp
+++ b/healthd/healthd_mode_charger_hidl.cpp
@@ -17,6 +17,7 @@
 #include "healthd_mode_charger_hidl.h"
 
 #include <android/hardware/health/2.0/types.h>
+#include <charger.sysprop.h>
 #include <cutils/klog.h>
 
 #include "charger_utils.h"
@@ -51,6 +52,10 @@
     return out_screen_on;
 }
 
+bool ChargerHidl::ChargerEnableSuspend() {
+    return android::sysprop::ChargerProperties::enable_suspend().value_or(false);
+}
+
 }  // namespace android
 
 int healthd_charger_main(int argc, char** argv) {
diff --git a/healthd/healthd_mode_charger_hidl.h b/healthd/healthd_mode_charger_hidl.h
index 9e70c5a..0149d07 100644
--- a/healthd/healthd_mode_charger_hidl.h
+++ b/healthd/healthd_mode_charger_hidl.h
@@ -37,6 +37,7 @@
     int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) override {
         return HalHealthLoop::RegisterEvent(fd, func, wakeup);
     }
+    bool ChargerEnableSuspend() override;
     // HealthLoop overrides
     void Heartbeat() override { charger_->OnHeartbeat(); }
     int PrepareToWait() override { return charger_->OnPrepareToWait(); }
diff --git a/healthd/include_charger/charger/healthd_mode_charger.h b/healthd/include_charger/charger/healthd_mode_charger.h
index a555b0a..216e5ad 100644
--- a/healthd/include_charger/charger/healthd_mode_charger.h
+++ b/healthd/include_charger/charger/healthd_mode_charger.h
@@ -59,6 +59,7 @@
     virtual int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) = 0;
 
     // Other configuration values
+    virtual bool ChargerEnableSuspend() = 0;
 };
 
 // charger UI
@@ -91,6 +92,8 @@
     void HandlePowerSupplyState(int64_t now);
     int InputCallback(int fd, unsigned int epevents);
     void InitAnimation();
+    int RequestEnableSuspend();
+    int RequestDisableSuspend();
 
     bool have_battery_state_ = false;
     bool screen_blanked_ = false;