health: Convert of health HAL to AIDL
On top of the hidl2aidl translation, the following is
done manually:
- Renamed the package from health2 to health. Also pulls in
health@1.0::Battery* enums.
- Removes Result and Constants enum. Result values are returned
as transaction status codes.
- Removes health@2.1 charger related APIs.
- remove shouldKeepScreenOn
- remove getHealthConfig
- remove HealthConfig type
- Removes StorageAttribute because it is not used in the framework
- Add units to HealthInfo fields and IHealth methods.
- Update docs (namely, u -> ยต in various places)
Bug: 177269435
Test: pass
Change-Id: I9c9a9d9dd5d49142258e608a463412d3e89e91a3
diff --git a/health/aidl/Android.bp b/health/aidl/Android.bp
new file mode 100644
index 0000000..940e4d8
--- /dev/null
+++ b/health/aidl/Android.bp
@@ -0,0 +1,62 @@
+// 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.
+
+aidl_interface {
+ name: "android.hardware.health",
+ vendor_available: true,
+ srcs: ["android/hardware/health/*.aidl"],
+ stability: "vintf",
+ backend: {
+ cpp: {
+ enabled: false,
+ },
+ java: {
+ enabled: true,
+ sdk_version: "module_current",
+ },
+ ndk: {
+ vndk: {
+ enabled: true,
+ },
+ },
+ },
+}
+
+cc_library {
+ name: "android.hardware.health-translate-ndk",
+ vendor_available: true,
+ srcs: ["android/hardware/health/translate-ndk.cpp"],
+ shared_libs: [
+ "libbinder_ndk",
+ "libhidlbase",
+ "android.hardware.health-V1-ndk",
+ "android.hardware.health@2.0",
+ "android.hardware.health@2.1",
+ ],
+ export_include_dirs: ["include"],
+ export_shared_lib_headers: [
+ "android.hardware.health@2.0",
+ "android.hardware.health@2.1",
+ ],
+}
+
+java_library {
+ name: "android.hardware.health-translate-java",
+ srcs: ["android/hardware/health/Translate.java"],
+ libs: [
+ "android.hardware.health-V1-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/BatteryCapacityLevel.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryCapacityLevel.aidl
new file mode 100644
index 0000000..e543886
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryCapacityLevel.aidl
@@ -0,0 +1,44 @@
+/*
+ * 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 BatteryCapacityLevel {
+ UNSUPPORTED = -1,
+ UNKNOWN = 0,
+ CRITICAL = 1,
+ LOW = 2,
+ NORMAL = 3,
+ HIGH = 4,
+ FULL = 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
new file mode 100644
index 0000000..4ce7952
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl
@@ -0,0 +1,44 @@
+/*
+ * 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 BatteryHealth {
+ UNKNOWN = 1,
+ GOOD = 2,
+ OVERHEAT = 3,
+ DEAD = 4,
+ OVER_VOLTAGE = 5,
+ UNSPECIFIED_FAILURE = 6,
+ COLD = 7,
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryStatus.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryStatus.aidl
new file mode 100644
index 0000000..340b2ec
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryStatus.aidl
@@ -0,0 +1,42 @@
+/*
+ * 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 BatteryStatus {
+ UNKNOWN = 1,
+ CHARGING = 2,
+ DISCHARGING = 3,
+ NOT_CHARGING = 4,
+ FULL = 5,
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/DiskStats.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/DiskStats.aidl
new file mode 100644
index 0000000..5aa5890
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/DiskStats.aidl
@@ -0,0 +1,48 @@
+/*
+ * 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;
+@VintfStability
+parcelable DiskStats {
+ long reads;
+ long readMerges;
+ long readSectors;
+ long readTicks;
+ long writes;
+ long writeMerges;
+ long writeSectors;
+ long writeTicks;
+ long ioInFlight;
+ long ioTicks;
+ long ioInQueue;
+}
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
new file mode 100644
index 0000000..34a87a6
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl
@@ -0,0 +1,60 @@
+/*
+ * 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;
+@VintfStability
+parcelable HealthInfo {
+ boolean chargerAcOnline;
+ boolean chargerUsbOnline;
+ boolean chargerWirelessOnline;
+ int maxChargingCurrentMicroamps;
+ int maxChargingVoltageMicrovolts;
+ android.hardware.health.BatteryStatus batteryStatus;
+ android.hardware.health.BatteryHealth batteryHealth;
+ boolean batteryPresent;
+ int batteryLevel;
+ int batteryVoltageMillivolts;
+ int batteryTemperatureTenthsCelsius;
+ int batteryCurrentMicroamps;
+ int batteryCycleCount;
+ int batteryFullChargeUah;
+ int batteryChargeCounterUah;
+ String batteryTechnology;
+ int batteryCurrentAverageMicroamps;
+ android.hardware.health.DiskStats[] diskStats;
+ android.hardware.health.StorageInfo[] storageInfos;
+ android.hardware.health.BatteryCapacityLevel batteryCapacityLevel;
+ long batteryChargeTimeToFullNowSeconds;
+ int batteryFullChargeDesignCapacityUah;
+ 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
new file mode 100644
index 0000000..7016ae4
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl
@@ -0,0 +1,51 @@
+/*
+ * 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;
+@VintfStability
+interface IHealth {
+ void registerCallback(in android.hardware.health.IHealthInfoCallback callback);
+ void unregisterCallback(in android.hardware.health.IHealthInfoCallback callback);
+ void update();
+ int getChargeCounterUah();
+ int getCurrentNowMicroamps();
+ int getCurrentAverageMicroamps();
+ int getCapacity();
+ long getEnergyCounterNwh();
+ android.hardware.health.BatteryStatus getChargeStatus();
+ android.hardware.health.StorageInfo[] getStorageInfo();
+ android.hardware.health.DiskStats[] getDiskStats();
+ android.hardware.health.HealthInfo getHealthInfo();
+ const int STATUS_UNKNOWN = 2;
+ const int STATUS_CALLBACK_DIED = 4;
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealthInfoCallback.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealthInfoCallback.aidl
new file mode 100644
index 0000000..1b6366f
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealthInfoCallback.aidl
@@ -0,0 +1,38 @@
+/*
+ * 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;
+@VintfStability
+interface IHealthInfoCallback {
+ oneway void healthInfoChanged(in android.hardware.health.HealthInfo info);
+}
diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/StorageInfo.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/StorageInfo.aidl
new file mode 100644
index 0000000..eaae5a6
--- /dev/null
+++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/StorageInfo.aidl
@@ -0,0 +1,41 @@
+/*
+ * 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;
+@VintfStability
+parcelable StorageInfo {
+ int eol;
+ int lifetimeA;
+ int lifetimeB;
+ String version;
+}
diff --git a/health/aidl/android/hardware/health/BatteryCapacityLevel.aidl b/health/aidl/android/hardware/health/BatteryCapacityLevel.aidl
new file mode 100644
index 0000000..0c26fa2
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryCapacityLevel.aidl
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+/**
+ * Battery capacity level. This enum provides additional information along side
+ * with the battery capacity.
+ * Clients of this HAL must use this value before inferring it from the
+ * battery capacity.
+ */
+@VintfStability
+@Backing(type="int")
+enum BatteryCapacityLevel {
+ /**
+ * Battery capacity level is unsupported.
+ * Battery capacity level must be set to this value if and only if the
+ * implementation is unsupported.
+ */
+ UNSUPPORTED = -1,
+ /**
+ * Battery capacity level is unknown.
+ * Battery capacity level must be set to this value if and only if battery
+ * is not present or the battery capacity level is unknown/uninitialized.
+ */
+ UNKNOWN,
+ /**
+ * Battery is at critical level. The Android framework must schedule a
+ * shutdown when it sees this value from the HAL.
+ */
+ CRITICAL,
+ /**
+ * Battery is low. The Android framework may limit the performance of
+ * the device when it sees this value from the HAL.
+ */
+ LOW,
+ /**
+ * Battery level is normal.
+ */
+ NORMAL,
+ /**
+ * Battery level is high.
+ */
+ HIGH,
+ /**
+ * Battery is full. It must be set to FULL if and only if battery level is
+ * 100.
+ */
+ FULL,
+}
diff --git a/health/aidl/android/hardware/health/BatteryHealth.aidl b/health/aidl/android/hardware/health/BatteryHealth.aidl
new file mode 100644
index 0000000..2b6e51f
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryHealth.aidl
@@ -0,0 +1,37 @@
+/*
+ * 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 BatteryHealth {
+ UNKNOWN = 1,
+ GOOD = 2,
+ OVERHEAT = 3,
+ DEAD = 4,
+ OVER_VOLTAGE = 5,
+ /**
+ * Battery experienced an unknown/unspecified failure.
+ */
+ UNSPECIFIED_FAILURE = 6,
+ COLD = 7,
+}
diff --git a/health/aidl/android/hardware/health/BatteryStatus.aidl b/health/aidl/android/hardware/health/BatteryStatus.aidl
new file mode 100644
index 0000000..774b28e
--- /dev/null
+++ b/health/aidl/android/hardware/health/BatteryStatus.aidl
@@ -0,0 +1,36 @@
+/*
+ * 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 Status.
+ * Note: These are currently in sync with BatteryManager and must not
+ * be extended / altered.
+ */
+@VintfStability
+@Backing(type="int")
+enum BatteryStatus {
+ UNKNOWN = 1,
+ CHARGING = 2,
+ DISCHARGING = 3,
+ /**
+ * Battery is *not* charging - special case when charger is present
+ * but battery isn't charging
+ */
+ NOT_CHARGING = 4,
+ FULL = 5,
+}
diff --git a/health/aidl/android/hardware/health/DiskStats.aidl b/health/aidl/android/hardware/health/DiskStats.aidl
new file mode 100644
index 0000000..532cbfd
--- /dev/null
+++ b/health/aidl/android/hardware/health/DiskStats.aidl
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+/*
+ * Disk statistics since boot.
+ *
+ * See {@code struct disk_stats} in {@code storaged} for interpretations of these fields.
+ *
+ * All integers in this struct must be interpreted as unsigned.
+ */
+@VintfStability
+parcelable DiskStats {
+ /**
+ * Number of reads processed.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long reads;
+ /**
+ * number of read I/Os merged with in-queue I/Os.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long readMerges;
+ /**
+ * number of sectors read.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long readSectors;
+ /**
+ * total wait time for read requests.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long readTicks;
+ /**
+ * number of writes processed.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long writes;
+ /**
+ * number of writes merged with in-queue I/Os.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long writeMerges;
+ /**
+ * number of sectors written.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long writeSectors;
+ /**
+ * total wait time for write requests.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long writeTicks;
+ /**
+ * number of I/Os currently in flight.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long ioInFlight;
+ /**
+ * total time this block device has been active.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long ioTicks;
+ /**
+ * total wait time for all requests.
+ *
+ * Value must be interpreted as unsigned.
+ */
+ long ioInQueue;
+}
diff --git a/health/aidl/android/hardware/health/HealthInfo.aidl b/health/aidl/android/hardware/health/HealthInfo.aidl
new file mode 100644
index 0000000..504e218
--- /dev/null
+++ b/health/aidl/android/hardware/health/HealthInfo.aidl
@@ -0,0 +1,132 @@
+/*
+ * 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;
+
+import android.hardware.health.BatteryCapacityLevel;
+import android.hardware.health.BatteryHealth;
+import android.hardware.health.BatteryStatus;
+import android.hardware.health.DiskStats;
+import android.hardware.health.StorageInfo;
+
+/**
+ * Health Information.
+ */
+@VintfStability
+parcelable HealthInfo {
+ /**
+ * AC charger state - 'true' if online
+ */
+ boolean chargerAcOnline;
+ /**
+ * USB charger state - 'true' if online
+ */
+ boolean chargerUsbOnline;
+ /**
+ * Wireless charger state - 'true' if online
+ */
+ boolean chargerWirelessOnline;
+ /**
+ * Maximum charging current supported by charger in µA
+ */
+ int maxChargingCurrentMicroamps;
+ /**
+ * Maximum charging voltage supported by charger in µV
+ */
+ int maxChargingVoltageMicrovolts;
+
+ android.hardware.health.BatteryStatus batteryStatus;
+
+ android.hardware.health.BatteryHealth batteryHealth;
+ /**
+ * 'true' if battery is present
+ */
+ boolean batteryPresent;
+ /**
+ * Remaining battery capacity in percent
+ */
+ int batteryLevel;
+ /**
+ * Instantaneous battery voltage in millivolts (mV).
+ *
+ * Historically, the unit of this field is microvolts (µV), but all
+ * clients and implementations uses millivolts in practice, making it
+ * the de-facto standard.
+ */
+ int batteryVoltageMillivolts;
+ /**
+ * Instantaneous battery temperature in tenths of degrees Celsius
+ */
+ int batteryTemperatureTenthsCelsius;
+ /**
+ * Instantaneous battery current in µA
+ */
+ int batteryCurrentMicroamps;
+ /**
+ * Battery charge cycle count
+ */
+ int batteryCycleCount;
+ /**
+ * Battery charge value when it is considered to be "full" in µA-h
+ */
+ int batteryFullChargeUah;
+ /**
+ * Instantaneous battery capacity in µA-h
+ */
+ int batteryChargeCounterUah;
+ /**
+ * Battery technology, e.g. "Li-ion, Li-Poly" etc.
+ */
+ String batteryTechnology;
+ /**
+ * Average battery current in µA. Will be 0 if unsupported.
+ */
+ int batteryCurrentAverageMicroamps;
+ /**
+ * Disk Statistics. Will be an empty vector if unsupported.
+ */
+ DiskStats[] diskStats;
+ /**
+ * Information on storage devices. Will be an empty vector if
+ * unsupported.
+ */
+ StorageInfo[] storageInfos;
+ /**
+ * Battery capacity level. See {@link BatteryCapacityLevel} for more details.
+ */
+ BatteryCapacityLevel batteryCapacityLevel;
+
+ /**
+ * Value of {@link #batteryChargeTimeToFullNowSeconds} if it is not
+ * supported.
+ */
+ const int BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED = -1;
+ /**
+ * Estimated time to fully charge the device (in seconds).
+ * Value must be BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED if and
+ * only if the implementation is unsupported.
+ * Value must be 0 if and only if batteryCapacityLevel is FULL or UNKNOWN.
+ * Otherwise, value must be positive.
+ */
+ long batteryChargeTimeToFullNowSeconds;
+ /**
+ * Estimated battery full charge design capacity (in microamp hours, µAh).
+ * Value must be 0 if unknown.
+ * Value must be greater than 100 000 µAh if known.
+ * Value must be less than 100 000 000 µAh if known.
+ */
+ int batteryFullChargeDesignCapacityUah;
+}
diff --git a/health/aidl/android/hardware/health/IHealth.aidl b/health/aidl/android/hardware/health/IHealth.aidl
new file mode 100644
index 0000000..d541eca
--- /dev/null
+++ b/health/aidl/android/hardware/health/IHealth.aidl
@@ -0,0 +1,203 @@
+/*
+ * 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;
+
+import android.hardware.health.BatteryStatus;
+import android.hardware.health.DiskStats;
+import android.hardware.health.HealthInfo;
+import android.hardware.health.IHealthInfoCallback;
+import android.hardware.health.StorageInfo;
+
+/**
+ * IHealth manages health info and posts events on registered callbacks.
+ *
+ * Implementations must send health info to all callbacks periodically.
+ */
+@VintfStability
+interface IHealth {
+ /** Status code for function. The operation encounters an unknown error. */
+ const int STATUS_UNKNOWN = 2;
+
+ /**
+ * Status code for function.
+ * A registered callback object is dead.
+ */
+ const int STATUS_CALLBACK_DIED = 4;
+
+ /**
+ * Register a callback for any health info events.
+ *
+ * Registering a new callback must not unregister the old one; the old
+ * callback remains registered until one of the following happens:
+ * - A client explicitly calls {@link #unregisterCallback} to unregister it.
+ * - The client process that hosts the callback dies.
+ *
+ * @param callback the callback to register.
+ * @return If error, return service specific error with code STATUS_UNKNOWN.
+ */
+ void registerCallback(in IHealthInfoCallback callback);
+
+ /**
+ * Explicitly unregister a callback that is previously registered through
+ * {@link #registerCallback}.
+ *
+ * @param callback the callback to unregister.
+ * @return If error:
+ * - Return exception with code EX_ILLEGAL_ARGUMENT
+ * if callback is not registered previously,
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ void unregisterCallback(in IHealthInfoCallback callback);
+
+ /**
+ * Schedule update.
+ *
+ * When update() is called, the service must notify all registered callbacks
+ * with the most recent health info.
+ *
+ * @return If error, return service specific error with code:
+ * - STATUS_CALLBACK_DIED if any registered callback is dead,
+ * - STATUS_UNKNOWN for other errors.
+ */
+ void update();
+
+ /**
+ * Get battery capacity in microampere-hours(µAh).
+ *
+ * @return battery capacity 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),
+ * - Retrurn service specific error with code
+ * STATUS_UNKNOWN for other errors.
+ */
+ int getChargeCounterUah();
+
+ /**
+ * Get instantaneous battery current in microamperes(µA).
+ *
+ * Positive values indicate net current entering the battery from a charge
+ * source, negative values indicate net current discharging from the
+ * battery.
+ *
+ * @return instantaneous battery current 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 for other errors.
+ */
+ int getCurrentNowMicroamps();
+
+ /**
+ * Get average battery current in microamperes(µA).
+ *
+ * Positive values indicate net current entering the battery from a charge
+ * source, negative values indicate net current discharging from the
+ * battery. The time period over which the average is computed may depend on
+ * the fuel gauge hardware and its configuration.
+ *
+ * @return average battery current 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 for other errors.
+ */
+ int getCurrentAverageMicroamps();
+
+ /**
+ * Get remaining battery capacity percentage of total capacity
+ * (with no fractional part).
+ *
+ * @return remaining battery capacity 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 for other errors.
+ */
+ int getCapacity();
+
+ /**
+ * Get battery remaining energy in nanowatt-hours.
+ *
+ * @return remaining energy if successful.
+ * If error:
+ * - 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.
+ */
+ long getEnergyCounterNwh();
+
+ /**
+ * Get battery charge status.
+ *
+ * @return charge status 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.
+ */
+ BatteryStatus getChargeStatus();
+
+ /**
+ * Get storage info.
+ *
+ * @return vector of StorageInfo structs if successful.
+ * If error:
+ * - Return exception with code EX_UNSUPPORTED_OPERATION
+ * if this property is not supported,
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ StorageInfo[] getStorageInfo();
+
+ /**
+ * Gets disk statistics (number of reads/writes processed, number of I/O
+ * operations in flight etc).
+ *
+ * @return vector of disk statistics if successful.
+ * The mapping is index 0->sda, 1->sdb and so on.
+ * If error:
+ * - Return exception with code EX_UNSUPPORTED_OPERATION
+ * if this property is not supported,
+ * - Return service specific error with code STATUS_UNKNOWN
+ * for other errors.
+ */
+ DiskStats[] getDiskStats();
+
+ /**
+ * Get Health Information.
+ *
+ * @return Health information if successful.
+ * If error:
+ * - 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.
+ */
+ HealthInfo getHealthInfo();
+}
diff --git a/health/aidl/android/hardware/health/IHealthInfoCallback.aidl b/health/aidl/android/hardware/health/IHealthInfoCallback.aidl
new file mode 100644
index 0000000..e9720fa
--- /dev/null
+++ b/health/aidl/android/hardware/health/IHealthInfoCallback.aidl
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import android.hardware.health.HealthInfo;
+
+/**
+ * IHealthInfoCallback is the updated callback interface to
+ * {@link IHealth#registerCallback}.
+ */
+@VintfStability
+interface IHealthInfoCallback {
+ /**
+ * An implementation of IHealth must call healthInfoChanged on all
+ * registered callbacks after health info changes.
+ * @param info the updated HealthInfo
+ */
+ oneway void healthInfoChanged(in HealthInfo info);
+}
diff --git a/health/aidl/android/hardware/health/StorageInfo.aidl b/health/aidl/android/hardware/health/StorageInfo.aidl
new file mode 100644
index 0000000..4c4dace
--- /dev/null
+++ b/health/aidl/android/hardware/health/StorageInfo.aidl
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/*
+ * Information on storage device including life time estimates, end of life
+ * information and other attributes.
+ *
+ * All integers in this struct must be interpreted as non-negative.
+ */
+@VintfStability
+parcelable StorageInfo {
+ /**
+ * pre-eol (end of life) information. Follows JEDEC standard No.84-B50.
+ *
+ * Value must be interpreted as non-negative.
+ */
+ int eol;
+ /**
+ * device life time estimation (type A). Follows JEDEC standard No.84-B50.
+ *
+ * Value must be interpreted as non-negative.
+ */
+ int lifetimeA;
+ /**
+ * device life time estimation (type B). Follows JEDEC standard No.84-B50.
+ *
+ * Value must be interpreted as non-negative.
+ */
+ int lifetimeB;
+ /**
+ * version string
+ */
+ String version;
+}
diff --git a/health/aidl/android/hardware/health/Translate.java b/health/aidl/android/hardware/health/Translate.java
new file mode 100644
index 0000000..c8ace1c
--- /dev/null
+++ b/health/aidl/android/hardware/health/Translate.java
@@ -0,0 +1,80 @@
+/*
+ * 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;
+
+public class Translate {
+ static public android.hardware.health.StorageInfo h2aTranslate(
+ android.hardware.health.V2_0.StorageInfo in) {
+ android.hardware.health.StorageInfo out = new android.hardware.health.StorageInfo();
+ out.eol = in.eol;
+ out.lifetimeA = in.lifetimeA;
+ out.lifetimeB = in.lifetimeB;
+ out.version = in.version;
+ return out;
+ }
+
+ static public android.hardware.health.DiskStats h2aTranslate(
+ android.hardware.health.V2_0.DiskStats in) {
+ android.hardware.health.DiskStats out = new android.hardware.health.DiskStats();
+ out.reads = in.reads;
+ out.readMerges = in.readMerges;
+ out.readSectors = in.readSectors;
+ out.readTicks = in.readTicks;
+ out.writes = in.writes;
+ out.writeMerges = in.writeMerges;
+ out.writeSectors = in.writeSectors;
+ out.writeTicks = in.writeTicks;
+ out.ioInFlight = in.ioInFlight;
+ out.ioTicks = in.ioTicks;
+ out.ioInQueue = in.ioInQueue;
+ return out;
+ }
+
+ static public android.hardware.health.HealthInfo h2aTranslate(
+ android.hardware.health.V2_1.HealthInfo in) {
+ android.hardware.health.HealthInfo out = new android.hardware.health.HealthInfo();
+ out.chargerAcOnline = in.legacy.legacy.chargerAcOnline;
+ out.chargerUsbOnline = in.legacy.legacy.chargerUsbOnline;
+ out.chargerWirelessOnline = in.legacy.legacy.chargerWirelessOnline;
+ out.maxChargingCurrentMicroamps = in.legacy.legacy.maxChargingCurrent;
+ out.maxChargingVoltageMicrovolts = in.legacy.legacy.maxChargingVoltage;
+ out.batteryStatus = in.legacy.legacy.batteryStatus;
+ out.batteryHealth = in.legacy.legacy.batteryHealth;
+ out.batteryPresent = in.legacy.legacy.batteryPresent;
+ out.batteryLevel = in.legacy.legacy.batteryLevel;
+ out.batteryVoltageMillivolts = in.legacy.legacy.batteryVoltage;
+ out.batteryTemperatureTenthsCelsius = in.legacy.legacy.batteryTemperature;
+ out.batteryCurrentMicroamps = in.legacy.legacy.batteryCurrent;
+ out.batteryCycleCount = in.legacy.legacy.batteryCycleCount;
+ out.batteryFullChargeUah = in.legacy.legacy.batteryFullCharge;
+ out.batteryChargeCounterUah = in.legacy.legacy.batteryChargeCounter;
+ out.batteryTechnology = in.legacy.legacy.batteryTechnology;
+ out.batteryCurrentAverageMicroamps = in.legacy.batteryCurrentAverage;
+ out.diskStats = new android.hardware.health.DiskStats[in.legacy.diskStats.size()];
+ for (int i = 0; i < in.legacy.diskStats.size(); i++) {
+ out.diskStats[i] = h2aTranslate(in.legacy.diskStats.get(i));
+ }
+ out.storageInfos = new android.hardware.health.StorageInfo[in.legacy.storageInfos.size()];
+ for (int i = 0; i < in.legacy.storageInfos.size(); i++) {
+ out.storageInfos[i] = h2aTranslate(in.legacy.storageInfos.get(i));
+ }
+ out.batteryCapacityLevel = in.batteryCapacityLevel;
+ out.batteryChargeTimeToFullNowSeconds = in.batteryChargeTimeToFullNowSeconds;
+ out.batteryFullChargeDesignCapacityUah = in.batteryFullChargeDesignCapacityUah;
+ return out;
+ }
+}
diff --git a/health/aidl/android/hardware/health/translate-ndk.cpp b/health/aidl/android/hardware/health/translate-ndk.cpp
new file mode 100644
index 0000000..7fe6ced
--- /dev/null
+++ b/health/aidl/android/hardware/health/translate-ndk.cpp
@@ -0,0 +1,148 @@
+/*
+ * 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.
+ */
+
+#include "android/hardware/health/translate-ndk.h"
+
+namespace android::h2a {
+
+static_assert(aidl::android::hardware::health::BatteryStatus::UNKNOWN ==
+ static_cast<aidl::android::hardware::health::BatteryStatus>(
+ ::android::hardware::health::V1_0::BatteryStatus::UNKNOWN));
+static_assert(aidl::android::hardware::health::BatteryStatus::CHARGING ==
+ static_cast<aidl::android::hardware::health::BatteryStatus>(
+ ::android::hardware::health::V1_0::BatteryStatus::CHARGING));
+static_assert(aidl::android::hardware::health::BatteryStatus::DISCHARGING ==
+ static_cast<aidl::android::hardware::health::BatteryStatus>(
+ ::android::hardware::health::V1_0::BatteryStatus::DISCHARGING));
+static_assert(aidl::android::hardware::health::BatteryStatus::NOT_CHARGING ==
+ static_cast<aidl::android::hardware::health::BatteryStatus>(
+ ::android::hardware::health::V1_0::BatteryStatus::NOT_CHARGING));
+static_assert(aidl::android::hardware::health::BatteryStatus::FULL ==
+ static_cast<aidl::android::hardware::health::BatteryStatus>(
+ ::android::hardware::health::V1_0::BatteryStatus::FULL));
+
+static_assert(aidl::android::hardware::health::BatteryHealth::UNKNOWN ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::UNKNOWN));
+static_assert(aidl::android::hardware::health::BatteryHealth::GOOD ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::GOOD));
+static_assert(aidl::android::hardware::health::BatteryHealth::OVERHEAT ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::OVERHEAT));
+static_assert(aidl::android::hardware::health::BatteryHealth::DEAD ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::DEAD));
+static_assert(aidl::android::hardware::health::BatteryHealth::OVER_VOLTAGE ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::OVER_VOLTAGE));
+static_assert(aidl::android::hardware::health::BatteryHealth::UNSPECIFIED_FAILURE ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::UNSPECIFIED_FAILURE));
+static_assert(aidl::android::hardware::health::BatteryHealth::COLD ==
+ static_cast<aidl::android::hardware::health::BatteryHealth>(
+ ::android::hardware::health::V1_0::BatteryHealth::COLD));
+
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::UNSUPPORTED ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::UNSUPPORTED));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::UNKNOWN ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::UNKNOWN));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::CRITICAL ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::CRITICAL));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::LOW ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::LOW));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::NORMAL ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::NORMAL));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::HIGH ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::HIGH));
+static_assert(aidl::android::hardware::health::BatteryCapacityLevel::FULL ==
+ static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ ::android::hardware::health::V2_1::BatteryCapacityLevel::FULL));
+
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_0::StorageInfo& in,
+ aidl::android::hardware::health::StorageInfo* out) {
+ out->eol = in.eol;
+ out->lifetimeA = in.lifetimeA;
+ out->lifetimeB = in.lifetimeB;
+ out->version = in.version;
+ return true;
+}
+
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_0::DiskStats& in,
+ aidl::android::hardware::health::DiskStats* out) {
+ out->reads = static_cast<int64_t>(in.reads);
+ out->readMerges = static_cast<int64_t>(in.readMerges);
+ out->readSectors = static_cast<int64_t>(in.readSectors);
+ out->readTicks = static_cast<int64_t>(in.readTicks);
+ out->writes = static_cast<int64_t>(in.writes);
+ out->writeMerges = static_cast<int64_t>(in.writeMerges);
+ out->writeSectors = static_cast<int64_t>(in.writeSectors);
+ out->writeTicks = static_cast<int64_t>(in.writeTicks);
+ out->ioInFlight = static_cast<int64_t>(in.ioInFlight);
+ out->ioTicks = static_cast<int64_t>(in.ioTicks);
+ out->ioInQueue = static_cast<int64_t>(in.ioInQueue);
+ return true;
+}
+
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_1::HealthInfo& in,
+ aidl::android::hardware::health::HealthInfo* out) {
+ out->chargerAcOnline = static_cast<bool>(in.legacy.legacy.chargerAcOnline);
+ out->chargerUsbOnline = static_cast<bool>(in.legacy.legacy.chargerUsbOnline);
+ out->chargerWirelessOnline = static_cast<bool>(in.legacy.legacy.chargerWirelessOnline);
+ out->maxChargingCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.maxChargingCurrent);
+ out->maxChargingVoltageMicrovolts = static_cast<int32_t>(in.legacy.legacy.maxChargingVoltage);
+ out->batteryStatus = static_cast<aidl::android::hardware::health::BatteryStatus>(
+ in.legacy.legacy.batteryStatus);
+ out->batteryHealth = static_cast<aidl::android::hardware::health::BatteryHealth>(
+ in.legacy.legacy.batteryHealth);
+ out->batteryPresent = static_cast<bool>(in.legacy.legacy.batteryPresent);
+ out->batteryLevel = static_cast<int32_t>(in.legacy.legacy.batteryLevel);
+ out->batteryVoltageMillivolts = static_cast<int32_t>(in.legacy.legacy.batteryVoltage);
+ out->batteryTemperatureTenthsCelsius =
+ static_cast<int32_t>(in.legacy.legacy.batteryTemperature);
+ out->batteryCurrentMicroamps = static_cast<int32_t>(in.legacy.legacy.batteryCurrent);
+ out->batteryCycleCount = static_cast<int32_t>(in.legacy.legacy.batteryCycleCount);
+ out->batteryFullChargeUah = static_cast<int32_t>(in.legacy.legacy.batteryFullCharge);
+ out->batteryChargeCounterUah = static_cast<int32_t>(in.legacy.legacy.batteryChargeCounter);
+ out->batteryTechnology = in.legacy.legacy.batteryTechnology;
+ out->batteryCurrentAverageMicroamps = static_cast<int32_t>(in.legacy.batteryCurrentAverage);
+ out->diskStats.clear();
+ out->diskStats.resize(in.legacy.diskStats.size());
+ for (size_t i = 0; i < in.legacy.diskStats.size(); ++i)
+ if (!translate(in.legacy.diskStats[i], &out->diskStats[i])) return false;
+ out->storageInfos.clear();
+ out->storageInfos.resize(in.legacy.storageInfos.size());
+ for (size_t i = 0; i < in.legacy.storageInfos.size(); ++i)
+ if (!translate(in.legacy.storageInfos[i], &out->storageInfos[i])) return false;
+ out->batteryCapacityLevel = static_cast<aidl::android::hardware::health::BatteryCapacityLevel>(
+ in.batteryCapacityLevel);
+ out->batteryChargeTimeToFullNowSeconds =
+ static_cast<int64_t>(in.batteryChargeTimeToFullNowSeconds);
+ out->batteryFullChargeDesignCapacityUah =
+ static_cast<int32_t>(in.batteryFullChargeDesignCapacityUah);
+ return true;
+}
+
+} // namespace android::h2a
diff --git a/health/aidl/include/android/hardware/health/translate-ndk.h b/health/aidl/include/android/hardware/health/translate-ndk.h
new file mode 100644
index 0000000..2f8fe04
--- /dev/null
+++ b/health/aidl/include/android/hardware/health/translate-ndk.h
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/health/BatteryCapacityLevel.h>
+#include <aidl/android/hardware/health/DiskStats.h>
+#include <aidl/android/hardware/health/HealthInfo.h>
+#include <aidl/android/hardware/health/StorageInfo.h>
+#include <android/hardware/health/2.0/types.h>
+#include <android/hardware/health/2.1/types.h>
+#include <limits>
+
+namespace android::h2a {
+
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_0::StorageInfo& in,
+ aidl::android::hardware::health::StorageInfo* out);
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_0::DiskStats& in,
+ aidl::android::hardware::health::DiskStats* out);
+__attribute__((warn_unused_result)) bool translate(
+ const ::android::hardware::health::V2_1::HealthInfo& in,
+ aidl::android::hardware::health::HealthInfo* out);
+
+} // namespace android::h2a