@@ -60,7 +60,24 @@ class MockProtoMotion {
6060 MOCK_METHOD (MockProtoPointer*, add_pointer, ());
6161};
6262
63- using TestProtoConverter = AndroidInputEventProtoConverter<MockProtoMotion, proto::AndroidKeyEvent,
63+ class MockProtoKey {
64+ public:
65+ MOCK_METHOD (void , set_event_id, (uint32_t ));
66+ MOCK_METHOD (void , set_event_time_nanos, (int64_t ));
67+ MOCK_METHOD (void , set_down_time_nanos, (int64_t ));
68+ MOCK_METHOD (void , set_source, (uint32_t ));
69+ MOCK_METHOD (void , set_action, (int32_t ));
70+ MOCK_METHOD (void , set_device_id, (uint32_t ));
71+ MOCK_METHOD (void , set_display_id, (uint32_t ));
72+ MOCK_METHOD (void , set_repeat_count, (uint32_t ));
73+ MOCK_METHOD (void , set_flags, (uint32_t ));
74+ MOCK_METHOD (void , set_policy_flags, (uint32_t ));
75+ MOCK_METHOD (void , set_key_code, (uint32_t ));
76+ MOCK_METHOD (void , set_scan_code, (uint32_t ));
77+ MOCK_METHOD (void , set_meta_state, (uint32_t ));
78+ };
79+
80+ using TestProtoConverter = AndroidInputEventProtoConverter<MockProtoMotion, MockProtoKey,
6481 proto::AndroidWindowInputDispatchEvent,
6582 proto::AndroidInputEventConfig::Decoder>;
6683
@@ -256,6 +273,168 @@ TEST(AndroidInputEventProtoConverterTest, ToProtoMotionEvent_Redacted) {
256273 TestProtoConverter::toProtoMotionEvent (event, proto, /* isRedacted=*/ true );
257274}
258275
276+ // Test any special handling for zero values for pointer events.
277+ TEST (AndroidInputEventProtoConverterTest, ToProtoMotionEvent_ZeroValues) {
278+ TracedMotionEvent event{};
279+ event.id = 0 ;
280+ event.eventTime = 0 ;
281+ event.downTime = 0 ;
282+ event.source = AINPUT_SOURCE_MOUSE;
283+ event.action = AMOTION_EVENT_ACTION_BUTTON_PRESS;
284+ event.deviceId = 0 ;
285+ event.displayId = ui::LogicalDisplayId (0 );
286+ event.classification = {};
287+ event.flags = 0 ;
288+ event.policyFlags = 0 ;
289+ event.buttonState = 0 ;
290+ event.actionButton = 0 ;
291+ event.xCursorPosition = 0 .0f ;
292+ event.yCursorPosition = 0 .0f ;
293+ event.metaState = 0 ;
294+ event.xPrecision = 0 .0f ;
295+ event.yPrecision = 0 .0f ;
296+ event.pointerProperties .emplace_back (PointerProperties{
297+ .id = 0 ,
298+ .toolType = ToolType::MOUSE,
299+ });
300+ event.pointerProperties .emplace_back (PointerProperties{
301+ .id = 1 ,
302+ .toolType = ToolType::FINGER,
303+ });
304+ // Zero values for x and y axes are always traced for pointer events.
305+ // However, zero values for other axes may not necessarily be traced.
306+ event.pointerCoords .emplace_back ();
307+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_X, 0 .0f );
308+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_Y, 1 .0f );
309+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_PRESSURE, 0 .0f );
310+ event.pointerCoords .emplace_back ();
311+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_X, 0 .0f );
312+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_Y, 0 .0f );
313+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_PRESSURE, 0 .0f );
314+
315+ testing::StrictMock<MockProtoMotion> proto;
316+ testing::StrictMock<MockProtoPointer> pointer1;
317+ testing::StrictMock<MockProtoPointer> pointer2;
318+ testing::StrictMock<MockProtoAxisValue> axisValue1;
319+ testing::StrictMock<MockProtoAxisValue> axisValue2;
320+ testing::StrictMock<MockProtoAxisValue> axisValue3;
321+ testing::StrictMock<MockProtoAxisValue> axisValue4;
322+
323+ EXPECT_CALL (proto, set_event_id (0 ));
324+ EXPECT_CALL (proto, set_event_time_nanos (0 ));
325+ EXPECT_CALL (proto, set_down_time_nanos (0 ));
326+ EXPECT_CALL (proto, set_source (AINPUT_SOURCE_MOUSE));
327+ EXPECT_CALL (proto, set_action (AMOTION_EVENT_ACTION_BUTTON_PRESS));
328+ EXPECT_CALL (proto, set_device_id (0 ));
329+ EXPECT_CALL (proto, set_display_id (0 ));
330+ EXPECT_CALL (proto, set_classification (0 ));
331+ EXPECT_CALL (proto, set_flags (0 ));
332+ EXPECT_CALL (proto, set_policy_flags (0 ));
333+ EXPECT_CALL (proto, set_button_state (0 ));
334+ EXPECT_CALL (proto, set_action_button (0 ));
335+ EXPECT_CALL (proto, set_cursor_position_x (0 .0f ));
336+ EXPECT_CALL (proto, set_cursor_position_y (0 .0f ));
337+ EXPECT_CALL (proto, set_meta_state (0 ));
338+ EXPECT_CALL (proto, set_precision_x (0 .0f ));
339+ EXPECT_CALL (proto, set_precision_y (0 .0f ));
340+
341+ EXPECT_CALL (proto, add_pointer ()).WillOnce (Return (&pointer1)).WillOnce (Return (&pointer2));
342+
343+ EXPECT_CALL (pointer1, set_pointer_id (0 ));
344+ EXPECT_CALL (pointer1, set_tool_type (AMOTION_EVENT_TOOL_TYPE_MOUSE));
345+ EXPECT_CALL (pointer1, add_axis_value ())
346+ .WillOnce (Return (&axisValue1))
347+ .WillOnce (Return (&axisValue2));
348+ EXPECT_CALL (axisValue1, set_axis (AMOTION_EVENT_AXIS_X));
349+ EXPECT_CALL (axisValue1, set_value (0 .0f ));
350+ EXPECT_CALL (axisValue2, set_axis (AMOTION_EVENT_AXIS_Y));
351+ EXPECT_CALL (axisValue2, set_value (1 .0f ));
352+
353+ EXPECT_CALL (pointer2, set_pointer_id (1 ));
354+ EXPECT_CALL (pointer2, set_tool_type (AMOTION_EVENT_TOOL_TYPE_FINGER));
355+ EXPECT_CALL (pointer2, add_axis_value ())
356+ .WillOnce (Return (&axisValue3))
357+ .WillOnce (Return (&axisValue4));
358+ EXPECT_CALL (axisValue3, set_axis (AMOTION_EVENT_AXIS_X));
359+ EXPECT_CALL (axisValue3, set_value (0 .0f ));
360+ EXPECT_CALL (axisValue4, set_axis (AMOTION_EVENT_AXIS_Y));
361+ EXPECT_CALL (axisValue4, set_value (0 .0f ));
362+
363+ TestProtoConverter::toProtoMotionEvent (event, proto, /* isRedacted=*/ false );
364+ }
365+
366+ TEST (AndroidInputEventProtoConverterTest, ToProtoKeyEvent) {
367+ TracedKeyEvent event{};
368+ event.id = 1 ;
369+ event.eventTime = 2 ;
370+ event.downTime = 3 ;
371+ event.source = AINPUT_SOURCE_KEYBOARD;
372+ event.action = AKEY_EVENT_ACTION_DOWN;
373+ event.deviceId = 4 ;
374+ event.displayId = ui::LogicalDisplayId (5 );
375+ event.repeatCount = 6 ;
376+ event.flags = 7 ;
377+ event.policyFlags = 8 ;
378+ event.keyCode = 9 ;
379+ event.scanCode = 10 ;
380+ event.metaState = 11 ;
381+
382+ testing::StrictMock<MockProtoKey> proto;
383+
384+ EXPECT_CALL (proto, set_event_id (1 ));
385+ EXPECT_CALL (proto, set_event_time_nanos (2 ));
386+ EXPECT_CALL (proto, set_down_time_nanos (3 ));
387+ EXPECT_CALL (proto, set_source (AINPUT_SOURCE_KEYBOARD));
388+ EXPECT_CALL (proto, set_action (AKEY_EVENT_ACTION_DOWN));
389+ EXPECT_CALL (proto, set_device_id (4 ));
390+ EXPECT_CALL (proto, set_display_id (5 ));
391+ EXPECT_CALL (proto, set_repeat_count (6 ));
392+ EXPECT_CALL (proto, set_flags (7 ));
393+ EXPECT_CALL (proto, set_policy_flags (8 ));
394+ EXPECT_CALL (proto, set_key_code (9 ));
395+ EXPECT_CALL (proto, set_scan_code (10 ));
396+ EXPECT_CALL (proto, set_meta_state (11 ));
397+
398+ TestProtoConverter::toProtoKeyEvent (event, proto, /* isRedacted=*/ false );
399+ }
400+
401+ TEST (AndroidInputEventProtoConverterTest, ToProtoKeyEvent_Redacted) {
402+ TracedKeyEvent event{};
403+ event.id = 1 ;
404+ event.eventTime = 2 ;
405+ event.downTime = 3 ;
406+ event.source = AINPUT_SOURCE_KEYBOARD;
407+ event.action = AKEY_EVENT_ACTION_DOWN;
408+ event.deviceId = 4 ;
409+ event.displayId = ui::LogicalDisplayId (5 );
410+ event.repeatCount = 6 ;
411+ event.flags = 7 ;
412+ event.policyFlags = 8 ;
413+ event.keyCode = 9 ;
414+ event.scanCode = 10 ;
415+ event.metaState = 11 ;
416+
417+ testing::StrictMock<MockProtoKey> proto;
418+
419+ EXPECT_CALL (proto, set_event_id (1 ));
420+ EXPECT_CALL (proto, set_event_time_nanos (2 ));
421+ EXPECT_CALL (proto, set_down_time_nanos (3 ));
422+ EXPECT_CALL (proto, set_source (AINPUT_SOURCE_KEYBOARD));
423+ EXPECT_CALL (proto, set_action (AKEY_EVENT_ACTION_DOWN));
424+ EXPECT_CALL (proto, set_device_id (4 ));
425+ EXPECT_CALL (proto, set_display_id (5 ));
426+ EXPECT_CALL (proto, set_repeat_count (6 ));
427+ EXPECT_CALL (proto, set_flags (7 ));
428+ EXPECT_CALL (proto, set_policy_flags (8 ));
429+
430+ // Redacted fields
431+ EXPECT_CALL (proto, set_key_code (_)).Times (0 );
432+ EXPECT_CALL (proto, set_scan_code (_)).Times (0 );
433+ EXPECT_CALL (proto, set_meta_state (_)).Times (0 );
434+
435+ TestProtoConverter::toProtoKeyEvent (event, proto, /* isRedacted=*/ true );
436+ }
437+
259438} // namespace
260439
261440} // namespace android::inputdispatcher::trace
0 commit comments