Implement getBatteryHealthData in HealthServiceWrapper

Extend the HealthServiceWrapper with the new getBatteryHealthData API,
introduced in the AIDL Health HAL v3.

Flag: EXEMPT statsd atoms/metrics changes
Bug: 343691107
Test: statsd_testdrive 10220
Change-Id: I2f4a7c420f97314089c202297f3a2e07c0272bf7
Signed-off-by: Alessio Balsini <balsini@google.com>
diff --git a/services/core/java/com/android/server/health/HealthServiceWrapper.java b/services/core/java/com/android/server/health/HealthServiceWrapper.java
index 25d1a88..9c14b5b 100644
--- a/services/core/java/com/android/server/health/HealthServiceWrapper.java
+++ b/services/core/java/com/android/server/health/HealthServiceWrapper.java
@@ -71,6 +71,21 @@
     public abstract android.hardware.health.HealthInfo getHealthInfo() throws RemoteException;
 
     /**
+     * Calls into getBatteryHealthData() in the health HAL.
+     * This function does not have a corresponding HIDL implementation, so
+     * returns null by default, unless there is an AIDL class that overrides
+     * this one.
+     *
+     * @return battery health data. {@code null} if no health HAL service.
+     *     {@code null} if any service-specific error when calling {@code
+     *     getBatteryHealthData}, e.g. it is unsupported.
+     * @throws RemoteException for any transaction-level errors
+     */
+    public android.hardware.health.BatteryHealthData getBatteryHealthData() throws RemoteException {
+        return null;
+    }
+
+    /**
      * Create a new HealthServiceWrapper instance.
      *
      * @param healthInfoCallback the callback to call when health info changes
diff --git a/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java b/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java
index fd3a92e..2a3fbc3 100644
--- a/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java
+++ b/services/core/java/com/android/server/health/HealthServiceWrapperAidl.java
@@ -212,6 +212,17 @@
         }
     }
 
+    @Override
+    public BatteryHealthData getBatteryHealthData() throws RemoteException {
+        IHealth service = mLastService.get();
+        if (service == null) return null;
+        try {
+            return service.getBatteryHealthData();
+        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
+            return null;
+        }
+    }
+
     public void setChargingPolicy(int policy) throws RemoteException {
         IHealth service = mLastService.get();
         if (service == null) return;