Loading include/input/InputTransport.h +4 −4 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ struct InputMessage { */ class InputChannel : public Parcelable { public: static std::shared_ptr<InputChannel> create(const std::string& name, static std::unique_ptr<InputChannel> create(const std::string& name, android::base::unique_fd fd, sp<IBinder> token); InputChannel() = default; InputChannel(const InputChannel& other) Loading @@ -208,8 +208,8 @@ public: * Return OK on success. */ static status_t openInputChannelPair(const std::string& name, std::shared_ptr<InputChannel>& outServerChannel, std::shared_ptr<InputChannel>& outClientChannel); std::unique_ptr<InputChannel>& outServerChannel, std::unique_ptr<InputChannel>& outClientChannel); inline std::string getName() const { return mName; } inline const android::base::unique_fd& getFd() const { return mFd; } Loading Loading @@ -241,7 +241,7 @@ public: status_t receiveMessage(InputMessage* msg); /* Return a new object that has a duplicate of this channel's fd. */ std::shared_ptr<InputChannel> dup() const; std::unique_ptr<InputChannel> dup() const; status_t readFromParcel(const android::Parcel* parcel) override; status_t writeToParcel(android::Parcel* parcel) const override; Loading libs/gui/tests/EndToEndNativeInputTest.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -68,8 +68,9 @@ class InputSurface { public: InputSurface(const sp<SurfaceControl> &sc, int width, int height) { mSurfaceControl = sc; InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel); std::unique_ptr<InputChannel> clientChannel; InputChannel::openInputChannelPair("testchannels", mServerChannel, clientChannel); mClientChannel = std::move(clientChannel); mInputFlinger = getInputFlinger(); mInputFlinger->registerInputChannel(*mServerChannel); Loading Loading @@ -211,7 +212,7 @@ private: } public: sp<SurfaceControl> mSurfaceControl; std::shared_ptr<InputChannel> mServerChannel; std::unique_ptr<InputChannel> mServerChannel; std::shared_ptr<InputChannel> mClientChannel; sp<IInputFlinger> mInputFlinger; Loading libs/input/InputTransport.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { // --- InputChannel --- std::shared_ptr<InputChannel> InputChannel::create(const std::string& name, std::unique_ptr<InputChannel> InputChannel::create(const std::string& name, android::base::unique_fd fd, sp<IBinder> token) { const int result = fcntl(fd, F_SETFL, O_NONBLOCK); if (result != 0) { Loading @@ -252,7 +252,7 @@ std::shared_ptr<InputChannel> InputChannel::create(const std::string& name, return nullptr; } // using 'new' to access a non-public constructor return std::shared_ptr<InputChannel>(new InputChannel(name, std::move(fd), token)); return std::unique_ptr<InputChannel>(new InputChannel(name, std::move(fd), token)); } InputChannel::InputChannel(const std::string name, android::base::unique_fd fd, sp<IBinder> token) Loading @@ -269,8 +269,8 @@ InputChannel::~InputChannel() { } status_t InputChannel::openInputChannelPair(const std::string& name, std::shared_ptr<InputChannel>& outServerChannel, std::shared_ptr<InputChannel>& outClientChannel) { std::unique_ptr<InputChannel>& outServerChannel, std::unique_ptr<InputChannel>& outClientChannel) { int sockets[2]; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { status_t result = -errno; Loading Loading @@ -376,7 +376,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { return OK; } std::shared_ptr<InputChannel> InputChannel::dup() const { std::unique_ptr<InputChannel> InputChannel::dup() const { android::base::unique_fd newFd(::dup(getFd())); if (!newFd.ok()) { ALOGE("Could not duplicate fd %i for channel %s: %s", getFd().get(), getName().c_str(), Loading libs/input/tests/InputChannel_test.cpp +10 −13 Original line number Diff line number Diff line Loading @@ -33,9 +33,6 @@ namespace android { class InputChannelTest : public testing::Test { protected: virtual void SetUp() { } virtual void TearDown() { } }; Loading @@ -47,7 +44,7 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor android::base::unique_fd sendFd(pipe.sendFd); std::shared_ptr<InputChannel> inputChannel = std::unique_ptr<InputChannel> inputChannel = InputChannel::create("channel name", std::move(sendFd), new BBinder()); EXPECT_NE(inputChannel, nullptr) << "channel should be successfully created"; Loading @@ -62,14 +59,14 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor TEST_F(InputChannelTest, SetAndGetToken) { Pipe pipe; sp<IBinder> token = new BBinder(); std::shared_ptr<InputChannel> channel = std::unique_ptr<InputChannel> channel = InputChannel::create("test channel", android::base::unique_fd(pipe.sendFd), token); EXPECT_EQ(token, channel->getConnectionToken()); } TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading Loading @@ -120,7 +117,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { } TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -134,7 +131,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { } TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -150,7 +147,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { } TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -167,7 +164,7 @@ TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { } TEST_F(InputChannelTest, SendAndReceive_MotionClassification) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) Loading Loading @@ -199,7 +196,7 @@ TEST_F(InputChannelTest, SendAndReceive_MotionClassification) { } TEST_F(InputChannelTest, InputChannelParcelAndUnparcel) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel parceling", serverChannel, clientChannel); Loading @@ -218,14 +215,14 @@ TEST_F(InputChannelTest, InputChannelParcelAndUnparcel) { } TEST_F(InputChannelTest, DuplicateChannelAndAssertEqual) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel dup", serverChannel, clientChannel); ASSERT_EQ(OK, result) << "should have successfully opened a channel pair"; std::shared_ptr<InputChannel> dupChan = serverChannel->dup(); std::unique_ptr<InputChannel> dupChan = serverChannel->dup(); EXPECT_EQ(*serverChannel == *dupChan, true) << "inputchannel should be equal after duplication"; } Loading libs/input/tests/InputPublisherAndConsumer_test.cpp +11 −23 Original line number Diff line number Diff line Loading @@ -30,33 +30,21 @@ namespace android { class InputPublisherAndConsumerTest : public testing::Test { protected: std::shared_ptr<InputChannel> serverChannel, clientChannel; InputPublisher* mPublisher; InputConsumer* mConsumer; std::shared_ptr<InputChannel> mServerChannel, mClientChannel; std::unique_ptr<InputPublisher> mPublisher; std::unique_ptr<InputConsumer> mConsumer; PreallocatedInputEventFactory mEventFactory; virtual void SetUp() { void SetUp() override { std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result); mServerChannel = std::move(serverChannel); mClientChannel = std::move(clientChannel); mPublisher = new InputPublisher(serverChannel); mConsumer = new InputConsumer(clientChannel); } virtual void TearDown() { if (mPublisher) { delete mPublisher; mPublisher = nullptr; } if (mConsumer) { delete mConsumer; mConsumer = nullptr; } serverChannel.reset(); clientChannel.reset(); mPublisher = std::make_unique<InputPublisher>(mServerChannel); mConsumer = std::make_unique<InputConsumer>(mClientChannel); } void PublishAndConsumeKeyEvent(); Loading @@ -65,8 +53,8 @@ protected: }; TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) { EXPECT_EQ(serverChannel.get(), mPublisher->getChannel().get()); EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get()); EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get()); EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get()); } void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { Loading Loading
include/input/InputTransport.h +4 −4 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ struct InputMessage { */ class InputChannel : public Parcelable { public: static std::shared_ptr<InputChannel> create(const std::string& name, static std::unique_ptr<InputChannel> create(const std::string& name, android::base::unique_fd fd, sp<IBinder> token); InputChannel() = default; InputChannel(const InputChannel& other) Loading @@ -208,8 +208,8 @@ public: * Return OK on success. */ static status_t openInputChannelPair(const std::string& name, std::shared_ptr<InputChannel>& outServerChannel, std::shared_ptr<InputChannel>& outClientChannel); std::unique_ptr<InputChannel>& outServerChannel, std::unique_ptr<InputChannel>& outClientChannel); inline std::string getName() const { return mName; } inline const android::base::unique_fd& getFd() const { return mFd; } Loading Loading @@ -241,7 +241,7 @@ public: status_t receiveMessage(InputMessage* msg); /* Return a new object that has a duplicate of this channel's fd. */ std::shared_ptr<InputChannel> dup() const; std::unique_ptr<InputChannel> dup() const; status_t readFromParcel(const android::Parcel* parcel) override; status_t writeToParcel(android::Parcel* parcel) const override; Loading
libs/gui/tests/EndToEndNativeInputTest.cpp +4 −3 Original line number Diff line number Diff line Loading @@ -68,8 +68,9 @@ class InputSurface { public: InputSurface(const sp<SurfaceControl> &sc, int width, int height) { mSurfaceControl = sc; InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel); std::unique_ptr<InputChannel> clientChannel; InputChannel::openInputChannelPair("testchannels", mServerChannel, clientChannel); mClientChannel = std::move(clientChannel); mInputFlinger = getInputFlinger(); mInputFlinger->registerInputChannel(*mServerChannel); Loading Loading @@ -211,7 +212,7 @@ private: } public: sp<SurfaceControl> mSurfaceControl; std::shared_ptr<InputChannel> mServerChannel; std::unique_ptr<InputChannel> mServerChannel; std::shared_ptr<InputChannel> mClientChannel; sp<IInputFlinger> mInputFlinger; Loading
libs/input/InputTransport.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -243,7 +243,7 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { // --- InputChannel --- std::shared_ptr<InputChannel> InputChannel::create(const std::string& name, std::unique_ptr<InputChannel> InputChannel::create(const std::string& name, android::base::unique_fd fd, sp<IBinder> token) { const int result = fcntl(fd, F_SETFL, O_NONBLOCK); if (result != 0) { Loading @@ -252,7 +252,7 @@ std::shared_ptr<InputChannel> InputChannel::create(const std::string& name, return nullptr; } // using 'new' to access a non-public constructor return std::shared_ptr<InputChannel>(new InputChannel(name, std::move(fd), token)); return std::unique_ptr<InputChannel>(new InputChannel(name, std::move(fd), token)); } InputChannel::InputChannel(const std::string name, android::base::unique_fd fd, sp<IBinder> token) Loading @@ -269,8 +269,8 @@ InputChannel::~InputChannel() { } status_t InputChannel::openInputChannelPair(const std::string& name, std::shared_ptr<InputChannel>& outServerChannel, std::shared_ptr<InputChannel>& outClientChannel) { std::unique_ptr<InputChannel>& outServerChannel, std::unique_ptr<InputChannel>& outClientChannel) { int sockets[2]; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) { status_t result = -errno; Loading Loading @@ -376,7 +376,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) { return OK; } std::shared_ptr<InputChannel> InputChannel::dup() const { std::unique_ptr<InputChannel> InputChannel::dup() const { android::base::unique_fd newFd(::dup(getFd())); if (!newFd.ok()) { ALOGE("Could not duplicate fd %i for channel %s: %s", getFd().get(), getName().c_str(), Loading
libs/input/tests/InputChannel_test.cpp +10 −13 Original line number Diff line number Diff line Loading @@ -33,9 +33,6 @@ namespace android { class InputChannelTest : public testing::Test { protected: virtual void SetUp() { } virtual void TearDown() { } }; Loading @@ -47,7 +44,7 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor android::base::unique_fd sendFd(pipe.sendFd); std::shared_ptr<InputChannel> inputChannel = std::unique_ptr<InputChannel> inputChannel = InputChannel::create("channel name", std::move(sendFd), new BBinder()); EXPECT_NE(inputChannel, nullptr) << "channel should be successfully created"; Loading @@ -62,14 +59,14 @@ TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptor TEST_F(InputChannelTest, SetAndGetToken) { Pipe pipe; sp<IBinder> token = new BBinder(); std::shared_ptr<InputChannel> channel = std::unique_ptr<InputChannel> channel = InputChannel::create("test channel", android::base::unique_fd(pipe.sendFd), token); EXPECT_EQ(token, channel->getConnectionToken()); } TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading Loading @@ -120,7 +117,7 @@ TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) { } TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -134,7 +131,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) { } TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -150,7 +147,7 @@ TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) { } TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); Loading @@ -167,7 +164,7 @@ TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) { } TEST_F(InputChannelTest, SendAndReceive_MotionClassification) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result) Loading Loading @@ -199,7 +196,7 @@ TEST_F(InputChannelTest, SendAndReceive_MotionClassification) { } TEST_F(InputChannelTest, InputChannelParcelAndUnparcel) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel parceling", serverChannel, clientChannel); Loading @@ -218,14 +215,14 @@ TEST_F(InputChannelTest, InputChannelParcelAndUnparcel) { } TEST_F(InputChannelTest, DuplicateChannelAndAssertEqual) { std::shared_ptr<InputChannel> serverChannel, clientChannel; std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel dup", serverChannel, clientChannel); ASSERT_EQ(OK, result) << "should have successfully opened a channel pair"; std::shared_ptr<InputChannel> dupChan = serverChannel->dup(); std::unique_ptr<InputChannel> dupChan = serverChannel->dup(); EXPECT_EQ(*serverChannel == *dupChan, true) << "inputchannel should be equal after duplication"; } Loading
libs/input/tests/InputPublisherAndConsumer_test.cpp +11 −23 Original line number Diff line number Diff line Loading @@ -30,33 +30,21 @@ namespace android { class InputPublisherAndConsumerTest : public testing::Test { protected: std::shared_ptr<InputChannel> serverChannel, clientChannel; InputPublisher* mPublisher; InputConsumer* mConsumer; std::shared_ptr<InputChannel> mServerChannel, mClientChannel; std::unique_ptr<InputPublisher> mPublisher; std::unique_ptr<InputConsumer> mConsumer; PreallocatedInputEventFactory mEventFactory; virtual void SetUp() { void SetUp() override { std::unique_ptr<InputChannel> serverChannel, clientChannel; status_t result = InputChannel::openInputChannelPair("channel name", serverChannel, clientChannel); ASSERT_EQ(OK, result); mServerChannel = std::move(serverChannel); mClientChannel = std::move(clientChannel); mPublisher = new InputPublisher(serverChannel); mConsumer = new InputConsumer(clientChannel); } virtual void TearDown() { if (mPublisher) { delete mPublisher; mPublisher = nullptr; } if (mConsumer) { delete mConsumer; mConsumer = nullptr; } serverChannel.reset(); clientChannel.reset(); mPublisher = std::make_unique<InputPublisher>(mServerChannel); mConsumer = std::make_unique<InputConsumer>(mClientChannel); } void PublishAndConsumeKeyEvent(); Loading @@ -65,8 +53,8 @@ protected: }; TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) { EXPECT_EQ(serverChannel.get(), mPublisher->getChannel().get()); EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get()); EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get()); EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get()); } void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { Loading