Loading services/inputflinger/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ cc_defaults { filegroup { name: "libinputflinger_sources", srcs: [ "InputClassifier.cpp", "InputProcessor.cpp", "InputCommonConverter.cpp", "PreferStylusOverTouchBlocker.cpp", "UnwantedInteractionBlocker.cpp", Loading services/inputflinger/InputManager.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -55,14 +55,14 @@ static int32_t exceptionCodeFromStatusT(status_t status) { /** * The event flow is via the "InputListener" interface, as follows: * InputReader -> UnwantedInteractionBlocker -> InputClassifier -> InputDispatcher * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher */ InputManager::InputManager( const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { mDispatcher = createInputDispatcher(dispatcherPolicy); mClassifier = std::make_unique<InputClassifier>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mClassifier); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); mReader = createInputReader(readerPolicy, *mBlocker); } Loading Loading @@ -110,12 +110,12 @@ InputReaderInterface& InputManager::getReader() { return *mReader; } UnwantedInteractionBlockerInterface& InputManager::getUnwantedInteractionBlocker() { UnwantedInteractionBlockerInterface& InputManager::getBlocker() { return *mBlocker; } InputClassifierInterface& InputManager::getClassifier() { return *mClassifier; InputProcessorInterface& InputManager::getProcessor() { return *mProcessor; } InputDispatcherInterface& InputManager::getDispatcher() { Loading @@ -125,7 +125,7 @@ InputDispatcherInterface& InputManager::getDispatcher() { void InputManager::monitor() { mReader->monitor(); mBlocker->monitor(); mClassifier->monitor(); mProcessor->monitor(); mDispatcher->monitor(); } Loading services/inputflinger/InputManager.h +12 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ * Native input manager. */ #include "InputClassifier.h" #include "InputProcessor.h" #include "InputReaderBase.h" #include "include/UnwantedInteractionBlockerInterface.h" Loading Loading @@ -52,10 +52,11 @@ class InputDispatcherThread; * this could be a palm on the screen. This stage would alter the event stream to remove either * partially (some of the pointers) or fully (all touches) the unwanted interaction. The events * are processed on the InputReader thread, without any additional queue. The events are then * posted to the queue managed by the InputClassifier. * 3. The InputClassifier class starts a thread to communicate with the device-specific * classifiers. It then waits on the queue of events from UnwantedInteractionBlocker, applies * a classification to them, and queues them for the InputDispatcher. * posted to the queue managed by the InputProcessor. * 3. The InputProcessor class starts a thread to communicate with the device-specific * IInputProcessor HAL. It then waits on the queue of events from UnwantedInteractionBlocker, * processes the events (for example, applies a classification to the events), and queues them * for the InputDispatcher. * 4. The InputDispatcher class starts a thread that waits for new events on the * previous queue and asynchronously dispatches them to applications. * Loading Loading @@ -83,10 +84,10 @@ public: virtual InputReaderInterface& getReader() = 0; /* Gets the unwanted interaction blocker. */ virtual UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() = 0; virtual UnwantedInteractionBlockerInterface& getBlocker() = 0; /* Gets the input classifier */ virtual InputClassifierInterface& getClassifier() = 0; /* Gets the input processor */ virtual InputProcessorInterface& getProcessor() = 0; /* Gets the input dispatcher. */ virtual InputDispatcherInterface& getDispatcher() = 0; Loading @@ -108,8 +109,8 @@ public: status_t stop() override; InputReaderInterface& getReader() override; UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() override; InputClassifierInterface& getClassifier() override; UnwantedInteractionBlockerInterface& getBlocker() override; InputProcessorInterface& getProcessor() override; InputDispatcherInterface& getDispatcher() override; void monitor() override; Loading @@ -123,7 +124,7 @@ private: std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker; std::unique_ptr<InputClassifierInterface> mClassifier; std::unique_ptr<InputProcessorInterface> mProcessor; std::unique_ptr<InputDispatcherInterface> mDispatcher; }; Loading services/inputflinger/InputClassifier.cpp→services/inputflinger/InputProcessor.cpp +49 −51 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ * limitations under the License. */ #define LOG_TAG "InputClassifier" #define LOG_TAG "InputProcessor" #include "InputClassifier.h" #include "InputProcessor.h" #include "InputCommonConverter.h" #include <android-base/stringprintf.h> Loading Loading @@ -123,15 +123,15 @@ ScopedDeathRecipient::~ScopedDeathRecipient() { // --- ClassifierEvent --- ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : type(ClassifierEventType::MOTION), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyDeviceResetArgs> args) : type(ClassifierEventType::DEVICE_RESET), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(ClassifierEventType type, std::unique_ptr<NotifyArgs> args) : type(type), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : type(ClassifierEventType::MOTION), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyDeviceResetArgs> args) : type(ClassifierEventType::DEVICE_RESET), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(ClassifierEventType type, std::unique_ptr<NotifyArgs> args) : type(type), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(ClassifierEvent&& other) : type(other.type), args(std::move(other.args)) { }; ClassifierEvent::ClassifierEvent(ClassifierEvent&& other) : type(other.type), args(std::move(other.args)){}; ClassifierEvent& ClassifierEvent::operator=(ClassifierEvent&& other) { type = other.type; Loading Loading @@ -180,7 +180,7 @@ MotionClassifier::MotionClassifier(std::shared_ptr<IInputProcessor> service) mHalThread = std::thread(&MotionClassifier::processEvents, this); #if defined(__linux__) // Set the thread name for debugging pthread_setname_np(mHalThread.native_handle(), "InputClassifier"); pthread_setname_np(mHalThread.native_handle(), "InputProcessor"); #endif } Loading @@ -198,7 +198,7 @@ MotionClassifier::~MotionClassifier() { /** * Obtain the classification from the HAL for a given MotionEvent. * Should only be called from the InputClassifier thread (mHalThread). * Should only be called from the InputProcessor thread (mHalThread). * Should not be called from the thread that notifyMotion runs on. * * There is no way to provide a timeout for a HAL call. So if the HAL takes too long Loading Loading @@ -239,7 +239,7 @@ void MotionClassifier::processEvents() { } } if (!halResponseOk) { ALOGE("Error communicating with InputClassifier HAL. " ALOGE("Error communicating with InputProcessor HAL. " "Exiting MotionClassifier HAL thread"); clearClassifications(); return; Loading Loading @@ -319,7 +319,7 @@ void MotionClassifier::reset() { /** * Per-device reset. Clear the outstanding events that are going to be sent to HAL. * Request InputClassifier thread to call resetDevice for this particular device. * Request InputProcessor thread to call resetDevice for this particular device. */ void MotionClassifier::reset(const NotifyDeviceResetArgs& args) { int32_t deviceId = args.deviceId; Loading @@ -334,8 +334,7 @@ void MotionClassifier::reset(const NotifyDeviceResetArgs& args) { void MotionClassifier::dump(std::string& dump) { std::scoped_lock lock(mLock); dump += StringPrintf(INDENT2 "mService connected: %s\n", mService ? "true" : "false"); dump += StringPrintf(INDENT2 "mEvents: %zu element(s) (max=%zu)\n", mEvents.size(), MAX_EVENTS); dump += StringPrintf(INDENT2 "mEvents: %zu element(s) (max=%zu)\n", mEvents.size(), MAX_EVENTS); dump += INDENT2 "mClassifications, mLastDownTimes:\n"; dump += INDENT3 "Device Id\tClassification\tLast down time"; // Combine mClassifications and mLastDownTimes into a single table. Loading @@ -349,8 +348,8 @@ void MotionClassifier::dump(std::string& dump) { const MotionClassification classification = getValueForKey(mClassifications, deviceId, MotionClassification::NONE); const nsecs_t downTime = getValueForKey(mLastDownTimes, deviceId, static_cast<nsecs_t>(0)); dump += StringPrintf("\n" INDENT4 "%" PRId32 "\t%s\t%" PRId64, deviceId, motionClassificationToString(classification), downTime); dump += StringPrintf("\n" INDENT4 "%" PRId32 "\t%s\t%" PRId64, deviceId, motionClassificationToString(classification), downTime); } } Loading @@ -366,20 +365,20 @@ void MotionClassifier::monitor() { } } // --- InputClassifier --- // --- InputProcessor --- InputClassifier::InputClassifier(InputListenerInterface& listener) : mQueuedListener(listener) {} InputProcessor::InputProcessor(InputListenerInterface& listener) : mQueuedListener(listener) {} void InputClassifier::onBinderDied(void* cookie) { InputClassifier* classifier = static_cast<InputClassifier*>(cookie); if (classifier == nullptr) { void InputProcessor::onBinderDied(void* cookie) { InputProcessor* processor = static_cast<InputProcessor*>(cookie); if (processor == nullptr) { LOG_ALWAYS_FATAL("Cookie is not valid"); return; } classifier->setMotionClassifierEnabled(false); processor->setMotionClassifierEnabled(false); } void InputClassifier::setMotionClassifierEnabled(bool enabled) { void InputProcessor::setMotionClassifierEnabled(bool enabled) { std::scoped_lock lock(mLock); if (enabled) { ALOGI("Enabling motion classifier"); Loading @@ -392,7 +391,7 @@ void InputClassifier::setMotionClassifierEnabled(bool enabled) { * and we can't continue because 'mInitializeMotionClassifier' will block in its * destructor. */ LOG_ALWAYS_FATAL("The thread to load IInputClassifier is stuck!"); LOG_ALWAYS_FATAL("The thread to load IInputProcessor is stuck!"); } } mInitializeMotionClassifier = std::async(std::launch::async, [this] { Loading @@ -416,19 +415,19 @@ void InputClassifier::setMotionClassifierEnabled(bool enabled) { } } void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { void InputProcessor::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { // pass through mQueuedListener.notifyConfigurationChanged(args); mQueuedListener.flush(); } void InputClassifier::notifyKey(const NotifyKeyArgs* args) { void InputProcessor::notifyKey(const NotifyKeyArgs* args) { // pass through mQueuedListener.notifyKey(args); mQueuedListener.flush(); } void InputClassifier::notifyMotion(const NotifyMotionArgs* args) { void InputProcessor::notifyMotion(const NotifyMotionArgs* args) { { // acquire lock std::scoped_lock lock(mLock); // MotionClassifier is only used for touch events, for now Loading @@ -444,25 +443,25 @@ void InputClassifier::notifyMotion(const NotifyMotionArgs* args) { mQueuedListener.flush(); } void InputClassifier::notifySensor(const NotifySensorArgs* args) { void InputProcessor::notifySensor(const NotifySensorArgs* args) { // pass through mQueuedListener.notifySensor(args); mQueuedListener.flush(); } void InputClassifier::notifyVibratorState(const NotifyVibratorStateArgs* args) { void InputProcessor::notifyVibratorState(const NotifyVibratorStateArgs* args) { // pass through mQueuedListener.notifyVibratorState(args); mQueuedListener.flush(); } void InputClassifier::notifySwitch(const NotifySwitchArgs* args) { void InputProcessor::notifySwitch(const NotifySwitchArgs* args) { // pass through mQueuedListener.notifySwitch(args); mQueuedListener.flush(); } void InputClassifier::notifyDeviceReset(const NotifyDeviceResetArgs* args) { void InputProcessor::notifyDeviceReset(const NotifyDeviceResetArgs* args) { { // acquire lock std::scoped_lock lock(mLock); if (mMotionClassifier) { Loading @@ -475,13 +474,13 @@ void InputClassifier::notifyDeviceReset(const NotifyDeviceResetArgs* args) { mQueuedListener.flush(); } void InputClassifier::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) { void InputProcessor::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) { // pass through mQueuedListener.notifyPointerCaptureChanged(args); mQueuedListener.flush(); } void InputClassifier::setMotionClassifierLocked( void InputProcessor::setMotionClassifierLocked( std::unique_ptr<MotionClassifierInterface> motionClassifier) REQUIRES(mLock) { if (motionClassifier == nullptr) { // Destroy the ScopedDeathRecipient object, which will cause it to unlinkToDeath. Loading @@ -491,9 +490,9 @@ void InputClassifier::setMotionClassifierLocked( mMotionClassifier = std::move(motionClassifier); } void InputClassifier::dump(std::string& dump) { void InputProcessor::dump(std::string& dump) { std::scoped_lock lock(mLock); dump += "Input Classifier State:\n"; dump += "Input Processor State:\n"; dump += INDENT1 "Motion Classifier:\n"; if (mMotionClassifier) { mMotionClassifier->dump(dump); Loading @@ -503,12 +502,11 @@ void InputClassifier::dump(std::string& dump) { dump += "\n"; } void InputClassifier::monitor() { void InputProcessor::monitor() { std::scoped_lock lock(mLock); if (mMotionClassifier) mMotionClassifier->monitor(); } InputClassifier::~InputClassifier() { } InputProcessor::~InputProcessor() {} } // namespace android services/inputflinger/InputClassifier.h→services/inputflinger/InputProcessor.h +20 −20 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ public: * Base interface for an InputListener stage. * Provides classification to events. */ class InputClassifierInterface : public InputListenerInterface { class InputProcessorInterface : public InputListenerInterface { public: virtual void setMotionClassifierEnabled(bool enabled) = 0; /** Loading @@ -104,8 +104,8 @@ public: /** Called by the heartbeat to ensure that the classifier has not deadlocked. */ virtual void monitor() = 0; InputClassifierInterface() { } virtual ~InputClassifierInterface() { } InputProcessorInterface() {} virtual ~InputProcessorInterface() {} }; // --- Implementations --- Loading @@ -124,10 +124,10 @@ private: }; /** * Implementation of MotionClassifierInterface that calls the InputClassifier HAL * Implementation of MotionClassifierInterface that calls the InputProcessor HAL * in order to determine the classification for the current gesture. * * The InputClassifier HAL may keep track of the entire gesture in order to determine * The InputProcessor HAL may keep track of the entire gesture in order to determine * the classification, and may be hardware-specific. It may use the data in * NotifyMotionArgs::videoFrames field to drive the classification decisions. * The HAL is called from a separate thread. Loading Loading @@ -174,20 +174,20 @@ private: */ void enqueueEvent(ClassifierEvent&& event); /** * Thread that will communicate with InputClassifier HAL. * This should be the only thread that communicates with InputClassifier HAL, * Thread that will communicate with InputProcessor HAL. * This should be the only thread that communicates with InputProcessor HAL, * because this thread is allowed to block on the HAL calls. */ std::thread mHalThread; /** * Process events and call the InputClassifier HAL * Process events and call the InputProcessor HAL */ void processEvents(); /** * Access to the InputProcessor HAL. May be null if init() hasn't completed yet. * When init() successfully completes, mService is guaranteed to remain non-null and to not * change its value until MotionClassifier is destroyed. * This variable is *not* guarded by mLock in the InputClassifier thread, because * This variable is *not* guarded by mLock in the InputProcessor thread, because * that thread knows exactly when this variable is initialized. * When accessed in any other thread, mService is checked for nullness with a lock. */ Loading @@ -197,8 +197,8 @@ private: * Per-device input classifications. Should only be accessed using the * getClassification / setClassification methods. */ std::unordered_map<int32_t /*deviceId*/, MotionClassification> mClassifications GUARDED_BY(mLock); std::unordered_map<int32_t /*deviceId*/, MotionClassification> mClassifications GUARDED_BY(mLock); /** * Set the current classification for a given device. */ Loading @@ -217,7 +217,7 @@ private: * Per-device times when the last ACTION_DOWN was received. * Used to reject late classifications that do not belong to the current gesture. * * Accessed indirectly by both InputClassifier thread and the thread that receives notifyMotion. * Accessed indirectly by both InputProcessor thread and the thread that receives notifyMotion. */ std::unordered_map<int32_t /*deviceId*/, nsecs_t /*downTime*/> mLastDownTimes GUARDED_BY(mLock); Loading @@ -226,7 +226,7 @@ private: void clearDeviceState(int32_t deviceId); /** * Exit the InputClassifier HAL thread. * Exit the InputProcessor HAL thread. * Useful for tests to ensure proper cleanup. */ void requestExit(); Loading @@ -237,14 +237,14 @@ private: }; /** * Implementation of the InputClassifierInterface. * Implementation of the InputProcessorInterface. * Represents a separate stage of input processing. All of the input events go through this stage. * Acts as a passthrough for all input events except for motion events. * The events of motion type are sent to MotionClassifier. */ class InputClassifier : public InputClassifierInterface { class InputProcessor : public InputProcessorInterface { public: explicit InputClassifier(InputListenerInterface& listener); explicit InputProcessor(InputListenerInterface& listener); void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override; void notifyKey(const NotifyKeyArgs* args) override; Loading @@ -258,7 +258,7 @@ public: void dump(std::string& dump) override; void monitor() override; ~InputClassifier(); ~InputProcessor(); // Called from InputManager void setMotionClassifierEnabled(bool enabled) override; Loading Loading
services/inputflinger/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ cc_defaults { filegroup { name: "libinputflinger_sources", srcs: [ "InputClassifier.cpp", "InputProcessor.cpp", "InputCommonConverter.cpp", "PreferStylusOverTouchBlocker.cpp", "UnwantedInteractionBlocker.cpp", Loading
services/inputflinger/InputManager.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -55,14 +55,14 @@ static int32_t exceptionCodeFromStatusT(status_t status) { /** * The event flow is via the "InputListener" interface, as follows: * InputReader -> UnwantedInteractionBlocker -> InputClassifier -> InputDispatcher * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher */ InputManager::InputManager( const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { mDispatcher = createInputDispatcher(dispatcherPolicy); mClassifier = std::make_unique<InputClassifier>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mClassifier); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); mReader = createInputReader(readerPolicy, *mBlocker); } Loading Loading @@ -110,12 +110,12 @@ InputReaderInterface& InputManager::getReader() { return *mReader; } UnwantedInteractionBlockerInterface& InputManager::getUnwantedInteractionBlocker() { UnwantedInteractionBlockerInterface& InputManager::getBlocker() { return *mBlocker; } InputClassifierInterface& InputManager::getClassifier() { return *mClassifier; InputProcessorInterface& InputManager::getProcessor() { return *mProcessor; } InputDispatcherInterface& InputManager::getDispatcher() { Loading @@ -125,7 +125,7 @@ InputDispatcherInterface& InputManager::getDispatcher() { void InputManager::monitor() { mReader->monitor(); mBlocker->monitor(); mClassifier->monitor(); mProcessor->monitor(); mDispatcher->monitor(); } Loading
services/inputflinger/InputManager.h +12 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ * Native input manager. */ #include "InputClassifier.h" #include "InputProcessor.h" #include "InputReaderBase.h" #include "include/UnwantedInteractionBlockerInterface.h" Loading Loading @@ -52,10 +52,11 @@ class InputDispatcherThread; * this could be a palm on the screen. This stage would alter the event stream to remove either * partially (some of the pointers) or fully (all touches) the unwanted interaction. The events * are processed on the InputReader thread, without any additional queue. The events are then * posted to the queue managed by the InputClassifier. * 3. The InputClassifier class starts a thread to communicate with the device-specific * classifiers. It then waits on the queue of events from UnwantedInteractionBlocker, applies * a classification to them, and queues them for the InputDispatcher. * posted to the queue managed by the InputProcessor. * 3. The InputProcessor class starts a thread to communicate with the device-specific * IInputProcessor HAL. It then waits on the queue of events from UnwantedInteractionBlocker, * processes the events (for example, applies a classification to the events), and queues them * for the InputDispatcher. * 4. The InputDispatcher class starts a thread that waits for new events on the * previous queue and asynchronously dispatches them to applications. * Loading Loading @@ -83,10 +84,10 @@ public: virtual InputReaderInterface& getReader() = 0; /* Gets the unwanted interaction blocker. */ virtual UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() = 0; virtual UnwantedInteractionBlockerInterface& getBlocker() = 0; /* Gets the input classifier */ virtual InputClassifierInterface& getClassifier() = 0; /* Gets the input processor */ virtual InputProcessorInterface& getProcessor() = 0; /* Gets the input dispatcher. */ virtual InputDispatcherInterface& getDispatcher() = 0; Loading @@ -108,8 +109,8 @@ public: status_t stop() override; InputReaderInterface& getReader() override; UnwantedInteractionBlockerInterface& getUnwantedInteractionBlocker() override; InputClassifierInterface& getClassifier() override; UnwantedInteractionBlockerInterface& getBlocker() override; InputProcessorInterface& getProcessor() override; InputDispatcherInterface& getDispatcher() override; void monitor() override; Loading @@ -123,7 +124,7 @@ private: std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker; std::unique_ptr<InputClassifierInterface> mClassifier; std::unique_ptr<InputProcessorInterface> mProcessor; std::unique_ptr<InputDispatcherInterface> mDispatcher; }; Loading
services/inputflinger/InputClassifier.cpp→services/inputflinger/InputProcessor.cpp +49 −51 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ * limitations under the License. */ #define LOG_TAG "InputClassifier" #define LOG_TAG "InputProcessor" #include "InputClassifier.h" #include "InputProcessor.h" #include "InputCommonConverter.h" #include <android-base/stringprintf.h> Loading Loading @@ -123,15 +123,15 @@ ScopedDeathRecipient::~ScopedDeathRecipient() { // --- ClassifierEvent --- ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : type(ClassifierEventType::MOTION), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyDeviceResetArgs> args) : type(ClassifierEventType::DEVICE_RESET), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(ClassifierEventType type, std::unique_ptr<NotifyArgs> args) : type(type), args(std::move(args)) { }; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : type(ClassifierEventType::MOTION), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyDeviceResetArgs> args) : type(ClassifierEventType::DEVICE_RESET), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(ClassifierEventType type, std::unique_ptr<NotifyArgs> args) : type(type), args(std::move(args)){}; ClassifierEvent::ClassifierEvent(ClassifierEvent&& other) : type(other.type), args(std::move(other.args)) { }; ClassifierEvent::ClassifierEvent(ClassifierEvent&& other) : type(other.type), args(std::move(other.args)){}; ClassifierEvent& ClassifierEvent::operator=(ClassifierEvent&& other) { type = other.type; Loading Loading @@ -180,7 +180,7 @@ MotionClassifier::MotionClassifier(std::shared_ptr<IInputProcessor> service) mHalThread = std::thread(&MotionClassifier::processEvents, this); #if defined(__linux__) // Set the thread name for debugging pthread_setname_np(mHalThread.native_handle(), "InputClassifier"); pthread_setname_np(mHalThread.native_handle(), "InputProcessor"); #endif } Loading @@ -198,7 +198,7 @@ MotionClassifier::~MotionClassifier() { /** * Obtain the classification from the HAL for a given MotionEvent. * Should only be called from the InputClassifier thread (mHalThread). * Should only be called from the InputProcessor thread (mHalThread). * Should not be called from the thread that notifyMotion runs on. * * There is no way to provide a timeout for a HAL call. So if the HAL takes too long Loading Loading @@ -239,7 +239,7 @@ void MotionClassifier::processEvents() { } } if (!halResponseOk) { ALOGE("Error communicating with InputClassifier HAL. " ALOGE("Error communicating with InputProcessor HAL. " "Exiting MotionClassifier HAL thread"); clearClassifications(); return; Loading Loading @@ -319,7 +319,7 @@ void MotionClassifier::reset() { /** * Per-device reset. Clear the outstanding events that are going to be sent to HAL. * Request InputClassifier thread to call resetDevice for this particular device. * Request InputProcessor thread to call resetDevice for this particular device. */ void MotionClassifier::reset(const NotifyDeviceResetArgs& args) { int32_t deviceId = args.deviceId; Loading @@ -334,8 +334,7 @@ void MotionClassifier::reset(const NotifyDeviceResetArgs& args) { void MotionClassifier::dump(std::string& dump) { std::scoped_lock lock(mLock); dump += StringPrintf(INDENT2 "mService connected: %s\n", mService ? "true" : "false"); dump += StringPrintf(INDENT2 "mEvents: %zu element(s) (max=%zu)\n", mEvents.size(), MAX_EVENTS); dump += StringPrintf(INDENT2 "mEvents: %zu element(s) (max=%zu)\n", mEvents.size(), MAX_EVENTS); dump += INDENT2 "mClassifications, mLastDownTimes:\n"; dump += INDENT3 "Device Id\tClassification\tLast down time"; // Combine mClassifications and mLastDownTimes into a single table. Loading @@ -349,8 +348,8 @@ void MotionClassifier::dump(std::string& dump) { const MotionClassification classification = getValueForKey(mClassifications, deviceId, MotionClassification::NONE); const nsecs_t downTime = getValueForKey(mLastDownTimes, deviceId, static_cast<nsecs_t>(0)); dump += StringPrintf("\n" INDENT4 "%" PRId32 "\t%s\t%" PRId64, deviceId, motionClassificationToString(classification), downTime); dump += StringPrintf("\n" INDENT4 "%" PRId32 "\t%s\t%" PRId64, deviceId, motionClassificationToString(classification), downTime); } } Loading @@ -366,20 +365,20 @@ void MotionClassifier::monitor() { } } // --- InputClassifier --- // --- InputProcessor --- InputClassifier::InputClassifier(InputListenerInterface& listener) : mQueuedListener(listener) {} InputProcessor::InputProcessor(InputListenerInterface& listener) : mQueuedListener(listener) {} void InputClassifier::onBinderDied(void* cookie) { InputClassifier* classifier = static_cast<InputClassifier*>(cookie); if (classifier == nullptr) { void InputProcessor::onBinderDied(void* cookie) { InputProcessor* processor = static_cast<InputProcessor*>(cookie); if (processor == nullptr) { LOG_ALWAYS_FATAL("Cookie is not valid"); return; } classifier->setMotionClassifierEnabled(false); processor->setMotionClassifierEnabled(false); } void InputClassifier::setMotionClassifierEnabled(bool enabled) { void InputProcessor::setMotionClassifierEnabled(bool enabled) { std::scoped_lock lock(mLock); if (enabled) { ALOGI("Enabling motion classifier"); Loading @@ -392,7 +391,7 @@ void InputClassifier::setMotionClassifierEnabled(bool enabled) { * and we can't continue because 'mInitializeMotionClassifier' will block in its * destructor. */ LOG_ALWAYS_FATAL("The thread to load IInputClassifier is stuck!"); LOG_ALWAYS_FATAL("The thread to load IInputProcessor is stuck!"); } } mInitializeMotionClassifier = std::async(std::launch::async, [this] { Loading @@ -416,19 +415,19 @@ void InputClassifier::setMotionClassifierEnabled(bool enabled) { } } void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { void InputProcessor::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { // pass through mQueuedListener.notifyConfigurationChanged(args); mQueuedListener.flush(); } void InputClassifier::notifyKey(const NotifyKeyArgs* args) { void InputProcessor::notifyKey(const NotifyKeyArgs* args) { // pass through mQueuedListener.notifyKey(args); mQueuedListener.flush(); } void InputClassifier::notifyMotion(const NotifyMotionArgs* args) { void InputProcessor::notifyMotion(const NotifyMotionArgs* args) { { // acquire lock std::scoped_lock lock(mLock); // MotionClassifier is only used for touch events, for now Loading @@ -444,25 +443,25 @@ void InputClassifier::notifyMotion(const NotifyMotionArgs* args) { mQueuedListener.flush(); } void InputClassifier::notifySensor(const NotifySensorArgs* args) { void InputProcessor::notifySensor(const NotifySensorArgs* args) { // pass through mQueuedListener.notifySensor(args); mQueuedListener.flush(); } void InputClassifier::notifyVibratorState(const NotifyVibratorStateArgs* args) { void InputProcessor::notifyVibratorState(const NotifyVibratorStateArgs* args) { // pass through mQueuedListener.notifyVibratorState(args); mQueuedListener.flush(); } void InputClassifier::notifySwitch(const NotifySwitchArgs* args) { void InputProcessor::notifySwitch(const NotifySwitchArgs* args) { // pass through mQueuedListener.notifySwitch(args); mQueuedListener.flush(); } void InputClassifier::notifyDeviceReset(const NotifyDeviceResetArgs* args) { void InputProcessor::notifyDeviceReset(const NotifyDeviceResetArgs* args) { { // acquire lock std::scoped_lock lock(mLock); if (mMotionClassifier) { Loading @@ -475,13 +474,13 @@ void InputClassifier::notifyDeviceReset(const NotifyDeviceResetArgs* args) { mQueuedListener.flush(); } void InputClassifier::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) { void InputProcessor::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) { // pass through mQueuedListener.notifyPointerCaptureChanged(args); mQueuedListener.flush(); } void InputClassifier::setMotionClassifierLocked( void InputProcessor::setMotionClassifierLocked( std::unique_ptr<MotionClassifierInterface> motionClassifier) REQUIRES(mLock) { if (motionClassifier == nullptr) { // Destroy the ScopedDeathRecipient object, which will cause it to unlinkToDeath. Loading @@ -491,9 +490,9 @@ void InputClassifier::setMotionClassifierLocked( mMotionClassifier = std::move(motionClassifier); } void InputClassifier::dump(std::string& dump) { void InputProcessor::dump(std::string& dump) { std::scoped_lock lock(mLock); dump += "Input Classifier State:\n"; dump += "Input Processor State:\n"; dump += INDENT1 "Motion Classifier:\n"; if (mMotionClassifier) { mMotionClassifier->dump(dump); Loading @@ -503,12 +502,11 @@ void InputClassifier::dump(std::string& dump) { dump += "\n"; } void InputClassifier::monitor() { void InputProcessor::monitor() { std::scoped_lock lock(mLock); if (mMotionClassifier) mMotionClassifier->monitor(); } InputClassifier::~InputClassifier() { } InputProcessor::~InputProcessor() {} } // namespace android
services/inputflinger/InputClassifier.h→services/inputflinger/InputProcessor.h +20 −20 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ public: * Base interface for an InputListener stage. * Provides classification to events. */ class InputClassifierInterface : public InputListenerInterface { class InputProcessorInterface : public InputListenerInterface { public: virtual void setMotionClassifierEnabled(bool enabled) = 0; /** Loading @@ -104,8 +104,8 @@ public: /** Called by the heartbeat to ensure that the classifier has not deadlocked. */ virtual void monitor() = 0; InputClassifierInterface() { } virtual ~InputClassifierInterface() { } InputProcessorInterface() {} virtual ~InputProcessorInterface() {} }; // --- Implementations --- Loading @@ -124,10 +124,10 @@ private: }; /** * Implementation of MotionClassifierInterface that calls the InputClassifier HAL * Implementation of MotionClassifierInterface that calls the InputProcessor HAL * in order to determine the classification for the current gesture. * * The InputClassifier HAL may keep track of the entire gesture in order to determine * The InputProcessor HAL may keep track of the entire gesture in order to determine * the classification, and may be hardware-specific. It may use the data in * NotifyMotionArgs::videoFrames field to drive the classification decisions. * The HAL is called from a separate thread. Loading Loading @@ -174,20 +174,20 @@ private: */ void enqueueEvent(ClassifierEvent&& event); /** * Thread that will communicate with InputClassifier HAL. * This should be the only thread that communicates with InputClassifier HAL, * Thread that will communicate with InputProcessor HAL. * This should be the only thread that communicates with InputProcessor HAL, * because this thread is allowed to block on the HAL calls. */ std::thread mHalThread; /** * Process events and call the InputClassifier HAL * Process events and call the InputProcessor HAL */ void processEvents(); /** * Access to the InputProcessor HAL. May be null if init() hasn't completed yet. * When init() successfully completes, mService is guaranteed to remain non-null and to not * change its value until MotionClassifier is destroyed. * This variable is *not* guarded by mLock in the InputClassifier thread, because * This variable is *not* guarded by mLock in the InputProcessor thread, because * that thread knows exactly when this variable is initialized. * When accessed in any other thread, mService is checked for nullness with a lock. */ Loading @@ -197,8 +197,8 @@ private: * Per-device input classifications. Should only be accessed using the * getClassification / setClassification methods. */ std::unordered_map<int32_t /*deviceId*/, MotionClassification> mClassifications GUARDED_BY(mLock); std::unordered_map<int32_t /*deviceId*/, MotionClassification> mClassifications GUARDED_BY(mLock); /** * Set the current classification for a given device. */ Loading @@ -217,7 +217,7 @@ private: * Per-device times when the last ACTION_DOWN was received. * Used to reject late classifications that do not belong to the current gesture. * * Accessed indirectly by both InputClassifier thread and the thread that receives notifyMotion. * Accessed indirectly by both InputProcessor thread and the thread that receives notifyMotion. */ std::unordered_map<int32_t /*deviceId*/, nsecs_t /*downTime*/> mLastDownTimes GUARDED_BY(mLock); Loading @@ -226,7 +226,7 @@ private: void clearDeviceState(int32_t deviceId); /** * Exit the InputClassifier HAL thread. * Exit the InputProcessor HAL thread. * Useful for tests to ensure proper cleanup. */ void requestExit(); Loading @@ -237,14 +237,14 @@ private: }; /** * Implementation of the InputClassifierInterface. * Implementation of the InputProcessorInterface. * Represents a separate stage of input processing. All of the input events go through this stage. * Acts as a passthrough for all input events except for motion events. * The events of motion type are sent to MotionClassifier. */ class InputClassifier : public InputClassifierInterface { class InputProcessor : public InputProcessorInterface { public: explicit InputClassifier(InputListenerInterface& listener); explicit InputProcessor(InputListenerInterface& listener); void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override; void notifyKey(const NotifyKeyArgs* args) override; Loading @@ -258,7 +258,7 @@ public: void dump(std::string& dump) override; void monitor() override; ~InputClassifier(); ~InputProcessor(); // Called from InputManager void setMotionClassifierEnabled(bool enabled) override; Loading