blob: b26a194a0e00404b917f1f2e5073e9b519c4f8a2 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 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
Prabir Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Jeff Brown5912f952013-07-01 19:10:31 -070018
Robert Carr2c358bf2018-08-08 15:58:15 -070019#pragma GCC system_header
20
Jeff Brown5912f952013-07-01 19:10:31 -070021/**
22 * Native input transport.
23 *
24 * The InputChannel provides a mechanism for exchanging InputMessage structures across processes.
25 *
26 * The InputPublisher and InputConsumer each handle one end-point of an input channel.
27 * The InputPublisher is used by the input dispatcher to send events to the application.
28 * The InputConsumer is used by the application to receive events from the input dispatcher.
29 */
30
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010031#include <string>
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -100032#include <unordered_map>
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010033
Atif Niyaz3d3fa522019-07-25 11:12:39 -070034#include <android-base/chrono_utils.h>
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +000035#include <android-base/result.h>
Siarhei Vishniakou38b7f7f2021-03-05 01:57:08 +000036#include <android-base/unique_fd.h>
Atif Niyaz3d3fa522019-07-25 11:12:39 -070037
Siarhei Vishniakou8d660132024-01-11 16:48:44 -080038#include <android/os/InputChannelCore.h>
Robert Carr803535b2018-08-02 16:38:15 -070039#include <binder/IBinder.h>
Jeff Brown5912f952013-07-01 19:10:31 -070040#include <input/Input.h>
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -080041#include <input/InputVerifier.h>
Chris Ye0783e992020-06-02 21:34:49 -070042#include <sys/stat.h>
chaviw9eaa22c2020-07-01 16:21:27 -070043#include <ui/Transform.h>
Jeff Brown5912f952013-07-01 19:10:31 -070044#include <utils/BitSet.h>
Atif Niyaz3d3fa522019-07-25 11:12:39 -070045#include <utils/Errors.h>
Atif Niyaz3d3fa522019-07-25 11:12:39 -070046#include <utils/Timers.h>
Jeff Brown5912f952013-07-01 19:10:31 -070047
48namespace android {
Robert Carr3720ed02018-08-08 16:08:27 -070049class Parcel;
Jeff Brown5912f952013-07-01 19:10:31 -070050
51/*
52 * Intermediate representation used to send input events and related signals.
Fengwei Yin83e0e422014-05-24 05:32:09 +080053 *
54 * Note that this structure is used for IPCs so its layout must be identical
55 * on 64 and 32 bit processes. This is tested in StructLayout_test.cpp.
Siarhei Vishniakou1f7c0e42018-11-16 22:18:53 -080056 *
57 * Since the struct must be aligned to an 8-byte boundary, there could be uninitialized bytes
58 * in-between the defined fields. This padding data should be explicitly accounted for by adding
59 * "empty" fields into the struct. This data is memset to zero before sending the struct across
60 * the socket. Adding the explicit fields ensures that the memset is not optimized away by the
61 * compiler. When a new field is added to the struct, the corresponding change
62 * in StructLayout_test should be made.
Jeff Brown5912f952013-07-01 19:10:31 -070063 */
64struct InputMessage {
Siarhei Vishniakou52402772019-10-22 09:32:30 -070065 enum class Type : uint32_t {
66 KEY,
67 MOTION,
68 FINISHED,
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -080069 FOCUS,
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -080070 CAPTURE,
arthurhung7632c332020-12-30 16:58:01 +080071 DRAG,
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +000072 TIMELINE,
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -070073 TOUCH_MODE,
Dominik Laskowski75788452021-02-09 18:51:25 -080074
75 ftl_last = TOUCH_MODE
Jeff Brown5912f952013-07-01 19:10:31 -070076 };
77
78 struct Header {
Siarhei Vishniakou52402772019-10-22 09:32:30 -070079 Type type; // 4 bytes
Siarhei Vishniakoua64c1592020-06-22 12:02:29 -050080 uint32_t seq;
Jeff Brown5912f952013-07-01 19:10:31 -070081 } header;
82
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060083 // For keys and motions, rely on the fact that std::array takes up exactly as much space
84 // as the underlying data. This is not guaranteed by C++, but it simplifies the conversions.
85 static_assert(sizeof(std::array<uint8_t, 32>) == 32);
Siarhei Vishniakou38b7f7f2021-03-05 01:57:08 +000086
87 // For bool values, rely on the fact that they take up exactly one byte. This is not guaranteed
88 // by C++ and is implementation-dependent, but it simplifies the conversions.
89 static_assert(sizeof(bool) == 1);
90
91 // Body *must* be 8 byte aligned.
Jeff Brown5912f952013-07-01 19:10:31 -070092 union Body {
93 struct Key {
Garfield Tan1c7bc862020-01-28 13:24:04 -080094 int32_t eventId;
Siarhei Vishniakoua64c1592020-06-22 12:02:29 -050095 uint32_t empty1;
Fengwei Yin83e0e422014-05-24 05:32:09 +080096 nsecs_t eventTime __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -070097 int32_t deviceId;
98 int32_t source;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010099 int32_t displayId;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600100 std::array<uint8_t, 32> hmac;
Jeff Brown5912f952013-07-01 19:10:31 -0700101 int32_t action;
102 int32_t flags;
103 int32_t keyCode;
104 int32_t scanCode;
105 int32_t metaState;
106 int32_t repeatCount;
Siarhei Vishniakou1f7c0e42018-11-16 22:18:53 -0800107 uint32_t empty2;
Fengwei Yin83e0e422014-05-24 05:32:09 +0800108 nsecs_t downTime __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700109
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800110 inline size_t size() const { return sizeof(Key); }
Jeff Brown5912f952013-07-01 19:10:31 -0700111 } key;
112
113 struct Motion {
Garfield Tan1c7bc862020-01-28 13:24:04 -0800114 int32_t eventId;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700115 uint32_t pointerCount;
Fengwei Yin83e0e422014-05-24 05:32:09 +0800116 nsecs_t eventTime __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700117 int32_t deviceId;
118 int32_t source;
Tarandeep Singh58641502017-07-31 10:51:54 -0700119 int32_t displayId;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600120 std::array<uint8_t, 32> hmac;
Jeff Brown5912f952013-07-01 19:10:31 -0700121 int32_t action;
Michael Wright7b159c92015-05-14 14:48:03 +0100122 int32_t actionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700123 int32_t flags;
124 int32_t metaState;
125 int32_t buttonState;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800126 MotionClassification classification; // base type: uint8_t
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800127 uint8_t empty2[3]; // 3 bytes to fill gap created by classification
Jeff Brown5912f952013-07-01 19:10:31 -0700128 int32_t edgeFlags;
Fengwei Yin83e0e422014-05-24 05:32:09 +0800129 nsecs_t downTime __attribute__((aligned(8)));
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700130 float dsdx; // Begin window transform
131 float dtdx; //
132 float dtdy; //
133 float dsdy; //
134 float tx; //
135 float ty; // End window transform
Jeff Brown5912f952013-07-01 19:10:31 -0700136 float xPrecision;
137 float yPrecision;
Garfield Tan00f511d2019-06-12 16:55:40 -0700138 float xCursorPosition;
139 float yCursorPosition;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700140 float dsdxRaw; // Begin raw transform
141 float dtdxRaw; //
142 float dtdyRaw; //
143 float dsdyRaw; //
144 float txRaw; //
145 float tyRaw; // End raw transform
Siarhei Vishniakou10fe6762019-11-25 11:44:11 -0800146 /**
147 * The "pointers" field must be the last field of the struct InputMessage.
148 * When we send the struct InputMessage across the socket, we are not
149 * writing the entire "pointers" array, but only the pointerCount portion
150 * of it as an optimization. Adding a field after "pointers" would break this.
151 */
Michael Wrightb03f1032015-05-14 16:29:13 +0100152 struct Pointer {
Jeff Brown5912f952013-07-01 19:10:31 -0700153 PointerProperties properties;
154 PointerCoords coords;
Siarhei Vishniakou10fe6762019-11-25 11:44:11 -0800155 } pointers[MAX_POINTERS] __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700156
157 int32_t getActionId() const {
158 uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
159 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
160 return pointers[index].properties.id;
161 }
162
163 inline size_t size() const {
164 return sizeof(Motion) - sizeof(Pointer) * MAX_POINTERS
165 + sizeof(Pointer) * pointerCount;
166 }
167 } motion;
168
169 struct Finished {
Siarhei Vishniakou38b7f7f2021-03-05 01:57:08 +0000170 bool handled;
171 uint8_t empty[7];
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000172 nsecs_t consumeTime; // The time when the event was consumed by the receiving end
Jeff Brown5912f952013-07-01 19:10:31 -0700173
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800174 inline size_t size() const { return sizeof(Finished); }
Jeff Brown5912f952013-07-01 19:10:31 -0700175 } finished;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800176
177 struct Focus {
Garfield Tan1c7bc862020-01-28 13:24:04 -0800178 int32_t eventId;
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700179 // The following 2 fields take up 4 bytes total
Siarhei Vishniakou38b7f7f2021-03-05 01:57:08 +0000180 bool hasFocus;
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700181 uint8_t empty[3];
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800182
183 inline size_t size() const { return sizeof(Focus); }
184 } focus;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800185
186 struct Capture {
187 int32_t eventId;
Siarhei Vishniakou38b7f7f2021-03-05 01:57:08 +0000188 bool pointerCaptureEnabled;
189 uint8_t empty[3];
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800190
191 inline size_t size() const { return sizeof(Capture); }
192 } capture;
arthurhung7632c332020-12-30 16:58:01 +0800193
194 struct Drag {
195 int32_t eventId;
196 float x;
197 float y;
198 bool isExiting;
199 uint8_t empty[3];
200
201 inline size_t size() const { return sizeof(Drag); }
202 } drag;
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000203
204 struct Timeline {
205 int32_t eventId;
206 uint32_t empty;
207 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
208
209 inline size_t size() const { return sizeof(Timeline); }
210 } timeline;
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700211
212 struct TouchMode {
213 int32_t eventId;
214 // The following 2 fields take up 4 bytes total
215 bool isInTouchMode;
216 uint8_t empty[3];
217
218 inline size_t size() const { return sizeof(TouchMode); }
219 } touchMode;
Fengwei Yin83e0e422014-05-24 05:32:09 +0800220 } __attribute__((aligned(8))) body;
Jeff Brown5912f952013-07-01 19:10:31 -0700221
222 bool isValid(size_t actualSize) const;
223 size_t size() const;
Siarhei Vishniakou1f7c0e42018-11-16 22:18:53 -0800224 void getSanitizedCopy(InputMessage* msg) const;
Jeff Brown5912f952013-07-01 19:10:31 -0700225};
226
227/*
228 * An input channel consists of a local unix domain socket used to send and receive
229 * input messages across processes. Each channel has a descriptive name for debugging purposes.
230 *
231 * Each endpoint has its own InputChannel object that specifies its file descriptor.
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800232 * For parceling, this relies on android::os::InputChannelCore, defined in aidl.
Jeff Brown5912f952013-07-01 19:10:31 -0700233 *
234 * The input channel is closed when all references to it are released.
235 */
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800236class InputChannel : private android::os::InputChannelCore {
Chris Ye0783e992020-06-02 21:34:49 -0700237public:
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800238 static std::unique_ptr<InputChannel> create(android::os::InputChannelCore&& parceledChannel);
239 ~InputChannel();
240
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700241 /**
242 * Create a pair of input channels.
243 * The two returned input channels are equivalent, and are labeled as "server" and "client"
244 * for convenience. The two input channels share the same token.
Jeff Brown5912f952013-07-01 19:10:31 -0700245 *
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700246 * Return OK on success.
Jeff Brown5912f952013-07-01 19:10:31 -0700247 */
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800248 static status_t openInputChannelPair(const std::string& name,
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500249 std::unique_ptr<InputChannel>& outServerChannel,
250 std::unique_ptr<InputChannel>& outClientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -0700251
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800252 inline std::string getName() const { return name; }
253 inline int getFd() const { return fd.get(); }
Jeff Brown5912f952013-07-01 19:10:31 -0700254
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700255 /* Send a message to the other endpoint.
Jeff Brown5912f952013-07-01 19:10:31 -0700256 *
257 * If the channel is full then the message is guaranteed not to have been sent at all.
258 * Try again after the consumer has sent a finished signal indicating that it has
259 * consumed some of the pending messages from the channel.
260 *
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700261 * Return OK on success.
262 * Return WOULD_BLOCK if the channel is full.
263 * Return DEAD_OBJECT if the channel's peer has been closed.
Jeff Brown5912f952013-07-01 19:10:31 -0700264 * Other errors probably indicate that the channel is broken.
265 */
266 status_t sendMessage(const InputMessage* msg);
267
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700268 /* Receive a message sent by the other endpoint.
Jeff Brown5912f952013-07-01 19:10:31 -0700269 *
270 * If there is no message present, try again after poll() indicates that the fd
271 * is readable.
272 *
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700273 * Return OK on success.
274 * Return WOULD_BLOCK if there is no message present.
275 * Return DEAD_OBJECT if the channel's peer has been closed.
Jeff Brown5912f952013-07-01 19:10:31 -0700276 * Other errors probably indicate that the channel is broken.
277 */
Paul Ramirez10bae112024-06-18 21:33:33 +0000278 android::base::Result<InputMessage> receiveMessage();
Jeff Brown5912f952013-07-01 19:10:31 -0700279
Egor Paskoa0d32af2023-12-14 17:45:41 +0100280 /* Tells whether there is a message in the channel available to be received.
281 *
282 * This is only a performance hint and may return false negative results. Clients should not
283 * rely on availability of the message based on the return value.
284 */
285 bool probablyHasInput() const;
286
Egor Pasko5a67a562024-01-16 16:46:45 +0100287 /* Wait until there is a message in the channel.
288 *
289 * The |timeout| specifies how long to block waiting for an input event to appear. Negative
290 * values are not allowed.
291 *
292 * In some cases returning before timeout expiration can happen without a message available.
293 * This could happen after the channel was closed on the other side. Another possible reason
294 * is incorrect setup of the channel.
295 */
296 void waitForMessage(std::chrono::milliseconds timeout) const;
297
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700298 /* Return a new object that has a duplicate of this channel's fd. */
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500299 std::unique_ptr<InputChannel> dup() const;
Jeff Brown5912f952013-07-01 19:10:31 -0700300
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800301 void copyTo(android::os::InputChannelCore& outChannel) const;
Robert Carr3720ed02018-08-08 16:08:27 -0700302
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700303 /**
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800304 * Similar to "copyTo", but it takes ownership of the provided InputChannel (and after this is
305 * called, it destroys it).
306 * @param from the InputChannel that should be converted to InputChannelCore
307 * @param outChannel the pre-allocated InputChannelCore to which to transfer the 'from' channel
308 */
309 static void moveChannel(std::unique_ptr<InputChannel> from,
310 android::os::InputChannelCore& outChannel);
311
312 /**
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700313 * The connection token is used to identify the input connection, i.e.
314 * the pair of input channels that were created simultaneously. Input channels
315 * are always created in pairs, and the token can be used to find the server-side
316 * input channel from the client-side input channel, and vice versa.
317 *
318 * Do not use connection token to check equality of a specific input channel object
319 * to another, because two different (client and server) input channels will share the
320 * same connection token.
321 *
322 * Return the token that identifies this connection.
323 */
324 sp<IBinder> getConnectionToken() const;
Robert Carr803535b2018-08-02 16:38:15 -0700325
Jeff Brown5912f952013-07-01 19:10:31 -0700326private:
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800327 static std::unique_ptr<InputChannel> create(const std::string& name,
328 android::base::unique_fd fd, sp<IBinder> token);
Garfield Tan15601662020-09-22 15:32:38 -0700329
Siarhei Vishniakou8d660132024-01-11 16:48:44 -0800330 InputChannel(const std::string name, android::base::unique_fd fd, sp<IBinder> token);
Jeff Brown5912f952013-07-01 19:10:31 -0700331};
332
333/*
334 * Publishes input events to an input channel.
335 */
336class InputPublisher {
337public:
338 /* Creates a publisher associated with an input channel. */
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500339 explicit InputPublisher(const std::shared_ptr<InputChannel>& channel);
Jeff Brown5912f952013-07-01 19:10:31 -0700340
341 /* Destroys the publisher and releases its input channel. */
342 ~InputPublisher();
343
344 /* Gets the underlying input channel. */
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800345 inline InputChannel& getChannel() const { return *mChannel; }
Jeff Brown5912f952013-07-01 19:10:31 -0700346
347 /* Publishes a key event to the input channel.
348 *
349 * Returns OK on success.
350 * Returns WOULD_BLOCK if the channel is full.
351 * Returns DEAD_OBJECT if the channel's peer has been closed.
352 * Returns BAD_VALUE if seq is 0.
353 * Other errors probably indicate that the channel is broken.
354 */
Garfield Tan1c7bc862020-01-28 13:24:04 -0800355 status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source,
Linnan Li13bf76a2024-05-05 19:18:02 +0800356 ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac,
357 int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
358 int32_t metaState, int32_t repeatCount, nsecs_t downTime,
359 nsecs_t eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700360
361 /* Publishes a motion event to the input channel.
362 *
363 * Returns OK on success.
364 * Returns WOULD_BLOCK if the channel is full.
365 * Returns DEAD_OBJECT if the channel's peer has been closed.
366 * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS.
367 * Other errors probably indicate that the channel is broken.
368 */
Garfield Tan1c7bc862020-01-28 13:24:04 -0800369 status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source,
Linnan Li13bf76a2024-05-05 19:18:02 +0800370 ui::LogicalDisplayId displayId, std::array<uint8_t, 32> hmac,
371 int32_t action, int32_t actionButton, int32_t flags,
372 int32_t edgeFlags, int32_t metaState, int32_t buttonState,
chaviw9eaa22c2020-07-01 16:21:27 -0700373 MotionClassification classification, const ui::Transform& transform,
374 float xPrecision, float yPrecision, float xCursorPosition,
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700375 float yCursorPosition, const ui::Transform& rawTransform,
376 nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount,
Evan Rosky84f07f02021-04-16 10:42:42 -0700377 const PointerProperties* pointerProperties,
Garfield Tan00f511d2019-06-12 16:55:40 -0700378 const PointerCoords* pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700379
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800380 /* Publishes a focus event to the input channel.
381 *
382 * Returns OK on success.
383 * Returns WOULD_BLOCK if the channel is full.
384 * Returns DEAD_OBJECT if the channel's peer has been closed.
385 * Other errors probably indicate that the channel is broken.
386 */
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700387 status_t publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800388
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800389 /* Publishes a capture event to the input channel.
390 *
391 * Returns OK on success.
392 * Returns WOULD_BLOCK if the channel is full.
393 * Returns DEAD_OBJECT if the channel's peer has been closed.
394 * Other errors probably indicate that the channel is broken.
395 */
396 status_t publishCaptureEvent(uint32_t seq, int32_t eventId, bool pointerCaptureEnabled);
397
arthurhung7632c332020-12-30 16:58:01 +0800398 /* Publishes a drag event to the input channel.
399 *
400 * Returns OK on success.
401 * Returns WOULD_BLOCK if the channel is full.
402 * Returns DEAD_OBJECT if the channel's peer has been closed.
403 * Other errors probably indicate that the channel is broken.
404 */
405 status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting);
406
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700407 /* Publishes a touch mode event to the input channel.
408 *
409 * Returns OK on success.
410 * Returns WOULD_BLOCK if the channel is full.
411 * Returns DEAD_OBJECT if the channel's peer has been closed.
412 * Other errors probably indicate that the channel is broken.
413 */
414 status_t publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode);
415
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000416 struct Finished {
417 uint32_t seq;
418 bool handled;
419 nsecs_t consumeTime;
420 };
421
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000422 struct Timeline {
423 int32_t inputEventId;
424 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
425 };
426
427 typedef std::variant<Finished, Timeline> ConsumerResponse;
428 /* Receive a signal from the consumer in reply to the original dispatch signal.
429 * If a signal was received, returns a Finished or a Timeline object.
430 * The InputConsumer should return a Finished object for every InputMessage that it is sent
431 * to confirm that it has been processed and that the InputConsumer is responsive.
432 * If several InputMessages are sent to InputConsumer, it's possible to receive Finished
433 * events out of order for those messages.
Jeff Brown5912f952013-07-01 19:10:31 -0700434 *
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000435 * The Timeline object is returned whenever the receiving end has processed a graphical frame
436 * and is returning the timeline of the frame. Not all input events will cause a Timeline
437 * object to be returned, and there is not guarantee about when it will arrive.
438 *
439 * If an object of Finished is returned, the returned sequence number is never 0 unless the
440 * operation failed.
Jeff Brown5912f952013-07-01 19:10:31 -0700441 *
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000442 * Returned error codes:
443 * OK on success.
444 * WOULD_BLOCK if there is no signal present.
445 * DEAD_OBJECT if the channel's peer has been closed.
446 * Other errors probably indicate that the channel is broken.
Jeff Brown5912f952013-07-01 19:10:31 -0700447 */
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000448 android::base::Result<ConsumerResponse> receiveConsumerResponse();
Jeff Brown5912f952013-07-01 19:10:31 -0700449
450private:
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500451 std::shared_ptr<InputChannel> mChannel;
Siarhei Vishniakou92c8fd52023-01-29 14:57:43 -0800452 InputVerifier mInputVerifier;
Jeff Brown5912f952013-07-01 19:10:31 -0700453};
454
Jeff Brown5912f952013-07-01 19:10:31 -0700455} // namespace android