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

Commit dda911ce authored by Chris Ye's avatar Chris Ye Committed by Automerger Merge Worker
Browse files

Merge "Change native lights to be consistent with java API." into sc-dev am: 3a7faf30

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14597492

Change-Id: Id09dcf51315283d7eaecc34d5ef093f7ca950300
parents c45dbdf8 3a7faf30
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ enum class InputDeviceSensorReportingMode : int32_t {
};

enum class InputDeviceLightType : int32_t {
    SINGLE = 0,
    MONO = 0,
    PLAYER_ID = 1,
    RGB = 2,
    MULTI_COLOR = 3,
+8 −9
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ void PeripheralController::Light::setRawLightBrightness(int32_t rawLightId, int3
    context.setLightBrightness(rawLightId, brightness);
}

bool PeripheralController::SingleLight::setLightColor(int32_t color) {
bool PeripheralController::MonoLight::setLightColor(int32_t color) {
    int32_t brightness = getAlpha(color);
    setRawLightBrightness(rawId, brightness);

@@ -148,7 +148,7 @@ bool PeripheralController::MultiColorLight::setLightColor(int32_t color) {
    return true;
}

std::optional<int32_t> PeripheralController::SingleLight::getLightColor() {
std::optional<int32_t> PeripheralController::MonoLight::getLightColor() {
    std::optional<int32_t> brightness = getRawLightBrightness(rawId);
    if (!brightness.has_value()) {
        return std::nullopt;
@@ -234,7 +234,7 @@ std::optional<int32_t> PeripheralController::PlayerIdLight::getLightPlayerId() {
    return std::nullopt;
}

void PeripheralController::SingleLight::dump(std::string& dump) {
void PeripheralController::MonoLight::dump(std::string& dump) {
    dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
}

@@ -423,7 +423,7 @@ void PeripheralController::configureLights() {
                                                playerIdLightIds);
        mLights.insert_or_assign(light->id, std::move(light));
        // Remove these raw lights from raw light info as they've been used to compose a
        // Player ID light, so we do not expose these raw lights as single lights.
        // Player ID light, so we do not expose these raw lights as mono lights.
        for (const auto& [playerId, rawId] : playerIdLightIds) {
            rawInfos.erase(rawId);
        }
@@ -460,13 +460,12 @@ void PeripheralController::configureLights() {
            mLights.insert_or_assign(light->id, std::move(light));
            continue;
        }
        // Construct a single LED light
        // Construct a Mono LED light
        if (DEBUG_LIGHT_DETAILS) {
            ALOGD("Single light Id %d name %s \n", rawInfo.id, rawInfo.name.c_str());
            ALOGD("Mono light Id %d name %s \n", rawInfo.id, rawInfo.name.c_str());
        }
        std::unique_ptr<Light> light =
                std::make_unique<SingleLight>(getDeviceContext(), rawInfo.name, ++mNextId,
                                              rawInfo.id);
        std::unique_ptr<Light> light = std::make_unique<MonoLight>(getDeviceContext(), rawInfo.name,
                                                                   ++mNextId, rawInfo.id);

        mLights.insert_or_assign(light->id, std::move(light));
    }
+4 −4
Original line number Diff line number Diff line
@@ -78,10 +78,10 @@ private:
        void setRawLightBrightness(int32_t rawLightId, int32_t brightness);
    };

    struct SingleLight : public Light {
        explicit SingleLight(InputDeviceContext& context, const std::string& name, int32_t id,
    struct MonoLight : public Light {
        explicit MonoLight(InputDeviceContext& context, const std::string& name, int32_t id,
                           int32_t rawId)
              : Light(context, name, id, InputDeviceLightType::SINGLE), rawId(rawId) {}
              : Light(context, name, id, InputDeviceLightType::MONO), rawId(rawId) {}
        int32_t rawId;

        bool setLightColor(int32_t color) override;
+8 −8
Original line number Diff line number Diff line
@@ -8743,20 +8743,20 @@ protected:
    }
};

TEST_F(LightControllerTest, SingleLight) {
    RawLightInfo infoSingle = {.id = 1,
TEST_F(LightControllerTest, MonoLight) {
    RawLightInfo infoMono = {.id = 1,
                             .name = "Mono",
                             .maxBrightness = 255,
                             .flags = InputLightClass::BRIGHTNESS,
                             .path = ""};
    mFakeEventHub->addRawLightInfo(infoSingle.id, std::move(infoSingle));
    mFakeEventHub->addRawLightInfo(infoMono.id, std::move(infoMono));

    PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
    InputDeviceInfo info;
    controller.populateDeviceInfo(&info);
    const auto& ids = info.getLightIds();
    ASSERT_EQ(1UL, ids.size());
    ASSERT_EQ(InputDeviceLightType::SINGLE, info.getLightInfo(ids[0])->type);
    ASSERT_EQ(InputDeviceLightType::MONO, info.getLightInfo(ids[0])->type);

    ASSERT_TRUE(controller.setLightColor(ids[0], LIGHT_BRIGHTNESS));
    ASSERT_EQ(controller.getLightColor(ids[0]).value_or(-1), LIGHT_BRIGHTNESS);