From ac5a0d316be22bc5e99b63c2c792a77afaeb2031 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 9 Oct 2019 15:48:17 +0200 Subject: [PATCH] health VTS: Status::UNKNOWN is OK if not present Documentation: https://source.android.com/devices/tech/power/batteryless If a battery device is not detected, the following battery-related defaults are used on Android 9 and higher: * Present: false * Status: unknown * Remaining capacity: 0 * Health: unknown * AC charger online: not modified The previous version of the test failed devices if the vendor HAL reported BatteryStatus::UNKNOWN. However, the tests were skipped if the default HAL was the one being used, so this has not come up before for other batteryless devices. Bug: 142081126 Test: vts-tradefed run vts -m VtsHalHealthV2_0 Change-Id: I8ca758677478b47511e24990fee545fafa6c7f83 --- .../vts/functional/VtsHalHealthV2_0TargetTest.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp index 74fe4fbd83..6e13a9896d 100644 --- a/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp +++ b/health/2.0/vts/functional/VtsHalHealthV2_0TargetTest.cpp @@ -257,15 +257,21 @@ bool verifyHealthInfo(const HealthInfo& health_info) { using V1_0::BatteryStatus; using V1_0::BatteryHealth; - if (!((health_info.legacy.batteryChargeCounter > 0) && - (health_info.legacy.batteryCurrent != INT32_MIN) && + if (!((health_info.legacy.batteryCurrent != INT32_MIN) && (0 <= health_info.legacy.batteryLevel && health_info.legacy.batteryLevel <= 100) && verifyEnum(health_info.legacy.batteryHealth) && - (health_info.legacy.batteryStatus != BatteryStatus::UNKNOWN) && verifyEnum(health_info.legacy.batteryStatus))) { return false; } + if (health_info.legacy.batteryPresent) { + // If a battery is present, the battery status must be known. + if (!((health_info.legacy.batteryChargeCounter > 0) && + (health_info.legacy.batteryStatus != BatteryStatus::UNKNOWN))) { + return false; + } + } + return true; }