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/Android.bp b/services/inputflinger/reader/Android.bp
index 7468894..7db32e3 100644
--- a/services/inputflinger/reader/Android.bp
+++ b/services/inputflinger/reader/Android.bp
@@ -36,7 +36,7 @@
     srcs: [
         "EventHub.cpp",
         "InputDevice.cpp",
-        "controller/InputController.cpp",
+        "controller/PeripheralController.cpp",
         "mapper/accumulator/CursorButtonAccumulator.cpp",
         "mapper/accumulator/CursorScrollAccumulator.cpp",
         "mapper/accumulator/SingleTouchMotionAccumulator.cpp",
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 045d24c..e3e6c12 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -363,7 +363,7 @@
         virtualKeyMap(nullptr),
         ffEffectPlaying(false),
         ffEffectId(-1),
-        miscDevice(nullptr),
+        associatedDevice(nullptr),
         controllerNumber(0),
         enabled(true),
         isVirtual(fd < 0) {}
@@ -554,7 +554,7 @@
 }
 
 // Check the sysfs path for any input device batteries, returns true if battery found.
-bool EventHub::MiscDevice::configureBatteryLocked() {
+bool EventHub::AssociatedDevice::configureBatteryLocked() {
     nextBatteryId = 0;
     // Check if device has any battery.
     const auto& paths = findSysfsNodes(sysfsRootPath, SysfsClass::POWER_SUPPLY);
@@ -580,7 +580,7 @@
 }
 
 // Check the sysfs path for any input device lights, returns true if lights found.
-bool EventHub::MiscDevice::configureLightsLocked() {
+bool EventHub::AssociatedDevice::configureLightsLocked() {
     nextLightId = 0;
     // Check if device has any lights.
     const auto& paths = findSysfsNodes(sysfsRootPath, SysfsClass::LEDS);
@@ -988,14 +988,10 @@
         int32_t deviceId) const {
     static const std::unordered_map<int32_t, RawBatteryInfo> EMPTY_BATTERY_INFO = {};
     Device* device = getDeviceLocked(deviceId);
-    if (device == nullptr) {
+    if (device == nullptr || !device->associatedDevice) {
         return EMPTY_BATTERY_INFO;
     }
-    auto it = mMiscDevices.find(device->identifier.descriptor);
-    if (it == mMiscDevices.end()) {
-        return EMPTY_BATTERY_INFO;
-    }
-    return it->second->batteryInfos;
+    return device->associatedDevice->batteryInfos;
 }
 
 const std::vector<int32_t> EventHub::getRawBatteryIds(int32_t deviceId) {
@@ -1028,14 +1024,10 @@
         int32_t deviceId) const {
     static const std::unordered_map<int32_t, RawLightInfo> EMPTY_LIGHT_INFO = {};
     Device* device = getDeviceLocked(deviceId);
-    if (device == nullptr) {
+    if (device == nullptr || !device->associatedDevice) {
         return EMPTY_LIGHT_INFO;
     }
-    auto it = mMiscDevices.find(device->identifier.descriptor);
-    if (it == mMiscDevices.end()) {
-        return EMPTY_LIGHT_INFO;
-    }
-    return it->second->lightInfos;
+    return device->associatedDevice->lightInfos;
 }
 
 const std::vector<int32_t> EventHub::getRawLightIds(int32_t deviceId) {
@@ -1946,18 +1938,20 @@
     // Check the sysfs root path
     std::optional<std::filesystem::path> sysfsRootPath = getSysfsRootPath(devicePath.c_str());
     if (sysfsRootPath.has_value()) {
-        std::shared_ptr<MiscDevice> miscDevice;
-        auto it = mMiscDevices.find(device->identifier.descriptor);
-        if (it == mMiscDevices.end()) {
-            miscDevice = std::make_shared<MiscDevice>(sysfsRootPath.value());
-        } else {
-            miscDevice = it->second;
+        std::shared_ptr<AssociatedDevice> associatedDevice;
+        for (const auto& [id, dev] : mDevices) {
+            if (device->identifier.descriptor == dev->identifier.descriptor &&
+                !dev->associatedDevice) {
+                associatedDevice = dev->associatedDevice;
+            }
         }
-        hasBattery = miscDevice->configureBatteryLocked();
-        hasLights = miscDevice->configureLightsLocked();
+        if (!associatedDevice) {
+            associatedDevice = std::make_shared<AssociatedDevice>(sysfsRootPath.value());
+        }
+        hasBattery = associatedDevice->configureBatteryLocked();
+        hasLights = associatedDevice->configureLightsLocked();
 
-        device->miscDevice = miscDevice;
-        mMiscDevices.insert_or_assign(device->identifier.descriptor, std::move(miscDevice));
+        device->associatedDevice = associatedDevice;
     }
 
     // Figure out the kinds of events the device reports.
@@ -2329,12 +2323,6 @@
     mClosingDevices.push_back(std::move(mDevices[device.id]));
 
     mDevices.erase(device.id);
-    // If all devices with the descriptor have been removed then the miscellaneous device should
-    // be removed too.
-    std::string descriptor = device.identifier.descriptor;
-    if (getDeviceByDescriptorLocked(descriptor) == nullptr) {
-        mMiscDevices.erase(descriptor);
-    }
 }
 
 status_t EventHub::readNotifyLocked() {
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index f935c36..8f75d22 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -23,11 +23,11 @@
 
 #include "CursorInputMapper.h"
 #include "ExternalStylusInputMapper.h"
-#include "InputController.h"
 #include "InputReaderContext.h"
 #include "JoystickInputMapper.h"
 #include "KeyboardInputMapper.h"
 #include "MultiTouchInputMapper.h"
+#include "PeripheralController.h"
 #include "RotaryEncoderInputMapper.h"
 #include "SensorInputMapper.h"
 #include "SingleTouchInputMapper.h"
@@ -165,9 +165,9 @@
     }
 
     // Battery-like devices or light-containing devices.
-    // InputController will be created with associated EventHub device.
+    // PeripheralController will be created with associated EventHub device.
     if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
-        mController = std::make_unique<InputController>(*contextPtr);
+        mController = std::make_unique<PeripheralController>(*contextPtr);
     }
 
     // Keyboard-like devices.
@@ -504,8 +504,6 @@
     for_each_mapper([when, readTime](InputMapper& mapper) { mapper.cancelTouch(when, readTime); });
 }
 
-// TODO b/180733860 support multiple battery in API and remove this.
-constexpr int32_t DEFAULT_BATTERY_ID = 1;
 std::optional<int32_t> InputDevice::getBatteryCapacity() {
     return mController ? mController->getBatteryCapacity(DEFAULT_BATTERY_ID) : std::nullopt;
 }
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;
diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h
index c970c8b..410a706 100644
--- a/services/inputflinger/reader/include/EventHub.h
+++ b/services/inputflinger/reader/include/EventHub.h
@@ -528,7 +528,7 @@
     ~EventHub() override;
 
 private:
-    struct MiscDevice {
+    struct AssociatedDevice {
         // The device descriptor from evdev device the misc device associated with.
         std::string descriptor;
         // The sysfs root path of the misc device.
@@ -538,7 +538,7 @@
         int32_t nextLightId;
         std::unordered_map<int32_t, RawBatteryInfo> batteryInfos;
         std::unordered_map<int32_t, RawLightInfo> lightInfos;
-        explicit MiscDevice(std::filesystem::path sysfsRootPath)
+        explicit AssociatedDevice(std::filesystem::path sysfsRootPath)
               : sysfsRootPath(sysfsRootPath), nextBatteryId(0), nextLightId(0) {}
         bool configureBatteryLocked();
         bool configureLightsLocked();
@@ -573,7 +573,9 @@
         bool ffEffectPlaying;
         int16_t ffEffectId; // initially -1
 
-        std::shared_ptr<MiscDevice> miscDevice;
+        // A shared_ptr of a device associated with the input device.
+        // The input devices with same descriptor has the same associated device.
+        std::shared_ptr<AssociatedDevice> associatedDevice;
 
         int32_t controllerNumber;
 
@@ -690,11 +692,6 @@
     std::vector<std::unique_ptr<Device>> mOpeningDevices;
     std::vector<std::unique_ptr<Device>> mClosingDevices;
 
-    // Map from std::string descriptor, to a shared_ptr of a miscellaneous device associated with
-    // the input device. The descriptor is the same from the EventHub device which it associates
-    // with.
-    std::unordered_map<std::string, std::shared_ptr<MiscDevice>> mMiscDevices;
-
     bool mNeedToSendFinishedDeviceScan;
     bool mNeedToReopenDevices;
     bool mNeedToScanDevices;
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 5d56f5a..b2b23e5 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -32,9 +32,11 @@
 #include "InputReaderContext.h"
 
 namespace android {
+// TODO b/180733860 support multiple battery in API and remove this.
+constexpr int32_t DEFAULT_BATTERY_ID = 1;
 
-class InputController;
-class InputControllerInterface;
+class PeripheralController;
+class PeripheralControllerInterface;
 class InputDeviceContext;
 class InputMapper;
 
@@ -162,7 +164,7 @@
     // Map from EventHub ID to pair of device context and vector of mapper.
     std::unordered_map<int32_t, DevicePair> mDevices;
     // Misc devices controller for lights, battery, etc.
-    std::unique_ptr<InputControllerInterface> mController;
+    std::unique_ptr<PeripheralControllerInterface> mController;
 
     uint32_t mSources;
     bool mIsExternal;
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 3d99a6b..0e721e9 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -15,7 +15,6 @@
  */
 
 #include <CursorInputMapper.h>
-#include <InputController.h>
 #include <InputDevice.h>
 #include <InputMapper.h>
 #include <InputReader.h>
@@ -23,6 +22,7 @@
 #include <InputReaderFactory.h>
 #include <KeyboardInputMapper.h>
 #include <MultiTouchInputMapper.h>
+#include <PeripheralController.h>
 #include <SensorInputMapper.h>
 #include <SingleTouchInputMapper.h>
 #include <SwitchInputMapper.h>
@@ -2015,13 +2015,13 @@
     ASSERT_EQ(mReader->getVibratorIds(deviceId).size(), 2U);
 }
 
-// --- FakeInputController ---
+// --- FakePeripheralController ---
 
-class FakeInputController : public InputControllerInterface {
+class FakePeripheralController : public PeripheralControllerInterface {
 public:
-    FakeInputController(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
+    FakePeripheralController(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
 
-    ~FakeInputController() override {}
+    ~FakePeripheralController() override {}
 
     void populateDeviceInfo(InputDeviceInfo* deviceInfo) override {}
 
@@ -2064,7 +2064,8 @@
     constexpr int32_t eventHubId = 1;
     const char* DEVICE_LOCATION = "BLUETOOTH";
     std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
-    FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+    FakePeripheralController& controller =
+            device->addController<FakePeripheralController>(eventHubId);
     mReader->pushNextDevice(device);
 
     ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -2079,7 +2080,8 @@
     constexpr int32_t eventHubId = 1;
     const char* DEVICE_LOCATION = "BLUETOOTH";
     std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
-    FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+    FakePeripheralController& controller =
+            device->addController<FakePeripheralController>(eventHubId);
     mReader->pushNextDevice(device);
 
     ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -2094,7 +2096,8 @@
     constexpr int32_t eventHubId = 1;
     const char* DEVICE_LOCATION = "BLUETOOTH";
     std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
-    FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+    FakePeripheralController& controller =
+            device->addController<FakePeripheralController>(eventHubId);
     mReader->pushNextDevice(device);
     RawLightInfo info = {.id = 1,
                          .name = "Mono",
@@ -8598,9 +8601,9 @@
     ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper.getSources());
 }
 
-// --- InputControllerTest ---
+// --- PeripheralControllerTest ---
 
-class InputControllerTest : public testing::Test {
+class PeripheralControllerTest : public testing::Test {
 protected:
     static const char* DEVICE_NAME;
     static const char* DEVICE_LOCATION;
@@ -8663,41 +8666,43 @@
     }
 };
 
-const char* InputControllerTest::DEVICE_NAME = "device";
-const char* InputControllerTest::DEVICE_LOCATION = "BLUETOOTH";
-const int32_t InputControllerTest::DEVICE_ID = END_RESERVED_ID + 1000;
-const int32_t InputControllerTest::DEVICE_GENERATION = 2;
-const int32_t InputControllerTest::DEVICE_CONTROLLER_NUMBER = 0;
-const Flags<InputDeviceClass> InputControllerTest::DEVICE_CLASSES =
+const char* PeripheralControllerTest::DEVICE_NAME = "device";
+const char* PeripheralControllerTest::DEVICE_LOCATION = "BLUETOOTH";
+const int32_t PeripheralControllerTest::DEVICE_ID = END_RESERVED_ID + 1000;
+const int32_t PeripheralControllerTest::DEVICE_GENERATION = 2;
+const int32_t PeripheralControllerTest::DEVICE_CONTROLLER_NUMBER = 0;
+const Flags<InputDeviceClass> PeripheralControllerTest::DEVICE_CLASSES =
         Flags<InputDeviceClass>(0); // not needed for current tests
-const int32_t InputControllerTest::EVENTHUB_ID = 1;
+const int32_t PeripheralControllerTest::EVENTHUB_ID = 1;
 
 // --- BatteryControllerTest ---
-class BatteryControllerTest : public InputControllerTest {
+class BatteryControllerTest : public PeripheralControllerTest {
 protected:
     void SetUp() override {
-        InputControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::BATTERY);
+        PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::BATTERY);
     }
 };
 
 TEST_F(BatteryControllerTest, GetBatteryCapacity) {
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
 
     ASSERT_TRUE(controller.getBatteryCapacity(DEFAULT_BATTERY));
     ASSERT_EQ(controller.getBatteryCapacity(DEFAULT_BATTERY).value_or(-1), BATTERY_CAPACITY);
 }
 
 TEST_F(BatteryControllerTest, GetBatteryStatus) {
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
 
     ASSERT_TRUE(controller.getBatteryStatus(DEFAULT_BATTERY));
     ASSERT_EQ(controller.getBatteryStatus(DEFAULT_BATTERY).value_or(-1), BATTERY_STATUS);
 }
 
 // --- LightControllerTest ---
-class LightControllerTest : public InputControllerTest {
+class LightControllerTest : public PeripheralControllerTest {
 protected:
-    void SetUp() override { InputControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::LIGHT); }
+    void SetUp() override {
+        PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::LIGHT);
+    }
 };
 
 TEST_F(LightControllerTest, SingleLight) {
@@ -8708,7 +8713,7 @@
                                .path = ""};
     mFakeEventHub->addRawLightInfo(infoSingle.id, std::move(infoSingle));
 
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
     InputDeviceInfo info;
     controller.populateDeviceInfo(&info);
     const auto& ids = info.getLightIds();
@@ -8739,7 +8744,7 @@
     mFakeEventHub->addRawLightInfo(infoGreen.id, std::move(infoGreen));
     mFakeEventHub->addRawLightInfo(infoBlue.id, std::move(infoBlue));
 
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
     InputDeviceInfo info;
     controller.populateDeviceInfo(&info);
     const auto& ids = info.getLightIds();
@@ -8761,7 +8766,7 @@
 
     mFakeEventHub->addRawLightInfo(infoColor.id, std::move(infoColor));
 
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
     InputDeviceInfo info;
     controller.populateDeviceInfo(&info);
     const auto& ids = info.getLightIds();
@@ -8798,7 +8803,7 @@
     mFakeEventHub->addRawLightInfo(info3.id, std::move(info3));
     mFakeEventHub->addRawLightInfo(info4.id, std::move(info4));
 
-    InputController& controller = addControllerAndConfigure<InputController>();
+    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
     InputDeviceInfo info;
     controller.populateDeviceInfo(&info);
     const auto& ids = info.getLightIds();