@@ -256,6 +256,96 @@ TEST(AndroidInputEventProtoConverterTest, ToProtoMotionEvent_Redacted) {
256256 TestProtoConverter::toProtoMotionEvent (event, proto, /* isRedacted=*/ true );
257257}
258258
259+ // Test any special handling for zero values for pointer events.
260+ TEST (AndroidInputEventProtoConverterTest, ToProtoMotionEvent_ZeroValues) {
261+ TracedMotionEvent event{};
262+ event.id = 0 ;
263+ event.eventTime = 0 ;
264+ event.downTime = 0 ;
265+ event.source = AINPUT_SOURCE_MOUSE;
266+ event.action = AMOTION_EVENT_ACTION_BUTTON_PRESS;
267+ event.deviceId = 0 ;
268+ event.displayId = ui::LogicalDisplayId (0 );
269+ event.classification = {};
270+ event.flags = 0 ;
271+ event.policyFlags = 0 ;
272+ event.buttonState = 0 ;
273+ event.actionButton = 0 ;
274+ event.xCursorPosition = 0 .0f ;
275+ event.yCursorPosition = 0 .0f ;
276+ event.metaState = 0 ;
277+ event.xPrecision = 0 .0f ;
278+ event.yPrecision = 0 .0f ;
279+ event.pointerProperties .emplace_back (PointerProperties{
280+ .id = 0 ,
281+ .toolType = ToolType::MOUSE,
282+ });
283+ event.pointerProperties .emplace_back (PointerProperties{
284+ .id = 1 ,
285+ .toolType = ToolType::FINGER,
286+ });
287+ // Zero values for x and y axes are always traced for pointer events.
288+ // However, zero values for other axes may not necessarily be traced.
289+ event.pointerCoords .emplace_back ();
290+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_X, 0 .0f );
291+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_Y, 1 .0f );
292+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_PRESSURE, 0 .0f );
293+ event.pointerCoords .emplace_back ();
294+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_X, 0 .0f );
295+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_Y, 0 .0f );
296+ event.pointerCoords .back ().setAxisValue (AMOTION_EVENT_AXIS_PRESSURE, 0 .0f );
297+
298+ testing::StrictMock<MockProtoMotion> proto;
299+ testing::StrictMock<MockProtoPointer> pointer1;
300+ testing::StrictMock<MockProtoPointer> pointer2;
301+ testing::StrictMock<MockProtoAxisValue> axisValue1;
302+ testing::StrictMock<MockProtoAxisValue> axisValue2;
303+ testing::StrictMock<MockProtoAxisValue> axisValue3;
304+ testing::StrictMock<MockProtoAxisValue> axisValue4;
305+
306+ EXPECT_CALL (proto, set_event_id (0 ));
307+ EXPECT_CALL (proto, set_event_time_nanos (0 ));
308+ EXPECT_CALL (proto, set_down_time_nanos (0 ));
309+ EXPECT_CALL (proto, set_source (AINPUT_SOURCE_MOUSE));
310+ EXPECT_CALL (proto, set_action (AMOTION_EVENT_ACTION_BUTTON_PRESS));
311+ EXPECT_CALL (proto, set_device_id (0 ));
312+ EXPECT_CALL (proto, set_display_id (0 ));
313+ EXPECT_CALL (proto, set_classification (0 ));
314+ EXPECT_CALL (proto, set_flags (0 ));
315+ EXPECT_CALL (proto, set_policy_flags (0 ));
316+ EXPECT_CALL (proto, set_button_state (0 ));
317+ EXPECT_CALL (proto, set_action_button (0 ));
318+ EXPECT_CALL (proto, set_cursor_position_x (0 .0f ));
319+ EXPECT_CALL (proto, set_cursor_position_y (0 .0f ));
320+ EXPECT_CALL (proto, set_meta_state (0 ));
321+ EXPECT_CALL (proto, set_precision_x (0 .0f ));
322+ EXPECT_CALL (proto, set_precision_y (0 .0f ));
323+
324+ EXPECT_CALL (proto, add_pointer ()).WillOnce (Return (&pointer1)).WillOnce (Return (&pointer2));
325+
326+ EXPECT_CALL (pointer1, set_pointer_id (0 ));
327+ EXPECT_CALL (pointer1, set_tool_type (AMOTION_EVENT_TOOL_TYPE_MOUSE));
328+ EXPECT_CALL (pointer1, add_axis_value ())
329+ .WillOnce (Return (&axisValue1))
330+ .WillOnce (Return (&axisValue2));
331+ EXPECT_CALL (axisValue1, set_axis (AMOTION_EVENT_AXIS_X));
332+ EXPECT_CALL (axisValue1, set_value (0 .0f ));
333+ EXPECT_CALL (axisValue2, set_axis (AMOTION_EVENT_AXIS_Y));
334+ EXPECT_CALL (axisValue2, set_value (1 .0f ));
335+
336+ EXPECT_CALL (pointer2, set_pointer_id (1 ));
337+ EXPECT_CALL (pointer2, set_tool_type (AMOTION_EVENT_TOOL_TYPE_FINGER));
338+ EXPECT_CALL (pointer2, add_axis_value ())
339+ .WillOnce (Return (&axisValue3))
340+ .WillOnce (Return (&axisValue4));
341+ EXPECT_CALL (axisValue3, set_axis (AMOTION_EVENT_AXIS_X));
342+ EXPECT_CALL (axisValue3, set_value (0 .0f ));
343+ EXPECT_CALL (axisValue4, set_axis (AMOTION_EVENT_AXIS_Y));
344+ EXPECT_CALL (axisValue4, set_value (0 .0f ));
345+
346+ TestProtoConverter::toProtoMotionEvent (event, proto, /* isRedacted=*/ false );
347+ }
348+
259349} // namespace
260350
261351} // namespace android::inputdispatcher::trace
0 commit comments