Loading services/inputflinger/dispatcher/Entry.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,8 @@ static std::string motionActionToString(int32_t action) { return "MOVE"; return "MOVE"; case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_UP: return "UP"; return "UP"; case AMOTION_EVENT_ACTION_CANCEL: return "CANCEL"; case AMOTION_EVENT_ACTION_POINTER_DOWN: case AMOTION_EVENT_ACTION_POINTER_DOWN: return "POINTER_DOWN"; return "POINTER_DOWN"; case AMOTION_EVENT_ACTION_POINTER_UP: case AMOTION_EVENT_ACTION_POINTER_UP: Loading @@ -57,6 +59,7 @@ static std::string keyActionToString(int32_t action) { } } return StringPrintf("%" PRId32, action); return StringPrintf("%" PRId32, action); } } VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry) { VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry) { return {{VerifiedInputEvent::Type::KEY, entry.deviceId, entry.eventTime, entry.source, return {{VerifiedInputEvent::Type::KEY, entry.deviceId, entry.eventTime, entry.source, entry.displayId}, entry.displayId}, Loading services/inputflinger/include/InputListener.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <input/Input.h> #include <input/Input.h> #include <input/TouchVideoFrame.h> #include <input/TouchVideoFrame.h> #include <utils/RefBase.h> #include <utils/RefBase.h> #include <utils/Vector.h> namespace android { namespace android { Loading services/inputflinger/tests/InputDispatcher_test.cpp +19 −6 Original line number Original line Diff line number Diff line Loading @@ -83,9 +83,13 @@ public: args.displayId); args.displayId); } } void assertFilterInputEventWasNotCalled() { ASSERT_EQ(nullptr, mFilteredEvent); } void assertFilterInputEventWasNotCalled() { std::scoped_lock lock(mLock); ASSERT_EQ(nullptr, mFilteredEvent); } void assertNotifyConfigurationChangedWasCalled(nsecs_t when) { void assertNotifyConfigurationChangedWasCalled(nsecs_t when) { std::scoped_lock lock(mLock); ASSERT_TRUE(mConfigurationChangedTime) ASSERT_TRUE(mConfigurationChangedTime) << "Timed out waiting for configuration changed call"; << "Timed out waiting for configuration changed call"; ASSERT_EQ(*mConfigurationChangedTime, when); ASSERT_EQ(*mConfigurationChangedTime, when); Loading @@ -93,6 +97,7 @@ public: } } void assertNotifySwitchWasCalled(const NotifySwitchArgs& args) { void assertNotifySwitchWasCalled(const NotifySwitchArgs& args) { std::scoped_lock lock(mLock); ASSERT_TRUE(mLastNotifySwitch); ASSERT_TRUE(mLastNotifySwitch); // We do not check id because it is not exposed to the policy // We do not check id because it is not exposed to the policy EXPECT_EQ(args.eventTime, mLastNotifySwitch->eventTime); EXPECT_EQ(args.eventTime, mLastNotifySwitch->eventTime); Loading @@ -103,11 +108,13 @@ public: } } void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) { void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) { std::scoped_lock lock(mLock); ASSERT_EQ(touchedToken, mOnPointerDownToken); ASSERT_EQ(touchedToken, mOnPointerDownToken); mOnPointerDownToken.clear(); mOnPointerDownToken.clear(); } } void assertOnPointerDownWasNotCalled() { void assertOnPointerDownWasNotCalled() { std::scoped_lock lock(mLock); ASSERT_TRUE(mOnPointerDownToken == nullptr) ASSERT_TRUE(mOnPointerDownToken == nullptr) << "Expected onPointerDownOutsideFocus to not have been called"; << "Expected onPointerDownOutsideFocus to not have been called"; } } Loading @@ -118,12 +125,14 @@ public: } } private: private: std::unique_ptr<InputEvent> mFilteredEvent; std::mutex mLock; std::optional<nsecs_t> mConfigurationChangedTime; std::unique_ptr<InputEvent> mFilteredEvent GUARDED_BY(mLock); sp<IBinder> mOnPointerDownToken; std::optional<nsecs_t> mConfigurationChangedTime GUARDED_BY(mLock); std::optional<NotifySwitchArgs> mLastNotifySwitch; sp<IBinder> mOnPointerDownToken GUARDED_BY(mLock); std::optional<NotifySwitchArgs> mLastNotifySwitch GUARDED_BY(mLock); virtual void notifyConfigurationChanged(nsecs_t when) override { virtual void notifyConfigurationChanged(nsecs_t when) override { std::scoped_lock lock(mLock); mConfigurationChangedTime = when; mConfigurationChangedTime = when; } } Loading @@ -141,6 +150,7 @@ private: } } virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { std::scoped_lock lock(mLock); switch (inputEvent->getType()) { switch (inputEvent->getType()) { case AINPUT_EVENT_TYPE_KEY: { case AINPUT_EVENT_TYPE_KEY: { const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent); const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent); Loading Loading @@ -173,6 +183,7 @@ private: virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) override { uint32_t policyFlags) override { std::scoped_lock lock(mLock); /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is * essentially a passthrough for notifySwitch. * essentially a passthrough for notifySwitch. */ */ Loading @@ -186,11 +197,13 @@ private: } } virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override { virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override { std::scoped_lock lock(mLock); mOnPointerDownToken = newToken; mOnPointerDownToken = newToken; } } void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action, void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action, int32_t displayId) { int32_t displayId) { std::scoped_lock lock(mLock); ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called."; ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called."; ASSERT_EQ(mFilteredEvent->getType(), type); ASSERT_EQ(mFilteredEvent->getType(), type); Loading Loading @@ -485,7 +498,7 @@ TEST_F(InputDispatcherTest, NotifySwitch_CallsPolicy) { // --- InputDispatcherTest SetInputWindowTest --- // --- InputDispatcherTest SetInputWindowTest --- static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; static constexpr std::chrono::duration DISPATCHING_TIMEOUT = 5s; static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s; class FakeApplicationHandle : public InputApplicationHandle { class FakeApplicationHandle : public InputApplicationHandle { public: public: Loading Loading
services/inputflinger/dispatcher/Entry.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,8 @@ static std::string motionActionToString(int32_t action) { return "MOVE"; return "MOVE"; case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_UP: return "UP"; return "UP"; case AMOTION_EVENT_ACTION_CANCEL: return "CANCEL"; case AMOTION_EVENT_ACTION_POINTER_DOWN: case AMOTION_EVENT_ACTION_POINTER_DOWN: return "POINTER_DOWN"; return "POINTER_DOWN"; case AMOTION_EVENT_ACTION_POINTER_UP: case AMOTION_EVENT_ACTION_POINTER_UP: Loading @@ -57,6 +59,7 @@ static std::string keyActionToString(int32_t action) { } } return StringPrintf("%" PRId32, action); return StringPrintf("%" PRId32, action); } } VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry) { VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry) { return {{VerifiedInputEvent::Type::KEY, entry.deviceId, entry.eventTime, entry.source, return {{VerifiedInputEvent::Type::KEY, entry.deviceId, entry.eventTime, entry.source, entry.displayId}, entry.displayId}, Loading
services/inputflinger/include/InputListener.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <input/Input.h> #include <input/Input.h> #include <input/TouchVideoFrame.h> #include <input/TouchVideoFrame.h> #include <utils/RefBase.h> #include <utils/RefBase.h> #include <utils/Vector.h> namespace android { namespace android { Loading
services/inputflinger/tests/InputDispatcher_test.cpp +19 −6 Original line number Original line Diff line number Diff line Loading @@ -83,9 +83,13 @@ public: args.displayId); args.displayId); } } void assertFilterInputEventWasNotCalled() { ASSERT_EQ(nullptr, mFilteredEvent); } void assertFilterInputEventWasNotCalled() { std::scoped_lock lock(mLock); ASSERT_EQ(nullptr, mFilteredEvent); } void assertNotifyConfigurationChangedWasCalled(nsecs_t when) { void assertNotifyConfigurationChangedWasCalled(nsecs_t when) { std::scoped_lock lock(mLock); ASSERT_TRUE(mConfigurationChangedTime) ASSERT_TRUE(mConfigurationChangedTime) << "Timed out waiting for configuration changed call"; << "Timed out waiting for configuration changed call"; ASSERT_EQ(*mConfigurationChangedTime, when); ASSERT_EQ(*mConfigurationChangedTime, when); Loading @@ -93,6 +97,7 @@ public: } } void assertNotifySwitchWasCalled(const NotifySwitchArgs& args) { void assertNotifySwitchWasCalled(const NotifySwitchArgs& args) { std::scoped_lock lock(mLock); ASSERT_TRUE(mLastNotifySwitch); ASSERT_TRUE(mLastNotifySwitch); // We do not check id because it is not exposed to the policy // We do not check id because it is not exposed to the policy EXPECT_EQ(args.eventTime, mLastNotifySwitch->eventTime); EXPECT_EQ(args.eventTime, mLastNotifySwitch->eventTime); Loading @@ -103,11 +108,13 @@ public: } } void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) { void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) { std::scoped_lock lock(mLock); ASSERT_EQ(touchedToken, mOnPointerDownToken); ASSERT_EQ(touchedToken, mOnPointerDownToken); mOnPointerDownToken.clear(); mOnPointerDownToken.clear(); } } void assertOnPointerDownWasNotCalled() { void assertOnPointerDownWasNotCalled() { std::scoped_lock lock(mLock); ASSERT_TRUE(mOnPointerDownToken == nullptr) ASSERT_TRUE(mOnPointerDownToken == nullptr) << "Expected onPointerDownOutsideFocus to not have been called"; << "Expected onPointerDownOutsideFocus to not have been called"; } } Loading @@ -118,12 +125,14 @@ public: } } private: private: std::unique_ptr<InputEvent> mFilteredEvent; std::mutex mLock; std::optional<nsecs_t> mConfigurationChangedTime; std::unique_ptr<InputEvent> mFilteredEvent GUARDED_BY(mLock); sp<IBinder> mOnPointerDownToken; std::optional<nsecs_t> mConfigurationChangedTime GUARDED_BY(mLock); std::optional<NotifySwitchArgs> mLastNotifySwitch; sp<IBinder> mOnPointerDownToken GUARDED_BY(mLock); std::optional<NotifySwitchArgs> mLastNotifySwitch GUARDED_BY(mLock); virtual void notifyConfigurationChanged(nsecs_t when) override { virtual void notifyConfigurationChanged(nsecs_t when) override { std::scoped_lock lock(mLock); mConfigurationChangedTime = when; mConfigurationChangedTime = when; } } Loading @@ -141,6 +150,7 @@ private: } } virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { std::scoped_lock lock(mLock); switch (inputEvent->getType()) { switch (inputEvent->getType()) { case AINPUT_EVENT_TYPE_KEY: { case AINPUT_EVENT_TYPE_KEY: { const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent); const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent); Loading Loading @@ -173,6 +183,7 @@ private: virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) override { uint32_t policyFlags) override { std::scoped_lock lock(mLock); /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is * essentially a passthrough for notifySwitch. * essentially a passthrough for notifySwitch. */ */ Loading @@ -186,11 +197,13 @@ private: } } virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override { virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override { std::scoped_lock lock(mLock); mOnPointerDownToken = newToken; mOnPointerDownToken = newToken; } } void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action, void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action, int32_t displayId) { int32_t displayId) { std::scoped_lock lock(mLock); ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called."; ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called."; ASSERT_EQ(mFilteredEvent->getType(), type); ASSERT_EQ(mFilteredEvent->getType(), type); Loading Loading @@ -485,7 +498,7 @@ TEST_F(InputDispatcherTest, NotifySwitch_CallsPolicy) { // --- InputDispatcherTest SetInputWindowTest --- // --- InputDispatcherTest SetInputWindowTest --- static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 500ms; static constexpr std::chrono::duration DISPATCHING_TIMEOUT = 5s; static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s; class FakeApplicationHandle : public InputApplicationHandle { class FakeApplicationHandle : public InputApplicationHandle { public: public: Loading