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

Commit 74be44dd authored by Kim Low's avatar Kim Low Committed by Chris Ye
Browse files

Added the ability to read external batteries

Extended InputDevice and EventHub with capabilites to detect and read
external battery status and capacity. This allows devices such as
wireless gamepads to provide battery information to applications.

Bug: 161633432
Test: atest InputDeviceBatteryTest

Change-Id: I3c65166a1f0b055c5b85bad286afd5beb60bb303
parent 40c61822
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -213,6 +213,9 @@ public:
    inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
    inline bool hasVibrator() const { return mHasVibrator; }

    inline void setHasBattery(bool hasBattery) { mHasBattery = hasBattery; }
    inline bool hasBattery() const { return mHasBattery; }

    inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
    inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }

@@ -239,6 +242,7 @@ private:
    int32_t mKeyboardType;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
    bool mHasVibrator;
    bool mHasBattery;
    bool mHasButtonUnderPad;
    bool mHasSensor;

+2 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
        mHasVibrator(other.mHasVibrator),
        mHasBattery(other.mHasBattery),
        mHasButtonUnderPad(other.mHasButtonUnderPad),
        mHasSensor(other.mHasSensor),
        mMotionRanges(other.mMotionRanges),
@@ -187,6 +188,7 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
    mSources = 0;
    mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
    mHasVibrator = false;
    mHasBattery = false;
    mHasButtonUnderPad = false;
    mHasSensor = false;
    mMotionRanges.clear();
+3 −0
Original line number Diff line number Diff line
@@ -28,4 +28,7 @@ interface IInputConstants
      * to identify apps that are using this flag.
      */
    const long BLOCK_FLAG_SLIPPERY = 157929241;

    // Indicate invalid battery capacity
    const int INVALID_BATTERY_CAPACITY = -1;
}
+4 −0
Original line number Diff line number Diff line
@@ -108,6 +108,10 @@ public:
    virtual bool isVibrating(int32_t deviceId) = 0;

    virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0;
    /* Get battery level of a particular input device. */
    virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0;
    /* Get battery status of a particular input device. */
    virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0;

    /* Return true if the device can send input events to the specified display. */
    virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ filegroup {
        "mapper/accumulator/CursorScrollAccumulator.cpp",
        "mapper/accumulator/SingleTouchMotionAccumulator.cpp",
        "mapper/accumulator/TouchButtonAccumulator.cpp",
        "mapper/BatteryInputMapper.cpp",
        "mapper/CursorInputMapper.cpp",
        "mapper/ExternalStylusInputMapper.cpp",
        "mapper/InputMapper.cpp",
@@ -60,7 +61,11 @@ cc_defaults {
        "libui",
        "libutils",
    ],
    static_libs: [
        "libc++fs",
    ],
    header_libs: [
        "libbatteryservice_headers",
        "libinputreader_headers",
    ],
}
Loading