Allow values from SourceClass inside rust Source
Inside ViewTest::testOnTouchEventScroll, some MotionEvents are created
without a valid source. During injection, they get appended with
SourceClass::Pointer.
If these events are sent into the InputVerifier, it's basically being
asked to convert 0x2 === AINPUT_SOURCE_CLASS_POINTER into rust's
input::Source.
This fails during unwrap:
$ TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
[ RUN ] InputVerifierTest.BadSourceProcess
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', frameworks/native/libs/input/rust/lib.rs:84:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
Aborted
To mitigate this, add the SourceClass definitions into Source, thus
allowing such conversions.
Bug: 303143553
Bug: 211379801
Test: TEST=libinput_rust_test; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I46415d88251937959104bb82a3976e72ffcfcaf9
diff --git a/libs/input/tests/InputVerifier_test.cpp b/libs/input/tests/InputVerifier_test.cpp
index e24fa6e..e2eb080 100644
--- a/libs/input/tests/InputVerifier_test.cpp
+++ b/libs/input/tests/InputVerifier_test.cpp
@@ -20,10 +20,35 @@
namespace android {
+using android::base::Result;
+
TEST(InputVerifierTest, CreationWithInvalidUtfStringDoesNotCrash) {
constexpr char bytes[] = {static_cast<char>(0xC0), static_cast<char>(0x80)};
const std::string name(bytes, sizeof(bytes));
InputVerifier verifier(name);
}
+TEST(InputVerifierTest, ProcessSourceClassPointer) {
+ InputVerifier verifier("Verify testOnTouchEventScroll");
+
+ std::vector<PointerProperties> properties;
+ properties.push_back({});
+ properties.back().clear();
+ properties.back().id = 0;
+ properties.back().toolType = ToolType::UNKNOWN;
+
+ std::vector<PointerCoords> coords;
+ coords.push_back({});
+ coords.back().clear();
+ coords.back().setAxisValue(AMOTION_EVENT_AXIS_X, 75);
+ coords.back().setAxisValue(AMOTION_EVENT_AXIS_Y, 300);
+
+ const Result<void> result =
+ verifier.processMovement(/*deviceId=*/0, AINPUT_SOURCE_CLASS_POINTER,
+ AMOTION_EVENT_ACTION_DOWN,
+ /*pointerCount=*/properties.size(), properties.data(),
+ coords.data(), /*flags=*/0);
+ ASSERT_TRUE(result.ok());
+}
+
} // namespace android