Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1046a89 authored by Josep del Rio's avatar Josep del Rio Committed by Josep del Río
Browse files

Group player leds in Sony Dualsense controller

Sony reported that Android will not group the player LEDs properly
for the DualSense controller. After investigating, our mechanism
to group LEDs would not support the standard name for player ID
lights. This fix expands the regular expression so it will support
this format in addition of the name that the gamepad driver will
use in certain older devices.

Bug: 289067916
Flag: EXEMPT bugfix
Test: `adb shell dumpsys input`
Change-Id: I5b5e3f5e8478422bbc717a6c272a24e6568464fc
parent 22a5a666
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -418,7 +418,11 @@ void PeripheralController::configureLights() {
        }
        rawInfos.insert_or_assign(rawId, rawInfo.value());
        // Check if this is a group LEDs for player ID
        std::regex lightPattern("([a-z]+)([0-9]+)");
        // The name for the light has already been parsed and is the `function`
        // value; for player ID lights the function is expected to be `player-#`.
        // However, the Sony driver will use `sony#` instead on SIXAXIS
        // gamepads.
        std::regex lightPattern("(player|sony)-?([0-9]+)");
        std::smatch results;
        if (std::regex_match(rawInfo->name, results, lightPattern)) {
            std::string commonName = results[1].str();
+47 −4
Original line number Diff line number Diff line
@@ -10595,24 +10595,66 @@ TEST_F(LightControllerTest, MultiColorRGBKeyboardBacklight) {
    ASSERT_EQ(controller.getLightColor(lights[0].id).value_or(-1), LIGHT_COLOR);
}

TEST_F(LightControllerTest, SonyPlayerIdLight) {
    RawLightInfo info1 = {.id = 1,
                          .name = "sony1",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info2 = {.id = 2,
                          .name = "sony2",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info3 = {.id = 3,
                          .name = "sony3",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info4 = {.id = 4,
                          .name = "sony4",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    mFakeEventHub->addRawLightInfo(info1.id, std::move(info1));
    mFakeEventHub->addRawLightInfo(info2.id, std::move(info2));
    mFakeEventHub->addRawLightInfo(info3.id, std::move(info3));
    mFakeEventHub->addRawLightInfo(info4.id, std::move(info4));

    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
    InputDeviceInfo info;
    controller.populateDeviceInfo(&info);
    std::vector<InputDeviceLightInfo> lights = info.getLights();
    ASSERT_EQ(1U, lights.size());
    ASSERT_STREQ("sony", lights[0].name.c_str());
    ASSERT_EQ(InputDeviceLightType::PLAYER_ID, lights[0].type);
    ASSERT_FALSE(lights[0].capabilityFlags.test(InputDeviceLightCapability::BRIGHTNESS));
    ASSERT_FALSE(lights[0].capabilityFlags.test(InputDeviceLightCapability::RGB));

    ASSERT_FALSE(controller.setLightColor(lights[0].id, LIGHT_COLOR));
    ASSERT_TRUE(controller.setLightPlayerId(lights[0].id, LIGHT_PLAYER_ID));
    ASSERT_EQ(controller.getLightPlayerId(lights[0].id).value_or(-1), LIGHT_PLAYER_ID);
    ASSERT_STREQ("sony", lights[0].name.c_str());
}

TEST_F(LightControllerTest, PlayerIdLight) {
    RawLightInfo info1 = {.id = 1,
                          .name = "player1",
                          .name = "player-1",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info2 = {.id = 2,
                          .name = "player2",
                          .name = "player-2",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info3 = {.id = 3,
                          .name = "player3",
                          .name = "player-3",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
    RawLightInfo info4 = {.id = 4,
                          .name = "player4",
                          .name = "player-4",
                          .maxBrightness = 255,
                          .flags = InputLightClass::BRIGHTNESS,
                          .path = ""};
@@ -10626,6 +10668,7 @@ TEST_F(LightControllerTest, PlayerIdLight) {
    controller.populateDeviceInfo(&info);
    std::vector<InputDeviceLightInfo> lights = info.getLights();
    ASSERT_EQ(1U, lights.size());
    ASSERT_STREQ("player", lights[0].name.c_str());
    ASSERT_EQ(InputDeviceLightType::PLAYER_ID, lights[0].type);
    ASSERT_FALSE(lights[0].capabilityFlags.test(InputDeviceLightCapability::BRIGHTNESS));
    ASSERT_FALSE(lights[0].capabilityFlags.test(InputDeviceLightCapability::RGB));