From 15db54bd7e063a7aeff58d9418f264f926ed76b2 Mon Sep 17 00:00:00 2001 From: Benergy Meenan Ravuri Date: Sat, 18 Jul 2020 19:14:31 +0530 Subject: [PATCH] sdm660-common: Update Lights HAL to return supported lights only. Add Lights in list only if its corresponding function pointer is available. Update map to store light id & function pointer. For Invalid Id , return operation not supported. Change-Id: Id89345fec8b1dfb89bcfbd71c56063707ba6bb2d CRs-Fixed: 2709805 Signed-off-by: pix106 --- light/aidl/Lights.cpp | 24 +++++++++++++----------- light/aidl/Lights.h | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/light/aidl/Lights.cpp b/light/aidl/Lights.cpp index aa288b03..1e6f27bb 100644 --- a/light/aidl/Lights.cpp +++ b/light/aidl/Lights.cpp @@ -56,32 +56,34 @@ light_device_t* getLightDevice(const char* name) { } Lights::Lights() { - std::map lights; + std::map lights; std::vector availableLights; + int lightCount =0; for(auto const &pair : kLogicalLights) { LightType type = pair.first; const char* name = pair.second; light_device_t* lightDevice = getLightDevice(name); + lightCount++; if (lightDevice != nullptr) { - lights[type] = lightDevice; + HwLight hwLight{}; + hwLight.id = (int)type; + hwLight.type = type; + hwLight.ordinal = 0; + lights[hwLight.id] = lightDevice; + availableLights.emplace_back(hwLight); } - HwLight hwLight{}; - hwLight.id = availableLights.size(); - hwLight.type = type; - hwLight.ordinal = 0; - availableLights.emplace_back(hwLight); } mAvailableLights = availableLights; mLights = lights; + maxLights = lightCount; } ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) { - if (id >= mAvailableLights.size()) { + if (id >= maxLights) { ALOGE("Invalid Light id : %d", id); - return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - HwLight const& light = mAvailableLights[id]; - auto it = mLights.find(light.type); + auto it = mLights.find(id); if (it == mLights.end()) { ALOGE("Light not supported"); return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); diff --git a/light/aidl/Lights.h b/light/aidl/Lights.h index 879ea552..89d0cfe0 100644 --- a/light/aidl/Lights.h +++ b/light/aidl/Lights.h @@ -33,8 +33,9 @@ class Lights : public BnLights { ndk::ScopedAStatus getLights(std::vector* types) override; private: - std::map mLights; + std::map mLights; std::vector mAvailableLights; + int maxLights; }; } // namespace light