From d28e45f7cfed0f7da57ebbdb118845e8505f2e36 Mon Sep 17 00:00:00 2001 From: Sahil Somani Date: Wed, 27 Jul 2022 16:43:30 -0700 Subject: [PATCH] Added dummy Lights to the Light HAL default implementation Most of the VTS tests for the Light HAL involve looping over the list of Light objects returned by Lights::getLights(), but the current default implementation of this function returns no Light objects. Lights::getLights() was changed to create a few dummy Light objects when called. Lights::setLightStatus() was also changed to determine whether a given Light id was created by Lights::getLights() and thus valid or not. Test: VtsHalLightTargetTest Bug: 240485903 Change-Id: I5ad0bdfdccacc2bde80c2dd89eaa84702f22a7fb --- light/aidl/default/Lights.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/light/aidl/default/Lights.cpp b/light/aidl/default/Lights.cpp index 74747d57bd..9bf3b20c83 100644 --- a/light/aidl/default/Lights.cpp +++ b/light/aidl/default/Lights.cpp @@ -23,12 +23,21 @@ namespace android { namespace hardware { namespace light { +static constexpr int kNumDefaultLights = 3; + ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) { LOG(INFO) << "Lights setting state for id=" << id << " to color " << std::hex << state.color; - return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + if (id <= 0 || id > kNumDefaultLights) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } else { + return ndk::ScopedAStatus::ok(); + } } -ndk::ScopedAStatus Lights::getLights(std::vector* /*lights*/) { +ndk::ScopedAStatus Lights::getLights(std::vector* lights) { + for (int i = 1; i <= kNumDefaultLights; i++) { + lights->push_back({i, i}); + } LOG(INFO) << "Lights reporting supported lights"; return ndk::ScopedAStatus::ok(); }