blob: a15ad80bae12ae9868d124e40693b3c41751bfb0 [file] [log] [blame]
Prabir Pradhandae52792023-12-15 07:36:40 +00001/*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "AndroidInputEventProtoConverter.h"
18
19#include <android-base/logging.h>
20#include <perfetto/trace/android/android_input_event.pbzero.h>
21
22namespace android::inputdispatcher::trace {
23
24void AndroidInputEventProtoConverter::toProtoMotionEvent(const TracedMotionEvent& event,
25 proto::AndroidMotionEvent& outProto) {
26 outProto.set_event_id(event.id);
27 outProto.set_event_time_nanos(event.eventTime);
28 outProto.set_down_time_nanos(event.downTime);
29 outProto.set_source(event.source);
30 outProto.set_action(event.action);
31 outProto.set_device_id(event.deviceId);
32 outProto.set_display_id(event.displayId);
33 outProto.set_classification(static_cast<int32_t>(event.classification));
34 outProto.set_cursor_position_x(event.xCursorPosition);
35 outProto.set_cursor_position_y(event.yCursorPosition);
36 outProto.set_flags(event.flags);
37 outProto.set_policy_flags(event.policyFlags);
38
39 for (uint32_t i = 0; i < event.pointerProperties.size(); i++) {
40 auto* pointer = outProto.add_pointer();
41
42 const auto& props = event.pointerProperties[i];
43 pointer->set_pointer_id(props.id);
44 pointer->set_tool_type(static_cast<int32_t>(props.toolType));
45
46 const auto& coords = event.pointerCoords[i];
47 auto bits = BitSet64(coords.bits);
48 for (int32_t axisIndex = 0; !bits.isEmpty(); axisIndex++) {
49 const auto axis = bits.clearFirstMarkedBit();
50 auto axisEntry = pointer->add_axis_value();
51 axisEntry->set_axis(axis);
52 axisEntry->set_value(coords.values[axisIndex]);
53 }
54 }
55}
56
57void AndroidInputEventProtoConverter::toProtoKeyEvent(const TracedKeyEvent& event,
58 proto::AndroidKeyEvent& outProto) {
59 outProto.set_event_id(event.id);
60 outProto.set_event_time_nanos(event.eventTime);
61 outProto.set_down_time_nanos(event.downTime);
62 outProto.set_source(event.source);
63 outProto.set_action(event.action);
64 outProto.set_device_id(event.deviceId);
65 outProto.set_display_id(event.displayId);
66 outProto.set_key_code(event.keyCode);
67 outProto.set_scan_code(event.scanCode);
68 outProto.set_meta_state(event.metaState);
69 outProto.set_repeat_count(event.repeatCount);
70 outProto.set_flags(event.flags);
71 outProto.set_policy_flags(event.policyFlags);
72}
73
74} // namespace android::inputdispatcher::trace