From b1553a0987f88b307615f43449b2fbd4811cbbc6 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Wed, 30 Oct 2024 11:26:59 -0700 Subject: [PATCH] Health HAL: add hinge info Add a hingeinfo field to the Health HAL that returns information related to a foldable's hinge health + rated life expectancy. Ignore-AOSP-First: deprecated_ota_test compilation Bug: 371322457 Test: th Change-Id: I23688be268afcc542fa4bc90af37933e9c1c36e7 --- .../compatibility_matrix.202504.xml | 2 +- health/aidl/Android.bp | 7 ++-- .../hardware/health/BatteryPartStatus.aidl | 6 +-- .../android/hardware/health/HealthInfo.aidl | 1 + .../android/hardware/health/HingeInfo.aidl | 39 +++++++++++++++++++ .../android/hardware/health/IHealth.aidl | 1 + .../android/hardware/health/HealthInfo.aidl | 6 ++- .../android/hardware/health/HingeInfo.aidl | 37 ++++++++++++++++++ .../aidl/android/hardware/health/IHealth.aidl | 14 +++++++ health/aidl/default/Android.bp | 6 +-- health/aidl/default/Health.cpp | 6 +++ ...ndroid.hardware.health-service.example.xml | 2 +- .../aidl/default/include/health-impl/Health.h | 1 + health/aidl/vts/functional/Android.bp | 2 +- .../vts/functional/VtsHalHealthTargetTest.cpp | 13 +++++++ health/utils/libhealthshim/Android.bp | 2 +- .../libhealthshim/include/health-shim/shim.h | 1 + health/utils/libhealthshim/shim.cpp | 4 ++ 18 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HingeInfo.aidl create mode 100644 health/aidl/android/hardware/health/HingeInfo.aidl diff --git a/compatibility_matrices/compatibility_matrix.202504.xml b/compatibility_matrices/compatibility_matrix.202504.xml index b3a3778289..879758dbe4 100644 --- a/compatibility_matrices/compatibility_matrix.202504.xml +++ b/compatibility_matrices/compatibility_matrix.202504.xml @@ -249,7 +249,7 @@ android.hardware.health - 3 + 3-4 IHealth default diff --git a/health/aidl/Android.bp b/health/aidl/Android.bp index 97de0e2698..d2ad3b1181 100644 --- a/health/aidl/Android.bp +++ b/health/aidl/Android.bp @@ -50,9 +50,8 @@ aidl_interface { version: "3", imports: [], }, - ], - frozen: true, + frozen: false, } @@ -84,7 +83,7 @@ cc_library { name: "android.hardware.health-translate-ndk", defaults: ["android.hardware.health-translate-ndk_defaults"], shared_libs: [ - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", ], } @@ -101,7 +100,7 @@ java_library { name: "android.hardware.health-translate-java", srcs: ["android/hardware/health/Translate.java"], libs: [ - "android.hardware.health-V3-java", + "android.hardware.health-V4-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/BatteryPartStatus.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryPartStatus.aidl index e013e31a24..9303767975 100644 --- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryPartStatus.aidl +++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/BatteryPartStatus.aidl @@ -34,7 +34,7 @@ package android.hardware.health; @Backing(type="int") @VintfStability enum BatteryPartStatus { - UNSUPPORTED, - ORIGINAL, - REPLACED, + UNSUPPORTED = 0, + ORIGINAL = 1, + REPLACED = 2, } diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl index bfa14758f3..548a7932b2 100644 --- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl +++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HealthInfo.aidl @@ -60,5 +60,6 @@ parcelable HealthInfo { android.hardware.health.BatteryChargingState chargingState; android.hardware.health.BatteryChargingPolicy chargingPolicy; @nullable android.hardware.health.BatteryHealthData batteryHealthData; + @nullable android.hardware.health.HingeInfo[] foldInfos; const int BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED = (-1) /* -1 */; } diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HingeInfo.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HingeInfo.aidl new file mode 100644 index 0000000000..b3c38ad54f --- /dev/null +++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/HingeInfo.aidl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 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 HingeInfo { + int numTimesFolded; + int expectedHingeLifespan; +} diff --git a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl index b49dfffbe4..e919f1485e 100644 --- a/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl +++ b/health/aidl/aidl_api/android.hardware.health/current/android/hardware/health/IHealth.aidl @@ -49,6 +49,7 @@ interface IHealth { void setChargingPolicy(android.hardware.health.BatteryChargingPolicy in_value); android.hardware.health.BatteryChargingPolicy getChargingPolicy(); android.hardware.health.BatteryHealthData getBatteryHealthData(); + android.hardware.health.HingeInfo[] getHingeInfo(); const int STATUS_UNKNOWN = 2; const int STATUS_CALLBACK_DIED = 4; } diff --git a/health/aidl/android/hardware/health/HealthInfo.aidl b/health/aidl/android/hardware/health/HealthInfo.aidl index af84089598..12a397a965 100644 --- a/health/aidl/android/hardware/health/HealthInfo.aidl +++ b/health/aidl/android/hardware/health/HealthInfo.aidl @@ -24,6 +24,7 @@ import android.hardware.health.BatteryHealthData; import android.hardware.health.BatteryStatus; import android.hardware.health.DiskStats; import android.hardware.health.StorageInfo; +import android.hardware.health.HingeInfo; /** * Health Information. @@ -115,7 +116,6 @@ parcelable HealthInfo { * Battery capacity level. See {@link BatteryCapacityLevel} for more details. */ BatteryCapacityLevel batteryCapacityLevel; - /** * Value of {@link #batteryChargeTimeToFullNowSeconds} if it is not * supported. @@ -148,4 +148,8 @@ parcelable HealthInfo { * Battery health data */ @nullable BatteryHealthData batteryHealthData; + /** + * Information about foldable hinge health. Will be an empty vector if no hinges present + */ + @nullable HingeInfo[] foldInfos; } diff --git a/health/aidl/android/hardware/health/HingeInfo.aidl b/health/aidl/android/hardware/health/HingeInfo.aidl new file mode 100644 index 0000000000..19b46dfeb5 --- /dev/null +++ b/health/aidl/android/hardware/health/HingeInfo.aidl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 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 foldable hinge health life time estimates, end of life + * information and other attributes. + * + * All integers in this struct must be interpreted as non-negative. + */ +@VintfStability +parcelable HingeInfo { + /** + * returns count of times a given hinge has been folded. + * + * opening fully counts as 1 fold and closing fully counts as another + */ + int numTimesFolded; + /** + * returns the expected lifespan of hinge in units of number of folds + */ + int expectedHingeLifespan; +} diff --git a/health/aidl/android/hardware/health/IHealth.aidl b/health/aidl/android/hardware/health/IHealth.aidl index bdfe07a8d2..c88141ccf4 100644 --- a/health/aidl/android/hardware/health/IHealth.aidl +++ b/health/aidl/android/hardware/health/IHealth.aidl @@ -23,6 +23,7 @@ import android.hardware.health.DiskStats; import android.hardware.health.HealthInfo; import android.hardware.health.IHealthInfoCallback; import android.hardware.health.StorageInfo; +import android.hardware.health.HingeInfo; /** * IHealth manages health info and posts events on registered callbacks. @@ -242,4 +243,17 @@ interface IHealth { * for other errors. */ BatteryHealthData getBatteryHealthData(); + + /** + * Get Hinge info. + * + * @return vector of HingeInfo 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. + */ + HingeInfo[] getHingeInfo(); + } diff --git a/health/aidl/default/Android.bp b/health/aidl/default/Android.bp index 2071f08f61..cc5d0a05b0 100644 --- a/health/aidl/default/Android.bp +++ b/health/aidl/default/Android.bp @@ -29,7 +29,7 @@ cc_defaults { "libcutils", "liblog", "libutils", - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", // TODO(b/177269435): remove when BatteryMonitor works with AIDL HealthInfo. "libhidlbase", @@ -48,7 +48,7 @@ cc_defaults { name: "libhealth_aidl_charger_defaults", shared_libs: [ // common - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", "libbase", "libcutils", "liblog", @@ -195,7 +195,7 @@ cc_fuzz { "service_fuzzer_defaults", ], static_libs: [ - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", "libbase", "liblog", "fuzz_libhealth_aidl_impl", diff --git a/health/aidl/default/Health.cpp b/health/aidl/default/Health.cpp index 37662eacf3..d0e2dacf6a 100644 --- a/health/aidl/default/Health.cpp +++ b/health/aidl/default/Health.cpp @@ -192,6 +192,12 @@ ndk::ScopedAStatus Health::getStorageInfo(std::vector*) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } +ndk::ScopedAStatus Health::getHingeInfo(std::vector*) { + // This implementation does not support HingeInfo. An implementation may extend this + // class and override this function to support storage info. + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); +} + ndk::ScopedAStatus Health::getHealthInfo(HealthInfo* out) { battery_monitor_.updateValues(); diff --git a/health/aidl/default/android.hardware.health-service.example.xml b/health/aidl/default/android.hardware.health-service.example.xml index 2acaabacbe..8ddfbdaaee 100644 --- a/health/aidl/default/android.hardware.health-service.example.xml +++ b/health/aidl/default/android.hardware.health-service.example.xml @@ -1,7 +1,7 @@ android.hardware.health - 3 + 4 IHealth/default diff --git a/health/aidl/default/include/health-impl/Health.h b/health/aidl/default/include/health-impl/Health.h index 429ae2ab96..96df5172f9 100644 --- a/health/aidl/default/include/health-impl/Health.h +++ b/health/aidl/default/include/health-impl/Health.h @@ -72,6 +72,7 @@ class Health : public BnHealth, public HalHealthLoopCallback { // The default implementations return nothing in |out|. ndk::ScopedAStatus getDiskStats(std::vector* out) override; ndk::ScopedAStatus getStorageInfo(std::vector* out) override; + ndk::ScopedAStatus getHingeInfo(std::vector* out) override; ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override; ndk::ScopedAStatus getChargingPolicy(BatteryChargingPolicy* out) override; diff --git a/health/aidl/vts/functional/Android.bp b/health/aidl/vts/functional/Android.bp index 25ba5f8721..75bec97f6c 100644 --- a/health/aidl/vts/functional/Android.bp +++ b/health/aidl/vts/functional/Android.bp @@ -40,7 +40,7 @@ cc_test { "libbinder_ndk", ], static_libs: [ - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", "libgmock", ], header_libs: [ diff --git a/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp b/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp index 45a1e40501..c47ddca07f 100644 --- a/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp +++ b/health/aidl/vts/functional/VtsHalHealthTargetTest.cpp @@ -359,6 +359,19 @@ TEST_P(HealthAidl, getStorageInfo) { ASSERT_THAT(value, Each(IsValidStorageInfo())); } +/* + * Tests the values returned by getHingeInfo() from interface IHealth. + */ +TEST_P(HealthAidl, getHingeInfo) { + std::vector value; + auto status = health->getHingeInfo(&value); + ASSERT_THAT(status, AnyOf(IsOk(), ExceptionIs(EX_UNSUPPORTED_OPERATION))); + if (!status.isOk()) return; + for (auto& hinge : value) { + ASSERT_TRUE(hinge.expectedHingeLifespan > 0); + } +} + /* * Tests the values returned by getDiskStats() from interface IHealth. */ diff --git a/health/utils/libhealthshim/Android.bp b/health/utils/libhealthshim/Android.bp index b0ea743ea6..9f9970f3e2 100644 --- a/health/utils/libhealthshim/Android.bp +++ b/health/utils/libhealthshim/Android.bp @@ -34,7 +34,7 @@ cc_defaults { "-Werror", ], static_libs: [ - "android.hardware.health-V3-ndk", + "android.hardware.health-V4-ndk", "android.hardware.health-translate-ndk", "android.hardware.health@1.0", "android.hardware.health@2.0", diff --git a/health/utils/libhealthshim/include/health-shim/shim.h b/health/utils/libhealthshim/include/health-shim/shim.h index ff6849b116..9a6260148d 100644 --- a/health/utils/libhealthshim/include/health-shim/shim.h +++ b/health/utils/libhealthshim/include/health-shim/shim.h @@ -43,6 +43,7 @@ class HealthShim : public BnHealth { ndk::ScopedAStatus getEnergyCounterNwh(int64_t* _aidl_return) override; ndk::ScopedAStatus getChargeStatus(BatteryStatus* _aidl_return) override; ndk::ScopedAStatus getStorageInfo(std::vector* _aidl_return) override; + ndk::ScopedAStatus getHingeInfo(std::vector* _aidl_return) override; ndk::ScopedAStatus getDiskStats(std::vector* _aidl_return) override; ndk::ScopedAStatus getHealthInfo(HealthInfo* _aidl_return) override; ndk::ScopedAStatus setChargingPolicy(BatteryChargingPolicy in_value) override; diff --git a/health/utils/libhealthshim/shim.cpp b/health/utils/libhealthshim/shim.cpp index a5ba919dd9..2ddf97e9c9 100644 --- a/health/utils/libhealthshim/shim.cpp +++ b/health/utils/libhealthshim/shim.cpp @@ -190,6 +190,10 @@ ScopedAStatus HealthShim::getStorageInfo(std::vector* out) { return ReturnAndResultToStatus(ret, out_result); } +ScopedAStatus HealthShim::getHingeInfo(std::vector* /*out*/) { + return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); +} + ScopedAStatus HealthShim::getDiskStats(std::vector* out) { Result out_result = Result::UNKNOWN; auto ret = service_->getDiskStats([out, &out_result](auto result, const auto& value) {