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 <sbordenave@gmail.com>
This commit is contained in:
parent
123d8346a3
commit
15db54bd7e
2 changed files with 15 additions and 12 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue