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