Override the 'online' status for AC/USB for battery defender

Bug: 175614345
Test: 'atest HealthTestCases'
Change-Id: Icd9e44d53995591ee59d48839fefd30554c66704
Merged-In: Icd9e44d53995591ee59d48839fefd30554c66704
(cherry picked from commit 7c4bb68259df7e7954f06b0dbd7039412d54443b)
diff --git a/health/HealthService.cpp b/health/HealthService.cpp
index 098ca51..93eebfe 100644
--- a/health/HealthService.cpp
+++ b/health/HealthService.cpp
@@ -22,6 +22,7 @@
 #include <health2/service.h>
 #include <healthd/healthd.h>
 #include <hidl/HidlTransportSupport.h>
+#include <pixelhealth/BatteryDefender.h>
 #include <pixelhealth/BatteryMetricsLogger.h>
 #include <pixelhealth/BatteryThermalControl.h>
 #include <pixelhealth/CycleCountBackupRestore.h>
@@ -41,6 +42,7 @@
 using android::hardware::health::V2_0::StorageAttribute;
 using android::hardware::health::V2_0::StorageInfo;
 using ::device::google::crosshatch::health::BatteryRechargingControl;
+using hardware::google::pixel::health::BatteryDefender;
 using hardware::google::pixel::health::BatteryMetricsLogger;
 using hardware::google::pixel::health::BatteryThermalControl;
 using hardware::google::pixel::health::CycleCountBackupRestore;
@@ -51,6 +53,7 @@
 constexpr char kBatteryOCV[] = "/sys/class/power_supply/maxfg/voltage_ocv";
 constexpr char kVoltageAvg[] = "/sys/class/power_supply/maxfg/voltage_avg";
 
+static BatteryDefender battDefender;
 static BatteryRechargingControl battRechargingControl;
 static BatteryThermalControl battThermalControl("sys/devices/virtual/thermal/tz-by-name/soc/mode");
 static BatteryMetricsLogger battMetricsLogger(kBatteryResistance, kBatteryOCV);
@@ -120,6 +123,7 @@
     shutdownMetrics.logShutdownVoltage(props);
     ccBackupRestoreBMS.Backup(props->batteryLevel);
     ccBackupRestoreMAX.Backup(props->batteryLevel);
+    battDefender.update(props);
     if (!android::base::WriteStringToFile(std::to_string(props->batteryLevel),
                                           "/sys/class/power_supply/wireless/capacity"))
         LOG(INFO) << "Unable to write battery level to wireless capacity";
diff --git a/init.hardware.rc b/init.hardware.rc
index 480ccb2..a065339 100644
--- a/init.hardware.rc
+++ b/init.hardware.rc
@@ -821,12 +821,6 @@
     setprop persist.vendor.charge.stop.level 35
     setprop persist.vendor.charge.start.level 30
 
-on property:persist.vendor.charge.stop.level=*
-    write /sys/devices/platform/soc/soc:google,charger/charge_stop_level ${persist.vendor.charge.stop.level}
-
-on property:persist.vendor.charge.start.level=*
-    write /sys/devices/platform/soc/soc:google,charger/charge_start_level ${persist.vendor.charge.start.level}
-
 # For Japan radio builds, always enforce camera shutter sound
 # Since this property is read by the audio server in system service,
 # it should be written by the system init.