Loading include/input/InputConsumerNoResampling.h +1 −12 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <input/Input.h> #include <input/InputTransport.h> #include <input/LooperInterface.h> #include <input/Resampler.h> #include <utils/Looper.h> Loading Loading @@ -71,16 +70,6 @@ public: */ class InputConsumerNoResampling final { public: /** * This constructor is exclusively for test code. Any real use of InputConsumerNoResampling must * use the constructor that takes an sp<Looper> parameter instead of * std::shared_ptr<LooperInterface>. */ explicit InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, std::shared_ptr<LooperInterface> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler); /** * @param callbacks are used to interact with InputConsumerNoResampling. They're called whenever * the event is ready to consume. Loading Loading @@ -126,7 +115,7 @@ public: private: std::shared_ptr<InputChannel> mChannel; std::shared_ptr<LooperInterface> mLooper; sp<Looper> mLooper; InputConsumerCallbacks& mCallbacks; std::unique_ptr<Resampler> mResampler; Loading include/input/LooperInterface.hdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line /** * Copyright 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/Looper.h> #include <utils/StrongPointer.h> namespace android { /** * LooperInterface allows the use of TestLooper in InputConsumerNoResampling without reassigning to * Looper. LooperInterface is needed to control how InputConsumerNoResampling consumes and batches * InputMessages. */ class LooperInterface { public: virtual ~LooperInterface() = default; virtual int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) = 0; virtual int removeFd(int fd) = 0; virtual sp<Looper> getLooper() const = 0; }; } // namespace android libs/input/InputConsumerNoResampling.cpp +3 −31 Original line number Diff line number Diff line Loading @@ -46,27 +46,6 @@ using std::chrono::nanoseconds; const bool DEBUG_TRANSPORT_CONSUMER = __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); /** * RealLooper is a wrapper of Looper. All the member functions exclusively call the internal looper. * This class' behavior is the same as Looper. */ class RealLooper final : public LooperInterface { public: RealLooper(sp<Looper> looper) : mLooper{looper} {} int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) override { return mLooper->addFd(fd, ident, events, callback, data); } int removeFd(int fd) override { return mLooper->removeFd(fd); } sp<Looper> getLooper() const override { return mLooper; } private: sp<Looper> mLooper; }; std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) { std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, Loading Loading @@ -201,12 +180,12 @@ using android::base::Result; // --- InputConsumerNoResampling --- InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, std::shared_ptr<LooperInterface> looper, sp<Looper> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler) : mChannel{channel}, mLooper{looper}, mCallbacks(callbacks), mCallbacks{callbacks}, mResampler{std::move(resampler)}, mFdEvents(0) { LOG_ALWAYS_FATAL_IF(mLooper == nullptr); Loading @@ -218,13 +197,6 @@ InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<Input setFdEvents(ALOOPER_EVENT_INPUT); } InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, sp<Looper> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler) : InputConsumerNoResampling(channel, std::make_shared<RealLooper>(looper), callbacks, std::move(resampler)) {} InputConsumerNoResampling::~InputConsumerNoResampling() { ensureCalledOnLooperThread(__func__); consumeBatchedInputEvents(/*requestedFrameTime=*/std::nullopt); Loading Loading @@ -556,7 +528,7 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( void InputConsumerNoResampling::ensureCalledOnLooperThread(const char* func) const { sp<Looper> callingThreadLooper = Looper::getForThread(); if (callingThreadLooper != mLooper->getLooper()) { if (callingThreadLooper != mLooper) { LOG(FATAL) << "The function " << func << " can only be called on the looper thread"; } } Loading libs/input/tests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ cc_test { "Resampler_test.cpp", "RingBuffer_test.cpp", "TestInputChannel.cpp", "TestLooper.cpp", "TfLiteMotionPredictor_test.cpp", "TouchResampling_test.cpp", "TouchVideoFrame_test.cpp", Loading libs/input/tests/InputConsumer_test.cpp +17 −11 Original line number Diff line number Diff line Loading @@ -18,16 +18,15 @@ #include <memory> #include <optional> #include <utility> #include <TestEventMatchers.h> #include <TestInputChannel.h> #include <TestLooper.h> #include <android-base/logging.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <input/BlockingQueue.h> #include <input/InputEventBuilders.h> #include <utils/Looper.h> #include <utils/StrongPointer.h> namespace android { Loading @@ -46,13 +45,20 @@ class InputConsumerTest : public testing::Test, public InputConsumerCallbacks { protected: InputConsumerTest() : mClientTestChannel{std::make_shared<TestInputChannel>("TestChannel")}, mTestLooper{std::make_shared<TestLooper>()} { Looper::setForThread(mTestLooper->getLooper()); mLooper{sp<Looper>::make(/*allowNonCallbacks=*/false)} { Looper::setForThread(mLooper); mConsumer = std::make_unique<InputConsumerNoResampling>(mClientTestChannel, mTestLooper, *this, std::make_unique<InputConsumerNoResampling>(mClientTestChannel, mLooper, *this, std::make_unique<LegacyResampler>()); } void invokeLooperCallback() const { sp<LooperCallback> callback; ASSERT_TRUE(mLooper->getFdStateDebug(mClientTestChannel->getFd(), /*ident=*/nullptr, /*events=*/nullptr, &callback, /*data=*/nullptr)); callback->handleEvent(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT, /*data=*/nullptr); } void assertOnBatchedInputEventPendingWasCalled() { ASSERT_GT(mOnBatchedInputEventPendingInvocationCount, 0UL) << "onBatchedInputEventPending has not been called."; Loading @@ -66,7 +72,7 @@ protected: } std::shared_ptr<TestInputChannel> mClientTestChannel; std::shared_ptr<TestLooper> mTestLooper; sp<Looper> mLooper; std::unique_ptr<InputConsumerNoResampling> mConsumer; BlockingQueue<std::unique_ptr<KeyEvent>> mKeyEvents; Loading Loading @@ -128,7 +134,7 @@ TEST_F(InputConsumerTest, MessageStreamBatchedInMotionEvent) { mClientTestChannel->assertNoSentMessages(); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertOnBatchedInputEventPendingWasCalled(); Loading Loading @@ -166,7 +172,7 @@ TEST_F(InputConsumerTest, LastBatchedSampleIsLessThanResampleTime) { mClientTestChannel->assertNoSentMessages(); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertOnBatchedInputEventPendingWasCalled(); Loading Loading @@ -199,7 +205,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_DOWN) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_DOWN))); mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/1} Loading @@ -220,7 +226,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_DOWN) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(1), WithMotionAction(AMOTION_EVENT_ACTION_DOWN))); mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/5} Loading @@ -228,7 +234,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_UP) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_MOVE), Not(MotionEventIsResampled()))); Loading Loading
include/input/InputConsumerNoResampling.h +1 −12 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <input/Input.h> #include <input/InputTransport.h> #include <input/LooperInterface.h> #include <input/Resampler.h> #include <utils/Looper.h> Loading Loading @@ -71,16 +70,6 @@ public: */ class InputConsumerNoResampling final { public: /** * This constructor is exclusively for test code. Any real use of InputConsumerNoResampling must * use the constructor that takes an sp<Looper> parameter instead of * std::shared_ptr<LooperInterface>. */ explicit InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, std::shared_ptr<LooperInterface> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler); /** * @param callbacks are used to interact with InputConsumerNoResampling. They're called whenever * the event is ready to consume. Loading Loading @@ -126,7 +115,7 @@ public: private: std::shared_ptr<InputChannel> mChannel; std::shared_ptr<LooperInterface> mLooper; sp<Looper> mLooper; InputConsumerCallbacks& mCallbacks; std::unique_ptr<Resampler> mResampler; Loading
include/input/LooperInterface.hdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line /** * Copyright 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <utils/Looper.h> #include <utils/StrongPointer.h> namespace android { /** * LooperInterface allows the use of TestLooper in InputConsumerNoResampling without reassigning to * Looper. LooperInterface is needed to control how InputConsumerNoResampling consumes and batches * InputMessages. */ class LooperInterface { public: virtual ~LooperInterface() = default; virtual int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) = 0; virtual int removeFd(int fd) = 0; virtual sp<Looper> getLooper() const = 0; }; } // namespace android
libs/input/InputConsumerNoResampling.cpp +3 −31 Original line number Diff line number Diff line Loading @@ -46,27 +46,6 @@ using std::chrono::nanoseconds; const bool DEBUG_TRANSPORT_CONSUMER = __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); /** * RealLooper is a wrapper of Looper. All the member functions exclusively call the internal looper. * This class' behavior is the same as Looper. */ class RealLooper final : public LooperInterface { public: RealLooper(sp<Looper> looper) : mLooper{looper} {} int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) override { return mLooper->addFd(fd, ident, events, callback, data); } int removeFd(int fd) override { return mLooper->removeFd(fd); } sp<Looper> getLooper() const override { return mLooper; } private: sp<Looper> mLooper; }; std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) { std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, Loading Loading @@ -201,12 +180,12 @@ using android::base::Result; // --- InputConsumerNoResampling --- InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, std::shared_ptr<LooperInterface> looper, sp<Looper> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler) : mChannel{channel}, mLooper{looper}, mCallbacks(callbacks), mCallbacks{callbacks}, mResampler{std::move(resampler)}, mFdEvents(0) { LOG_ALWAYS_FATAL_IF(mLooper == nullptr); Loading @@ -218,13 +197,6 @@ InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<Input setFdEvents(ALOOPER_EVENT_INPUT); } InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel, sp<Looper> looper, InputConsumerCallbacks& callbacks, std::unique_ptr<Resampler> resampler) : InputConsumerNoResampling(channel, std::make_shared<RealLooper>(looper), callbacks, std::move(resampler)) {} InputConsumerNoResampling::~InputConsumerNoResampling() { ensureCalledOnLooperThread(__func__); consumeBatchedInputEvents(/*requestedFrameTime=*/std::nullopt); Loading Loading @@ -556,7 +528,7 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( void InputConsumerNoResampling::ensureCalledOnLooperThread(const char* func) const { sp<Looper> callingThreadLooper = Looper::getForThread(); if (callingThreadLooper != mLooper->getLooper()) { if (callingThreadLooper != mLooper) { LOG(FATAL) << "The function " << func << " can only be called on the looper thread"; } } Loading
libs/input/tests/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ cc_test { "Resampler_test.cpp", "RingBuffer_test.cpp", "TestInputChannel.cpp", "TestLooper.cpp", "TfLiteMotionPredictor_test.cpp", "TouchResampling_test.cpp", "TouchVideoFrame_test.cpp", Loading
libs/input/tests/InputConsumer_test.cpp +17 −11 Original line number Diff line number Diff line Loading @@ -18,16 +18,15 @@ #include <memory> #include <optional> #include <utility> #include <TestEventMatchers.h> #include <TestInputChannel.h> #include <TestLooper.h> #include <android-base/logging.h> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <input/BlockingQueue.h> #include <input/InputEventBuilders.h> #include <utils/Looper.h> #include <utils/StrongPointer.h> namespace android { Loading @@ -46,13 +45,20 @@ class InputConsumerTest : public testing::Test, public InputConsumerCallbacks { protected: InputConsumerTest() : mClientTestChannel{std::make_shared<TestInputChannel>("TestChannel")}, mTestLooper{std::make_shared<TestLooper>()} { Looper::setForThread(mTestLooper->getLooper()); mLooper{sp<Looper>::make(/*allowNonCallbacks=*/false)} { Looper::setForThread(mLooper); mConsumer = std::make_unique<InputConsumerNoResampling>(mClientTestChannel, mTestLooper, *this, std::make_unique<InputConsumerNoResampling>(mClientTestChannel, mLooper, *this, std::make_unique<LegacyResampler>()); } void invokeLooperCallback() const { sp<LooperCallback> callback; ASSERT_TRUE(mLooper->getFdStateDebug(mClientTestChannel->getFd(), /*ident=*/nullptr, /*events=*/nullptr, &callback, /*data=*/nullptr)); callback->handleEvent(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT, /*data=*/nullptr); } void assertOnBatchedInputEventPendingWasCalled() { ASSERT_GT(mOnBatchedInputEventPendingInvocationCount, 0UL) << "onBatchedInputEventPending has not been called."; Loading @@ -66,7 +72,7 @@ protected: } std::shared_ptr<TestInputChannel> mClientTestChannel; std::shared_ptr<TestLooper> mTestLooper; sp<Looper> mLooper; std::unique_ptr<InputConsumerNoResampling> mConsumer; BlockingQueue<std::unique_ptr<KeyEvent>> mKeyEvents; Loading Loading @@ -128,7 +134,7 @@ TEST_F(InputConsumerTest, MessageStreamBatchedInMotionEvent) { mClientTestChannel->assertNoSentMessages(); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertOnBatchedInputEventPendingWasCalled(); Loading Loading @@ -166,7 +172,7 @@ TEST_F(InputConsumerTest, LastBatchedSampleIsLessThanResampleTime) { mClientTestChannel->assertNoSentMessages(); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertOnBatchedInputEventPendingWasCalled(); Loading Loading @@ -199,7 +205,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_DOWN) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_DOWN))); mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/1} Loading @@ -220,7 +226,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_DOWN) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(1), WithMotionAction(AMOTION_EVENT_ACTION_DOWN))); mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/5} Loading @@ -228,7 +234,7 @@ TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) { .action(AMOTION_EVENT_ACTION_UP) .build()); mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT); invokeLooperCallback(); assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_MOVE), Not(MotionEventIsResampled()))); Loading