health: expose battery health data and update version to V2
1. add the new propertes
- batteryHealthData
- batteryStateOfHealth
- chargingState
- chargingPolicy
2. add new types to health status
3. add new methods
- setChargingPolicy
- getChargingPolicy
- getBatteryHealthData
Bug: 251425963
Test: m android.hardware.health-update-api
Change-Id: Ie2339c50e1f9bfc28427e4108a95b1a16c739205
Signed-off-by: Jack Wu <wjack@google.com>
diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml
index 16237bd..64bfc7a 100644
--- a/compatibility_matrices/compatibility_matrix.current.xml
+++ b/compatibility_matrices/compatibility_matrix.current.xml
@@ -349,7 +349,7 @@
</hal>
<hal format="aidl" optional="false">
<name>android.hardware.health</name>
- <version>1</version>
+ <version>1-2</version>
<interface>
<name>IHealth</name>
<instance>default</instance>
diff --git a/health/aidl/Android.bp b/health/aidl/Android.bp
index 64d83f3..6d4f914 100644
--- a/health/aidl/Android.bp
+++ b/health/aidl/Android.bp
@@ -74,7 +74,7 @@
name: "android.hardware.health-translate-ndk",
defaults: ["android.hardware.health-translate-ndk_defaults"],
shared_libs: [
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
],
}
@@ -91,7 +91,7 @@
name: "android.hardware.health-translate-java",
srcs: ["android/hardware/health/Translate.java"],
libs: [
- "android.hardware.health-V1-java",
+ "android.hardware.health-V2-java",
"android.hardware.health-V2.0-java",
"android.hardware.health-V2.1-java",
],
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingPolicy.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingPolicy.aidl
new file mode 100644
index 0000000..42fbf95
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingPolicy.aidl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.health;
+@Backing(type="int") @VintfStability
+enum BatteryChargingPolicy {
+ INVALID = 0,
+ DEFAULT = 1,
+ LONG_LIFE = 2,
+ ADAPTIVE = 3,
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingState.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingState.aidl
new file mode 100644
index 0000000..e21eb28
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryChargingState.aidl
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.health;
+@Backing(type="int") @VintfStability
+enum BatteryChargingState {
+ INVALID = 0,
+ NORMAL = 1,
+ TOO_COLD = 2,
+ TOO_HOT = 3,
+ LONG_LIFE = 4,
+ ADAPTIVE = 5,
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl
index 4ce7952..8d13198 100644
--- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl
@@ -41,4 +41,7 @@
OVER_VOLTAGE = 5,
UNSPECIFIED_FAILURE = 6,
COLD = 7,
+ FAIR = 8,
+ NOT_AVAILABLE = 11,
+ INCONSISTENT = 12,
}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealthData.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealthData.aidl
new file mode 100644
index 0000000..d523fad
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealthData.aidl
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+// the interface (from the latest frozen version), the build system will
+// prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.health;
+@VintfStability
+parcelable BatteryHealthData {
+ long batteryManufacturingDateSeconds;
+ long batteryFirstUsageSeconds;
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl
index 97d9e84..664cc70 100644
--- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl
@@ -57,5 +57,9 @@
android.hardware.health.BatteryCapacityLevel batteryCapacityLevel;
long batteryChargeTimeToFullNowSeconds;
int batteryFullChargeDesignCapacityUah;
+ int batteryStateOfHealth;
+ android.hardware.health.BatteryChargingState chargingState;
+ android.hardware.health.BatteryChargingPolicy chargingPolicy;
+ @nullable android.hardware.health.BatteryHealthData batteryHealthData;
const int BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED = -1;
}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl
index 7016ae4..b49dfff 100644
--- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl
@@ -46,6 +46,9 @@
android.hardware.health.StorageInfo[] getStorageInfo();
android.hardware.health.DiskStats[] getDiskStats();
android.hardware.health.HealthInfo getHealthInfo();
+ void setChargingPolicy(android.hardware.health.BatteryChargingPolicy in_value);
+ android.hardware.health.BatteryChargingPolicy getChargingPolicy();
+ android.hardware.health.BatteryHealthData getBatteryHealthData();
const int STATUS_UNKNOWN = 2;
const int STATUS_CALLBACK_DIED = 4;
}
diff --git a/health/aidl/android/hardware/health/BatteryChargingPolicy.aidl b/health/aidl/android/hardware/health/BatteryChargingPolicy.aidl
new file mode 100644
index 0000000..0aeee41
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryChargingPolicy.aidl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.health;
+
+/**
+ * Battery charging policy.
+ */
+@VintfStability
+@Backing(type="int")
+enum BatteryChargingPolicy {
+ INVALID = 0,
+ /**
+ * default policy
+ */
+ DEFAULT = 1,
+ /**
+ * @see BatteryChargingState.LONG_LIFE
+ */
+ LONG_LIFE = 2,
+ /**
+ * @see BatteryChargingState.ADAPTIVE
+ */
+ ADAPTIVE = 3,
+}
diff --git a/health/aidl/android/hardware/health/BatteryChargingState.aidl b/health/aidl/android/hardware/health/BatteryChargingState.aidl
new file mode 100644
index 0000000..af62077
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryChargingState.aidl
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.health;
+
+/**
+ * Possible values for Battery Health.
+ * Note: These are currently in sync with BatteryManager and must not
+ * be extended / altered.
+ */
+@VintfStability
+@Backing(type="int")
+enum BatteryChargingState {
+ INVALID = 0,
+ /**
+ * Default state.
+ */
+ NORMAL = 1,
+ /**
+ * Reported when the battery is too cold to charge at a normal
+ * rate or stopped charging due to low temperature.
+ */
+ TOO_COLD = 2,
+ /**
+ * Reported when the battery is too hot to charge at a normal
+ * rate or stopped charging due to hot temperature.
+ */
+ TOO_HOT = 3,
+ /**
+ * The device is using a special charging profile that designed
+ * to prevent accelerated aging.
+ */
+ LONG_LIFE = 4,
+ /**
+ * The device is using a special charging profile designed to
+ * improve battery cycle life, performances or both.
+ */
+ ADAPTIVE = 5,
+}
diff --git a/health/aidl/android/hardware/health/BatteryHealth.aidl b/health/aidl/android/hardware/health/BatteryHealth.aidl
index 2b6e51f..65abdc2 100644
--- a/health/aidl/android/hardware/health/BatteryHealth.aidl
+++ b/health/aidl/android/hardware/health/BatteryHealth.aidl
@@ -24,8 +24,15 @@
@VintfStability
@Backing(type="int")
enum BatteryHealth {
+ /**
+ * Battery health is not supported from the device.
+ */
UNKNOWN = 1,
GOOD = 2,
+ /**
+ * Must be consistent with BatteryChargingState.
+ * If BatteryHealth is OVERHEAT, then BatteryChargingState must be TOO_HOT.
+ */
OVERHEAT = 3,
DEAD = 4,
OVER_VOLTAGE = 5,
@@ -33,5 +40,28 @@
* Battery experienced an unknown/unspecified failure.
*/
UNSPECIFIED_FAILURE = 6,
+ /**
+ * Must be consistent with BatteryChargingState.
+ * If BatteryHealth is COLD, then BatteryChargingState must be TOO_COLD.
+ */
COLD = 7,
+ /**
+ * Battery health is marginal.
+ */
+ FAIR = 8,
+ /**
+ * The reserve data below 10 are used to recognize the battery real health.
+ */
+ /**
+ * There is not enough information to determine an accurate
+ * value. The value might become UNSPECIFIED_FAILURE, DEAD
+ * or any other state except for UNKNOWN later.
+ */
+ NOT_AVAILABLE = 11,
+ /**
+ * The internal data is inconsistent and the battery needs to
+ * go through a recalibration process. The value might become
+ * UNSPECIFIED_FAILURE, DEAD or any other state except for UNKNOWN later.
+ */
+ INCONSISTENT = 12,
}
diff --git a/health/aidl/android/hardware/health/BatteryHealthData.aidl b/health/aidl/android/hardware/health/BatteryHealthData.aidl
new file mode 100644
index 0000000..fb17f63
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryHealthData.aidl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.health;
+
+/*
+ * Battery health data
+ */
+@VintfStability
+parcelable BatteryHealthData {
+ /**
+ * Battery manufacturing date is reported in epoch.
+ */
+ long batteryManufacturingDateSeconds;
+ /**
+ * The date of first usage is reported in epoch.
+ */
+ long batteryFirstUsageSeconds;
+}
diff --git a/health/aidl/android/hardware/health/HealthInfo.aidl b/health/aidl/android/hardware/health/HealthInfo.aidl
index 5b98baf..238f524 100644
--- a/health/aidl/android/hardware/health/HealthInfo.aidl
+++ b/health/aidl/android/hardware/health/HealthInfo.aidl
@@ -17,7 +17,10 @@
package android.hardware.health;
import android.hardware.health.BatteryCapacityLevel;
+import android.hardware.health.BatteryChargingPolicy;
+import android.hardware.health.BatteryChargingState;
import android.hardware.health.BatteryHealth;
+import android.hardware.health.BatteryHealthData;
import android.hardware.health.BatteryStatus;
import android.hardware.health.DiskStats;
import android.hardware.health.StorageInfo;
@@ -133,4 +136,23 @@
* Value must be less than 100 000 000 µAh if known.
*/
int batteryFullChargeDesignCapacityUah;
+ /**
+ * Measured battery state of health (remaining estimate full charge capacity
+ * relative to the rated capacity in %).
+ * Value must be 0 if batteryStatus is UNKNOWN.
+ * Otherwise, value must be in the range 0 to 100.
+ */
+ int batteryStateOfHealth;
+ /**
+ * Battery charging state
+ */
+ BatteryChargingState chargingState;
+ /**
+ * Battery charging policy. See {@link BatteryChargingPolicy} for more details.
+ */
+ BatteryChargingPolicy chargingPolicy;
+ /**
+ * Battery health data
+ */
+ @nullable BatteryHealthData batteryHealthData;
}
diff --git a/health/aidl/android/hardware/health/IHealth.aidl b/health/aidl/android/hardware/health/IHealth.aidl
index d541eca..bdfe07a 100644
--- a/health/aidl/android/hardware/health/IHealth.aidl
+++ b/health/aidl/android/hardware/health/IHealth.aidl
@@ -16,6 +16,8 @@
package android.hardware.health;
+import android.hardware.health.BatteryChargingPolicy;
+import android.hardware.health.BatteryHealthData;
import android.hardware.health.BatteryStatus;
import android.hardware.health.DiskStats;
import android.hardware.health.HealthInfo;
@@ -102,7 +104,7 @@
* if this property is not supported
* (e.g. the file that stores this property does not exist),
* - Return service specific error with code STATUS_UNKNOWN
- * for for other errors.
+ * for other errors.
*/
int getCurrentNowMicroamps();
@@ -120,7 +122,7 @@
* if this property is not supported
* (e.g. the file that stores this property does not exist),
* - Return service specific error with code STATUS_UNKNOWN
- * for for other errors.
+ * for other errors.
*/
int getCurrentAverageMicroamps();
@@ -134,7 +136,7 @@
* if this property is not supported
* (e.g. the file that stores this property does not exist),
* - Return service specific error with code STATUS_UNKNOWN
- * for for other errors.
+ * for other errors.
*/
int getCapacity();
@@ -146,7 +148,7 @@
* - Return exception with code EX_UNSUPPORTED_OPERATION
* if this property is not supported,
* - Return service specific error with code STATUS_UNKNOWN
- * for for other errors.
+ * for other errors.
*/
long getEnergyCounterNwh();
@@ -197,7 +199,47 @@
* - Return exception with code EX_UNSUPPORTED_OPERATION
* if this API is not supported,
* - Return service specific error with code STATUS_UNKNOWN
- * for for other errors.
+ * for other errors.
*/
HealthInfo getHealthInfo();
+
+ /**
+ * Set battery charging policy
+ *
+ * @return If error, return service specific error with code:
+ * - Return exception with code EX_UNSUPPORTED_OPERATION
+ * if this property is not supported
+ * (e.g. the file that stores this property does not exist),
+ * - Return status with code INVALID_OPERATION
+ * if the operation failed.
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ void setChargingPolicy(BatteryChargingPolicy in_value);
+
+ /**
+ * Get current battery charging policy
+ *
+ * @return current battery charging policy if successful.
+ * If error:
+ * - Return exception with code EX_UNSUPPORTED_OPERATION
+ * if this property is not supported
+ * (e.g. the file that stores this property does not exist),
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ BatteryChargingPolicy getChargingPolicy();
+
+ /**
+ * Get battery health data
+ *
+ * @return Battery health data if successful.
+ * If error:
+ * - Return exception with code EX_UNSUPPORTED_OPERATION
+ * if this property is not supported
+ * (e.g. the file that stores this property does not exist),
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ BatteryHealthData getBatteryHealthData();
}
diff --git a/health/aidl/default/Android.bp b/health/aidl/default/Android.bp
index 4eb3cb1..b51e4f3 100644
--- a/health/aidl/default/Android.bp
+++ b/health/aidl/default/Android.bp
@@ -29,7 +29,7 @@
"libcutils",
"liblog",
"libutils",
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
// TODO(b/177269435): remove when BatteryMonitor works with AIDL HealthInfo.
"libhidlbase",
@@ -48,7 +48,7 @@
name: "libhealth_aidl_charger_defaults",
shared_libs: [
// common
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
"libbase",
"libcutils",
"liblog",
@@ -195,7 +195,7 @@
"service_fuzzer_defaults",
],
static_libs: [
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
"libbase",
"liblog",
"fuzz_libhealth_aidl_impl",
diff --git a/health/aidl/default/Health.cpp b/health/aidl/default/Health.cpp
index d41d01a..15a3dbc 100644
--- a/health/aidl/default/Health.cpp
+++ b/health/aidl/default/Health.cpp
@@ -115,6 +115,42 @@
BatteryStatus::UNKNOWN, out);
}
+ndk::ScopedAStatus Health::setChargingPolicy(BatteryChargingPolicy in_value) {
+ ::android::status_t err = battery_monitor_.setChargingPolicy(static_cast<int>(in_value));
+
+ switch (err) {
+ case ::android::OK:
+ return ndk::ScopedAStatus::ok();
+ case ::android::NAME_NOT_FOUND:
+ return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
+ case ::android::BAD_VALUE:
+ return ndk::ScopedAStatus::fromStatus(::android::INVALID_OPERATION);
+ default:
+ return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
+ IHealth::STATUS_UNKNOWN, ::android::statusToString(err).c_str());
+ }
+}
+
+ndk::ScopedAStatus Health::getChargingPolicy(BatteryChargingPolicy* out) {
+ return GetProperty(&battery_monitor_, ::android::BATTERY_PROP_CHARGING_POLICY,
+ BatteryChargingPolicy::DEFAULT, out);
+}
+
+ndk::ScopedAStatus Health::getBatteryHealthData(BatteryHealthData* out) {
+ if (auto res =
+ GetProperty<int64_t>(&battery_monitor_, ::android::BATTERY_PROP_MANUFACTURING_DATE,
+ 0, &out->batteryManufacturingDateSeconds);
+ !res.isOk()) {
+ LOG(WARNING) << "Cannot get Manufacturing_date: " << res.getDescription();
+ }
+ if (auto res = GetProperty<int64_t>(&battery_monitor_, ::android::BATTERY_PROP_FIRST_USAGE_DATE,
+ 0, &out->batteryFirstUsageSeconds);
+ !res.isOk()) {
+ LOG(WARNING) << "Cannot get First_usage_date: " << res.getDescription();
+ }
+ return ndk::ScopedAStatus::ok();
+}
+
ndk::ScopedAStatus Health::getDiskStats(std::vector<DiskStats>*) {
// This implementation does not support DiskStats. An implementation may extend this
// class and override this function to support disk stats.
diff --git a/health/aidl/default/android.hardware.health-service.example.xml b/health/aidl/default/android.hardware.health-service.example.xml
index 98026cb..1fe9b8d 100644
--- a/health/aidl/default/android.hardware.health-service.example.xml
+++ b/health/aidl/default/android.hardware.health-service.example.xml
@@ -1,7 +1,7 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.health</name>
- <version>1</version>
+ <version>2</version>
<fqname>IHealth/default</fqname>
</hal>
</manifest>
diff --git a/health/aidl/default/include/health-impl/Health.h b/health/aidl/default/include/health-impl/Health.h
index 6bd4946..dc3a0ef 100644
--- a/health/aidl/default/include/health-impl/Health.h
+++ b/health/aidl/default/include/health-impl/Health.h
@@ -72,6 +72,10 @@
ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* out) override;
ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* out) override;
+ ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override;
+ ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* out) override;
+ ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* out) override;
+
// A subclass may override these to provide a different implementation.
binder_status_t dump(int fd, const char** args, uint32_t num_args) override;
diff --git a/health/aidl/vts/functional/Android.bp b/health/aidl/vts/functional/Android.bp
index f9da79f..b735a87 100644
--- a/health/aidl/vts/functional/Android.bp
+++ b/health/aidl/vts/functional/Android.bp
@@ -39,7 +39,7 @@
"libbinder_ndk",
],
static_libs: [
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
"libgmock",
],
header_libs: [
diff --git a/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp b/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp
index 3e07188..dd0bd81 100644
--- a/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp
+++ b/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp
@@ -225,6 +225,61 @@
ASSERT_THAT(value, IsValidEnum<BatteryStatus>());
}
+/*
+ * Tests the values returned by getChargingPolicy() from interface IHealth.
+ */
+TEST_P(HealthAidl, getChargingPolicy) {
+ BatteryChargingPolicy value;
+ auto status = health->getChargingPolicy(&value);
+ ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
+ if (!status.isOk()) return;
+ ASSERT_THAT(value, IsValidEnum<BatteryChargingPolicy>());
+}
+
+/*
+ * Tests that setChargingPolicy() writes the value and compared the returned
+ * value by getChargingPolicy() from interface IHealth.
+ */
+TEST_P(HealthAidl, setChargingPolicy) {
+ BatteryChargingPolicy value;
+
+ /* set ChargingPolicy*/
+ auto status = health->setChargingPolicy(static_cast<BatteryChargingPolicy>(2)); // LONG_LIFE
+ ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
+ if (!status.isOk()) return;
+
+ /* get ChargingPolicy*/
+ status = health->getChargingPolicy(&value);
+ ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
+ if (!status.isOk()) return;
+ ASSERT_THAT(static_cast<int>(value), Eq(2));
+}
+
+MATCHER(IsValidHealthData, "") {
+ *result_listener << "value is " << arg.toString() << ".";
+ if (!ExplainMatchResult(Ge(-1), arg.batteryManufacturingDateSeconds, result_listener)) {
+ *result_listener << " for batteryManufacturingDateSeconds.";
+ return false;
+ }
+ if (!ExplainMatchResult(Ge(-1), arg.batteryFirstUsageSeconds, result_listener)) {
+ *result_listener << " for batteryFirstUsageSeconds.";
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Tests the values returned by getBatteryHealthData() from interface IHealth.
+ */
+TEST_P(HealthAidl, getBatteryHealthData) {
+ BatteryHealthData value;
+ auto status = health->getBatteryHealthData(&value);
+ ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION)));
+ if (!status.isOk()) return;
+ ASSERT_THAT(value, IsValidHealthData());
+}
+
MATCHER(IsValidStorageInfo, "") {
*result_listener << "value is " << arg.toString() << ".";
if (!ExplainMatchResult(InClosedRange(0, 3), arg.eol, result_listener)) {
diff --git a/health/utils/libhealthshim/Android.bp b/health/utils/libhealthshim/Android.bp
index 3a1415f..14c32ae 100644
--- a/health/utils/libhealthshim/Android.bp
+++ b/health/utils/libhealthshim/Android.bp
@@ -34,7 +34,7 @@
"-Werror",
],
static_libs: [
- "android.hardware.health-V1-ndk",
+ "android.hardware.health-V2-ndk",
"android.hardware.health-translate-ndk",
"android.hardware.health@1.0",
"android.hardware.health@2.0",
diff --git a/health/utils/libhealthshim/include/health-shim/shim.h b/health/utils/libhealthshim/include/health-shim/shim.h
index f36fa5d..ff6849b 100644
--- a/health/utils/libhealthshim/include/health-shim/shim.h
+++ b/health/utils/libhealthshim/include/health-shim/shim.h
@@ -45,6 +45,9 @@
ndk::ScopedAStatus getStorageInfo(std::vector<StorageInfo>* _aidl_return) override;
ndk::ScopedAStatus getDiskStats(std::vector<DiskStats>* _aidl_return) override;
ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override;
+ ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override;
+ ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* _aidl_return) override;
+ ndk::ScopedAStatus getBatteryHealthData(BatteryHealthData* _aidl_return) override;
private:
::android::sp<HidlHealth> service_;
diff --git a/health/utils/libhealthshim/shim.cpp b/health/utils/libhealthshim/shim.cpp
index 1329679..6a5f512 100644
--- a/health/utils/libhealthshim/shim.cpp
+++ b/health/utils/libhealthshim/shim.cpp
@@ -217,4 +217,20 @@
return ReturnAndResultToStatus(ret, out_result);
}
+ScopedAStatus HealthShim::setChargingPolicy(BatteryChargingPolicy in_value) {
+ in_value = static_cast<BatteryChargingPolicy>(0);
+ return ResultToStatus(Result::NOT_SUPPORTED);
+}
+
+ScopedAStatus HealthShim::getChargingPolicy(BatteryChargingPolicy* out) {
+ *out = static_cast<BatteryChargingPolicy>(0);
+ return ResultToStatus(Result::NOT_SUPPORTED);
+}
+
+ScopedAStatus HealthShim::getBatteryHealthData(BatteryHealthData* out) {
+ out->batteryManufacturingDateSeconds = 0;
+ out->batteryFirstUsageSeconds = 0;
+ return ResultToStatus(Result::NOT_SUPPORTED);
+}
+
} // namespace aidl::android::hardware::health