Improve EventHub const-correctness
Ensure that all methods that "get" state from event hub are
const-correct. While some "set" methods can also be const in event hub
because they write to the system (side effect) instead of changing
state, we leave these as non-const to make it easier for testing.
Bug: None
Test: atest inputflinger_tests
Change-Id: I086b50458203a2395b1960e2bc1102610a3c0801
diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h
index 60460b4..8aec367 100644
--- a/services/inputflinger/reader/include/EventHub.h
+++ b/services/inputflinger/reader/include/EventHub.h
@@ -282,22 +282,23 @@
*/
virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) = 0;
- virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t deviceId,
- int32_t absCode) = 0;
+ virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
+ int32_t deviceId, int32_t absCode) const = 0;
// Raw batteries are sysfs power_supply nodes we found from the EventHub device sysfs node,
// containing the raw info of the sysfs node structure.
- virtual const std::vector<int32_t> getRawBatteryIds(int32_t deviceId) = 0;
+ virtual std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const = 0;
virtual std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
- int32_t BatteryId) = 0;
+ int32_t BatteryId) const = 0;
// Raw lights are sysfs led light nodes we found from the EventHub device sysfs node,
// containing the raw info of the sysfs node structure.
- virtual const std::vector<int32_t> getRawLightIds(int32_t deviceId) = 0;
- virtual std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId, int32_t lightId) = 0;
- virtual std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) = 0;
+ virtual std::vector<int32_t> getRawLightIds(int32_t deviceId) const = 0;
+ virtual std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
+ int32_t lightId) const = 0;
+ virtual std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) const = 0;
virtual void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) = 0;
virtual std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
- int32_t deviceId, int32_t lightId) = 0;
+ int32_t deviceId, int32_t lightId) const = 0;
virtual void setLightIntensities(int32_t deviceId, int32_t lightId,
std::unordered_map<LightColor, int32_t> intensities) = 0;
/*
@@ -333,7 +334,7 @@
/* Control the vibrator. */
virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0;
virtual void cancelVibrate(int32_t deviceId) = 0;
- virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
+ virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) const = 0;
/* Query battery level. */
virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
@@ -349,13 +350,13 @@
virtual void wake() = 0;
/* Dump EventHub state to a string. */
- virtual void dump(std::string& dump) = 0;
+ virtual void dump(std::string& dump) const = 0;
/* Called by the heatbeat to ensures that the reader has not deadlocked. */
- virtual void monitor() = 0;
+ virtual void monitor() const = 0;
/* Return true if the device is enabled. */
- virtual bool isDeviceEnabled(int32_t deviceId) = 0;
+ virtual bool isDeviceEnabled(int32_t deviceId) const = 0;
/* Enable an input device */
virtual status_t enableDevice(int32_t deviceId) = 0;
@@ -463,20 +464,22 @@
AxisInfo* outAxisInfo) const override final;
base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
- int32_t deviceId, int32_t absCode) override final;
+ int32_t deviceId, int32_t absCode) const override final;
- const std::vector<int32_t> getRawBatteryIds(int32_t deviceId) override final;
+ std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const override final;
std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
- int32_t BatteryId) override final;
+ int32_t BatteryId) const override final;
- const std::vector<int32_t> getRawLightIds(int32_t deviceId) override final;
+ std::vector<int32_t> getRawLightIds(int32_t deviceId) const override final;
- std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId, int32_t lightId) override final;
+ std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
+ int32_t lightId) const override final;
- std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) override final;
+ std::optional<int32_t> getLightBrightness(int32_t deviceId,
+ int32_t lightId) const override final;
void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) override final;
std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
- int32_t deviceId, int32_t lightId) override final;
+ int32_t deviceId, int32_t lightId) const override final;
void setLightIntensities(int32_t deviceId, int32_t lightId,
std::unordered_map<LightColor, int32_t> intensities) override final;
@@ -512,15 +515,15 @@
void vibrate(int32_t deviceId, const VibrationElement& effect) override final;
void cancelVibrate(int32_t deviceId) override final;
- std::vector<int32_t> getVibratorIds(int32_t deviceId) override final;
+ std::vector<int32_t> getVibratorIds(int32_t deviceId) const override final;
void requestReopenDevices() override final;
void wake() override final;
- void dump(std::string& dump) override final;
+ void dump(std::string& dump) const override final;
- void monitor() override final;
+ void monitor() const override final;
std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
int32_t batteryId) const override final;
@@ -528,7 +531,7 @@
std::optional<int32_t> getBatteryStatus(int32_t deviceId,
int32_t batteryId) const override final;
- bool isDeviceEnabled(int32_t deviceId) override final;
+ bool isDeviceEnabled(int32_t deviceId) const override final;
status_t enableDevice(int32_t deviceId) override final;