Loading include/android/input.h +3 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,9 @@ enum { /** Drag event */ AINPUT_EVENT_TYPE_DRAG = 5, /** TouchMode event */ AINPUT_EVENT_TYPE_TOUCH_MODE = 6, }; /** Loading include/input/Input.h +24 −0 Original line number Diff line number Diff line Loading @@ -886,6 +886,25 @@ protected: float mX, mY; }; /* * Touch mode events. */ class TouchModeEvent : public InputEvent { public: virtual ~TouchModeEvent() {} virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; } inline bool isInTouchMode() const { return mIsInTouchMode; } void initialize(int32_t id, bool isInTouchMode); void initialize(const TouchModeEvent& from); protected: bool mIsInTouchMode; }; /** * Base class for verified events. * Do not create a VerifiedInputEvent explicitly. Loading Loading @@ -950,6 +969,7 @@ public: virtual FocusEvent* createFocusEvent() = 0; virtual CaptureEvent* createCaptureEvent() = 0; virtual DragEvent* createDragEvent() = 0; virtual TouchModeEvent* createTouchModeEvent() = 0; }; /* Loading @@ -966,6 +986,7 @@ public: virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; } virtual DragEvent* createDragEvent() override { return &mDragEvent; } virtual TouchModeEvent* createTouchModeEvent() override { return &mTouchModeEvent; } private: KeyEvent mKeyEvent; Loading @@ -973,6 +994,7 @@ private: FocusEvent mFocusEvent; CaptureEvent mCaptureEvent; DragEvent mDragEvent; TouchModeEvent mTouchModeEvent; }; /* Loading @@ -988,6 +1010,7 @@ public: virtual FocusEvent* createFocusEvent() override; virtual CaptureEvent* createCaptureEvent() override; virtual DragEvent* createDragEvent() override; virtual TouchModeEvent* createTouchModeEvent() override; void recycle(InputEvent* event); Loading @@ -999,6 +1022,7 @@ private: std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool; std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool; std::queue<std::unique_ptr<DragEvent>> mDragEventPool; std::queue<std::unique_ptr<TouchModeEvent>> mTouchModeEventPool; }; } // namespace android Loading include/input/InputTransport.h +20 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ struct InputMessage { CAPTURE, DRAG, TIMELINE, TOUCH_MODE, }; struct Header { Loading Loading @@ -206,6 +207,15 @@ struct InputMessage { inline size_t size() const { return sizeof(Timeline); } } timeline; struct TouchMode { int32_t eventId; // The following 2 fields take up 4 bytes total bool isInTouchMode; uint8_t empty[3]; inline size_t size() const { return sizeof(TouchMode); } } touchMode; } __attribute__((aligned(8))) body; bool isValid(size_t actualSize) const; Loading Loading @@ -388,6 +398,15 @@ public: */ status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting); /* Publishes a touch mode event to the input channel. * * Returns OK on success. * Returns WOULD_BLOCK if the channel is full. * Returns DEAD_OBJECT if the channel's peer has been closed. * Other errors probably indicate that the channel is broken. */ status_t publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode); struct Finished { uint32_t seq; bool handled; Loading Loading @@ -658,6 +677,7 @@ private: static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg); static void initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg); static void initializeDragEvent(DragEvent* event, const InputMessage* msg); static void initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); static bool canAddSample(const Batch& batch, const InputMessage* msg); static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); Loading libs/input/Input.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ const char* inputEventTypeToString(int32_t type) { case AINPUT_EVENT_TYPE_DRAG: { return "DRAG"; } case AINPUT_EVENT_TYPE_TOUCH_MODE: { return "TOUCH_MODE"; } } return "UNKNOWN"; } Loading Loading @@ -883,6 +886,19 @@ void DragEvent::initialize(const DragEvent& from) { mY = from.mY; } // --- TouchModeEvent --- void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, ADISPLAY_ID_NONE, INVALID_HMAC); mIsInTouchMode = isInTouchMode; } void TouchModeEvent::initialize(const TouchModeEvent& from) { InputEvent::initialize(from); mIsInTouchMode = from.mIsInTouchMode; } // --- PooledInputEventFactory --- PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) : Loading Loading @@ -937,6 +953,15 @@ DragEvent* PooledInputEventFactory::createDragEvent() { return event; } TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() { if (mTouchModeEventPool.empty()) { return new TouchModeEvent(); } TouchModeEvent* event = mTouchModeEventPool.front().release(); mTouchModeEventPool.pop(); return event; } void PooledInputEventFactory::recycle(InputEvent* event) { switch (event->getType()) { case AINPUT_EVENT_TYPE_KEY: Loading libs/input/InputTransport.cpp +42 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ bool InputMessage::isValid(size_t actualSize) const { case Type::FOCUS: case Type::CAPTURE: case Type::DRAG: case Type::TOUCH_MODE: return true; case Type::TIMELINE: { const nsecs_t gpuCompletedTime = Loading Loading @@ -151,6 +152,8 @@ size_t InputMessage::size() const { return sizeof(Header) + body.drag.size(); case Type::TIMELINE: return sizeof(Header) + body.timeline.size(); case Type::TOUCH_MODE: return sizeof(Header) + body.touchMode.size(); } return sizeof(Header); } Loading Loading @@ -293,6 +296,10 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { msg->body.timeline.graphicsTimeline = body.timeline.graphicsTimeline; break; } case InputMessage::Type::TOUCH_MODE: { msg->body.touchMode.eventId = body.touchMode.eventId; msg->body.touchMode.isInTouchMode = body.touchMode.isInTouchMode; } } } Loading Loading @@ -665,6 +672,22 @@ status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x return mChannel->sendMessage(&msg); } status_t InputPublisher::publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishTouchModeEvent(inputChannel=%s, isInTouchMode=%s)", mChannel->getName().c_str(), toString(isInTouchMode)); ATRACE_NAME(message.c_str()); } InputMessage msg; msg.header.type = InputMessage::Type::TOUCH_MODE; msg.header.seq = seq; msg.body.touchMode.eventId = eventId; msg.body.touchMode.isInTouchMode = isInTouchMode; return mChannel->sendMessage(&msg); } android::base::Result<InputPublisher::ConsumerResponse> InputPublisher::receiveConsumerResponse() { if (DEBUG_TRANSPORT_ACTIONS) { ALOGD("channel '%s' publisher ~ %s", mChannel->getName().c_str(), __func__); Loading Loading @@ -866,6 +889,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum *outEvent = dragEvent; break; } case InputMessage::Type::TOUCH_MODE: { TouchModeEvent* touchModeEvent = factory->createTouchModeEvent(); if (!touchModeEvent) return NO_MEMORY; initializeTouchModeEvent(touchModeEvent, &mMsg); *outSeq = mMsg.header.seq; *outEvent = touchModeEvent; break; } } } return OK; Loading Loading @@ -1370,6 +1403,10 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage msg->body.motion.eventTime, pointerCount, pointerProperties, pointerCoords); } void InputConsumer::initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg) { event->initialize(msg->body.touchMode.eventId, msg->body.touchMode.isInTouchMode); } void InputConsumer::addSample(MotionEvent* event, const InputMessage* msg) { uint32_t pointerCount = msg->body.motion.pointerCount; PointerCoords pointerCoords[pointerCount]; Loading Loading @@ -1476,6 +1513,11 @@ std::string InputConsumer::dump() const { presentTime); break; } case InputMessage::Type::TOUCH_MODE: { out += android::base::StringPrintf("isInTouchMode=%s", toString(msg.body.touchMode.isInTouchMode)); break; } } out += "\n"; } Loading Loading
include/android/input.h +3 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,9 @@ enum { /** Drag event */ AINPUT_EVENT_TYPE_DRAG = 5, /** TouchMode event */ AINPUT_EVENT_TYPE_TOUCH_MODE = 6, }; /** Loading
include/input/Input.h +24 −0 Original line number Diff line number Diff line Loading @@ -886,6 +886,25 @@ protected: float mX, mY; }; /* * Touch mode events. */ class TouchModeEvent : public InputEvent { public: virtual ~TouchModeEvent() {} virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; } inline bool isInTouchMode() const { return mIsInTouchMode; } void initialize(int32_t id, bool isInTouchMode); void initialize(const TouchModeEvent& from); protected: bool mIsInTouchMode; }; /** * Base class for verified events. * Do not create a VerifiedInputEvent explicitly. Loading Loading @@ -950,6 +969,7 @@ public: virtual FocusEvent* createFocusEvent() = 0; virtual CaptureEvent* createCaptureEvent() = 0; virtual DragEvent* createDragEvent() = 0; virtual TouchModeEvent* createTouchModeEvent() = 0; }; /* Loading @@ -966,6 +986,7 @@ public: virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; } virtual DragEvent* createDragEvent() override { return &mDragEvent; } virtual TouchModeEvent* createTouchModeEvent() override { return &mTouchModeEvent; } private: KeyEvent mKeyEvent; Loading @@ -973,6 +994,7 @@ private: FocusEvent mFocusEvent; CaptureEvent mCaptureEvent; DragEvent mDragEvent; TouchModeEvent mTouchModeEvent; }; /* Loading @@ -988,6 +1010,7 @@ public: virtual FocusEvent* createFocusEvent() override; virtual CaptureEvent* createCaptureEvent() override; virtual DragEvent* createDragEvent() override; virtual TouchModeEvent* createTouchModeEvent() override; void recycle(InputEvent* event); Loading @@ -999,6 +1022,7 @@ private: std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool; std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool; std::queue<std::unique_ptr<DragEvent>> mDragEventPool; std::queue<std::unique_ptr<TouchModeEvent>> mTouchModeEventPool; }; } // namespace android Loading
include/input/InputTransport.h +20 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ struct InputMessage { CAPTURE, DRAG, TIMELINE, TOUCH_MODE, }; struct Header { Loading Loading @@ -206,6 +207,15 @@ struct InputMessage { inline size_t size() const { return sizeof(Timeline); } } timeline; struct TouchMode { int32_t eventId; // The following 2 fields take up 4 bytes total bool isInTouchMode; uint8_t empty[3]; inline size_t size() const { return sizeof(TouchMode); } } touchMode; } __attribute__((aligned(8))) body; bool isValid(size_t actualSize) const; Loading Loading @@ -388,6 +398,15 @@ public: */ status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting); /* Publishes a touch mode event to the input channel. * * Returns OK on success. * Returns WOULD_BLOCK if the channel is full. * Returns DEAD_OBJECT if the channel's peer has been closed. * Other errors probably indicate that the channel is broken. */ status_t publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode); struct Finished { uint32_t seq; bool handled; Loading Loading @@ -658,6 +677,7 @@ private: static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg); static void initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg); static void initializeDragEvent(DragEvent* event, const InputMessage* msg); static void initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg); static void addSample(MotionEvent* event, const InputMessage* msg); static bool canAddSample(const Batch& batch, const InputMessage* msg); static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); Loading
libs/input/Input.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -160,6 +160,9 @@ const char* inputEventTypeToString(int32_t type) { case AINPUT_EVENT_TYPE_DRAG: { return "DRAG"; } case AINPUT_EVENT_TYPE_TOUCH_MODE: { return "TOUCH_MODE"; } } return "UNKNOWN"; } Loading Loading @@ -883,6 +886,19 @@ void DragEvent::initialize(const DragEvent& from) { mY = from.mY; } // --- TouchModeEvent --- void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, ADISPLAY_ID_NONE, INVALID_HMAC); mIsInTouchMode = isInTouchMode; } void TouchModeEvent::initialize(const TouchModeEvent& from) { InputEvent::initialize(from); mIsInTouchMode = from.mIsInTouchMode; } // --- PooledInputEventFactory --- PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) : Loading Loading @@ -937,6 +953,15 @@ DragEvent* PooledInputEventFactory::createDragEvent() { return event; } TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() { if (mTouchModeEventPool.empty()) { return new TouchModeEvent(); } TouchModeEvent* event = mTouchModeEventPool.front().release(); mTouchModeEventPool.pop(); return event; } void PooledInputEventFactory::recycle(InputEvent* event) { switch (event->getType()) { case AINPUT_EVENT_TYPE_KEY: Loading
libs/input/InputTransport.cpp +42 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ bool InputMessage::isValid(size_t actualSize) const { case Type::FOCUS: case Type::CAPTURE: case Type::DRAG: case Type::TOUCH_MODE: return true; case Type::TIMELINE: { const nsecs_t gpuCompletedTime = Loading Loading @@ -151,6 +152,8 @@ size_t InputMessage::size() const { return sizeof(Header) + body.drag.size(); case Type::TIMELINE: return sizeof(Header) + body.timeline.size(); case Type::TOUCH_MODE: return sizeof(Header) + body.touchMode.size(); } return sizeof(Header); } Loading Loading @@ -293,6 +296,10 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { msg->body.timeline.graphicsTimeline = body.timeline.graphicsTimeline; break; } case InputMessage::Type::TOUCH_MODE: { msg->body.touchMode.eventId = body.touchMode.eventId; msg->body.touchMode.isInTouchMode = body.touchMode.isInTouchMode; } } } Loading Loading @@ -665,6 +672,22 @@ status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x return mChannel->sendMessage(&msg); } status_t InputPublisher::publishTouchModeEvent(uint32_t seq, int32_t eventId, bool isInTouchMode) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishTouchModeEvent(inputChannel=%s, isInTouchMode=%s)", mChannel->getName().c_str(), toString(isInTouchMode)); ATRACE_NAME(message.c_str()); } InputMessage msg; msg.header.type = InputMessage::Type::TOUCH_MODE; msg.header.seq = seq; msg.body.touchMode.eventId = eventId; msg.body.touchMode.isInTouchMode = isInTouchMode; return mChannel->sendMessage(&msg); } android::base::Result<InputPublisher::ConsumerResponse> InputPublisher::receiveConsumerResponse() { if (DEBUG_TRANSPORT_ACTIONS) { ALOGD("channel '%s' publisher ~ %s", mChannel->getName().c_str(), __func__); Loading Loading @@ -866,6 +889,16 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum *outEvent = dragEvent; break; } case InputMessage::Type::TOUCH_MODE: { TouchModeEvent* touchModeEvent = factory->createTouchModeEvent(); if (!touchModeEvent) return NO_MEMORY; initializeTouchModeEvent(touchModeEvent, &mMsg); *outSeq = mMsg.header.seq; *outEvent = touchModeEvent; break; } } } return OK; Loading Loading @@ -1370,6 +1403,10 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage msg->body.motion.eventTime, pointerCount, pointerProperties, pointerCoords); } void InputConsumer::initializeTouchModeEvent(TouchModeEvent* event, const InputMessage* msg) { event->initialize(msg->body.touchMode.eventId, msg->body.touchMode.isInTouchMode); } void InputConsumer::addSample(MotionEvent* event, const InputMessage* msg) { uint32_t pointerCount = msg->body.motion.pointerCount; PointerCoords pointerCoords[pointerCount]; Loading Loading @@ -1476,6 +1513,11 @@ std::string InputConsumer::dump() const { presentTime); break; } case InputMessage::Type::TOUCH_MODE: { out += android::base::StringPrintf("isInTouchMode=%s", toString(msg.body.touchMode.isInTouchMode)); break; } } out += "\n"; } Loading