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

Commit 3fdbfef3 authored by Chris Ye's avatar Chris Ye
Browse files

Support Inputdevice LightsManager feature in frameworks.

Add lights manager support to input frameworks.

Bug: 161633625
Test: atest LightsManagerTest, atest InputDeviceLightsManagerTest
Change-Id: Ie00357bce0f6c98e9eada5e0a79f93f48e7a4d1b
parent 97792f96
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -859,7 +859,7 @@ enum {
    /** HDMI */
    /** HDMI */
    AINPUT_SOURCE_HDMI = 0x02000000 | AINPUT_SOURCE_CLASS_BUTTON,
    AINPUT_SOURCE_HDMI = 0x02000000 | AINPUT_SOURCE_CLASS_BUTTON,
    /** sensor */
    /** sensor */
    AINPUT_SOURCE_SENSOR = 0x04000000 | AINPUT_SOURCE_UNKNOWN,
    AINPUT_SOURCE_SENSOR = 0x04000000 | AINPUT_SOURCE_CLASS_NONE,
    /** rotary encoder */
    /** rotary encoder */
    AINPUT_SOURCE_ROTARY_ENCODER = 0x00400000 | AINPUT_SOURCE_CLASS_NONE,
    AINPUT_SOURCE_ROTARY_ENCODER = 0x00400000 | AINPUT_SOURCE_CLASS_NONE,


+28 −0
Original line number Original line Diff line number Diff line
@@ -100,6 +100,13 @@ enum class InputDeviceSensorReportingMode : int32_t {
    SPECIAL_TRIGGER = 3,
    SPECIAL_TRIGGER = 3,
};
};


enum class InputDeviceLightType : int32_t {
    SINGLE = 0,
    PLAYER_ID = 1,
    RGB = 2,
    MULTI_COLOR = 3,
};

struct InputDeviceSensorInfo {
struct InputDeviceSensorInfo {
    explicit InputDeviceSensorInfo(std::string name, std::string vendor, int32_t version,
    explicit InputDeviceSensorInfo(std::string name, std::string vendor, int32_t version,
                                   InputDeviceSensorType type, InputDeviceSensorAccuracy accuracy,
                                   InputDeviceSensorType type, InputDeviceSensorAccuracy accuracy,
@@ -156,6 +163,20 @@ struct InputDeviceSensorInfo {
    int32_t id;
    int32_t id;
};
};


struct InputDeviceLightInfo {
    explicit InputDeviceLightInfo(std::string name, int32_t id, InputDeviceLightType type,
                                  int32_t ordinal)
          : name(name), id(id), type(type), ordinal(ordinal) {}
    // Name string of the light.
    std::string name;
    // Light id
    int32_t id;
    // Type of the light.
    InputDeviceLightType type;
    // Ordinal of the light
    int32_t ordinal;
};

/*
/*
 * Describes the characteristics and capabilities of an input device.
 * Describes the characteristics and capabilities of an input device.
 */
 */
@@ -198,6 +219,7 @@ public:
            float min, float max, float flat, float fuzz, float resolution);
            float min, float max, float flat, float fuzz, float resolution);
    void addMotionRange(const MotionRange& range);
    void addMotionRange(const MotionRange& range);
    void addSensorInfo(const InputDeviceSensorInfo& info);
    void addSensorInfo(const InputDeviceSensorInfo& info);
    void addLightInfo(const InputDeviceLightInfo& info);


    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }
@@ -230,6 +252,10 @@ public:


    const std::vector<InputDeviceSensorType> getSensorTypes();
    const std::vector<InputDeviceSensorType> getSensorTypes();


    const std::vector<int32_t> getLightIds();

    const InputDeviceLightInfo* getLightInfo(int32_t id);

private:
private:
    int32_t mId;
    int32_t mId;
    int32_t mGeneration;
    int32_t mGeneration;
@@ -248,6 +274,8 @@ private:


    std::vector<MotionRange> mMotionRanges;
    std::vector<MotionRange> mMotionRanges;
    std::unordered_map<InputDeviceSensorType, InputDeviceSensorInfo> mSensors;
    std::unordered_map<InputDeviceSensorType, InputDeviceSensorInfo> mSensors;
    /* Map from light ID to light info */
    std::unordered_map<int32_t, InputDeviceLightInfo> mLights;
};
};


/* Types of input device configuration files. */
/* Types of input device configuration files. */
+26 −1
Original line number Original line Diff line number Diff line
@@ -170,7 +170,8 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mHasButtonUnderPad(other.mHasButtonUnderPad),
        mHasButtonUnderPad(other.mHasButtonUnderPad),
        mHasSensor(other.mHasSensor),
        mHasSensor(other.mHasSensor),
        mMotionRanges(other.mMotionRanges),
        mMotionRanges(other.mMotionRanges),
        mSensors(other.mSensors) {}
        mSensors(other.mSensors),
        mLights(other.mLights) {}


InputDeviceInfo::~InputDeviceInfo() {
InputDeviceInfo::~InputDeviceInfo() {
}
}
@@ -193,6 +194,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
    mHasSensor = false;
    mHasSensor = false;
    mMotionRanges.clear();
    mMotionRanges.clear();
    mSensors.clear();
    mSensors.clear();
    mLights.clear();
}
}


const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(
const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(
@@ -229,6 +231,13 @@ void InputDeviceInfo::addSensorInfo(const InputDeviceSensorInfo& info) {
    mSensors.insert_or_assign(info.type, info);
    mSensors.insert_or_assign(info.type, info);
}
}


void InputDeviceInfo::addLightInfo(const InputDeviceLightInfo& info) {
    if (mLights.find(info.id) != mLights.end()) {
        ALOGW("Light id %d already exists, will be replaced by new light added.", info.id);
    }
    mLights.insert_or_assign(info.id, info);
}

const std::vector<InputDeviceSensorType> InputDeviceInfo::getSensorTypes() {
const std::vector<InputDeviceSensorType> InputDeviceInfo::getSensorTypes() {
    std::vector<InputDeviceSensorType> types;
    std::vector<InputDeviceSensorType> types;
    for (const auto& [type, info] : mSensors) {
    for (const auto& [type, info] : mSensors) {
@@ -245,4 +254,20 @@ const InputDeviceSensorInfo* InputDeviceInfo::getSensorInfo(InputDeviceSensorTyp
    return &it->second;
    return &it->second;
}
}


const std::vector<int32_t> InputDeviceInfo::getLightIds() {
    std::vector<int32_t> ids;
    for (const auto& [id, info] : mLights) {
        ids.push_back(id);
    }
    return ids;
}

const InputDeviceLightInfo* InputDeviceInfo::getLightInfo(int32_t id) {
    auto it = mLights.find(id);
    if (it == mLights.end()) {
        return nullptr;
    }
    return &it->second;
}

} // namespace android
} // namespace android
+13 −0
Original line number Original line Diff line number Diff line
@@ -113,6 +113,10 @@ public:
    /* Get battery status of a particular input device. */
    /* Get battery status of a particular input device. */
    virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;
    virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;


    virtual std::vector<int32_t> getLightIds(int32_t deviceId) = 0;

    virtual const InputDeviceLightInfo* getLightInfo(int32_t deviceId, int32_t lightId) = 0;

    /* Return true if the device can send input events to the specified display. */
    /* Return true if the device can send input events to the specified display. */
    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;


@@ -126,6 +130,15 @@ public:


    /* Flush sensor data in input reader mapper. */
    /* Flush sensor data in input reader mapper. */
    virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;
    virtual void flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) = 0;

    /* Set color for the light */
    virtual bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) = 0;
    /* Set player ID for the light */
    virtual bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) = 0;
    /* Get light color */
    virtual std::optional<int32_t> getLightColor(int32_t deviceId, int32_t lightId) = 0;
    /* Get light player ID */
    virtual std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) = 0;
};
};


// --- InputReaderConfiguration ---
// --- InputReaderConfiguration ---
+1 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ filegroup {
        "mapper/InputMapper.cpp",
        "mapper/InputMapper.cpp",
        "mapper/JoystickInputMapper.cpp",
        "mapper/JoystickInputMapper.cpp",
        "mapper/KeyboardInputMapper.cpp",
        "mapper/KeyboardInputMapper.cpp",
        "mapper/LightInputMapper.cpp",
        "mapper/MultiTouchInputMapper.cpp",
        "mapper/MultiTouchInputMapper.cpp",
        "mapper/RotaryEncoderInputMapper.cpp",
        "mapper/RotaryEncoderInputMapper.cpp",
        "mapper/SensorInputMapper.cpp",
        "mapper/SensorInputMapper.cpp",
Loading