Loading include/input/InputTransport.h +4 −5 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ #include <utils/Errors.h> #include <utils/Errors.h> #include <utils/Timers.h> #include <utils/Timers.h> #include <utils/RefBase.h> #include <utils/RefBase.h> #include <utils/String8.h> #include <utils/Vector.h> #include <utils/Vector.h> #include <utils/BitSet.h> #include <utils/BitSet.h> Loading Loading @@ -142,16 +141,16 @@ protected: virtual ~InputChannel(); virtual ~InputChannel(); public: public: InputChannel(const String8& name, int fd); InputChannel(const std::string& name, int fd); /* Creates a pair of input channels. /* Creates a pair of input channels. * * * Returns OK on success. * Returns OK on success. */ */ static status_t openInputChannelPair(const String8& name, static status_t openInputChannelPair(const std::string& name, sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel); sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel); inline String8 getName() const { return mName; } inline std::string getName() const { return mName; } inline int getFd() const { return mFd; } inline int getFd() const { return mFd; } /* Sends a message to the other endpoint. /* Sends a message to the other endpoint. Loading Loading @@ -183,7 +182,7 @@ public: sp<InputChannel> dup() const; sp<InputChannel> dup() const; private: private: String8 mName; std::string mName; int mFd; int mFd; }; }; Loading libs/input/InputTransport.cpp +31 −31 Original line number Original line Diff line number Diff line Loading @@ -99,34 +99,34 @@ size_t InputMessage::size() const { // --- InputChannel --- // --- InputChannel --- InputChannel::InputChannel(const String8& name, int fd) : InputChannel::InputChannel(const std::string& name, int fd) : mName(name), mFd(fd) { mName(name), mFd(fd) { #if DEBUG_CHANNEL_LIFECYCLE #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel constructed: name='%s', fd=%d", ALOGD("Input channel constructed: name='%s', fd=%d", mName.string(), fd); mName.c_str(), fd); #endif #endif int result = fcntl(mFd, F_SETFL, O_NONBLOCK); int result = fcntl(mFd, F_SETFL, O_NONBLOCK); LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket " LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket " "non-blocking. errno=%d", mName.string(), errno); "non-blocking. errno=%d", mName.c_str(), errno); } } InputChannel::~InputChannel() { InputChannel::~InputChannel() { #if DEBUG_CHANNEL_LIFECYCLE #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel destroyed: name='%s', fd=%d", ALOGD("Input channel destroyed: name='%s', fd=%d", mName.string(), mFd); mName.c_str(), mFd); #endif #endif ::close(mFd); ::close(mFd); } } status_t InputChannel::openInputChannelPair(const String8& name, status_t InputChannel::openInputChannelPair(const std::string& name, sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) { sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) { int sockets[2]; int sockets[2]; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { status_t result = -errno; status_t result = -errno; ALOGE("channel '%s' ~ Could not create socket pair. errno=%d", ALOGE("channel '%s' ~ Could not create socket pair. errno=%d", name.string(), errno); name.c_str(), errno); outServerChannel.clear(); outServerChannel.clear(); outClientChannel.clear(); outClientChannel.clear(); return result; return result; Loading @@ -138,12 +138,12 @@ status_t InputChannel::openInputChannelPair(const String8& name, setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); String8 serverChannelName = name; std::string serverChannelName = name; serverChannelName.append(" (server)"); serverChannelName += " (server)"; outServerChannel = new InputChannel(serverChannelName, sockets[0]); outServerChannel = new InputChannel(serverChannelName, sockets[0]); String8 clientChannelName = name; std::string clientChannelName = name; clientChannelName.append(" (client)"); clientChannelName += " (client)"; outClientChannel = new InputChannel(clientChannelName, sockets[1]); outClientChannel = new InputChannel(clientChannelName, sockets[1]); return OK; return OK; } } Loading @@ -158,7 +158,7 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (nWrite < 0) { if (nWrite < 0) { int error = errno; int error = errno; #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.string(), ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.c_str(), msg->header.type, error); msg->header.type, error); #endif #endif if (error == EAGAIN || error == EWOULDBLOCK) { if (error == EAGAIN || error == EWOULDBLOCK) { Loading @@ -173,13 +173,13 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (size_t(nWrite) != msgLength) { if (size_t(nWrite) != msgLength) { #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ error sending message type %d, send was incomplete", ALOGD("channel '%s' ~ error sending message type %d, send was incomplete", mName.string(), msg->header.type); mName.c_str(), msg->header.type); #endif #endif return DEAD_OBJECT; return DEAD_OBJECT; } } #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ sent message of type %d", mName.string(), msg->header.type); ALOGD("channel '%s' ~ sent message of type %d", mName.c_str(), msg->header.type); #endif #endif return OK; return OK; } } Loading @@ -193,7 +193,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead < 0) { if (nRead < 0) { int error = errno; int error = errno; #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.string(), errno); ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.c_str(), errno); #endif #endif if (error == EAGAIN || error == EWOULDBLOCK) { if (error == EAGAIN || error == EWOULDBLOCK) { return WOULD_BLOCK; return WOULD_BLOCK; Loading @@ -206,20 +206,20 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead == 0) { // check for EOF if (nRead == 0) { // check for EOF #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.string()); ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.c_str()); #endif #endif return DEAD_OBJECT; return DEAD_OBJECT; } } if (!msg->isValid(nRead)) { if (!msg->isValid(nRead)) { #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ received invalid message", mName.string()); ALOGD("channel '%s' ~ received invalid message", mName.c_str()); #endif #endif return BAD_VALUE; return BAD_VALUE; } } #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ received message of type %d", mName.string(), msg->header.type); ALOGD("channel '%s' ~ received message of type %d", mName.c_str(), msg->header.type); #endif #endif return OK; return OK; } } Loading Loading @@ -255,7 +255,7 @@ status_t InputPublisher::publishKeyEvent( ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," "downTime=%" PRId64 ", eventTime=%" PRId64, "downTime=%" PRId64 ", eventTime=%" PRId64, mChannel->getName().string(), seq, mChannel->getName().c_str(), seq, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, downTime, eventTime); downTime, eventTime); #endif #endif Loading Loading @@ -307,7 +307,7 @@ status_t InputPublisher::publishMotionEvent( "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "pointerCount=%" PRIu32, "pointerCount=%" PRIu32, mChannel->getName().string(), seq, mChannel->getName().c_str(), seq, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount); xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount); #endif #endif Loading @@ -319,7 +319,7 @@ status_t InputPublisher::publishMotionEvent( if (pointerCount > MAX_POINTERS || pointerCount < 1) { if (pointerCount > MAX_POINTERS || pointerCount < 1) { ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".", ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".", mChannel->getName().string(), pointerCount); mChannel->getName().c_str(), pointerCount); return BAD_VALUE; return BAD_VALUE; } } Loading Loading @@ -352,7 +352,7 @@ status_t InputPublisher::publishMotionEvent( status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' publisher ~ receiveFinishedSignal", ALOGD("channel '%s' publisher ~ receiveFinishedSignal", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif InputMessage msg; InputMessage msg; Loading @@ -364,7 +364,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle } } if (msg.header.type != InputMessage::TYPE_FINISHED) { if (msg.header.type != InputMessage::TYPE_FINISHED) { ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer", ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer", mChannel->getName().string(), msg.header.type); mChannel->getName().c_str(), msg.header.type); return UNKNOWN_ERROR; return UNKNOWN_ERROR; } } *outSeq = msg.body.finished.seq; *outSeq = msg.body.finished.seq; Loading Loading @@ -402,7 +402,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, int32_t* displayId) { int32_t* displayId) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, mChannel->getName().string(), consumeBatches ? "true" : "false", frameTime); mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime); #endif #endif *outSeq = 0; *outSeq = 0; Loading @@ -426,7 +426,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, if (*outEvent) { if (*outEvent) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u", ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -445,7 +445,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *outEvent = keyEvent; *outEvent = keyEvent; #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed key event, seq=%u", ALOGD("channel '%s' consumer ~ consumed key event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -458,7 +458,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ appended to batch event", ALOGD("channel '%s' consumer ~ appended to batch event", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif break; break; } else { } else { Loading @@ -474,7 +474,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event and " ALOGD("channel '%s' consumer ~ consumed batch event and " "deferred current event, seq=%u", "deferred current event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -488,7 +488,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ started batch event", ALOGD("channel '%s' consumer ~ started batch event", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif break; break; } } Loading @@ -503,14 +503,14 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *displayId = mMsg.body.motion.displayId; *displayId = mMsg.body.motion.displayId; #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } default: default: ALOGE("channel '%s' consumer ~ Received unexpected message of type %d", ALOGE("channel '%s' consumer ~ Received unexpected message of type %d", mChannel->getName().string(), mMsg.header.type); mChannel->getName().c_str(), mMsg.header.type); return UNKNOWN_ERROR; return UNKNOWN_ERROR; } } } } Loading Loading @@ -828,7 +828,7 @@ bool InputConsumer::shouldResampleTool(int32_t toolType) { status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", mChannel->getName().string(), seq, handled ? "true" : "false"); mChannel->getName().c_str(), seq, handled ? "true" : "false"); #endif #endif if (!seq) { if (!seq) { Loading libs/input/tests/InputChannel_test.cpp +8 −8 Original line number Original line Diff line number Diff line Loading @@ -41,9 +41,9 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor // of a pipe and to check for EPIPE on the other end after the channel is destroyed. // of a pipe and to check for EPIPE on the other end after the channel is destroyed. Pipe pipe; Pipe pipe; sp<InputChannel> inputChannel = new InputChannel(String8("channel name"), pipe.sendFd); sp<InputChannel> inputChannel = new InputChannel("channel name", pipe.sendFd); EXPECT_STREQ("channel name", inputChannel->getName().string()) EXPECT_STREQ("channel name", inputChannel->getName().c_str()) << "channel should have provided name"; << "channel should have provided name"; EXPECT_EQ(pipe.sendFd, inputChannel->getFd()) EXPECT_EQ(pipe.sendFd, inputChannel->getFd()) << "channel should have provided fd"; << "channel should have provided fd"; Loading @@ -60,16 +60,16 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) << "should have successfully opened a channel pair"; << "should have successfully opened a channel pair"; // Name // Name EXPECT_STREQ("channel name (server)", serverChannel->getName().string()) EXPECT_STREQ("channel name (server)", serverChannel->getName().c_str()) << "server channel should have suffixed name"; << "server channel should have suffixed name"; EXPECT_STREQ("channel name (client)", clientChannel->getName().string()) EXPECT_STREQ("channel name (client)", clientChannel->getName().c_str()) << "client channel should have suffixed name"; << "client channel should have suffixed name"; // Server->Client communication // Server->Client communication Loading Loading @@ -111,7 +111,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading @@ -125,7 +125,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading @@ -141,7 +141,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading libs/input/tests/InputPublisherAndConsumer_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ protected: PreallocatedInputEventFactory mEventFactory; PreallocatedInputEventFactory mEventFactory; virtual void SetUp() { virtual void SetUp() { status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); mPublisher = new InputPublisher(serverChannel); mPublisher = new InputPublisher(serverChannel); Loading services/inputflinger/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ cc_library_shared { ], ], shared_libs: [ shared_libs: [ "libbase", "libbinder", "libbinder", "libcrypto", "libcrypto", "libcutils", "libcutils", Loading Loading
include/input/InputTransport.h +4 −5 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ #include <utils/Errors.h> #include <utils/Errors.h> #include <utils/Timers.h> #include <utils/Timers.h> #include <utils/RefBase.h> #include <utils/RefBase.h> #include <utils/String8.h> #include <utils/Vector.h> #include <utils/Vector.h> #include <utils/BitSet.h> #include <utils/BitSet.h> Loading Loading @@ -142,16 +141,16 @@ protected: virtual ~InputChannel(); virtual ~InputChannel(); public: public: InputChannel(const String8& name, int fd); InputChannel(const std::string& name, int fd); /* Creates a pair of input channels. /* Creates a pair of input channels. * * * Returns OK on success. * Returns OK on success. */ */ static status_t openInputChannelPair(const String8& name, static status_t openInputChannelPair(const std::string& name, sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel); sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel); inline String8 getName() const { return mName; } inline std::string getName() const { return mName; } inline int getFd() const { return mFd; } inline int getFd() const { return mFd; } /* Sends a message to the other endpoint. /* Sends a message to the other endpoint. Loading Loading @@ -183,7 +182,7 @@ public: sp<InputChannel> dup() const; sp<InputChannel> dup() const; private: private: String8 mName; std::string mName; int mFd; int mFd; }; }; Loading
libs/input/InputTransport.cpp +31 −31 Original line number Original line Diff line number Diff line Loading @@ -99,34 +99,34 @@ size_t InputMessage::size() const { // --- InputChannel --- // --- InputChannel --- InputChannel::InputChannel(const String8& name, int fd) : InputChannel::InputChannel(const std::string& name, int fd) : mName(name), mFd(fd) { mName(name), mFd(fd) { #if DEBUG_CHANNEL_LIFECYCLE #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel constructed: name='%s', fd=%d", ALOGD("Input channel constructed: name='%s', fd=%d", mName.string(), fd); mName.c_str(), fd); #endif #endif int result = fcntl(mFd, F_SETFL, O_NONBLOCK); int result = fcntl(mFd, F_SETFL, O_NONBLOCK); LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket " LOG_ALWAYS_FATAL_IF(result != 0, "channel '%s' ~ Could not make socket " "non-blocking. errno=%d", mName.string(), errno); "non-blocking. errno=%d", mName.c_str(), errno); } } InputChannel::~InputChannel() { InputChannel::~InputChannel() { #if DEBUG_CHANNEL_LIFECYCLE #if DEBUG_CHANNEL_LIFECYCLE ALOGD("Input channel destroyed: name='%s', fd=%d", ALOGD("Input channel destroyed: name='%s', fd=%d", mName.string(), mFd); mName.c_str(), mFd); #endif #endif ::close(mFd); ::close(mFd); } } status_t InputChannel::openInputChannelPair(const String8& name, status_t InputChannel::openInputChannelPair(const std::string& name, sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) { sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) { int sockets[2]; int sockets[2]; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { status_t result = -errno; status_t result = -errno; ALOGE("channel '%s' ~ Could not create socket pair. errno=%d", ALOGE("channel '%s' ~ Could not create socket pair. errno=%d", name.string(), errno); name.c_str(), errno); outServerChannel.clear(); outServerChannel.clear(); outClientChannel.clear(); outClientChannel.clear(); return result; return result; Loading @@ -138,12 +138,12 @@ status_t InputChannel::openInputChannelPair(const String8& name, setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); String8 serverChannelName = name; std::string serverChannelName = name; serverChannelName.append(" (server)"); serverChannelName += " (server)"; outServerChannel = new InputChannel(serverChannelName, sockets[0]); outServerChannel = new InputChannel(serverChannelName, sockets[0]); String8 clientChannelName = name; std::string clientChannelName = name; clientChannelName.append(" (client)"); clientChannelName += " (client)"; outClientChannel = new InputChannel(clientChannelName, sockets[1]); outClientChannel = new InputChannel(clientChannelName, sockets[1]); return OK; return OK; } } Loading @@ -158,7 +158,7 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (nWrite < 0) { if (nWrite < 0) { int error = errno; int error = errno; #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.string(), ALOGD("channel '%s' ~ error sending message of type %d, errno=%d", mName.c_str(), msg->header.type, error); msg->header.type, error); #endif #endif if (error == EAGAIN || error == EWOULDBLOCK) { if (error == EAGAIN || error == EWOULDBLOCK) { Loading @@ -173,13 +173,13 @@ status_t InputChannel::sendMessage(const InputMessage* msg) { if (size_t(nWrite) != msgLength) { if (size_t(nWrite) != msgLength) { #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ error sending message type %d, send was incomplete", ALOGD("channel '%s' ~ error sending message type %d, send was incomplete", mName.string(), msg->header.type); mName.c_str(), msg->header.type); #endif #endif return DEAD_OBJECT; return DEAD_OBJECT; } } #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ sent message of type %d", mName.string(), msg->header.type); ALOGD("channel '%s' ~ sent message of type %d", mName.c_str(), msg->header.type); #endif #endif return OK; return OK; } } Loading @@ -193,7 +193,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead < 0) { if (nRead < 0) { int error = errno; int error = errno; #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.string(), errno); ALOGD("channel '%s' ~ receive message failed, errno=%d", mName.c_str(), errno); #endif #endif if (error == EAGAIN || error == EWOULDBLOCK) { if (error == EAGAIN || error == EWOULDBLOCK) { return WOULD_BLOCK; return WOULD_BLOCK; Loading @@ -206,20 +206,20 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { if (nRead == 0) { // check for EOF if (nRead == 0) { // check for EOF #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.string()); ALOGD("channel '%s' ~ receive message failed because peer was closed", mName.c_str()); #endif #endif return DEAD_OBJECT; return DEAD_OBJECT; } } if (!msg->isValid(nRead)) { if (!msg->isValid(nRead)) { #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ received invalid message", mName.string()); ALOGD("channel '%s' ~ received invalid message", mName.c_str()); #endif #endif return BAD_VALUE; return BAD_VALUE; } } #if DEBUG_CHANNEL_MESSAGES #if DEBUG_CHANNEL_MESSAGES ALOGD("channel '%s' ~ received message of type %d", mName.string(), msg->header.type); ALOGD("channel '%s' ~ received message of type %d", mName.c_str(), msg->header.type); #endif #endif return OK; return OK; } } Loading Loading @@ -255,7 +255,7 @@ status_t InputPublisher::publishKeyEvent( ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " ALOGD("channel '%s' publisher ~ publishKeyEvent: seq=%u, deviceId=%d, source=0x%x, " "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," "action=0x%x, flags=0x%x, keyCode=%d, scanCode=%d, metaState=0x%x, repeatCount=%d," "downTime=%" PRId64 ", eventTime=%" PRId64, "downTime=%" PRId64 ", eventTime=%" PRId64, mChannel->getName().string(), seq, mChannel->getName().c_str(), seq, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, deviceId, source, action, flags, keyCode, scanCode, metaState, repeatCount, downTime, eventTime); downTime, eventTime); #endif #endif Loading Loading @@ -307,7 +307,7 @@ status_t InputPublisher::publishMotionEvent( "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, " "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", " "pointerCount=%" PRIu32, "pointerCount=%" PRIu32, mChannel->getName().string(), seq, mChannel->getName().c_str(), seq, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState, xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount); xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount); #endif #endif Loading @@ -319,7 +319,7 @@ status_t InputPublisher::publishMotionEvent( if (pointerCount > MAX_POINTERS || pointerCount < 1) { if (pointerCount > MAX_POINTERS || pointerCount < 1) { ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".", ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %" PRIu32 ".", mChannel->getName().string(), pointerCount); mChannel->getName().c_str(), pointerCount); return BAD_VALUE; return BAD_VALUE; } } Loading Loading @@ -352,7 +352,7 @@ status_t InputPublisher::publishMotionEvent( status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandled) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' publisher ~ receiveFinishedSignal", ALOGD("channel '%s' publisher ~ receiveFinishedSignal", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif InputMessage msg; InputMessage msg; Loading @@ -364,7 +364,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle } } if (msg.header.type != InputMessage::TYPE_FINISHED) { if (msg.header.type != InputMessage::TYPE_FINISHED) { ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer", ALOGE("channel '%s' publisher ~ Received unexpected message of type %d from consumer", mChannel->getName().string(), msg.header.type); mChannel->getName().c_str(), msg.header.type); return UNKNOWN_ERROR; return UNKNOWN_ERROR; } } *outSeq = msg.body.finished.seq; *outSeq = msg.body.finished.seq; Loading Loading @@ -402,7 +402,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, int32_t* displayId) { int32_t* displayId) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64, mChannel->getName().string(), consumeBatches ? "true" : "false", frameTime); mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime); #endif #endif *outSeq = 0; *outSeq = 0; Loading @@ -426,7 +426,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, if (*outEvent) { if (*outEvent) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u", ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -445,7 +445,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *outEvent = keyEvent; *outEvent = keyEvent; #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed key event, seq=%u", ALOGD("channel '%s' consumer ~ consumed key event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -458,7 +458,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ appended to batch event", ALOGD("channel '%s' consumer ~ appended to batch event", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif break; break; } else { } else { Loading @@ -474,7 +474,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed batch event and " ALOGD("channel '%s' consumer ~ consumed batch event and " "deferred current event, seq=%u", "deferred current event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } Loading @@ -488,7 +488,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, batch.samples.push(mMsg); batch.samples.push(mMsg); #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ started batch event", ALOGD("channel '%s' consumer ~ started batch event", mChannel->getName().string()); mChannel->getName().c_str()); #endif #endif break; break; } } Loading @@ -503,14 +503,14 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, *displayId = mMsg.body.motion.displayId; *displayId = mMsg.body.motion.displayId; #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u", mChannel->getName().string(), *outSeq); mChannel->getName().c_str(), *outSeq); #endif #endif break; break; } } default: default: ALOGE("channel '%s' consumer ~ Received unexpected message of type %d", ALOGE("channel '%s' consumer ~ Received unexpected message of type %d", mChannel->getName().string(), mMsg.header.type); mChannel->getName().c_str(), mMsg.header.type); return UNKNOWN_ERROR; return UNKNOWN_ERROR; } } } } Loading Loading @@ -828,7 +828,7 @@ bool InputConsumer::shouldResampleTool(int32_t toolType) { status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { #if DEBUG_TRANSPORT_ACTIONS #if DEBUG_TRANSPORT_ACTIONS ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", ALOGD("channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", mChannel->getName().string(), seq, handled ? "true" : "false"); mChannel->getName().c_str(), seq, handled ? "true" : "false"); #endif #endif if (!seq) { if (!seq) { Loading
libs/input/tests/InputChannel_test.cpp +8 −8 Original line number Original line Diff line number Diff line Loading @@ -41,9 +41,9 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor // of a pipe and to check for EPIPE on the other end after the channel is destroyed. // of a pipe and to check for EPIPE on the other end after the channel is destroyed. Pipe pipe; Pipe pipe; sp<InputChannel> inputChannel = new InputChannel(String8("channel name"), pipe.sendFd); sp<InputChannel> inputChannel = new InputChannel("channel name", pipe.sendFd); EXPECT_STREQ("channel name", inputChannel->getName().string()) EXPECT_STREQ("channel name", inputChannel->getName().c_str()) << "channel should have provided name"; << "channel should have provided name"; EXPECT_EQ(pipe.sendFd, inputChannel->getFd()) EXPECT_EQ(pipe.sendFd, inputChannel->getFd()) << "channel should have provided fd"; << "channel should have provided fd"; Loading @@ -60,16 +60,16 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) << "should have successfully opened a channel pair"; << "should have successfully opened a channel pair"; // Name // Name EXPECT_STREQ("channel name (server)", serverChannel->getName().string()) EXPECT_STREQ("channel name (server)", serverChannel->getName().c_str()) << "server channel should have suffixed name"; << "server channel should have suffixed name"; EXPECT_STREQ("channel name (client)", clientChannel->getName().string()) EXPECT_STREQ("channel name (client)", clientChannel->getName().c_str()) << "client channel should have suffixed name"; << "client channel should have suffixed name"; // Server->Client communication // Server->Client communication Loading Loading @@ -111,7 +111,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading @@ -125,7 +125,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading @@ -141,7 +141,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { sp<InputChannel> serverChannel, clientChannel; sp<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); ASSERT_EQ(OK, result) ASSERT_EQ(OK, result) Loading
libs/input/tests/InputPublisherAndConsumer_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ protected: PreallocatedInputEventFactory mEventFactory; PreallocatedInputEventFactory mEventFactory; virtual void SetUp() { virtual void SetUp() { status_t result = InputChannel::openInputChannelPair(String8("channel name"), status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); serverChannel, clientChannel); mPublisher = new InputPublisher(serverChannel); mPublisher = new InputPublisher(serverChannel); Loading
services/inputflinger/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -26,6 +26,7 @@ cc_library_shared { ], ], shared_libs: [ shared_libs: [ "libbase", "libbinder", "libbinder", "libcrypto", "libcrypto", "libcutils", "libcutils", Loading