Add support for detecting Keyboard backlight using sysfs node
Add new light type for Keyboard backlight and corresponding
detection logic. Also, refactor PeripheralController logic to
support Light type and light capabilities similar to how it is
handled on Java side of code.
Test: atest inputflinger_tests
Bug: 245506418
Change-Id: Ic69e42555bf57a66683fcf359169869ee2a00749
diff --git a/services/inputflinger/reader/controller/PeripheralController.h b/services/inputflinger/reader/controller/PeripheralController.h
index 25cf435..8ac42c3 100644
--- a/services/inputflinger/reader/controller/PeripheralController.h
+++ b/services/inputflinger/reader/controller/PeripheralController.h
@@ -67,6 +67,7 @@
std::string name;
int32_t id;
InputDeviceLightType type;
+ ftl::Flags<InputDeviceLightCapability> capabilityFlags;
virtual bool setLightColor(int32_t color) { return false; }
virtual std::optional<int32_t> getLightColor() { return std::nullopt; }
@@ -81,8 +82,10 @@
struct MonoLight : public Light {
explicit MonoLight(InputDeviceContext& context, const std::string& name, int32_t id,
- int32_t rawId)
- : Light(context, name, id, InputDeviceLightType::MONO), rawId(rawId) {}
+ InputDeviceLightType type, int32_t rawId)
+ : Light(context, name, id, type), rawId(rawId) {
+ capabilityFlags |= InputDeviceLightCapability::BRIGHTNESS;
+ }
int32_t rawId;
bool setLightColor(int32_t color) override;
@@ -91,15 +94,15 @@
};
struct RgbLight : public Light {
- explicit RgbLight(InputDeviceContext& context, int32_t id,
+ explicit RgbLight(InputDeviceContext& context, int32_t id, InputDeviceLightType type,
const std::unordered_map<LightColor, int32_t>& rawRgbIds,
std::optional<int32_t> rawGlobalId)
- : Light(context, "RGB", id, InputDeviceLightType::RGB),
- rawRgbIds(rawRgbIds),
- rawGlobalId(rawGlobalId) {
+ : Light(context, "RGB", id, type), rawRgbIds(rawRgbIds), rawGlobalId(rawGlobalId) {
brightness = rawGlobalId.has_value()
? getRawLightBrightness(rawGlobalId.value()).value_or(MAX_BRIGHTNESS)
: MAX_BRIGHTNESS;
+ capabilityFlags |= InputDeviceLightCapability::BRIGHTNESS;
+ capabilityFlags |= InputDeviceLightCapability::RGB;
}
// Map from color to raw light id.
std::unordered_map<LightColor, int32_t /* rawLightId */> rawRgbIds;
@@ -114,8 +117,11 @@
struct MultiColorLight : public Light {
explicit MultiColorLight(InputDeviceContext& context, const std::string& name, int32_t id,
- int32_t rawId)
- : Light(context, name, id, InputDeviceLightType::MULTI_COLOR), rawId(rawId) {}
+ InputDeviceLightType type, int32_t rawId)
+ : Light(context, name, id, type), rawId(rawId) {
+ capabilityFlags |= InputDeviceLightCapability::BRIGHTNESS;
+ capabilityFlags |= InputDeviceLightCapability::RGB;
+ }
int32_t rawId;
bool setLightColor(int32_t color) override;
@@ -131,7 +137,7 @@
// Map from player Id to raw light Id
std::unordered_map<int32_t, int32_t> rawLightIds;
- bool setLightPlayerId(int32_t palyerId) override;
+ bool setLightPlayerId(int32_t playerId) override;
std::optional<int32_t> getLightPlayerId() override;
void dump(std::string& dump) override;
};