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

Commit 8c4160d3 authored by Abdelrahman Awadalla's avatar Abdelrahman Awadalla
Browse files

Notify TouchpadDebugActivity on finger/hardware state changes

Notifying TouchpadDebugActivity with any change in the finger or hardware state of the touchpad connected to the device and transferring it from TouchpadInputMapper to InputManagerService using JNI.

Bug: 286551975
Test: Manual testing by flashing the device and tracing the logs
Test: $ atest TouchpadInputMapper_test.cpp
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I5edfa3fc568a9c3cfd1a31036a5891829905a1da
parent fb775d52
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <vector>

#include "PointerControllerInterface.h"
#include "TouchpadHardwareState.h"
#include "VibrationElement.h"
#include "include/gestures.h"

@@ -461,6 +462,10 @@ public:
     */
    virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) = 0;

    /* Sends the hardware state of a connected touchpad */
    virtual void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
                                             int32_t deviceId) = 0;

    /* Gets the keyboard layout for a particular input device. */
    virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
            const InputDeviceIdentifier& identifier,
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <log/log_main.h>
#include <stats_pull_atom_callback.h>
#include <statslog.h>
#include "InputReaderBase.h"
#include "TouchCursorInputMapperCommon.h"
#include "TouchpadInputMapper.h"
#include "gestures/HardwareProperties.h"
@@ -424,10 +425,8 @@ std::list<NotifyArgs> TouchpadInputMapper::process(const RawEvent& rawEvent) {
    std::optional<SelfContainedHardwareState> state = mStateConverter.processRawEvent(rawEvent);
    if (state) {
        if (mTouchpadHardwareStateNotificationsEnabled) {
            // TODO(b/286551975): Notify policy of the touchpad hardware state.
            LOG(DEBUG) << "Notify touchpad hardware state here!";
            getPolicy()->notifyTouchpadHardwareState(*state, rawEvent.deviceId);
        }

        updatePalmDetectionMetrics();
        return sendHardwareState(rawEvent.when, rawEvent.readTime, *state);
    } else {
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "accumulator/TouchButtonAccumulator.h"
#include "include/TouchpadHardwareState.h"

#include "TouchpadHardwareState.h"
#include "include/gestures.h"

namespace android {
+18 −0
Original line number Diff line number Diff line
@@ -65,6 +65,17 @@ void FakeInputReaderPolicy::assertStylusGestureNotNotified() {
    ASSERT_FALSE(mDeviceIdOfNotifiedStylusGesture);
}

void FakeInputReaderPolicy::assertTouchpadHardwareStateNotified() {
    std::unique_lock lock(mLock);
    base::ScopedLockAssertion assumeLocked(mLock);

    const bool success =
            mTouchpadHardwareStateNotified.wait_for(lock, WAIT_TIMEOUT, [this]() REQUIRES(mLock) {
                return mTouchpadHardwareState.has_value();
            });
    ASSERT_TRUE(success) << "Timed out waiting for hardware state to be notified";
}

void FakeInputReaderPolicy::clearViewports() {
    mViewports.clear();
    mConfig.setDisplayViewports(mViewports);
@@ -234,6 +245,13 @@ void FakeInputReaderPolicy::notifyInputDevicesChanged(
    mDevicesChangedCondition.notify_all();
}

void FakeInputReaderPolicy::notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
                                                        int32_t deviceId) {
    std::scoped_lock lock(mLock);
    mTouchpadHardwareState = schs;
    mTouchpadHardwareStateNotified.notify_all();
}

std::shared_ptr<KeyCharacterMap> FakeInputReaderPolicy::getKeyboardLayoutOverlay(
        const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) {
    return nullptr;
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public:
    void assertInputDevicesNotChanged();
    void assertStylusGestureNotified(int32_t deviceId);
    void assertStylusGestureNotNotified();
    void assertTouchpadHardwareStateNotified();

    virtual void clearViewports();
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueId) const;
@@ -82,6 +83,8 @@ public:
private:
    void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
    void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
    void notifyTouchpadHardwareState(const SelfContainedHardwareState& schs,
                                     int32_t deviceId) override;
    std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
            const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) override;
    std::string getDeviceAlias(const InputDeviceIdentifier&) override;
@@ -101,6 +104,9 @@ private:
    std::condition_variable mStylusGestureNotifiedCondition;
    std::optional<DeviceId> mDeviceIdOfNotifiedStylusGesture GUARDED_BY(mLock){};

    std::condition_variable mTouchpadHardwareStateNotified;
    std::optional<SelfContainedHardwareState> mTouchpadHardwareState GUARDED_BY(mLock){};

    uint32_t mNextPointerCaptureSequenceNumber{0};
};

Loading