| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 17 | #ifndef _LIBINPUT_INPUT_TRANSPORT_H | 
|  | 18 | #define _LIBINPUT_INPUT_TRANSPORT_H | 
|  | 19 |  | 
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 20 | #pragma GCC system_header | 
|  | 21 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 22 | /** | 
|  | 23 | * Native input transport. | 
|  | 24 | * | 
|  | 25 | * The InputChannel provides a mechanism for exchanging InputMessage structures across processes. | 
|  | 26 | * | 
|  | 27 | * The InputPublisher and InputConsumer each handle one end-point of an input channel. | 
|  | 28 | * The InputPublisher is used by the input dispatcher to send events to the application. | 
|  | 29 | * The InputConsumer is used by the application to receive events from the input dispatcher. | 
|  | 30 | */ | 
|  | 31 |  | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 32 | #include <string> | 
|  | 33 |  | 
| Atif Niyaz | 3d3fa52 | 2019-07-25 11:12:39 -0700 | [diff] [blame] | 34 | #include <android-base/chrono_utils.h> | 
|  | 35 |  | 
| Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 36 | #include <binder/IBinder.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 37 | #include <binder/Parcelable.h> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 38 | #include <input/Input.h> | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | #include <sys/stat.h> | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 40 | #include <ui/Transform.h> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 41 | #include <utils/BitSet.h> | 
| Atif Niyaz | 3d3fa52 | 2019-07-25 11:12:39 -0700 | [diff] [blame] | 42 | #include <utils/Errors.h> | 
|  | 43 | #include <utils/RefBase.h> | 
|  | 44 | #include <utils/Timers.h> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 45 |  | 
| Josh Gao | 2ccbe3a | 2019-08-09 14:35:36 -0700 | [diff] [blame] | 46 | #include <android-base/unique_fd.h> | 
|  | 47 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 48 | namespace android { | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 49 | class Parcel; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 50 |  | 
|  | 51 | /* | 
|  | 52 | * Intermediate representation used to send input events and related signals. | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 53 | * | 
|  | 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 Vishniakou | 1f7c0e4 | 2018-11-16 22:18:53 -0800 | [diff] [blame] | 56 | * | 
|  | 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 Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 63 | */ | 
|  | 64 | struct InputMessage { | 
| Siarhei Vishniakou | 5240277 | 2019-10-22 09:32:30 -0700 | [diff] [blame] | 65 | enum class Type : uint32_t { | 
|  | 66 | KEY, | 
|  | 67 | MOTION, | 
|  | 68 | FINISHED, | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 69 | FOCUS, | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 70 | }; | 
|  | 71 |  | 
|  | 72 | struct Header { | 
| Siarhei Vishniakou | 5240277 | 2019-10-22 09:32:30 -0700 | [diff] [blame] | 73 | Type type; // 4 bytes | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 74 | uint32_t seq; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 75 | } header; | 
|  | 76 |  | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 77 | // Body *must* be 8 byte aligned. | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 78 | // For keys and motions, rely on the fact that std::array takes up exactly as much space | 
|  | 79 | // as the underlying data. This is not guaranteed by C++, but it simplifies the conversions. | 
|  | 80 | static_assert(sizeof(std::array<uint8_t, 32>) == 32); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 81 | union Body { | 
|  | 82 | struct Key { | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 83 | int32_t eventId; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 84 | uint32_t empty1; | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 85 | nsecs_t eventTime __attribute__((aligned(8))); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 86 | int32_t deviceId; | 
|  | 87 | int32_t source; | 
| Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 88 | int32_t displayId; | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 89 | std::array<uint8_t, 32> hmac; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 90 | int32_t action; | 
|  | 91 | int32_t flags; | 
|  | 92 | int32_t keyCode; | 
|  | 93 | int32_t scanCode; | 
|  | 94 | int32_t metaState; | 
|  | 95 | int32_t repeatCount; | 
| Siarhei Vishniakou | 1f7c0e4 | 2018-11-16 22:18:53 -0800 | [diff] [blame] | 96 | uint32_t empty2; | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 97 | nsecs_t downTime __attribute__((aligned(8))); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 98 |  | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 99 | inline size_t size() const { return sizeof(Key); } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 100 | } key; | 
|  | 101 |  | 
|  | 102 | struct Motion { | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 103 | int32_t eventId; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 104 | uint32_t empty1; | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 105 | nsecs_t eventTime __attribute__((aligned(8))); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 106 | int32_t deviceId; | 
|  | 107 | int32_t source; | 
| Tarandeep Singh | 5864150 | 2017-07-31 10:51:54 -0700 | [diff] [blame] | 108 | int32_t displayId; | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 109 | std::array<uint8_t, 32> hmac; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 110 | int32_t action; | 
| Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 111 | int32_t actionButton; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 112 | int32_t flags; | 
|  | 113 | int32_t metaState; | 
|  | 114 | int32_t buttonState; | 
| Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame] | 115 | MotionClassification classification; // base type: uint8_t | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 116 | uint8_t empty2[3];                   // 3 bytes to fill gap created by classification | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 117 | int32_t edgeFlags; | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 118 | nsecs_t downTime __attribute__((aligned(8))); | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 119 | float dsdx; | 
|  | 120 | float dtdx; | 
|  | 121 | float dtdy; | 
|  | 122 | float dsdy; | 
|  | 123 | float tx; | 
|  | 124 | float ty; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 125 | float xPrecision; | 
|  | 126 | float yPrecision; | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 127 | float xCursorPosition; | 
|  | 128 | float yCursorPosition; | 
| Narayan Kamath | ed5fd38 | 2014-05-02 17:53:33 +0100 | [diff] [blame] | 129 | uint32_t pointerCount; | 
| Siarhei Vishniakou | 1f7c0e4 | 2018-11-16 22:18:53 -0800 | [diff] [blame] | 130 | uint32_t empty3; | 
| Siarhei Vishniakou | 10fe676 | 2019-11-25 11:44:11 -0800 | [diff] [blame] | 131 | /** | 
|  | 132 | * The "pointers" field must be the last field of the struct InputMessage. | 
|  | 133 | * When we send the struct InputMessage across the socket, we are not | 
|  | 134 | * writing the entire "pointers" array, but only the pointerCount portion | 
|  | 135 | * of it as an optimization. Adding a field after "pointers" would break this. | 
|  | 136 | */ | 
| Michael Wright | b03f103 | 2015-05-14 16:29:13 +0100 | [diff] [blame] | 137 | struct Pointer { | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 138 | PointerProperties properties; | 
|  | 139 | PointerCoords coords; | 
| Siarhei Vishniakou | 10fe676 | 2019-11-25 11:44:11 -0800 | [diff] [blame] | 140 | } pointers[MAX_POINTERS] __attribute__((aligned(8))); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 141 |  | 
|  | 142 | int32_t getActionId() const { | 
|  | 143 | uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) | 
|  | 144 | >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; | 
|  | 145 | return pointers[index].properties.id; | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | inline size_t size() const { | 
|  | 149 | return sizeof(Motion) - sizeof(Pointer) * MAX_POINTERS | 
|  | 150 | + sizeof(Pointer) * pointerCount; | 
|  | 151 | } | 
|  | 152 | } motion; | 
|  | 153 |  | 
|  | 154 | struct Finished { | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 155 | uint32_t empty1; | 
| Siarhei Vishniakou | 10fe676 | 2019-11-25 11:44:11 -0800 | [diff] [blame] | 156 | uint32_t handled; // actually a bool, but we must maintain 8-byte alignment | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 157 |  | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 158 | inline size_t size() const { return sizeof(Finished); } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 159 | } finished; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 160 |  | 
|  | 161 | struct Focus { | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 162 | int32_t eventId; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 163 | // The following two fields take up 4 bytes total | 
|  | 164 | uint16_t hasFocus;    // actually a bool | 
|  | 165 | uint16_t inTouchMode; // actually a bool, but we must maintain 8-byte alignment | 
|  | 166 |  | 
|  | 167 | inline size_t size() const { return sizeof(Focus); } | 
|  | 168 | } focus; | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 169 | } __attribute__((aligned(8))) body; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 170 |  | 
|  | 171 | bool isValid(size_t actualSize) const; | 
|  | 172 | size_t size() const; | 
| Siarhei Vishniakou | 1f7c0e4 | 2018-11-16 22:18:53 -0800 | [diff] [blame] | 173 | void getSanitizedCopy(InputMessage* msg) const; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 174 |  | 
|  | 175 | static const char* typeToString(Type type) { | 
|  | 176 | switch (type) { | 
|  | 177 | case Type::KEY: | 
|  | 178 | return "KEY"; | 
|  | 179 | case Type::MOTION: | 
|  | 180 | return "MOTION"; | 
|  | 181 | case Type::FINISHED: | 
|  | 182 | return "FINISHED"; | 
|  | 183 | case Type::FOCUS: | 
|  | 184 | return "FOCUS"; | 
|  | 185 | } | 
|  | 186 | } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 187 | }; | 
|  | 188 |  | 
|  | 189 | /* | 
|  | 190 | * An input channel consists of a local unix domain socket used to send and receive | 
|  | 191 | * input messages across processes.  Each channel has a descriptive name for debugging purposes. | 
|  | 192 | * | 
|  | 193 | * Each endpoint has its own InputChannel object that specifies its file descriptor. | 
|  | 194 | * | 
|  | 195 | * The input channel is closed when all references to it are released. | 
|  | 196 | */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 197 | class InputChannel : public Parcelable { | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 198 | public: | 
| Siarhei Vishniakou | d258827 | 2020-07-10 11:15:40 -0500 | [diff] [blame] | 199 | static std::unique_ptr<InputChannel> create(const std::string& name, | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 200 | android::base::unique_fd fd, sp<IBinder> token); | 
|  | 201 | InputChannel() = default; | 
|  | 202 | InputChannel(const InputChannel& other) | 
|  | 203 | : mName(other.mName), mFd(::dup(other.mFd)), mToken(other.mToken){}; | 
|  | 204 | InputChannel(const std::string name, android::base::unique_fd fd, sp<IBinder> token); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 205 | virtual ~InputChannel(); | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 206 | /** | 
|  | 207 | * Create a pair of input channels. | 
|  | 208 | * The two returned input channels are equivalent, and are labeled as "server" and "client" | 
|  | 209 | * for convenience. The two input channels share the same token. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 210 | * | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 211 | * Return OK on success. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 212 | */ | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 213 | static status_t openInputChannelPair(const std::string& name, | 
| Siarhei Vishniakou | d258827 | 2020-07-10 11:15:40 -0500 | [diff] [blame] | 214 | std::unique_ptr<InputChannel>& outServerChannel, | 
|  | 215 | std::unique_ptr<InputChannel>& outClientChannel); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 216 |  | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 217 | inline std::string getName() const { return mName; } | 
|  | 218 | inline const android::base::unique_fd& getFd() const { return mFd; } | 
|  | 219 | inline sp<IBinder> getToken() const { return mToken; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 220 |  | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 221 | /* Send a message to the other endpoint. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 222 | * | 
|  | 223 | * If the channel is full then the message is guaranteed not to have been sent at all. | 
|  | 224 | * Try again after the consumer has sent a finished signal indicating that it has | 
|  | 225 | * consumed some of the pending messages from the channel. | 
|  | 226 | * | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 227 | * Return OK on success. | 
|  | 228 | * Return WOULD_BLOCK if the channel is full. | 
|  | 229 | * Return DEAD_OBJECT if the channel's peer has been closed. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 230 | * Other errors probably indicate that the channel is broken. | 
|  | 231 | */ | 
|  | 232 | status_t sendMessage(const InputMessage* msg); | 
|  | 233 |  | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 234 | /* Receive a message sent by the other endpoint. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 235 | * | 
|  | 236 | * If there is no message present, try again after poll() indicates that the fd | 
|  | 237 | * is readable. | 
|  | 238 | * | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 239 | * Return OK on success. | 
|  | 240 | * Return WOULD_BLOCK if there is no message present. | 
|  | 241 | * Return DEAD_OBJECT if the channel's peer has been closed. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 242 | * Other errors probably indicate that the channel is broken. | 
|  | 243 | */ | 
|  | 244 | status_t receiveMessage(InputMessage* msg); | 
|  | 245 |  | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 246 | /* Return a new object that has a duplicate of this channel's fd. */ | 
| Siarhei Vishniakou | d258827 | 2020-07-10 11:15:40 -0500 | [diff] [blame] | 247 | std::unique_ptr<InputChannel> dup() const; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 248 |  | 
| Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 249 | void copyTo(InputChannel& outChannel) const; | 
|  | 250 |  | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 251 | status_t readFromParcel(const android::Parcel* parcel) override; | 
|  | 252 | status_t writeToParcel(android::Parcel* parcel) const override; | 
| Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 253 |  | 
| Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 254 | /** | 
|  | 255 | * The connection token is used to identify the input connection, i.e. | 
|  | 256 | * the pair of input channels that were created simultaneously. Input channels | 
|  | 257 | * are always created in pairs, and the token can be used to find the server-side | 
|  | 258 | * input channel from the client-side input channel, and vice versa. | 
|  | 259 | * | 
|  | 260 | * Do not use connection token to check equality of a specific input channel object | 
|  | 261 | * to another, because two different (client and server) input channels will share the | 
|  | 262 | * same connection token. | 
|  | 263 | * | 
|  | 264 | * Return the token that identifies this connection. | 
|  | 265 | */ | 
|  | 266 | sp<IBinder> getConnectionToken() const; | 
| Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 267 |  | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 268 | bool operator==(const InputChannel& inputChannel) const { | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 269 | struct stat lhs, rhs; | 
|  | 270 | if (fstat(mFd.get(), &lhs) != 0) { | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 271 | return false; | 
|  | 272 | } | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 273 | if (fstat(inputChannel.getFd(), &rhs) != 0) { | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 274 | return false; | 
|  | 275 | } | 
|  | 276 | // If file descriptors are pointing to same inode they are duplicated fds. | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 277 | return inputChannel.getName() == getName() && inputChannel.getConnectionToken() == mToken && | 
|  | 278 | lhs.st_ino == rhs.st_ino; | 
| Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 279 | } | 
|  | 280 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 281 | private: | 
| Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 282 | base::unique_fd dupFd() const; | 
|  | 283 |  | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 284 | std::string mName; | 
|  | 285 | android::base::unique_fd mFd; | 
|  | 286 |  | 
|  | 287 | sp<IBinder> mToken; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 288 | }; | 
|  | 289 |  | 
|  | 290 | /* | 
|  | 291 | * Publishes input events to an input channel. | 
|  | 292 | */ | 
|  | 293 | class InputPublisher { | 
|  | 294 | public: | 
|  | 295 | /* Creates a publisher associated with an input channel. */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 296 | explicit InputPublisher(const std::shared_ptr<InputChannel>& channel); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 297 |  | 
|  | 298 | /* Destroys the publisher and releases its input channel. */ | 
|  | 299 | ~InputPublisher(); | 
|  | 300 |  | 
|  | 301 | /* Gets the underlying input channel. */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 302 | inline std::shared_ptr<InputChannel> getChannel() { return mChannel; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 303 |  | 
|  | 304 | /* Publishes a key event to the input channel. | 
|  | 305 | * | 
|  | 306 | * Returns OK on success. | 
|  | 307 | * Returns WOULD_BLOCK if the channel is full. | 
|  | 308 | * Returns DEAD_OBJECT if the channel's peer has been closed. | 
|  | 309 | * Returns BAD_VALUE if seq is 0. | 
|  | 310 | * Other errors probably indicate that the channel is broken. | 
|  | 311 | */ | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 312 | status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, | 
|  | 313 | int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, | 
|  | 314 | int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 315 | int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 316 |  | 
|  | 317 | /* Publishes a motion event to the input channel. | 
|  | 318 | * | 
|  | 319 | * Returns OK on success. | 
|  | 320 | * Returns WOULD_BLOCK if the channel is full. | 
|  | 321 | * Returns DEAD_OBJECT if the channel's peer has been closed. | 
|  | 322 | * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS. | 
|  | 323 | * Other errors probably indicate that the channel is broken. | 
|  | 324 | */ | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 325 | status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, | 
|  | 326 | int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, | 
|  | 327 | int32_t actionButton, int32_t flags, int32_t edgeFlags, | 
|  | 328 | int32_t metaState, int32_t buttonState, | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 329 | MotionClassification classification, const ui::Transform& transform, | 
|  | 330 | float xPrecision, float yPrecision, float xCursorPosition, | 
|  | 331 | float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, | 
|  | 332 | uint32_t pointerCount, const PointerProperties* pointerProperties, | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 333 | const PointerCoords* pointerCoords); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 334 |  | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 335 | /* Publishes a focus event to the input channel. | 
|  | 336 | * | 
|  | 337 | * Returns OK on success. | 
|  | 338 | * Returns WOULD_BLOCK if the channel is full. | 
|  | 339 | * Returns DEAD_OBJECT if the channel's peer has been closed. | 
|  | 340 | * Other errors probably indicate that the channel is broken. | 
|  | 341 | */ | 
| Garfield Tan | 1c7bc86 | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 342 | status_t publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus, bool inTouchMode); | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 343 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 344 | /* Receives the finished signal from the consumer in reply to the original dispatch signal. | 
|  | 345 | * If a signal was received, returns the message sequence number, | 
|  | 346 | * and whether the consumer handled the message. | 
|  | 347 | * | 
|  | 348 | * The returned sequence number is never 0 unless the operation failed. | 
|  | 349 | * | 
|  | 350 | * Returns OK on success. | 
|  | 351 | * Returns WOULD_BLOCK if there is no signal present. | 
|  | 352 | * Returns DEAD_OBJECT if the channel's peer has been closed. | 
|  | 353 | * Other errors probably indicate that the channel is broken. | 
|  | 354 | */ | 
|  | 355 | status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled); | 
|  | 356 |  | 
|  | 357 | private: | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 358 | std::shared_ptr<InputChannel> mChannel; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 359 | }; | 
|  | 360 |  | 
|  | 361 | /* | 
|  | 362 | * Consumes input events from an input channel. | 
|  | 363 | */ | 
|  | 364 | class InputConsumer { | 
|  | 365 | public: | 
|  | 366 | /* Creates a consumer associated with an input channel. */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 367 | explicit InputConsumer(const std::shared_ptr<InputChannel>& channel); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 368 |  | 
|  | 369 | /* Destroys the consumer and releases its input channel. */ | 
|  | 370 | ~InputConsumer(); | 
|  | 371 |  | 
|  | 372 | /* Gets the underlying input channel. */ | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 373 | inline std::shared_ptr<InputChannel> getChannel() { return mChannel; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 374 |  | 
|  | 375 | /* Consumes an input event from the input channel and copies its contents into | 
|  | 376 | * an InputEvent object created using the specified factory. | 
|  | 377 | * | 
|  | 378 | * Tries to combine a series of move events into larger batches whenever possible. | 
|  | 379 | * | 
|  | 380 | * If consumeBatches is false, then defers consuming pending batched events if it | 
|  | 381 | * is possible for additional samples to be added to them later.  Call hasPendingBatch() | 
|  | 382 | * to determine whether a pending batch is available to be consumed. | 
|  | 383 | * | 
|  | 384 | * If consumeBatches is true, then events are still batched but they are consumed | 
|  | 385 | * immediately as soon as the input channel is exhausted. | 
|  | 386 | * | 
|  | 387 | * The frameTime parameter specifies the time when the current display frame started | 
|  | 388 | * rendering in the CLOCK_MONOTONIC time base, or -1 if unknown. | 
|  | 389 | * | 
|  | 390 | * The returned sequence number is never 0 unless the operation failed. | 
|  | 391 | * | 
|  | 392 | * Returns OK on success. | 
|  | 393 | * Returns WOULD_BLOCK if there is no event present. | 
|  | 394 | * Returns DEAD_OBJECT if the channel's peer has been closed. | 
|  | 395 | * Returns NO_MEMORY if the event could not be created. | 
|  | 396 | * Other errors probably indicate that the channel is broken. | 
|  | 397 | */ | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 398 | status_t consume(InputEventFactoryInterface* factory, bool consumeBatches, nsecs_t frameTime, | 
|  | 399 | uint32_t* outSeq, InputEvent** outEvent); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 400 |  | 
|  | 401 | /* Sends a finished signal to the publisher to inform it that the message | 
|  | 402 | * with the specified sequence number has finished being process and whether | 
|  | 403 | * the message was handled by the consumer. | 
|  | 404 | * | 
|  | 405 | * Returns OK on success. | 
|  | 406 | * Returns BAD_VALUE if seq is 0. | 
|  | 407 | * Other errors probably indicate that the channel is broken. | 
|  | 408 | */ | 
|  | 409 | status_t sendFinishedSignal(uint32_t seq, bool handled); | 
|  | 410 |  | 
|  | 411 | /* Returns true if there is a deferred event waiting. | 
|  | 412 | * | 
|  | 413 | * Should be called after calling consume() to determine whether the consumer | 
|  | 414 | * has a deferred event to be processed.  Deferred events are somewhat special in | 
|  | 415 | * that they have already been removed from the input channel.  If the input channel | 
|  | 416 | * becomes empty, the client may need to do extra work to ensure that it processes | 
|  | 417 | * the deferred event despite the fact that the input channel's file descriptor | 
|  | 418 | * is not readable. | 
|  | 419 | * | 
|  | 420 | * One option is simply to call consume() in a loop until it returns WOULD_BLOCK. | 
|  | 421 | * This guarantees that all deferred events will be processed. | 
|  | 422 | * | 
|  | 423 | * Alternately, the caller can call hasDeferredEvent() to determine whether there is | 
|  | 424 | * a deferred event waiting and then ensure that its event loop wakes up at least | 
|  | 425 | * one more time to consume the deferred event. | 
|  | 426 | */ | 
|  | 427 | bool hasDeferredEvent() const; | 
|  | 428 |  | 
|  | 429 | /* Returns true if there is a pending batch. | 
|  | 430 | * | 
|  | 431 | * Should be called after calling consume() with consumeBatches == false to determine | 
|  | 432 | * whether consume() should be called again later on with consumeBatches == true. | 
|  | 433 | */ | 
|  | 434 | bool hasPendingBatch() const; | 
|  | 435 |  | 
| Arthur Hung | c7812be | 2020-02-27 22:40:27 +0800 | [diff] [blame] | 436 | /* Returns the source of first pending batch if exist. | 
|  | 437 | * | 
|  | 438 | * Should be called after calling consume() with consumeBatches == false to determine | 
|  | 439 | * whether consume() should be called again later on with consumeBatches == true. | 
|  | 440 | */ | 
|  | 441 | int32_t getPendingBatchSource() const; | 
|  | 442 |  | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 443 | std::string dump() const; | 
|  | 444 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 445 | private: | 
|  | 446 | // True if touch resampling is enabled. | 
|  | 447 | const bool mResampleTouch; | 
|  | 448 |  | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 449 | std::shared_ptr<InputChannel> mChannel; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 450 |  | 
|  | 451 | // The current input message. | 
|  | 452 | InputMessage mMsg; | 
|  | 453 |  | 
|  | 454 | // True if mMsg contains a valid input message that was deferred from the previous | 
|  | 455 | // call to consume and that still needs to be handled. | 
|  | 456 | bool mMsgDeferred; | 
|  | 457 |  | 
|  | 458 | // Batched motion events per device and source. | 
|  | 459 | struct Batch { | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 460 | std::vector<InputMessage> samples; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 461 | }; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 462 | std::vector<Batch> mBatches; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 463 |  | 
|  | 464 | // Touch state per device and source, only for sources of class pointer. | 
|  | 465 | struct History { | 
|  | 466 | nsecs_t eventTime; | 
|  | 467 | BitSet32 idBits; | 
|  | 468 | int32_t idToIndex[MAX_POINTER_ID + 1]; | 
|  | 469 | PointerCoords pointers[MAX_POINTERS]; | 
|  | 470 |  | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 471 | void initializeFrom(const InputMessage& msg) { | 
|  | 472 | eventTime = msg.body.motion.eventTime; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 473 | idBits.clear(); | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 474 | for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { | 
|  | 475 | uint32_t id = msg.body.motion.pointers[i].properties.id; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 476 | idBits.markBit(id); | 
|  | 477 | idToIndex[id] = i; | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 478 | pointers[i].copyFrom(msg.body.motion.pointers[i].coords); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 479 | } | 
|  | 480 | } | 
|  | 481 |  | 
| Siarhei Vishniakou | 56c9ae1 | 2017-11-06 21:16:47 -0800 | [diff] [blame] | 482 | void initializeFrom(const History& other) { | 
|  | 483 | eventTime = other.eventTime; | 
|  | 484 | idBits = other.idBits; // temporary copy | 
|  | 485 | for (size_t i = 0; i < other.idBits.count(); i++) { | 
|  | 486 | uint32_t id = idBits.clearFirstMarkedBit(); | 
|  | 487 | int32_t index = other.idToIndex[id]; | 
|  | 488 | idToIndex[id] = index; | 
|  | 489 | pointers[index].copyFrom(other.pointers[index]); | 
|  | 490 | } | 
|  | 491 | idBits = other.idBits; // final copy | 
|  | 492 | } | 
|  | 493 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 494 | const PointerCoords& getPointerById(uint32_t id) const { | 
|  | 495 | return pointers[idToIndex[id]]; | 
|  | 496 | } | 
| Siarhei Vishniakou | c7dc378 | 2017-08-24 20:36:28 -0700 | [diff] [blame] | 497 |  | 
|  | 498 | bool hasPointerId(uint32_t id) const { | 
|  | 499 | return idBits.hasBit(id); | 
|  | 500 | } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 501 | }; | 
|  | 502 | struct TouchState { | 
|  | 503 | int32_t deviceId; | 
|  | 504 | int32_t source; | 
|  | 505 | size_t historyCurrent; | 
|  | 506 | size_t historySize; | 
|  | 507 | History history[2]; | 
|  | 508 | History lastResample; | 
|  | 509 |  | 
|  | 510 | void initialize(int32_t deviceId, int32_t source) { | 
|  | 511 | this->deviceId = deviceId; | 
|  | 512 | this->source = source; | 
|  | 513 | historyCurrent = 0; | 
|  | 514 | historySize = 0; | 
|  | 515 | lastResample.eventTime = 0; | 
|  | 516 | lastResample.idBits.clear(); | 
|  | 517 | } | 
|  | 518 |  | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 519 | void addHistory(const InputMessage& msg) { | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 520 | historyCurrent ^= 1; | 
|  | 521 | if (historySize < 2) { | 
|  | 522 | historySize += 1; | 
|  | 523 | } | 
|  | 524 | history[historyCurrent].initializeFrom(msg); | 
|  | 525 | } | 
|  | 526 |  | 
|  | 527 | const History* getHistory(size_t index) const { | 
|  | 528 | return &history[(historyCurrent + index) & 1]; | 
|  | 529 | } | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 530 |  | 
|  | 531 | bool recentCoordinatesAreIdentical(uint32_t id) const { | 
|  | 532 | // Return true if the two most recently received "raw" coordinates are identical | 
|  | 533 | if (historySize < 2) { | 
|  | 534 | return false; | 
|  | 535 | } | 
| Siarhei Vishniakou | c7dc378 | 2017-08-24 20:36:28 -0700 | [diff] [blame] | 536 | if (!getHistory(0)->hasPointerId(id) || !getHistory(1)->hasPointerId(id)) { | 
|  | 537 | return false; | 
|  | 538 | } | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 539 | float currentX = getHistory(0)->getPointerById(id).getX(); | 
|  | 540 | float currentY = getHistory(0)->getPointerById(id).getY(); | 
|  | 541 | float previousX = getHistory(1)->getPointerById(id).getX(); | 
|  | 542 | float previousY = getHistory(1)->getPointerById(id).getY(); | 
|  | 543 | if (currentX == previousX && currentY == previousY) { | 
|  | 544 | return true; | 
|  | 545 | } | 
|  | 546 | return false; | 
|  | 547 | } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 548 | }; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 549 | std::vector<TouchState> mTouchStates; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 550 |  | 
|  | 551 | // Chain of batched sequence numbers.  When multiple input messages are combined into | 
|  | 552 | // a batch, we append a record here that associates the last sequence number in the | 
|  | 553 | // batch with the previous one.  When the finished signal is sent, we traverse the | 
|  | 554 | // chain to individually finish all input messages that were part of the batch. | 
|  | 555 | struct SeqChain { | 
|  | 556 | uint32_t seq;   // sequence number of batched input message | 
|  | 557 | uint32_t chain; // sequence number of previous batched input message | 
|  | 558 | }; | 
| Siarhei Vishniakou | a64c159 | 2020-06-22 12:02:29 -0500 | [diff] [blame] | 559 | std::vector<SeqChain> mSeqChains; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 560 |  | 
|  | 561 | status_t consumeBatch(InputEventFactoryInterface* factory, | 
| Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 562 | nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 563 | status_t consumeSamples(InputEventFactoryInterface* factory, | 
| Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 564 | Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 565 |  | 
| Siarhei Vishniakou | 086a02a | 2017-06-12 15:01:41 +0100 | [diff] [blame] | 566 | void updateTouchState(InputMessage& msg); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 567 | void resampleTouchState(nsecs_t frameTime, MotionEvent* event, | 
|  | 568 | const InputMessage *next); | 
|  | 569 |  | 
|  | 570 | ssize_t findBatch(int32_t deviceId, int32_t source) const; | 
|  | 571 | ssize_t findTouchState(int32_t deviceId, int32_t source) const; | 
|  | 572 |  | 
|  | 573 | status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); | 
|  | 574 |  | 
| Siarhei Vishniakou | 56c9ae1 | 2017-11-06 21:16:47 -0800 | [diff] [blame] | 575 | static void rewriteMessage(TouchState& state, InputMessage& msg); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 576 | static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); | 
|  | 577 | static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 578 | static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 579 | static void addSample(MotionEvent* event, const InputMessage* msg); | 
|  | 580 | static bool canAddSample(const Batch& batch, const InputMessage* msg); | 
|  | 581 | static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); | 
|  | 582 | static bool shouldResampleTool(int32_t toolType); | 
|  | 583 |  | 
|  | 584 | static bool isTouchResamplingEnabled(); | 
|  | 585 | }; | 
|  | 586 |  | 
|  | 587 | } // namespace android | 
|  | 588 |  | 
|  | 589 | #endif // _LIBINPUT_INPUT_TRANSPORT_H |