Refactor InputController into PeripheralController.
Rename the InputController and related class to PeripheralController,
and rename MiscDevice to AssociatedDevice to better reflect the behavior
of these hardwares.
Bug: 13831915
Test: atest inputflinger_tests
Change-Id: Ib61f7f6cc4fe616d08afc29bf1f1e08c1c9f565d
diff --git a/services/inputflinger/reader/controller/InputController.cpp b/services/inputflinger/reader/controller/PeripheralController.cpp
similarity index 90%
rename from services/inputflinger/reader/controller/InputController.cpp
rename to services/inputflinger/reader/controller/PeripheralController.cpp
index 45266fb..1a40d06 100644
--- a/services/inputflinger/reader/controller/InputController.cpp
+++ b/services/inputflinger/reader/controller/PeripheralController.cpp
@@ -19,7 +19,7 @@
#include "../Macros.h"
-#include "InputController.h"
+#include "PeripheralController.h"
#include "input/NamedEnum.h"
// Log detailed debug messages about input device lights.
@@ -52,15 +52,15 @@
* lights, getting and setting the lights brightness and color, by interacting with EventHub
* devices.
*/
-InputController::InputController(InputDeviceContext& deviceContext)
+PeripheralController::PeripheralController(InputDeviceContext& deviceContext)
: mDeviceContext(deviceContext) {
configureBattries();
configureLights();
}
-InputController::~InputController() {}
+PeripheralController::~PeripheralController() {}
-std::optional<std::int32_t> InputController::Light::getRawLightBrightness(int32_t rawLightId) {
+std::optional<std::int32_t> PeripheralController::Light::getRawLightBrightness(int32_t rawLightId) {
std::optional<RawLightInfo> rawInfoOpt = context.getRawLightInfo(rawLightId);
if (!rawInfoOpt.has_value()) {
return std::nullopt;
@@ -85,7 +85,7 @@
return brightness;
}
-void InputController::Light::setRawLightBrightness(int32_t rawLightId, int32_t brightness) {
+void PeripheralController::Light::setRawLightBrightness(int32_t rawLightId, int32_t brightness) {
std::optional<RawLightInfo> rawInfo = context.getRawLightInfo(rawLightId);
if (!rawInfo.has_value()) {
return;
@@ -104,14 +104,14 @@
context.setLightBrightness(rawLightId, brightness);
}
-bool InputController::SingleLight::setLightColor(int32_t color) {
+bool PeripheralController::SingleLight::setLightColor(int32_t color) {
int32_t brightness = getAlpha(color);
setRawLightBrightness(rawId, brightness);
return true;
}
-bool InputController::RgbLight::setLightColor(int32_t color) {
+bool PeripheralController::RgbLight::setLightColor(int32_t color) {
// Compose color value as per:
// https://developer.android.com/reference/android/graphics/Color?hl=en
// int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);
@@ -137,7 +137,7 @@
return true;
}
-bool InputController::MultiColorLight::setLightColor(int32_t color) {
+bool PeripheralController::MultiColorLight::setLightColor(int32_t color) {
std::unordered_map<LightColor, int32_t> intensities;
intensities.emplace(LightColor::RED, getRed(color));
intensities.emplace(LightColor::GREEN, getGreen(color));
@@ -148,7 +148,7 @@
return true;
}
-std::optional<int32_t> InputController::SingleLight::getLightColor() {
+std::optional<int32_t> PeripheralController::SingleLight::getLightColor() {
std::optional<int32_t> brightness = getRawLightBrightness(rawId);
if (!brightness.has_value()) {
return std::nullopt;
@@ -157,7 +157,7 @@
return toArgb(brightness.value(), 0 /* red */, 0 /* green */, 0 /* blue */);
}
-std::optional<int32_t> InputController::RgbLight::getLightColor() {
+std::optional<int32_t> PeripheralController::RgbLight::getLightColor() {
// If the Alpha component is zero, then return color 0.
if (brightness == 0) {
return 0;
@@ -192,7 +192,7 @@
return toArgb(brightness, red, green, blue);
}
-std::optional<int32_t> InputController::MultiColorLight::getLightColor() {
+std::optional<int32_t> PeripheralController::MultiColorLight::getLightColor() {
auto ret = context.getLightIntensities(rawId);
if (!ret.has_value()) {
return std::nullopt;
@@ -210,7 +210,7 @@
return std::nullopt;
}
-bool InputController::PlayerIdLight::setLightPlayerId(int32_t playerId) {
+bool PeripheralController::PlayerIdLight::setLightPlayerId(int32_t playerId) {
if (rawLightIds.find(playerId) == rawLightIds.end()) {
return false;
}
@@ -224,7 +224,7 @@
return true;
}
-std::optional<int32_t> InputController::PlayerIdLight::getLightPlayerId() {
+std::optional<int32_t> PeripheralController::PlayerIdLight::getLightPlayerId() {
for (const auto& [id, rawId] : rawLightIds) {
std::optional<int32_t> brightness = getRawLightBrightness(rawId);
if (brightness.has_value() && brightness.value() > 0) {
@@ -234,11 +234,11 @@
return std::nullopt;
}
-void InputController::SingleLight::dump(std::string& dump) {
+void PeripheralController::SingleLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
}
-void InputController::PlayerIdLight::dump(std::string& dump) {
+void PeripheralController::PlayerIdLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "PlayerId: %d\n", getLightPlayerId().value_or(-1));
dump += StringPrintf(INDENT4 "Raw Player ID LEDs:");
for (const auto& [id, rawId] : rawLightIds) {
@@ -247,7 +247,7 @@
dump += "\n";
}
-void InputController::RgbLight::dump(std::string& dump) {
+void PeripheralController::RgbLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
dump += StringPrintf(INDENT4 "Raw RGB LEDs: [%d, %d, %d] ", rawRgbIds.at(LightColor::RED),
rawRgbIds.at(LightColor::GREEN), rawRgbIds.at(LightColor::BLUE));
@@ -257,11 +257,11 @@
dump += "\n";
}
-void InputController::MultiColorLight::dump(std::string& dump) {
+void PeripheralController::MultiColorLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
}
-void InputController::populateDeviceInfo(InputDeviceInfo* deviceInfo) {
+void PeripheralController::populateDeviceInfo(InputDeviceInfo* deviceInfo) {
// TODO: b/180733860 Remove this after enabling multi-battery
if (!mBatteries.empty()) {
deviceInfo->setHasBattery(true);
@@ -279,7 +279,7 @@
}
}
-void InputController::dump(std::string& dump) {
+void PeripheralController::dump(std::string& dump) {
dump += INDENT2 "Input Controller:\n";
if (!mLights.empty()) {
dump += INDENT3 "Lights:\n";
@@ -340,7 +340,7 @@
}
}
-void InputController::configureBattries() {
+void PeripheralController::configureBattries() {
// Check raw batteries
const std::vector<int32_t> rawBatteryIds = getDeviceContext().getRawBatteryIds();
@@ -355,7 +355,7 @@
}
}
-void InputController::configureLights() {
+void PeripheralController::configureLights() {
bool hasRedLed = false;
bool hasGreenLed = false;
bool hasBlueLed = false;
@@ -472,15 +472,15 @@
}
}
-std::optional<int32_t> InputController::getBatteryCapacity(int batteryId) {
+std::optional<int32_t> PeripheralController::getBatteryCapacity(int batteryId) {
return getDeviceContext().getBatteryCapacity(batteryId);
}
-std::optional<int32_t> InputController::getBatteryStatus(int batteryId) {
+std::optional<int32_t> PeripheralController::getBatteryStatus(int batteryId) {
return getDeviceContext().getBatteryStatus(batteryId);
}
-bool InputController::setLightColor(int32_t lightId, int32_t color) {
+bool PeripheralController::setLightColor(int32_t lightId, int32_t color) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return false;
@@ -493,7 +493,7 @@
return light->setLightColor(color);
}
-std::optional<int32_t> InputController::getLightColor(int32_t lightId) {
+std::optional<int32_t> PeripheralController::getLightColor(int32_t lightId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return std::nullopt;
@@ -507,7 +507,7 @@
return color;
}
-bool InputController::setLightPlayerId(int32_t lightId, int32_t playerId) {
+bool PeripheralController::setLightPlayerId(int32_t lightId, int32_t playerId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return false;
@@ -516,7 +516,7 @@
return light->setLightPlayerId(playerId);
}
-std::optional<int32_t> InputController::getLightPlayerId(int32_t lightId) {
+std::optional<int32_t> PeripheralController::getLightPlayerId(int32_t lightId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return std::nullopt;
diff --git a/services/inputflinger/reader/controller/InputController.h b/services/inputflinger/reader/controller/PeripheralController.h
similarity index 96%
rename from services/inputflinger/reader/controller/InputController.h
rename to services/inputflinger/reader/controller/PeripheralController.h
index d4222e2..ff3607f 100644
--- a/services/inputflinger/reader/controller/InputController.h
+++ b/services/inputflinger/reader/controller/PeripheralController.h
@@ -17,19 +17,19 @@
#ifndef _UI_INPUTREADER_LIGHT_CONTROLLER_H
#define _UI_INPUTREADER_LIGHT_CONTROLLER_H
-#include "InputControllerInterface.h"
+#include "PeripheralControllerInterface.h"
namespace android {
-class InputController : public InputControllerInterface {
+class PeripheralController : public PeripheralControllerInterface {
// Refer to https://developer.android.com/reference/kotlin/android/graphics/Color
/* Number of colors : {red, green, blue} */
static constexpr size_t COLOR_NUM = 3;
static constexpr int32_t MAX_BRIGHTNESS = 0xff;
public:
- explicit InputController(InputDeviceContext& deviceContext);
- ~InputController() override;
+ explicit PeripheralController(InputDeviceContext& deviceContext);
+ ~PeripheralController() override;
void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
void dump(std::string& dump) override;
diff --git a/services/inputflinger/reader/controller/InputControllerInterface.h b/services/inputflinger/reader/controller/PeripheralControllerInterface.h
similarity index 87%
rename from services/inputflinger/reader/controller/InputControllerInterface.h
rename to services/inputflinger/reader/controller/PeripheralControllerInterface.h
index 504eded..7688a43 100644
--- a/services/inputflinger/reader/controller/InputControllerInterface.h
+++ b/services/inputflinger/reader/controller/PeripheralControllerInterface.h
@@ -24,14 +24,14 @@
namespace android {
-/* An input controller manages the miscellaneous devices associated with the input device,
+/* A peripheral controller manages the input device peripherals associated with the input device,
* like the sysfs based battery and light class devices.
*
*/
-class InputControllerInterface {
+class PeripheralControllerInterface {
public:
- InputControllerInterface() {}
- virtual ~InputControllerInterface() {}
+ PeripheralControllerInterface() {}
+ virtual ~PeripheralControllerInterface() {}
// Interface methods for Battery
virtual std::optional<int32_t> getBatteryCapacity(int32_t batteryId) = 0;