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 #pragma once 18 19 #pragma GCC system_header 20 21 /** 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 31 #include <string> 32 #include <unordered_map> 33 34 #include <android-base/chrono_utils.h> 35 #include <android-base/result.h> 36 #include <android-base/unique_fd.h> 37 38 #include <binder/IBinder.h> 39 #include <binder/Parcelable.h> 40 #include <input/Input.h> 41 #include <input/InputVerifier.h> 42 #include <sys/stat.h> 43 #include <ui/Transform.h> 44 #include <utils/BitSet.h> 45 #include <utils/Errors.h> 46 #include <utils/RefBase.h> 47 #include <utils/Timers.h> 48 49 50 namespace android { 51 class Parcel; 52 53 /* 54 * Intermediate representation used to send input events and related signals. 55 * 56 * Note that this structure is used for IPCs so its layout must be identical 57 * on 64 and 32 bit processes. This is tested in StructLayout_test.cpp. 58 * 59 * Since the struct must be aligned to an 8-byte boundary, there could be uninitialized bytes 60 * in-between the defined fields. This padding data should be explicitly accounted for by adding 61 * "empty" fields into the struct. This data is memset to zero before sending the struct across 62 * the socket. Adding the explicit fields ensures that the memset is not optimized away by the 63 * compiler. When a new field is added to the struct, the corresponding change 64 * in StructLayout_test should be made. 65 */ 66 struct InputMessage { 67 enum class Type : uint32_t { 68 KEY, 69 MOTION, 70 FINISHED, 71 FOCUS, 72 CAPTURE, 73 DRAG, 74 TIMELINE, 75 TOUCH_MODE, 76 77 ftl_last = TOUCH_MODE 78 }; 79 80 struct Header { 81 Type type; // 4 bytes 82 uint32_t seq; 83 } header; 84 85 // For keys and motions, rely on the fact that std::array takes up exactly as much space 86 // as the underlying data. This is not guaranteed by C++, but it simplifies the conversions. 87 static_assert(sizeof(std::array<uint8_t, 32>) == 32); 88 89 // For bool values, rely on the fact that they take up exactly one byte. This is not guaranteed 90 // by C++ and is implementation-dependent, but it simplifies the conversions. 91 static_assert(sizeof(bool) == 1); 92 93 // Body *must* be 8 byte aligned. 94 union Body { 95 struct Key { 96 int32_t eventId; 97 uint32_t empty1; 98 nsecs_t eventTime __attribute__((aligned(8))); 99 int32_t deviceId; 100 int32_t source; 101 int32_t displayId; 102 std::array<uint8_t, 32> hmac; 103 int32_t action; 104 int32_t flags; 105 int32_t keyCode; 106 int32_t scanCode; 107 int32_t metaState; 108 int32_t repeatCount; 109 uint32_t empty2; 110 nsecs_t downTime __attribute__((aligned(8))); 111 sizeInputMessage::Body::Key112 inline size_t size() const { return sizeof(Key); } 113 } key; 114 115 struct Motion { 116 int32_t eventId; 117 uint32_t pointerCount; 118 nsecs_t eventTime __attribute__((aligned(8))); 119 int32_t deviceId; 120 int32_t source; 121 int32_t displayId; 122 std::array<uint8_t, 32> hmac; 123 int32_t action; 124 int32_t actionButton; 125 int32_t flags; 126 int32_t metaState; 127 int32_t buttonState; 128 MotionClassification classification; // base type: uint8_t 129 uint8_t empty2[3]; // 3 bytes to fill gap created by classification 130 int32_t edgeFlags; 131 nsecs_t downTime __attribute__((aligned(8))); 132 float dsdx; // Begin window transform 133 float dtdx; // 134 float dtdy; // 135 float dsdy; // 136 float tx; // 137 float ty; // End window transform 138 float xPrecision; 139 float yPrecision; 140 float xCursorPosition; 141 float yCursorPosition; 142 float dsdxRaw; // Begin raw transform 143 float dtdxRaw; // 144 float dtdyRaw; // 145 float dsdyRaw; // 146 float txRaw; // 147 float tyRaw; // End raw transform 148 /** 149 * The "pointers" field must be the last field of the struct InputMessage. 150 * When we send the struct InputMessage across the socket, we are not 151 * writing the entire "pointers" array, but only the pointerCount portion 152 * of it as an optimization. Adding a field after "pointers" would break this. 153 */ 154 struct Pointer { 155 PointerProperties properties; 156 PointerCoords coords; 157 } pointers[MAX_POINTERS] __attribute__((aligned(8))); 158 getActionIdInputMessage::Body::Motion159 int32_t getActionId() const { 160 uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) 161 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; 162 return pointers[index].properties.id; 163 } 164 sizeInputMessage::Body::Motion165 inline size_t size() const { 166 return sizeof(Motion) - sizeof(Pointer) * MAX_POINTERS 167 + sizeof(Pointer) * pointerCount; 168 } 169 } motion; 170 171 struct Finished { 172 bool handled; 173 uint8_t empty[7]; 174 nsecs_t consumeTime; // The time when the event was consumed by the receiving end 175 sizeInputMessage::Body::Finished176 inline size_t size() const { return sizeof(Finished); } 177 } finished; 178 179 struct Focus { 180 int32_t eventId; 181 // The following 2 fields take up 4 bytes total 182 bool hasFocus; 183 uint8_t empty[3]; 184 sizeInputMessage::Body::Focus185 inline size_t size() const { return sizeof(Focus); } 186 } focus; 187 188 struct Capture { 189 int32_t eventId; 190 bool pointerCaptureEnabled; 191 uint8_t empty[3]; 192 sizeInputMessage::Body::Capture193 inline size_t size() const { return sizeof(Capture); } 194 } capture; 195 196 struct Drag { 197 int32_t eventId; 198 float x; 199 float y; 200 bool isExiting; 201 uint8_t empty[3]; 202 sizeInputMessage::Body::Drag203 inline size_t size() const { return sizeof(Drag); } 204 } drag; 205 206 struct Timeline { 207 int32_t eventId; 208 uint32_t empty; 209 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline; 210 sizeInputMessage::Body::Timeline211 inline size_t size() const { return sizeof(Timeline); } 212 } timeline; 213 214 struct TouchMode { 215 int32_t eventId; 216 // The following 2 fields take up 4 bytes total 217 bool isInTouchMode; 218 uint8_t empty[3]; 219 sizeInputMessage::Body::TouchMode220 inline size_t size() const { return sizeof(TouchMode); } 221 } touchMode; 222 } __attribute__((aligned(8))) body; 223 224 bool isValid(size_t actualSize) const; 225 size_t size() const; 226 void getSanitizedCopy(InputMessage* msg) const; 227 }; 228 229 /* 230 * An input channel consists of a local unix domain socket used to send and receive 231 * input messages across processes. Each channel has a descriptive name for debugging purposes. 232 * 233 * Each endpoint has its own InputChannel object that specifies its file descriptor. 234 * 235 * The input channel is closed when all references to it are released. 236 */ 237 class InputChannel : public Parcelable { 238 public: 239 static std::unique_ptr<InputChannel> create(const std::string& name, 240 android::base::unique_fd fd, sp<IBinder> token); 241 InputChannel() = default; InputChannel(const InputChannel & other)242 InputChannel(const InputChannel& other) 243 : mName(other.mName), mFd(::dup(other.mFd)), mToken(other.mToken){}; 244 InputChannel(const std::string name, android::base::unique_fd fd, sp<IBinder> token); 245 ~InputChannel() override; 246 /** 247 * Create a pair of input channels. 248 * The two returned input channels are equivalent, and are labeled as "server" and "client" 249 * for convenience. The two input channels share the same token. 250 * 251 * Return OK on success. 252 */ 253 static status_t openInputChannelPair(const std::string& name, 254 std::unique_ptr<InputChannel>& outServerChannel, 255 std::unique_ptr<InputChannel>& outClientChannel); 256 getName()257 inline std::string getName() const { return mName; } getFd()258 inline const android::base::unique_fd& getFd() const { return mFd; } getToken()259 inline sp<IBinder> getToken() const { return mToken; } 260 261 /* Send a message to the other endpoint. 262 * 263 * If the channel is full then the message is guaranteed not to have been sent at all. 264 * Try again after the consumer has sent a finished signal indicating that it has 265 * consumed some of the pending messages from the channel. 266 * 267 * Return OK on success. 268 * Return WOULD_BLOCK if the channel is full. 269 * Return DEAD_OBJECT if the channel's peer has been closed. 270 * Other errors probably indicate that the channel is broken. 271 */ 272 status_t sendMessage(const InputMessage* msg); 273 274 /* Receive a message sent by the other endpoint. 275 * 276 * If there is no message present, try again after poll() indicates that the fd 277 * is readable. 278 * 279 * Return OK on success. 280 * Return WOULD_BLOCK if there is no message present. 281 * Return DEAD_OBJECT if the channel's peer has been closed. 282 * Other errors probably indicate that the channel is broken. 283 */ 284 status_t receiveMessage(InputMessage* msg); 285 286 /* Return a new object that has a duplicate of this channel's fd. */ 287 std::unique_ptr<InputChannel> dup() const; 288 289 void copyTo(InputChannel& outChannel) const; 290 291 status_t readFromParcel(const android::Parcel* parcel) override; 292 status_t writeToParcel(android::Parcel* parcel) const override; 293 294 /** 295 * The connection token is used to identify the input connection, i.e. 296 * the pair of input channels that were created simultaneously. Input channels 297 * are always created in pairs, and the token can be used to find the server-side 298 * input channel from the client-side input channel, and vice versa. 299 * 300 * Do not use connection token to check equality of a specific input channel object 301 * to another, because two different (client and server) input channels will share the 302 * same connection token. 303 * 304 * Return the token that identifies this connection. 305 */ 306 sp<IBinder> getConnectionToken() const; 307 308 bool operator==(const InputChannel& inputChannel) const { 309 struct stat lhs, rhs; 310 if (fstat(mFd.get(), &lhs) != 0) { 311 return false; 312 } 313 if (fstat(inputChannel.getFd(), &rhs) != 0) { 314 return false; 315 } 316 // If file descriptors are pointing to same inode they are duplicated fds. 317 return inputChannel.getName() == getName() && inputChannel.getConnectionToken() == mToken && 318 lhs.st_ino == rhs.st_ino; 319 } 320 321 private: 322 base::unique_fd dupFd() const; 323 324 std::string mName; 325 android::base::unique_fd mFd; 326 327 sp<IBinder> mToken; 328 }; 329 330 /* 331 * Publishes input events to an input channel. 332 */ 333 class InputPublisher { 334 public: 335 /* Creates a publisher associated with an input channel. */ 336 explicit InputPublisher(const std::shared_ptr<InputChannel>& channel); 337 338 /* Destroys the publisher and releases its input channel. */ 339 ~InputPublisher(); 340 341 /* Gets the underlying input channel. */ getChannel()342 inline std::shared_ptr<InputChannel> getChannel() { return mChannel; } 343 344 /* Publishes a key event to the input channel. 345 * 346 * Returns OK on success. 347 * Returns WOULD_BLOCK if the channel is full. 348 * Returns DEAD_OBJECT if the channel's peer has been closed. 349 * Returns BAD_VALUE if seq is 0. 350 * Other errors probably indicate that the channel is broken. 351 */ 352 status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, 353 int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, 354 int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, 355 int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); 356 357 /* Publishes a motion event to the input channel. 358 * 359 * Returns OK on success. 360 * Returns WOULD_BLOCK if the channel is full. 361 * Returns DEAD_OBJECT if the channel's peer has been closed. 362 * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS. 363 * Other errors probably indicate that the channel is broken. 364 */ 365 status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, 366 int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, 367 int32_t actionButton, int32_t flags, int32_t edgeFlags, 368 int32_t metaState, int32_t buttonState, 369 MotionClassification classification, const ui::Transform& transform, 370 float xPrecision, float yPrecision, float xCursorPosition, 371 float yCursorPosition, const ui::Transform& rawTransform, 372 nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, 373 const PointerProperties* pointerProperties, 374 const PointerCoords* pointerCoords); 375 376 /* Publishes a focus event to the input channel. 377 * 378 * Returns OK on success. 379 * Returns WOULD_BLOCK if the channel is full. 380 * Returns DEAD_OBJECT if the channel's peer has been closed. 381 * Other errors probably indicate that the channel is broken. 382 */ 383 status_t publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus); 384 385 /* Publishes a capture event to the input channel. 386 * 387 * Returns OK on success. 388 * Returns WOULD_BLOCK if the channel is full. 389 * Returns DEAD_OBJECT if the channel's peer has been closed. 390 * Other errors probably indicate that the channel is broken. 391 */ 392 status_t publishCaptureEvent(uint32_t seq, int32_t eventId, bool pointerCaptureEnabled); 393 394 /* Publishes a drag event to the input channel. 395 * 396 * Returns OK on success. 397 * Returns WOULD_BLOCK if the channel is full. 398 * Returns DEAD_OBJECT if the channel's peer has been closed. 399 * Other errors probably indicate that the channel is broken. 400 */ 401 status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting); 402 403 /* Publishes a touch mode event to the input channel. 404 * 405 * Returns OK on success. 406 * Returns WOULD_BLOCK if the channel is full. 407 * Returns DEAD_OBJECT if the channel's peer has been closed. 408 * Other errors probably indicate that the channel is broken. 409 */ 410 status_t publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode); 411 412 struct Finished { 413 uint32_t seq; 414 bool handled; 415 nsecs_t consumeTime; 416 }; 417 418 struct Timeline { 419 int32_t inputEventId; 420 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline; 421 }; 422 423 typedef std::variant<Finished, Timeline> ConsumerResponse; 424 /* Receive a signal from the consumer in reply to the original dispatch signal. 425 * If a signal was received, returns a Finished or a Timeline object. 426 * The InputConsumer should return a Finished object for every InputMessage that it is sent 427 * to confirm that it has been processed and that the InputConsumer is responsive. 428 * If several InputMessages are sent to InputConsumer, it's possible to receive Finished 429 * events out of order for those messages. 430 * 431 * The Timeline object is returned whenever the receiving end has processed a graphical frame 432 * and is returning the timeline of the frame. Not all input events will cause a Timeline 433 * object to be returned, and there is not guarantee about when it will arrive. 434 * 435 * If an object of Finished is returned, the returned sequence number is never 0 unless the 436 * operation failed. 437 * 438 * Returned error codes: 439 * OK on success. 440 * WOULD_BLOCK if there is no signal present. 441 * DEAD_OBJECT if the channel's peer has been closed. 442 * Other errors probably indicate that the channel is broken. 443 */ 444 android::base::Result<ConsumerResponse> receiveConsumerResponse(); 445 446 private: 447 std::shared_ptr<InputChannel> mChannel; 448 InputVerifier mInputVerifier; 449 }; 450 451 /* 452 * Consumes input events from an input channel. 453 */ 454 class InputConsumer { 455 public: 456 /* Create a consumer associated with an input channel. */ 457 explicit InputConsumer(const std::shared_ptr<InputChannel>& channel); 458 /* Create a consumer associated with an input channel, override resampling system property */ 459 explicit InputConsumer(const std::shared_ptr<InputChannel>& channel, 460 bool enableTouchResampling); 461 462 /* Destroys the consumer and releases its input channel. */ 463 ~InputConsumer(); 464 465 /* Gets the underlying input channel. */ getChannel()466 inline std::shared_ptr<InputChannel> getChannel() { return mChannel; } 467 468 /* Consumes an input event from the input channel and copies its contents into 469 * an InputEvent object created using the specified factory. 470 * 471 * Tries to combine a series of move events into larger batches whenever possible. 472 * 473 * If consumeBatches is false, then defers consuming pending batched events if it 474 * is possible for additional samples to be added to them later. Call hasPendingBatch() 475 * to determine whether a pending batch is available to be consumed. 476 * 477 * If consumeBatches is true, then events are still batched but they are consumed 478 * immediately as soon as the input channel is exhausted. 479 * 480 * The frameTime parameter specifies the time when the current display frame started 481 * rendering in the CLOCK_MONOTONIC time base, or -1 if unknown. 482 * 483 * The returned sequence number is never 0 unless the operation failed. 484 * 485 * Returns OK on success. 486 * Returns WOULD_BLOCK if there is no event present. 487 * Returns DEAD_OBJECT if the channel's peer has been closed. 488 * Returns NO_MEMORY if the event could not be created. 489 * Other errors probably indicate that the channel is broken. 490 */ 491 status_t consume(InputEventFactoryInterface* factory, bool consumeBatches, nsecs_t frameTime, 492 uint32_t* outSeq, InputEvent** outEvent); 493 494 /* Sends a finished signal to the publisher to inform it that the message 495 * with the specified sequence number has finished being process and whether 496 * the message was handled by the consumer. 497 * 498 * Returns OK on success. 499 * Returns BAD_VALUE if seq is 0. 500 * Other errors probably indicate that the channel is broken. 501 */ 502 status_t sendFinishedSignal(uint32_t seq, bool handled); 503 504 status_t sendTimeline(int32_t inputEventId, 505 std::array<nsecs_t, GraphicsTimeline::SIZE> timeline); 506 507 /* Returns true if there is a pending batch. 508 * 509 * Should be called after calling consume() with consumeBatches == false to determine 510 * whether consume() should be called again later on with consumeBatches == true. 511 */ 512 bool hasPendingBatch() const; 513 514 /* Returns the source of first pending batch if exist. 515 * 516 * Should be called after calling consume() with consumeBatches == false to determine 517 * whether consume() should be called again later on with consumeBatches == true. 518 */ 519 int32_t getPendingBatchSource() const; 520 521 std::string dump() const; 522 523 private: 524 // True if touch resampling is enabled. 525 const bool mResampleTouch; 526 527 std::shared_ptr<InputChannel> mChannel; 528 529 // The current input message. 530 InputMessage mMsg; 531 532 // True if mMsg contains a valid input message that was deferred from the previous 533 // call to consume and that still needs to be handled. 534 bool mMsgDeferred; 535 536 // Batched motion events per device and source. 537 struct Batch { 538 std::vector<InputMessage> samples; 539 }; 540 std::vector<Batch> mBatches; 541 542 // Touch state per device and source, only for sources of class pointer. 543 struct History { 544 nsecs_t eventTime; 545 BitSet32 idBits; 546 int32_t idToIndex[MAX_POINTER_ID + 1]; 547 PointerCoords pointers[MAX_POINTERS]; 548 initializeFromHistory549 void initializeFrom(const InputMessage& msg) { 550 eventTime = msg.body.motion.eventTime; 551 idBits.clear(); 552 for (uint32_t i = 0; i < msg.body.motion.pointerCount; i++) { 553 uint32_t id = msg.body.motion.pointers[i].properties.id; 554 idBits.markBit(id); 555 idToIndex[id] = i; 556 pointers[i].copyFrom(msg.body.motion.pointers[i].coords); 557 } 558 } 559 initializeFromHistory560 void initializeFrom(const History& other) { 561 eventTime = other.eventTime; 562 idBits = other.idBits; // temporary copy 563 for (size_t i = 0; i < other.idBits.count(); i++) { 564 uint32_t id = idBits.clearFirstMarkedBit(); 565 int32_t index = other.idToIndex[id]; 566 idToIndex[id] = index; 567 pointers[index].copyFrom(other.pointers[index]); 568 } 569 idBits = other.idBits; // final copy 570 } 571 getPointerByIdHistory572 const PointerCoords& getPointerById(uint32_t id) const { 573 return pointers[idToIndex[id]]; 574 } 575 hasPointerIdHistory576 bool hasPointerId(uint32_t id) const { 577 return idBits.hasBit(id); 578 } 579 }; 580 struct TouchState { 581 int32_t deviceId; 582 int32_t source; 583 size_t historyCurrent; 584 size_t historySize; 585 History history[2]; 586 History lastResample; 587 initializeTouchState588 void initialize(int32_t deviceId, int32_t source) { 589 this->deviceId = deviceId; 590 this->source = source; 591 historyCurrent = 0; 592 historySize = 0; 593 lastResample.eventTime = 0; 594 lastResample.idBits.clear(); 595 } 596 addHistoryTouchState597 void addHistory(const InputMessage& msg) { 598 historyCurrent ^= 1; 599 if (historySize < 2) { 600 historySize += 1; 601 } 602 history[historyCurrent].initializeFrom(msg); 603 } 604 getHistoryTouchState605 const History* getHistory(size_t index) const { 606 return &history[(historyCurrent + index) & 1]; 607 } 608 recentCoordinatesAreIdenticalTouchState609 bool recentCoordinatesAreIdentical(uint32_t id) const { 610 // Return true if the two most recently received "raw" coordinates are identical 611 if (historySize < 2) { 612 return false; 613 } 614 if (!getHistory(0)->hasPointerId(id) || !getHistory(1)->hasPointerId(id)) { 615 return false; 616 } 617 float currentX = getHistory(0)->getPointerById(id).getX(); 618 float currentY = getHistory(0)->getPointerById(id).getY(); 619 float previousX = getHistory(1)->getPointerById(id).getX(); 620 float previousY = getHistory(1)->getPointerById(id).getY(); 621 if (currentX == previousX && currentY == previousY) { 622 return true; 623 } 624 return false; 625 } 626 }; 627 std::vector<TouchState> mTouchStates; 628 629 // Chain of batched sequence numbers. When multiple input messages are combined into 630 // a batch, we append a record here that associates the last sequence number in the 631 // batch with the previous one. When the finished signal is sent, we traverse the 632 // chain to individually finish all input messages that were part of the batch. 633 struct SeqChain { 634 uint32_t seq; // sequence number of batched input message 635 uint32_t chain; // sequence number of previous batched input message 636 }; 637 std::vector<SeqChain> mSeqChains; 638 639 // The time at which each event with the sequence number 'seq' was consumed. 640 // This data is provided in 'finishInputEvent' so that the receiving end can measure the latency 641 // This collection is populated when the event is received, and the entries are erased when the 642 // events are finished. It should not grow infinitely because if an event is not ack'd, ANR 643 // will be raised for that connection, and no further events will be posted to that channel. 644 std::unordered_map<uint32_t /*seq*/, nsecs_t /*consumeTime*/> mConsumeTimes; 645 646 status_t consumeBatch(InputEventFactoryInterface* factory, 647 nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent); 648 status_t consumeSamples(InputEventFactoryInterface* factory, 649 Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent); 650 651 void updateTouchState(InputMessage& msg); 652 void resampleTouchState(nsecs_t frameTime, MotionEvent* event, 653 const InputMessage *next); 654 655 ssize_t findBatch(int32_t deviceId, int32_t source) const; 656 ssize_t findTouchState(int32_t deviceId, int32_t source) const; 657 658 nsecs_t getConsumeTime(uint32_t seq) const; 659 void popConsumeTime(uint32_t seq); 660 status_t sendUnchainedFinishedSignal(uint32_t seq, bool handled); 661 662 static void rewriteMessage(TouchState& state, InputMessage& msg); 663 static void initializeKeyEvent(KeyEvent* event, const InputMessage* msg); 664 static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg); 665 static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg); 666 static void initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg); 667 static void initializeDragEvent(DragEvent* event, const InputMessage* msg); 668 static void initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg); 669 static void addSample(MotionEvent* event, const InputMessage* msg); 670 static bool canAddSample(const Batch& batch, const InputMessage* msg); 671 static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); 672 673 static bool isTouchResamplingEnabled(); 674 }; 675 676 } // namespace android 677