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

Commit b54ffb2a authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputReader: Get Bluetooth address from InputDeviceIdentifier

The InputDevice class in Reader stores the InputDeviceIdentifier. When
the policy wants to get the Bluetooth address of an InputDevice, fetch
it from there.

Bug: 243005009
Test: atest inputflinger_tests
Change-Id: I5d881a11cb1bc318258faf1f498db1ca29ae8537
parent 07525ef5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -142,6 +142,9 @@ public:
    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;

    /* Get the Bluetooth address of an input device, if known. */
    virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;
};

// --- InputReaderConfiguration ---
+10 −0
Original line number Diff line number Diff line
@@ -875,6 +875,16 @@ std::optional<int32_t> InputReader::getLightPlayerId(int32_t deviceId, int32_t l
    return std::nullopt;
}

std::optional<std::string> InputReader::getBluetoothAddress(int32_t deviceId) const {
    std::scoped_lock _l(mLock);

    InputDevice* device = findInputDeviceLocked(deviceId);
    if (device) {
        return device->getBluetoothAddress();
    }
    return std::nullopt;
}

bool InputReader::isInputDeviceEnabled(int32_t deviceId) {
    std::scoped_lock _l(mLock);

+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ public:
    inline int32_t getGeneration() const { return mGeneration; }
    inline const std::string getName() const { return mIdentifier.name; }
    inline const std::string getDescriptor() { return mIdentifier.descriptor; }
    inline std::optional<std::string> getBluetoothAddress() const {
        return mIdentifier.bluetoothAddress;
    }
    inline ftl::Flags<InputDeviceClass> getClasses() const { return mClasses; }
    inline uint32_t getSources() const { return mSources; }
    inline bool hasEventHubDevices() const { return !mDevices.empty(); }
+2 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ public:

    std::optional<int32_t> getLightPlayerId(int32_t deviceId, int32_t lightId) override;

    std::optional<std::string> getBluetoothAddress(int32_t deviceId) const override;

protected:
    // These members are protected so they can be instrumented by test cases.
    virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId,
+9 −0
Original line number Diff line number Diff line
@@ -2782,6 +2782,7 @@ protected:
    static const int32_t DEVICE_CONTROLLER_NUMBER;
    static const ftl::Flags<InputDeviceClass> DEVICE_CLASSES;
    static const int32_t EVENTHUB_ID;
    static const std::string DEVICE_BLUETOOTH_ADDRESS;

    std::shared_ptr<FakeEventHub> mFakeEventHub;
    sp<FakeInputReaderPolicy> mFakePolicy;
@@ -2798,6 +2799,7 @@ protected:
        InputDeviceIdentifier identifier;
        identifier.name = DEVICE_NAME;
        identifier.location = DEVICE_LOCATION;
        identifier.bluetoothAddress = DEVICE_BLUETOOTH_ADDRESS;
        mDevice = std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, DEVICE_GENERATION,
                                                identifier);
        mReader->pushNextDevice(mDevice);
@@ -2819,6 +2821,7 @@ const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0;
const ftl::Flags<InputDeviceClass> InputDeviceTest::DEVICE_CLASSES =
        InputDeviceClass::KEYBOARD | InputDeviceClass::TOUCH | InputDeviceClass::JOYSTICK;
const int32_t InputDeviceTest::EVENTHUB_ID = 1;
const std::string InputDeviceTest::DEVICE_BLUETOOTH_ADDRESS = "11:AA:22:BB:33:CC";

TEST_F(InputDeviceTest, ImmutableProperties) {
    ASSERT_EQ(DEVICE_ID, mDevice->getId());
@@ -3085,6 +3088,12 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) {
    device.dump(dumpStr, eventHubDevStr);
}

TEST_F(InputDeviceTest, GetBluetoothAddress) {
    const auto& address = mReader->getBluetoothAddress(DEVICE_ID);
    ASSERT_TRUE(address);
    ASSERT_EQ(DEVICE_BLUETOOTH_ADDRESS, *address);
}

// --- InputMapperTest ---

class InputMapperTest : public testing::Test {
Loading