Loading services/inputflinger/include/InputReaderBase.h +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ public: * * This method may be called on any thread (usually by the input manager). */ virtual void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) = 0; virtual std::vector<InputDeviceInfo> getInputDevices() const = 0; /* Query current input state. */ virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, Loading services/inputflinger/reader/InputReader.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ void InputReader::loopOnce() { int32_t oldGeneration; int32_t timeoutMillis; bool inputDevicesChanged = false; std::vector<InputDeviceInfo> inputDevices; { // acquire lock AutoMutex _l(mLock); Loading Loading @@ -128,13 +127,12 @@ void InputReader::loopOnce() { if (oldGeneration != mGeneration) { inputDevicesChanged = true; getInputDevicesLocked(inputDevices); } } // release lock // Send out a message that the describes the changed input devices. if (inputDevicesChanged) { mPolicy->notifyInputDevicesChanged(inputDevices); mPolicy->notifyInputDevicesChanged(getInputDevicesLocked()); } // Flush queued events out to the listener. Loading Loading @@ -474,13 +472,14 @@ int32_t InputReader::bumpGenerationLocked() { return ++mGeneration; } void InputReader::getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) { std::vector<InputDeviceInfo> InputReader::getInputDevices() const { AutoMutex _l(mLock); getInputDevicesLocked(outInputDevices); return getInputDevicesLocked(); } void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices) { outInputDevices.clear(); std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const { std::vector<InputDeviceInfo> outInputDevices; outInputDevices.reserve(mDeviceToEventHubIdsMap.size()); for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) { if (!device->isIgnored()) { Loading @@ -489,6 +488,7 @@ void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDe outInputDevices.push_back(info); } } return outInputDevices; } int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { Loading services/inputflinger/reader/include/InputReader.h +3 −3 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public: status_t start() override; status_t stop() override; void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) override; std::vector<InputDeviceInfo> getInputDevices() const override; bool isInputDeviceEnabled(int32_t deviceId) override; Loading Loading @@ -121,7 +121,7 @@ protected: private: std::unique_ptr<InputThread> mThread; Mutex mLock; mutable Mutex mLock; Condition mReaderIsAliveCondition; Loading Loading @@ -181,7 +181,7 @@ private: int32_t mNextInputDeviceId; int32_t nextInputDeviceIdLocked(); void getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices); std::vector<InputDeviceInfo> getInputDevicesLocked() const; nsecs_t mDisableVirtualKeysTimeout; void disableVirtualKeysUntilLocked(nsecs_t time); Loading services/inputflinger/tests/InputReader_test.cpp +21 −21 Original line number Diff line number Diff line Loading @@ -1330,22 +1330,27 @@ protected: } }; TEST_F(InputReaderTest, GetInputDevices) { TEST_F(InputReaderTest, ReaderGetInputDevices) { ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr)); ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", Flags<InputDeviceClass>(0), nullptr)); // no classes so device will be ignored std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); const std::vector<InputDeviceInfo> inputDevices = mReader->getInputDevices(); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId()); ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); } TEST_F(InputReaderTest, PolicyGetInputDevices) { ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr)); ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", Flags<InputDeviceClass>(0), nullptr)); // no classes so device will be ignored // Should also have received a notification describing the new input devices. inputDevices = mFakePolicy->getInputDevices(); const std::vector<InputDeviceInfo>& inputDevices = mFakePolicy->getInputDevices(); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId()); ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); Loading @@ -1372,9 +1377,7 @@ TEST_F(InputReaderTest, GetMergedInputDevices) { addDevice(eventHubIds[1], "fake2", InputDeviceClass::KEYBOARD, nullptr)); // Two devices will be merged to one input device as they have same identifier std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(1U, mReader->getInputDevices().size()); } TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) { Loading Loading @@ -1815,20 +1818,17 @@ TEST_F(InputReaderIntegrationTest, AddNewDevice) { ASSERT_EQ(initialNumDevices + 1, mFakePolicy->getInputDevices().size()); // Find the test device by its name. std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); InputDeviceInfo* keyboardInfo = nullptr; const char* keyboardName = keyboard->getName(); for (unsigned int i = 0; i < initialNumDevices + 1; i++) { if (!strcmp(inputDevices[i].getIdentifier().name.c_str(), keyboardName)) { keyboardInfo = &inputDevices[i]; break; } } ASSERT_NE(keyboardInfo, nullptr); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, keyboardInfo->getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyboardInfo->getSources()); ASSERT_EQ(0U, keyboardInfo->getMotionRanges().size()); const std::vector<InputDeviceInfo> inputDevices = mReader->getInputDevices(); const auto& it = std::find_if(inputDevices.begin(), inputDevices.end(), [&keyboard](const InputDeviceInfo& info) { return info.getIdentifier().name == keyboard->getName(); }); ASSERT_NE(it, inputDevices.end()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, it->getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, it->getSources()); ASSERT_EQ(0U, it->getMotionRanges().size()); keyboard.reset(); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); Loading Loading
services/inputflinger/include/InputReaderBase.h +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ public: * * This method may be called on any thread (usually by the input manager). */ virtual void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) = 0; virtual std::vector<InputDeviceInfo> getInputDevices() const = 0; /* Query current input state. */ virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask, Loading
services/inputflinger/reader/InputReader.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ void InputReader::loopOnce() { int32_t oldGeneration; int32_t timeoutMillis; bool inputDevicesChanged = false; std::vector<InputDeviceInfo> inputDevices; { // acquire lock AutoMutex _l(mLock); Loading Loading @@ -128,13 +127,12 @@ void InputReader::loopOnce() { if (oldGeneration != mGeneration) { inputDevicesChanged = true; getInputDevicesLocked(inputDevices); } } // release lock // Send out a message that the describes the changed input devices. if (inputDevicesChanged) { mPolicy->notifyInputDevicesChanged(inputDevices); mPolicy->notifyInputDevicesChanged(getInputDevicesLocked()); } // Flush queued events out to the listener. Loading Loading @@ -474,13 +472,14 @@ int32_t InputReader::bumpGenerationLocked() { return ++mGeneration; } void InputReader::getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) { std::vector<InputDeviceInfo> InputReader::getInputDevices() const { AutoMutex _l(mLock); getInputDevicesLocked(outInputDevices); return getInputDevicesLocked(); } void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices) { outInputDevices.clear(); std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const { std::vector<InputDeviceInfo> outInputDevices; outInputDevices.reserve(mDeviceToEventHubIdsMap.size()); for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) { if (!device->isIgnored()) { Loading @@ -489,6 +488,7 @@ void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDe outInputDevices.push_back(info); } } return outInputDevices; } int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { Loading
services/inputflinger/reader/include/InputReader.h +3 −3 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public: status_t start() override; status_t stop() override; void getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) override; std::vector<InputDeviceInfo> getInputDevices() const override; bool isInputDeviceEnabled(int32_t deviceId) override; Loading Loading @@ -121,7 +121,7 @@ protected: private: std::unique_ptr<InputThread> mThread; Mutex mLock; mutable Mutex mLock; Condition mReaderIsAliveCondition; Loading Loading @@ -181,7 +181,7 @@ private: int32_t mNextInputDeviceId; int32_t nextInputDeviceIdLocked(); void getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices); std::vector<InputDeviceInfo> getInputDevicesLocked() const; nsecs_t mDisableVirtualKeysTimeout; void disableVirtualKeysUntilLocked(nsecs_t time); Loading
services/inputflinger/tests/InputReader_test.cpp +21 −21 Original line number Diff line number Diff line Loading @@ -1330,22 +1330,27 @@ protected: } }; TEST_F(InputReaderTest, GetInputDevices) { TEST_F(InputReaderTest, ReaderGetInputDevices) { ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr)); ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", Flags<InputDeviceClass>(0), nullptr)); // no classes so device will be ignored std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); const std::vector<InputDeviceInfo> inputDevices = mReader->getInputDevices(); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId()); ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size()); } TEST_F(InputReaderTest, PolicyGetInputDevices) { ASSERT_NO_FATAL_FAILURE(addDevice(1, "keyboard", InputDeviceClass::KEYBOARD, nullptr)); ASSERT_NO_FATAL_FAILURE(addDevice(2, "ignored", Flags<InputDeviceClass>(0), nullptr)); // no classes so device will be ignored // Should also have received a notification describing the new input devices. inputDevices = mFakePolicy->getInputDevices(); const std::vector<InputDeviceInfo>& inputDevices = mFakePolicy->getInputDevices(); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(END_RESERVED_ID + 1, inputDevices[0].getId()); ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); Loading @@ -1372,9 +1377,7 @@ TEST_F(InputReaderTest, GetMergedInputDevices) { addDevice(eventHubIds[1], "fake2", InputDeviceClass::KEYBOARD, nullptr)); // Two devices will be merged to one input device as they have same identifier std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); ASSERT_EQ(1U, inputDevices.size()); ASSERT_EQ(1U, mReader->getInputDevices().size()); } TEST_F(InputReaderTest, WhenEnabledChanges_SendsDeviceResetNotification) { Loading Loading @@ -1815,20 +1818,17 @@ TEST_F(InputReaderIntegrationTest, AddNewDevice) { ASSERT_EQ(initialNumDevices + 1, mFakePolicy->getInputDevices().size()); // Find the test device by its name. std::vector<InputDeviceInfo> inputDevices; mReader->getInputDevices(inputDevices); InputDeviceInfo* keyboardInfo = nullptr; const char* keyboardName = keyboard->getName(); for (unsigned int i = 0; i < initialNumDevices + 1; i++) { if (!strcmp(inputDevices[i].getIdentifier().name.c_str(), keyboardName)) { keyboardInfo = &inputDevices[i]; break; } } ASSERT_NE(keyboardInfo, nullptr); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, keyboardInfo->getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyboardInfo->getSources()); ASSERT_EQ(0U, keyboardInfo->getMotionRanges().size()); const std::vector<InputDeviceInfo> inputDevices = mReader->getInputDevices(); const auto& it = std::find_if(inputDevices.begin(), inputDevices.end(), [&keyboard](const InputDeviceInfo& info) { return info.getIdentifier().name == keyboard->getName(); }); ASSERT_NE(it, inputDevices.end()); ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, it->getKeyboardType()); ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, it->getSources()); ASSERT_EQ(0U, it->getMotionRanges().size()); keyboard.reset(); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); Loading