summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenergy Meenan Ravuri <bravuri@codeaurora.org>2020-07-18 19:14:31 +0530
committerDivya Sharma <divyash@codeaurora.org>2020-08-05 15:27:26 -0700
commit77f8677228ee7be44f9ce5ca53b2eedc5ee89560 (patch)
treedbbb950e0b0a3164c842a9db14fd618a41dacc66
parent4a71d24956ece4be054d61ae04dbbc1c822dc0ec (diff)
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
-rw-r--r--lights/Lights.cpp24
-rw-r--r--lights/Lights.h3
2 files changed, 15 insertions, 12 deletions
diff --git a/lights/Lights.cpp b/lights/Lights.cpp
index aa288b0..1e6f27b 100644
--- a/lights/Lights.cpp
+++ b/lights/Lights.cpp
@@ -56,32 +56,34 @@ light_device_t* getLightDevice(const char* name) {
}
Lights::Lights() {
- std::map<LightType, light_device_t*> lights;
+ std::map<int, light_device_t*> lights;
std::vector<HwLight> 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/lights/Lights.h b/lights/Lights.h
index 879ea55..89d0cfe 100644
--- a/lights/Lights.h
+++ b/lights/Lights.h
@@ -33,8 +33,9 @@ class Lights : public BnLights {
ndk::ScopedAStatus getLights(std::vector<HwLight>* types) override;
private:
- std::map<LightType, light_device_t*> mLights;
+ std::map<int, light_device_t*> mLights;
std::vector<HwLight> mAvailableLights;
+ int maxLights;
};
} // namespace light