Loading include/input/Input.h +42 −4 Original line number Diff line number Diff line Loading @@ -265,6 +265,38 @@ enum class MotionClassification : uint8_t { */ const char* motionClassificationToString(MotionClassification classification); /** * Generator of unique numbers used to identify input events. * * Layout of ID: * |--------------------------|---------------------------| * | 2 bits for source | 30 bits for random number | * |--------------------------|---------------------------| */ class IdGenerator { private: static constexpr uint32_t SOURCE_SHIFT = 30; public: // Used to divide integer space to ensure no conflict among these sources./ enum class Source : int32_t { INPUT_READER = 0x0 << SOURCE_SHIFT, INPUT_DISPATCHER = 0x1 << SOURCE_SHIFT, OTHER = 0x3 << SOURCE_SHIFT, // E.g. app injected events }; IdGenerator(Source source); int32_t nextId() const; // Extract source from given id. static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); } private: const Source mSource; static constexpr int32_t SOURCE_MASK = 0x3 << SOURCE_SHIFT; }; /** * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't * use it for direct comparison with any other value, because NaN isn't equal to itself according to Loading Loading @@ -365,6 +397,8 @@ public: virtual int32_t getType() const = 0; inline int32_t getId() const { return mId; } inline int32_t getDeviceId() const { return mDeviceId; } inline uint32_t getSource() const { return mSource; } Loading @@ -377,11 +411,15 @@ public: inline std::array<uint8_t, 32> getHmac() const { return mHmac; } static int32_t nextId(); protected: void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac); void initialize(const InputEvent& from); int32_t mId; int32_t mDeviceId; uint32_t mSource; int32_t mDisplayId; Loading Loading @@ -418,7 +456,7 @@ public: static const char* getLabel(int32_t keyCode); static int32_t getKeyCodeFromLabel(const char* label); void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); Loading Loading @@ -642,7 +680,7 @@ public: ssize_t findPointerIndex(int32_t pointerId) const; void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, Loading Loading @@ -722,7 +760,7 @@ public: inline bool getInTouchMode() const { return mInTouchMode; } void initialize(bool hasFocus, bool inTouchMode); void initialize(int32_t id, bool hasFocus, bool inTouchMode); void initialize(const FocusEvent& from); Loading include/input/InputTransport.h +17 −14 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ struct InputMessage { union Body { struct Key { uint32_t seq; uint32_t empty1; int32_t eventId; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; Loading @@ -102,7 +102,7 @@ struct InputMessage { struct Motion { uint32_t seq; uint32_t empty1; int32_t eventId; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; Loading Loading @@ -159,6 +159,8 @@ struct InputMessage { struct Focus { uint32_t seq; int32_t eventId; uint32_t empty1; // The following two fields take up 4 bytes total uint16_t hasFocus; // actually a bool uint16_t inTouchMode; // actually a bool, but we must maintain 8-byte alignment Loading Loading @@ -276,9 +278,9 @@ public: * Returns BAD_VALUE if seq is 0. * Other errors probably indicate that the channel is broken. */ status_t publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); /* Publishes a motion event to the input channel. Loading @@ -289,14 +291,15 @@ public: * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS. * Other errors probably indicate that the channel is broken. */ status_t publishMotionEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties, status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); /* Publishes a focus event to the input channel. Loading @@ -306,7 +309,7 @@ public: * Returns DEAD_OBJECT if the channel's peer has been closed. * Other errors probably indicate that the channel is broken. */ status_t publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode); status_t publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus, bool inTouchMode); /* Receives the finished signal from the consumer in reply to the original dispatch signal. * If a signal was received, returns the message sequence number, Loading libs/gralloc/types/Gralloc4.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -1317,6 +1317,8 @@ std::string getPlaneLayoutComponentTypeName(const ExtendableType& planeLayoutCom return "G"; case PlaneLayoutComponentType::B: return "B"; case PlaneLayoutComponentType::RAW: return "RAW"; case PlaneLayoutComponentType::A: return "A"; } Loading libs/input/Input.cpp +47 −8 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ #define LOG_TAG "Input" //#define LOG_NDEBUG 0 #include <cutils/compiler.h> #include <limits.h> #include <string.h> #include <input/Input.h> #include <input/InputDevice.h> Loading @@ -25,6 +27,7 @@ #ifdef __ANDROID__ #include <binder/Parcel.h> #include <sys/random.h> #endif namespace android { Loading @@ -40,6 +43,32 @@ const char* motionClassificationToString(MotionClassification classification) { } } // --- IdGenerator --- IdGenerator::IdGenerator(Source source) : mSource(source) {} int32_t IdGenerator::nextId() const { constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; int32_t id = 0; // Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't // use sequence number so just always return mSource. #ifdef __ANDROID__ constexpr size_t BUF_LEN = sizeof(id); size_t totalBytes = 0; while (totalBytes < BUF_LEN) { ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); if (CC_UNLIKELY(bytes < 0)) { ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); id = 0; break; } totalBytes += bytes; } #endif // __ANDROID__ return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource); } // --- InputEvent --- const char* inputEventTypeToString(int32_t type) { Loading Loading @@ -81,8 +110,9 @@ VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) event.getButtonState()}; } void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac) { mId = id; mDeviceId = deviceId; mSource = source; mDisplayId = displayId; Loading @@ -90,12 +120,18 @@ void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId } void InputEvent::initialize(const InputEvent& from) { mId = from.mId; mDeviceId = from.mDeviceId; mSource = from.mSource; mDisplayId = from.mDisplayId; mHmac = from.mHmac; } int32_t InputEvent::nextId() { static IdGenerator idGen(IdGenerator::Source::OTHER); return idGen.nextId(); } // --- KeyEvent --- const char* KeyEvent::getLabel(int32_t keyCode) { Loading @@ -106,11 +142,11 @@ int32_t KeyEvent::getKeyCodeFromLabel(const char* label) { return getKeyCodeByLabel(label); } void KeyEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { InputEvent::initialize(deviceId, source, displayId, hmac); InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; mFlags = flags; mKeyCode = keyCode; Loading Loading @@ -269,7 +305,7 @@ void PointerProperties::copyFrom(const PointerProperties& other) { // --- MotionEvent --- void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, Loading @@ -278,7 +314,7 @@ void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayI nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { InputEvent::initialize(deviceId, source, displayId, hmac); InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; mActionButton = actionButton; mFlags = flags; Loading @@ -303,7 +339,8 @@ void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayI } void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { InputEvent::initialize(other->mDeviceId, other->mSource, other->mDisplayId, other->mHmac); InputEvent::initialize(other->mId, other->mDeviceId, other->mSource, other->mDisplayId, other->mHmac); mAction = other->mAction; mActionButton = other->mActionButton; mFlags = other->mFlags; Loading Loading @@ -511,6 +548,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { return BAD_VALUE; } mId = parcel->readInt32(); mDeviceId = parcel->readInt32(); mSource = parcel->readUint32(); mDisplayId = parcel->readInt32(); Loading Loading @@ -572,6 +610,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeInt32(pointerCount); parcel->writeInt32(sampleCount); parcel->writeInt32(mId); parcel->writeInt32(mDeviceId); parcel->writeUint32(mSource); parcel->writeInt32(mDisplayId); Loading Loading @@ -641,8 +680,8 @@ int32_t MotionEvent::getAxisFromLabel(const char* label) { // --- FocusEvent --- void FocusEvent::initialize(bool hasFocus, bool inTouchMode) { InputEvent::initialize(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, void FocusEvent::initialize(int32_t id, bool hasFocus, bool inTouchMode) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, ADISPLAY_ID_NONE, INVALID_HMAC); mHasFocus = hasFocus; mInTouchMode = inTouchMode; Loading libs/input/InputTransport.cpp +25 −13 Original line number Diff line number Diff line Loading @@ -139,6 +139,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { case InputMessage::Type::KEY: { // uint32_t seq msg->body.key.seq = body.key.seq; // int32_t eventId msg->body.key.eventId = body.key.eventId; // nsecs_t eventTime msg->body.key.eventTime = body.key.eventTime; // int32_t deviceId Loading Loading @@ -168,6 +170,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { case InputMessage::Type::MOTION: { // uint32_t seq msg->body.motion.seq = body.motion.seq; // int32_t eventId msg->body.motion.eventId = body.motion.eventId; // nsecs_t eventTime msg->body.motion.eventTime = body.motion.eventTime; // int32_t deviceId Loading Loading @@ -234,6 +238,7 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { } case InputMessage::Type::FOCUS: { msg->body.focus.seq = body.focus.seq; msg->body.focus.eventId = body.focus.eventId; msg->body.focus.hasFocus = body.focus.hasFocus; msg->body.focus.inTouchMode = body.focus.inTouchMode; break; Loading Loading @@ -432,11 +437,12 @@ InputPublisher::InputPublisher(const sp<InputChannel>& channel) : InputPublisher::~InputPublisher() { } status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishKeyEvent(inputChannel=%s, keyCode=%" PRId32 ")", mChannel->getName().c_str(), keyCode); Loading @@ -458,6 +464,7 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t InputMessage msg; msg.header.type = InputMessage::Type::KEY; msg.body.key.seq = seq; msg.body.key.eventId = eventId; msg.body.key.deviceId = deviceId; msg.body.key.source = source; msg.body.key.displayId = displayId; Loading @@ -474,7 +481,7 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t } status_t InputPublisher::publishMotionEvent( uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, Loading Loading @@ -515,6 +522,7 @@ status_t InputPublisher::publishMotionEvent( InputMessage msg; msg.header.type = InputMessage::Type::MOTION; msg.body.motion.seq = seq; msg.body.motion.eventId = eventId; msg.body.motion.deviceId = deviceId; msg.body.motion.source = source; msg.body.motion.displayId = displayId; Loading Loading @@ -545,7 +553,8 @@ status_t InputPublisher::publishMotionEvent( return mChannel->sendMessage(&msg); } status_t InputPublisher::publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode) { status_t InputPublisher::publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus, bool inTouchMode) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishFocusEvent(inputChannel=%s, hasFocus=%s, inTouchMode=%s)", Loading @@ -557,6 +566,7 @@ status_t InputPublisher::publishFocusEvent(uint32_t seq, bool hasFocus, bool inT InputMessage msg; msg.header.type = InputMessage::Type::FOCUS; msg.body.focus.seq = seq; msg.body.focus.eventId = eventId; msg.body.focus.hasFocus = hasFocus ? 1 : 0; msg.body.focus.inTouchMode = inTouchMode ? 1 : 0; return mChannel->sendMessage(&msg); Loading Loading @@ -1142,14 +1152,16 @@ ssize_t InputConsumer::findTouchState(int32_t deviceId, int32_t source) const { } void InputConsumer::initializeKeyEvent(KeyEvent* event, const InputMessage* msg) { event->initialize(msg->body.key.deviceId, msg->body.key.source, msg->body.key.displayId, msg->body.key.hmac, msg->body.key.action, msg->body.key.flags, msg->body.key.keyCode, msg->body.key.scanCode, msg->body.key.metaState, msg->body.key.repeatCount, msg->body.key.downTime, msg->body.key.eventTime); event->initialize(msg->body.key.eventId, msg->body.key.deviceId, msg->body.key.source, msg->body.key.displayId, msg->body.key.hmac, msg->body.key.action, msg->body.key.flags, msg->body.key.keyCode, msg->body.key.scanCode, msg->body.key.metaState, msg->body.key.repeatCount, msg->body.key.downTime, msg->body.key.eventTime); } void InputConsumer::initializeFocusEvent(FocusEvent* event, const InputMessage* msg) { event->initialize(msg->body.focus.hasFocus == 1, msg->body.focus.inTouchMode == 1); event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus == 1, msg->body.focus.inTouchMode == 1); } void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage* msg) { Loading @@ -1161,7 +1173,7 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage pointerCoords[i].copyFrom(msg->body.motion.pointers[i].coords); } event->initialize(msg->body.motion.deviceId, msg->body.motion.source, event->initialize(msg->body.motion.eventId, msg->body.motion.deviceId, msg->body.motion.source, msg->body.motion.displayId, msg->body.motion.hmac, msg->body.motion.action, msg->body.motion.actionButton, msg->body.motion.flags, msg->body.motion.edgeFlags, msg->body.motion.metaState, Loading Loading
include/input/Input.h +42 −4 Original line number Diff line number Diff line Loading @@ -265,6 +265,38 @@ enum class MotionClassification : uint8_t { */ const char* motionClassificationToString(MotionClassification classification); /** * Generator of unique numbers used to identify input events. * * Layout of ID: * |--------------------------|---------------------------| * | 2 bits for source | 30 bits for random number | * |--------------------------|---------------------------| */ class IdGenerator { private: static constexpr uint32_t SOURCE_SHIFT = 30; public: // Used to divide integer space to ensure no conflict among these sources./ enum class Source : int32_t { INPUT_READER = 0x0 << SOURCE_SHIFT, INPUT_DISPATCHER = 0x1 << SOURCE_SHIFT, OTHER = 0x3 << SOURCE_SHIFT, // E.g. app injected events }; IdGenerator(Source source); int32_t nextId() const; // Extract source from given id. static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); } private: const Source mSource; static constexpr int32_t SOURCE_MASK = 0x3 << SOURCE_SHIFT; }; /** * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't * use it for direct comparison with any other value, because NaN isn't equal to itself according to Loading Loading @@ -365,6 +397,8 @@ public: virtual int32_t getType() const = 0; inline int32_t getId() const { return mId; } inline int32_t getDeviceId() const { return mDeviceId; } inline uint32_t getSource() const { return mSource; } Loading @@ -377,11 +411,15 @@ public: inline std::array<uint8_t, 32> getHmac() const { return mHmac; } static int32_t nextId(); protected: void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac); void initialize(const InputEvent& from); int32_t mId; int32_t mDeviceId; uint32_t mSource; int32_t mDisplayId; Loading Loading @@ -418,7 +456,7 @@ public: static const char* getLabel(int32_t keyCode); static int32_t getKeyCodeFromLabel(const char* label); void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); Loading Loading @@ -642,7 +680,7 @@ public: ssize_t findPointerIndex(int32_t pointerId) const; void initialize(int32_t deviceId, uint32_t source, int32_t displayId, void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, Loading Loading @@ -722,7 +760,7 @@ public: inline bool getInTouchMode() const { return mInTouchMode; } void initialize(bool hasFocus, bool inTouchMode); void initialize(int32_t id, bool hasFocus, bool inTouchMode); void initialize(const FocusEvent& from); Loading
include/input/InputTransport.h +17 −14 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ struct InputMessage { union Body { struct Key { uint32_t seq; uint32_t empty1; int32_t eventId; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; Loading @@ -102,7 +102,7 @@ struct InputMessage { struct Motion { uint32_t seq; uint32_t empty1; int32_t eventId; nsecs_t eventTime __attribute__((aligned(8))); int32_t deviceId; int32_t source; Loading Loading @@ -159,6 +159,8 @@ struct InputMessage { struct Focus { uint32_t seq; int32_t eventId; uint32_t empty1; // The following two fields take up 4 bytes total uint16_t hasFocus; // actually a bool uint16_t inTouchMode; // actually a bool, but we must maintain 8-byte alignment Loading Loading @@ -276,9 +278,9 @@ public: * Returns BAD_VALUE if seq is 0. * Other errors probably indicate that the channel is broken. */ status_t publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, status_t publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime); /* Publishes a motion event to the input channel. Loading @@ -289,14 +291,15 @@ public: * Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS. * Other errors probably indicate that the channel is broken. */ status_t publishMotionEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties, status_t publishMotionEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition, float yCursorPosition, nsecs_t downTime, nsecs_t eventTime, uint32_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords); /* Publishes a focus event to the input channel. Loading @@ -306,7 +309,7 @@ public: * Returns DEAD_OBJECT if the channel's peer has been closed. * Other errors probably indicate that the channel is broken. */ status_t publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode); status_t publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus, bool inTouchMode); /* Receives the finished signal from the consumer in reply to the original dispatch signal. * If a signal was received, returns the message sequence number, Loading
libs/gralloc/types/Gralloc4.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -1317,6 +1317,8 @@ std::string getPlaneLayoutComponentTypeName(const ExtendableType& planeLayoutCom return "G"; case PlaneLayoutComponentType::B: return "B"; case PlaneLayoutComponentType::RAW: return "RAW"; case PlaneLayoutComponentType::A: return "A"; } Loading
libs/input/Input.cpp +47 −8 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ #define LOG_TAG "Input" //#define LOG_NDEBUG 0 #include <cutils/compiler.h> #include <limits.h> #include <string.h> #include <input/Input.h> #include <input/InputDevice.h> Loading @@ -25,6 +27,7 @@ #ifdef __ANDROID__ #include <binder/Parcel.h> #include <sys/random.h> #endif namespace android { Loading @@ -40,6 +43,32 @@ const char* motionClassificationToString(MotionClassification classification) { } } // --- IdGenerator --- IdGenerator::IdGenerator(Source source) : mSource(source) {} int32_t IdGenerator::nextId() const { constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; int32_t id = 0; // Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't // use sequence number so just always return mSource. #ifdef __ANDROID__ constexpr size_t BUF_LEN = sizeof(id); size_t totalBytes = 0; while (totalBytes < BUF_LEN) { ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); if (CC_UNLIKELY(bytes < 0)) { ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); id = 0; break; } totalBytes += bytes; } #endif // __ANDROID__ return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource); } // --- InputEvent --- const char* inputEventTypeToString(int32_t type) { Loading Loading @@ -81,8 +110,9 @@ VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) event.getButtonState()}; } void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac) { mId = id; mDeviceId = deviceId; mSource = source; mDisplayId = displayId; Loading @@ -90,12 +120,18 @@ void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId } void InputEvent::initialize(const InputEvent& from) { mId = from.mId; mDeviceId = from.mDeviceId; mSource = from.mSource; mDisplayId = from.mDisplayId; mHmac = from.mHmac; } int32_t InputEvent::nextId() { static IdGenerator idGen(IdGenerator::Source::OTHER); return idGen.nextId(); } // --- KeyEvent --- const char* KeyEvent::getLabel(int32_t keyCode) { Loading @@ -106,11 +142,11 @@ int32_t KeyEvent::getKeyCodeFromLabel(const char* label) { return getKeyCodeByLabel(label); } void KeyEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { InputEvent::initialize(deviceId, source, displayId, hmac); InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; mFlags = flags; mKeyCode = keyCode; Loading Loading @@ -269,7 +305,7 @@ void PointerProperties::copyFrom(const PointerProperties& other) { // --- MotionEvent --- void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId, void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, Loading @@ -278,7 +314,7 @@ void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayI nsecs_t downTime, nsecs_t eventTime, size_t pointerCount, const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) { InputEvent::initialize(deviceId, source, displayId, hmac); InputEvent::initialize(id, deviceId, source, displayId, hmac); mAction = action; mActionButton = actionButton; mFlags = flags; Loading @@ -303,7 +339,8 @@ void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayI } void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { InputEvent::initialize(other->mDeviceId, other->mSource, other->mDisplayId, other->mHmac); InputEvent::initialize(other->mId, other->mDeviceId, other->mSource, other->mDisplayId, other->mHmac); mAction = other->mAction; mActionButton = other->mActionButton; mFlags = other->mFlags; Loading Loading @@ -511,6 +548,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { return BAD_VALUE; } mId = parcel->readInt32(); mDeviceId = parcel->readInt32(); mSource = parcel->readUint32(); mDisplayId = parcel->readInt32(); Loading Loading @@ -572,6 +610,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { parcel->writeInt32(pointerCount); parcel->writeInt32(sampleCount); parcel->writeInt32(mId); parcel->writeInt32(mDeviceId); parcel->writeUint32(mSource); parcel->writeInt32(mDisplayId); Loading Loading @@ -641,8 +680,8 @@ int32_t MotionEvent::getAxisFromLabel(const char* label) { // --- FocusEvent --- void FocusEvent::initialize(bool hasFocus, bool inTouchMode) { InputEvent::initialize(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, void FocusEvent::initialize(int32_t id, bool hasFocus, bool inTouchMode) { InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, ADISPLAY_ID_NONE, INVALID_HMAC); mHasFocus = hasFocus; mInTouchMode = inTouchMode; Loading
libs/input/InputTransport.cpp +25 −13 Original line number Diff line number Diff line Loading @@ -139,6 +139,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { case InputMessage::Type::KEY: { // uint32_t seq msg->body.key.seq = body.key.seq; // int32_t eventId msg->body.key.eventId = body.key.eventId; // nsecs_t eventTime msg->body.key.eventTime = body.key.eventTime; // int32_t deviceId Loading Loading @@ -168,6 +170,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { case InputMessage::Type::MOTION: { // uint32_t seq msg->body.motion.seq = body.motion.seq; // int32_t eventId msg->body.motion.eventId = body.motion.eventId; // nsecs_t eventTime msg->body.motion.eventTime = body.motion.eventTime; // int32_t deviceId Loading Loading @@ -234,6 +238,7 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { } case InputMessage::Type::FOCUS: { msg->body.focus.seq = body.focus.seq; msg->body.focus.eventId = body.focus.eventId; msg->body.focus.hasFocus = body.focus.hasFocus; msg->body.focus.inTouchMode = body.focus.inTouchMode; break; Loading Loading @@ -432,11 +437,12 @@ InputPublisher::InputPublisher(const sp<InputChannel>& channel) : InputPublisher::~InputPublisher() { } status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, nsecs_t eventTime) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishKeyEvent(inputChannel=%s, keyCode=%" PRId32 ")", mChannel->getName().c_str(), keyCode); Loading @@ -458,6 +464,7 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t InputMessage msg; msg.header.type = InputMessage::Type::KEY; msg.body.key.seq = seq; msg.body.key.eventId = eventId; msg.body.key.deviceId = deviceId; msg.body.key.source = source; msg.body.key.displayId = displayId; Loading @@ -474,7 +481,7 @@ status_t InputPublisher::publishKeyEvent(uint32_t seq, int32_t deviceId, int32_t } status_t InputPublisher::publishMotionEvent( uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId, uint32_t seq, int32_t eventId, int32_t deviceId, int32_t source, int32_t displayId, std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xScale, float yScale, float xOffset, Loading Loading @@ -515,6 +522,7 @@ status_t InputPublisher::publishMotionEvent( InputMessage msg; msg.header.type = InputMessage::Type::MOTION; msg.body.motion.seq = seq; msg.body.motion.eventId = eventId; msg.body.motion.deviceId = deviceId; msg.body.motion.source = source; msg.body.motion.displayId = displayId; Loading Loading @@ -545,7 +553,8 @@ status_t InputPublisher::publishMotionEvent( return mChannel->sendMessage(&msg); } status_t InputPublisher::publishFocusEvent(uint32_t seq, bool hasFocus, bool inTouchMode) { status_t InputPublisher::publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus, bool inTouchMode) { if (ATRACE_ENABLED()) { std::string message = StringPrintf("publishFocusEvent(inputChannel=%s, hasFocus=%s, inTouchMode=%s)", Loading @@ -557,6 +566,7 @@ status_t InputPublisher::publishFocusEvent(uint32_t seq, bool hasFocus, bool inT InputMessage msg; msg.header.type = InputMessage::Type::FOCUS; msg.body.focus.seq = seq; msg.body.focus.eventId = eventId; msg.body.focus.hasFocus = hasFocus ? 1 : 0; msg.body.focus.inTouchMode = inTouchMode ? 1 : 0; return mChannel->sendMessage(&msg); Loading Loading @@ -1142,14 +1152,16 @@ ssize_t InputConsumer::findTouchState(int32_t deviceId, int32_t source) const { } void InputConsumer::initializeKeyEvent(KeyEvent* event, const InputMessage* msg) { event->initialize(msg->body.key.deviceId, msg->body.key.source, msg->body.key.displayId, msg->body.key.hmac, msg->body.key.action, msg->body.key.flags, msg->body.key.keyCode, msg->body.key.scanCode, msg->body.key.metaState, msg->body.key.repeatCount, msg->body.key.downTime, msg->body.key.eventTime); event->initialize(msg->body.key.eventId, msg->body.key.deviceId, msg->body.key.source, msg->body.key.displayId, msg->body.key.hmac, msg->body.key.action, msg->body.key.flags, msg->body.key.keyCode, msg->body.key.scanCode, msg->body.key.metaState, msg->body.key.repeatCount, msg->body.key.downTime, msg->body.key.eventTime); } void InputConsumer::initializeFocusEvent(FocusEvent* event, const InputMessage* msg) { event->initialize(msg->body.focus.hasFocus == 1, msg->body.focus.inTouchMode == 1); event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus == 1, msg->body.focus.inTouchMode == 1); } void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage* msg) { Loading @@ -1161,7 +1173,7 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage pointerCoords[i].copyFrom(msg->body.motion.pointers[i].coords); } event->initialize(msg->body.motion.deviceId, msg->body.motion.source, event->initialize(msg->body.motion.eventId, msg->body.motion.deviceId, msg->body.motion.source, msg->body.motion.displayId, msg->body.motion.hmac, msg->body.motion.action, msg->body.motion.actionButton, msg->body.motion.flags, msg->body.motion.edgeFlags, msg->body.motion.metaState, Loading