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

Commit 98996036 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Rename InputClassifier to InputProcessor

The InputClassifier stage now calls a HAL that was renamed to
IInputProcessor. Let's rename the input stage accordingly.

Bug: 210158587
Test: atest inputflinger_tests
Change-Id: Id1a4f01b07b404064917acd0beb04b839abb2929
parent 5cb98562
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ cc_defaults {
filegroup {
    name: "libinputflinger_sources",
    srcs: [
        "InputClassifier.cpp",
        "InputProcessor.cpp",
        "InputCommonConverter.cpp",
        "PreferStylusOverTouchBlocker.cpp",
        "UnwantedInteractionBlocker.cpp",
+7 −7
Original line number Diff line number Diff line
@@ -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);
}

@@ -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() {
@@ -125,7 +125,7 @@ InputDispatcherInterface& InputManager::getDispatcher() {
void InputManager::monitor() {
    mReader->monitor();
    mBlocker->monitor();
    mClassifier->monitor();
    mProcessor->monitor();
    mDispatcher->monitor();
}

+12 −11
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
 * Native input manager.
 */

#include "InputClassifier.h"
#include "InputProcessor.h"
#include "InputReaderBase.h"
#include "include/UnwantedInteractionBlockerInterface.h"

@@ -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.
 *
@@ -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;
@@ -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;

@@ -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;
};
+49 −51
Original line number Diff line number Diff line
@@ -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>
@@ -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;
@@ -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
}

@@ -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
@@ -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;
@@ -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;
@@ -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.
@@ -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);
    }
}

@@ -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");
@@ -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] {
@@ -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
@@ -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) {
@@ -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.
@@ -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);
@@ -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
+20 −20
Original line number Diff line number Diff line
@@ -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;
    /**
@@ -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 ---
@@ -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.
@@ -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.
     */
@@ -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.
     */
@@ -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);

@@ -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();
@@ -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;
@@ -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