From 52ecb3f421aef38572898473d28887ab85b34fc1 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 11 Jan 2021 17:04:33 -0800 Subject: [PATCH 1/3] health: Convert of health HAL to AIDL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- health/aidl/Android.bp | 62 ++++++ .../hardware/health/BatteryCapacityLevel.aidl | 44 ++++ .../hardware/health/BatteryHealth.aidl | 44 ++++ .../hardware/health/BatteryStatus.aidl | 42 ++++ .../android/hardware/health/DiskStats.aidl | 48 +++++ .../android/hardware/health/HealthInfo.aidl | 60 ++++++ .../android/hardware/health/IHealth.aidl | 51 +++++ .../hardware/health/IHealthInfoCallback.aidl | 38 ++++ .../android/hardware/health/StorageInfo.aidl | 41 ++++ .../hardware/health/BatteryCapacityLevel.aidl | 63 ++++++ .../hardware/health/BatteryHealth.aidl | 37 ++++ .../hardware/health/BatteryStatus.aidl | 36 ++++ .../android/hardware/health/DiskStats.aidl | 94 ++++++++ .../android/hardware/health/HealthInfo.aidl | 132 ++++++++++++ .../aidl/android/hardware/health/IHealth.aidl | 203 ++++++++++++++++++ .../hardware/health/IHealthInfoCallback.aidl | 33 +++ .../android/hardware/health/StorageInfo.aidl | 49 +++++ .../android/hardware/health/Translate.java | 80 +++++++ .../android/hardware/health/translate-ndk.cpp | 148 +++++++++++++ .../android/hardware/health/translate-ndk.h | 39 ++++ 20 files changed, 1344 insertions(+) create mode 100644 health/aidl/Android.bp create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryCapacityLevel.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryHealth.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryStatus.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/DiskStats.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealthInfoCallback.aidl create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/StorageInfo.aidl create mode 100644 health/aidl/android/hardware/health/BatteryCapacityLevel.aidl create mode 100644 health/aidl/android/hardware/health/BatteryHealth.aidl create mode 100644 health/aidl/android/hardware/health/BatteryStatus.aidl create mode 100644 health/aidl/android/hardware/health/DiskStats.aidl create mode 100644 health/aidl/android/hardware/health/HealthInfo.aidl create mode 100644 health/aidl/android/hardware/health/IHealth.aidl create mode 100644 health/aidl/android/hardware/health/IHealthInfoCallback.aidl create mode 100644 health/aidl/android/hardware/health/StorageInfo.aidl create mode 100644 health/aidl/android/hardware/health/Translate.java create mode 100644 health/aidl/android/hardware/health/translate-ndk.cpp create mode 100644 health/aidl/include/android/hardware/health/translate-ndk.h diff --git a/health/aidl/Android.bp b/health/aidl/Android.bp new file mode 100644 index 0000000000..940e4d86ad --- /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 0000000000..e5438865c1 --- /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 -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 0000000000..4ce7952af2 --- /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 -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 0000000000..340b2ecc3f --- /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 -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 0000000000..5aa58900bb --- /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 -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 0000000000..34a87a66ec --- /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 -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 0000000000..7016ae4c86 --- /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 -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 0000000000..1b6366fa7a --- /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 -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 0000000000..eaae5a6110 --- /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 -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 0000000000..0c26fa2d85 --- /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 0000000000..2b6e51f0a5 --- /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 0000000000..774b28e0ef --- /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 0000000000..532cbfdde2 --- /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 0000000000..504e218b83 --- /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 0000000000..d541eca328 --- /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 0000000000..e9720fa1b6 --- /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 0000000000..4c4dace72c --- /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 0000000000..c8ace1c085 --- /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 0000000000..7fe6ced444 --- /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( + ::android::hardware::health::V1_0::BatteryStatus::UNKNOWN)); +static_assert(aidl::android::hardware::health::BatteryStatus::CHARGING == + static_cast( + ::android::hardware::health::V1_0::BatteryStatus::CHARGING)); +static_assert(aidl::android::hardware::health::BatteryStatus::DISCHARGING == + static_cast( + ::android::hardware::health::V1_0::BatteryStatus::DISCHARGING)); +static_assert(aidl::android::hardware::health::BatteryStatus::NOT_CHARGING == + static_cast( + ::android::hardware::health::V1_0::BatteryStatus::NOT_CHARGING)); +static_assert(aidl::android::hardware::health::BatteryStatus::FULL == + static_cast( + ::android::hardware::health::V1_0::BatteryStatus::FULL)); + +static_assert(aidl::android::hardware::health::BatteryHealth::UNKNOWN == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::UNKNOWN)); +static_assert(aidl::android::hardware::health::BatteryHealth::GOOD == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::GOOD)); +static_assert(aidl::android::hardware::health::BatteryHealth::OVERHEAT == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::OVERHEAT)); +static_assert(aidl::android::hardware::health::BatteryHealth::DEAD == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::DEAD)); +static_assert(aidl::android::hardware::health::BatteryHealth::OVER_VOLTAGE == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::OVER_VOLTAGE)); +static_assert(aidl::android::hardware::health::BatteryHealth::UNSPECIFIED_FAILURE == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::UNSPECIFIED_FAILURE)); +static_assert(aidl::android::hardware::health::BatteryHealth::COLD == + static_cast( + ::android::hardware::health::V1_0::BatteryHealth::COLD)); + +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::UNSUPPORTED == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::UNSUPPORTED)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::UNKNOWN == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::UNKNOWN)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::CRITICAL == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::CRITICAL)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::LOW == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::LOW)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::NORMAL == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::NORMAL)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::HIGH == + static_cast( + ::android::hardware::health::V2_1::BatteryCapacityLevel::HIGH)); +static_assert(aidl::android::hardware::health::BatteryCapacityLevel::FULL == + static_cast( + ::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(in.reads); + out->readMerges = static_cast(in.readMerges); + out->readSectors = static_cast(in.readSectors); + out->readTicks = static_cast(in.readTicks); + out->writes = static_cast(in.writes); + out->writeMerges = static_cast(in.writeMerges); + out->writeSectors = static_cast(in.writeSectors); + out->writeTicks = static_cast(in.writeTicks); + out->ioInFlight = static_cast(in.ioInFlight); + out->ioTicks = static_cast(in.ioTicks); + out->ioInQueue = static_cast(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(in.legacy.legacy.chargerAcOnline); + out->chargerUsbOnline = static_cast(in.legacy.legacy.chargerUsbOnline); + out->chargerWirelessOnline = static_cast(in.legacy.legacy.chargerWirelessOnline); + out->maxChargingCurrentMicroamps = static_cast(in.legacy.legacy.maxChargingCurrent); + out->maxChargingVoltageMicrovolts = static_cast(in.legacy.legacy.maxChargingVoltage); + out->batteryStatus = static_cast( + in.legacy.legacy.batteryStatus); + out->batteryHealth = static_cast( + in.legacy.legacy.batteryHealth); + out->batteryPresent = static_cast(in.legacy.legacy.batteryPresent); + out->batteryLevel = static_cast(in.legacy.legacy.batteryLevel); + out->batteryVoltageMillivolts = static_cast(in.legacy.legacy.batteryVoltage); + out->batteryTemperatureTenthsCelsius = + static_cast(in.legacy.legacy.batteryTemperature); + out->batteryCurrentMicroamps = static_cast(in.legacy.legacy.batteryCurrent); + out->batteryCycleCount = static_cast(in.legacy.legacy.batteryCycleCount); + out->batteryFullChargeUah = static_cast(in.legacy.legacy.batteryFullCharge); + out->batteryChargeCounterUah = static_cast(in.legacy.legacy.batteryChargeCounter); + out->batteryTechnology = in.legacy.legacy.batteryTechnology; + out->batteryCurrentAverageMicroamps = static_cast(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( + in.batteryCapacityLevel); + out->batteryChargeTimeToFullNowSeconds = + static_cast(in.batteryChargeTimeToFullNowSeconds); + out->batteryFullChargeDesignCapacityUah = + static_cast(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 0000000000..2f8fe04161 --- /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 +#include +#include +#include +#include +#include +#include + +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 From b47f676008a5157eae8eafd846b76dafd817930d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 26 Oct 2021 10:55:19 -0700 Subject: [PATCH 2/3] health: separate_platform_variant = false Disable the generation of ndk_platform variant during the ndk_platform -> ndk migration. Test: builds Bug: 177269435 Change-Id: I467eaee53542b152df1d398a8f044eb42fd01772 --- health/aidl/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/health/aidl/Android.bp b/health/aidl/Android.bp index 940e4d86ad..3a11e644e1 100644 --- a/health/aidl/Android.bp +++ b/health/aidl/Android.bp @@ -26,6 +26,7 @@ aidl_interface { sdk_version: "module_current", }, ndk: { + separate_platform_variant: false, vndk: { enabled: true, }, From 21a22cece472e5e1ab7223342de60e245639233f Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 18 Oct 2021 19:15:56 -0700 Subject: [PATCH 3/3] health: Add to compatibility matrix. For now, add as optional. Once we finished implementing it on Android T devices, make it required. Test: pass Bug: 177269435 Change-Id: I148b7567d8e154cb5e16ec01b547785f90c7a706 --- compatibility_matrices/compatibility_matrix.current.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 7fa586efdb..d2747f6afe 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -276,6 +276,15 @@ default + + + android.hardware.health + 1 + + IHealth + default + + android.hardware.health.storage 1