xref: /aosp_15_r20/frameworks/native/services/inputflinger/include/NotifyArgs.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #include <vector>
20 
21 #include <input/Input.h>
22 #include <input/InputDevice.h>
23 #include <input/TouchVideoFrame.h>
24 
25 namespace android {
26 
27 /* Describes a change in any of the connected input devices. */
28 struct NotifyInputDevicesChangedArgs {
29     int32_t id;
30     std::vector<InputDeviceInfo> inputDeviceInfos;
31 
NotifyInputDevicesChangedArgsNotifyInputDevicesChangedArgs32     inline NotifyInputDevicesChangedArgs() {}
33 
34     NotifyInputDevicesChangedArgs(int32_t id, std::vector<InputDeviceInfo> infos);
35 
36     bool operator==(const NotifyInputDevicesChangedArgs& rhs) const = default;
37 
38     NotifyInputDevicesChangedArgs(const NotifyInputDevicesChangedArgs& other) = default;
39     NotifyInputDevicesChangedArgs& operator=(const NotifyInputDevicesChangedArgs&) = default;
40 };
41 
42 /* Describes a key event. */
43 struct NotifyKeyArgs {
44     int32_t id;
45     nsecs_t eventTime;
46 
47     int32_t deviceId;
48     uint32_t source;
49     ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID};
50     uint32_t policyFlags;
51     int32_t action;
52     int32_t flags;
53     int32_t keyCode;
54     int32_t scanCode;
55     int32_t metaState;
56     nsecs_t downTime;
57     nsecs_t readTime;
58 
NotifyKeyArgsNotifyKeyArgs59     inline NotifyKeyArgs() {}
60 
61     NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
62                   uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
63                   int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
64                   int32_t metaState, nsecs_t downTime);
65 
66     bool operator==(const NotifyKeyArgs& rhs) const = default;
67 
68     NotifyKeyArgs(const NotifyKeyArgs& other) = default;
69     NotifyKeyArgs& operator=(const NotifyKeyArgs&) = default;
70 };
71 
72 /* Describes a motion event. */
73 struct NotifyMotionArgs {
74     int32_t id;
75     nsecs_t eventTime;
76 
77     int32_t deviceId;
78     uint32_t source;
79     ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID};
80     uint32_t policyFlags;
81     int32_t action;
82     int32_t actionButton;
83     int32_t flags;
84     int32_t metaState;
85     int32_t buttonState;
86     /**
87      * Classification of the current touch gesture
88      */
89     MotionClassification classification;
90     int32_t edgeFlags;
91 
92     // Vectors 'pointerProperties' and 'pointerCoords' must always have the same number of elements
93     std::vector<PointerProperties> pointerProperties;
94     std::vector<PointerCoords> pointerCoords;
95     float xPrecision;
96     float yPrecision;
97     /**
98      * Mouse cursor position when this event is reported relative to the origin of the specified
99      * display. Only valid if this is a mouse event (originates from a mouse or from a trackpad in
100      * gestures enabled mode.
101      */
102     float xCursorPosition;
103     float yCursorPosition;
104     nsecs_t downTime;
105     nsecs_t readTime;
106     std::vector<TouchVideoFrame> videoFrames;
107 
NotifyMotionArgsNotifyMotionArgs108     inline NotifyMotionArgs() {}
109 
110     NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
111                      uint32_t source, ui::LogicalDisplayId displayId, uint32_t policyFlags,
112                      int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
113                      int32_t buttonState, MotionClassification classification, int32_t edgeFlags,
114                      uint32_t pointerCount, const PointerProperties* pointerProperties,
115                      const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
116                      float xCursorPosition, float yCursorPosition, nsecs_t downTime,
117                      const std::vector<TouchVideoFrame>& videoFrames);
118 
119     NotifyMotionArgs(const NotifyMotionArgs& other) = default;
120     NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default;
121 
122     bool operator==(const NotifyMotionArgs& rhs) const;
123 
getPointerCountNotifyMotionArgs124     inline size_t getPointerCount() const { return pointerProperties.size(); }
125 
126     std::string dump() const;
127 };
128 
129 /* Describes a sensor event. */
130 struct NotifySensorArgs {
131     int32_t id;
132     nsecs_t eventTime;
133 
134     int32_t deviceId;
135     uint32_t source;
136     InputDeviceSensorType sensorType;
137     InputDeviceSensorAccuracy accuracy;
138     bool accuracyChanged;
139     nsecs_t hwTimestamp;
140     std::vector<float> values;
141 
NotifySensorArgsNotifySensorArgs142     inline NotifySensorArgs() {}
143 
144     NotifySensorArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
145                      InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy,
146                      bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
147 
148     NotifySensorArgs(const NotifySensorArgs& other) = default;
149     NotifySensorArgs& operator=(const NotifySensorArgs&) = default;
150 };
151 
152 /* Describes a switch event. */
153 struct NotifySwitchArgs {
154     int32_t id;
155     nsecs_t eventTime;
156 
157     uint32_t policyFlags;
158     uint32_t switchValues;
159     uint32_t switchMask;
160 
NotifySwitchArgsNotifySwitchArgs161     inline NotifySwitchArgs() {}
162 
163     NotifySwitchArgs(int32_t id, nsecs_t eventTime, uint32_t policyFlags, uint32_t switchValues,
164                      uint32_t switchMask);
165 
166     NotifySwitchArgs(const NotifySwitchArgs& other) = default;
167     NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default;
168 
169     bool operator==(const NotifySwitchArgs& rhs) const = default;
170 };
171 
172 /* Describes a device reset event, such as when a device is added,
173  * reconfigured, or removed. */
174 struct NotifyDeviceResetArgs {
175     int32_t id;
176     nsecs_t eventTime;
177 
178     int32_t deviceId;
179 
NotifyDeviceResetArgsNotifyDeviceResetArgs180     inline NotifyDeviceResetArgs() {}
181 
182     NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
183 
184     NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
185     NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default;
186 
187     bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
188 };
189 
190 /* Describes a change in the state of Pointer Capture. */
191 struct NotifyPointerCaptureChangedArgs {
192     int32_t id;
193     nsecs_t eventTime;
194 
195     PointerCaptureRequest request;
196 
NotifyPointerCaptureChangedArgsNotifyPointerCaptureChangedArgs197     inline NotifyPointerCaptureChangedArgs() {}
198 
199     NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
200 
201     NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
202     NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default;
203 };
204 
205 /* Describes a vibrator state event. */
206 struct NotifyVibratorStateArgs {
207     int32_t id;
208     nsecs_t eventTime;
209 
210     int32_t deviceId;
211     bool isOn;
212 
NotifyVibratorStateArgsNotifyVibratorStateArgs213     inline NotifyVibratorStateArgs() {}
214 
215     NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
216 
217     NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
218     NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default;
219 };
220 
221 using NotifyArgs =
222         std::variant<NotifyInputDevicesChangedArgs, NotifyKeyArgs, NotifyMotionArgs,
223                      NotifySensorArgs, NotifySwitchArgs, NotifyDeviceResetArgs,
224                      NotifyPointerCaptureChangedArgs, NotifyVibratorStateArgs>;
225 
226 const char* toString(const NotifyArgs& args);
227 
228 } // namespace android
229