summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Abdelrahman Awadalla <blobou@google.com> 2024-08-05 16:26:10 +0000
committer Abdelrahman Awadalla <blobou@google.com> 2024-08-20 23:42:07 +0000
commit8c4160d30080b23c5bfe7f46b79af025d1e95d8a (patch)
tree00e946012076546516733a152bf538d8dfe9feba
parentfb775d52506e7be689ef4643c5e5522576bc3047 (diff)
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
-rw-r--r--services/inputflinger/include/InputReaderBase.h5
-rw-r--r--services/inputflinger/reader/mapper/TouchpadInputMapper.cpp5
-rw-r--r--services/inputflinger/reader/mapper/gestures/HardwareStateConverter.h1
-rw-r--r--services/inputflinger/tests/FakeInputReaderPolicy.cpp18
-rw-r--r--services/inputflinger/tests/FakeInputReaderPolicy.h6
-rw-r--r--services/inputflinger/tests/TouchpadInputMapper_test.cpp18
-rw-r--r--services/inputflinger/tests/fuzzers/MapperHelpers.h2
7 files changed, 52 insertions, 3 deletions
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index 4ef43ba773..7bec94eea1 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -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,
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index ed79233eed..dbc28721d1 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -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 {
diff --git a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.h b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.h
index 66d62f856b..148ca5aa9e 100644
--- a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.h
+++ b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.h
@@ -28,6 +28,7 @@
#include "accumulator/TouchButtonAccumulator.h"
#include "include/TouchpadHardwareState.h"
+#include "TouchpadHardwareState.h"
#include "include/gestures.h"
namespace android {
diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
index 6099c91daf..d77d539f74 100644
--- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp
+++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
@@ -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;
diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.h b/services/inputflinger/tests/FakeInputReaderPolicy.h
index 94f1311a1e..e5ba620555 100644
--- a/services/inputflinger/tests/FakeInputReaderPolicy.h
+++ b/services/inputflinger/tests/FakeInputReaderPolicy.h
@@ -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};
};
diff --git a/services/inputflinger/tests/TouchpadInputMapper_test.cpp b/services/inputflinger/tests/TouchpadInputMapper_test.cpp
index fc8a7dafb0..ea69fffeaa 100644
--- a/services/inputflinger/tests/TouchpadInputMapper_test.cpp
+++ b/services/inputflinger/tests/TouchpadInputMapper_test.cpp
@@ -172,4 +172,22 @@ TEST_F(TouchpadInputMapperTest, HoverAndLeftButtonPress) {
ASSERT_THAT(args, testing::IsEmpty());
}
+TEST_F(TouchpadInputMapperTest, TouchpadHardwareState) {
+ mReaderConfiguration.shouldNotifyTouchpadHardwareState = true;
+ std::list<NotifyArgs> args =
+ mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration,
+ InputReaderConfiguration::Change::TOUCHPAD_SETTINGS);
+
+ args += process(EV_ABS, ABS_MT_TRACKING_ID, 1);
+ args += process(EV_KEY, BTN_TOUCH, 1);
+ setScanCodeState(KeyState::DOWN, {BTN_TOOL_FINGER});
+ args += process(EV_KEY, BTN_TOOL_FINGER, 1);
+ args += process(EV_ABS, ABS_MT_POSITION_X, 50);
+ args += process(EV_ABS, ABS_MT_POSITION_Y, 50);
+ args += process(EV_ABS, ABS_MT_PRESSURE, 1);
+ args += process(EV_SYN, SYN_REPORT, 0);
+
+ mFakePolicy->assertTouchpadHardwareStateNotified();
+}
+
} // namespace android
diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h
index fea0d9a1c1..ddc3310448 100644
--- a/services/inputflinger/tests/fuzzers/MapperHelpers.h
+++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h
@@ -281,6 +281,8 @@ public:
FuzzInputReaderPolicy(std::shared_ptr<ThreadSafeFuzzedDataProvider> mFdp) : mFdp(mFdp) {}
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& identifier,
const std::optional<KeyboardLayoutInfo> layoutInfo) override {