diff options
| -rw-r--r-- | include/input/InputTransport.h | 8 | ||||
| -rw-r--r-- | libs/gui/tests/EndToEndNativeInputTest.cpp | 7 | ||||
| -rw-r--r-- | libs/input/InputTransport.cpp | 10 | ||||
| -rw-r--r-- | libs/input/tests/InputChannel_test.cpp | 23 | ||||
| -rw-r--r-- | libs/input/tests/InputPublisherAndConsumer_test.cpp | 34 | ||||
| -rw-r--r-- | services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp | 5 | ||||
| -rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 12 | ||||
| -rw-r--r-- | services/inputflinger/tests/InputFlingerService_test.cpp | 6 | 
8 files changed, 47 insertions, 58 deletions
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index f337d009a0..24f8e77446 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -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) @@ -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; } @@ -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; diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index 7ec2c1a913..cca8dddfe6 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -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); @@ -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; diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 1bbddea8db..8dcc415940 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -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) { @@ -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) @@ -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; @@ -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(), diff --git a/libs/input/tests/InputChannel_test.cpp b/libs/input/tests/InputChannel_test.cpp index cc1382bbcb..0661261003 100644 --- a/libs/input/tests/InputChannel_test.cpp +++ b/libs/input/tests/InputChannel_test.cpp @@ -33,9 +33,6 @@  namespace android {  class InputChannelTest : public testing::Test { -protected: -    virtual void SetUp() { } -    virtual void TearDown() { }  }; @@ -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"; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) @@ -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); @@ -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";  } diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 3a7d20bfa2..5ddc85877c 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -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(); @@ -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() { diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 3d66d30d18..1914a38e09 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -128,7 +128,10 @@ public:  protected:      explicit FakeInputReceiver(const sp<InputDispatcher>& dispatcher, const std::string name)            : mDispatcher(dispatcher) { -        InputChannel::openInputChannelPair(name, mServerChannel, mClientChannel); +        std::unique_ptr<InputChannel> serverChannel, clientChannel; +        InputChannel::openInputChannelPair(name, serverChannel, clientChannel); +        mServerChannel = std::move(serverChannel); +        mClientChannel = std::move(clientChannel);          mConsumer = std::make_unique<InputConsumer>(mClientChannel);      } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 89314e141c..ce4d17de56 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -755,11 +755,11 @@ public:                       int32_t displayId, sp<IBinder> token = nullptr)            : mName(name) {          if (token == nullptr) { -            std::shared_ptr<InputChannel> serverChannel, clientChannel; +            std::unique_ptr<InputChannel> serverChannel, clientChannel;              InputChannel::openInputChannelPair(name, serverChannel, clientChannel); -            mInputReceiver = std::make_unique<FakeInputReceiver>(clientChannel, name); -            dispatcher->registerInputChannel(serverChannel); +            mInputReceiver = std::make_unique<FakeInputReceiver>(std::move(clientChannel), name);              token = serverChannel->getConnectionToken(); +            dispatcher->registerInputChannel(std::move(serverChannel));          }          inputApplicationHandle->updateInfo(); @@ -1768,10 +1768,10 @@ class FakeMonitorReceiver {  public:      FakeMonitorReceiver(const sp<InputDispatcher>& dispatcher, const std::string name,                          int32_t displayId, bool isGestureMonitor = false) { -        std::shared_ptr<InputChannel> serverChannel, clientChannel; +        std::unique_ptr<InputChannel> serverChannel, clientChannel;          InputChannel::openInputChannelPair(name, serverChannel, clientChannel); -        mInputReceiver = std::make_unique<FakeInputReceiver>(clientChannel, name); -        dispatcher->registerInputMonitor(serverChannel, displayId, isGestureMonitor); +        mInputReceiver = std::make_unique<FakeInputReceiver>(std::move(clientChannel), name); +        dispatcher->registerInputMonitor(std::move(serverChannel), displayId, isGestureMonitor);      }      sp<IBinder> getToken() { return mInputReceiver->getToken(); } diff --git a/services/inputflinger/tests/InputFlingerService_test.cpp b/services/inputflinger/tests/InputFlingerService_test.cpp index b88bc52aa1..206e260e37 100644 --- a/services/inputflinger/tests/InputFlingerService_test.cpp +++ b/services/inputflinger/tests/InputFlingerService_test.cpp @@ -113,7 +113,7 @@ protected:  private:      sp<SetInputWindowsListener> mSetInputWindowsListener; -    std::shared_ptr<InputChannel> mServerChannel, mClientChannel; +    std::unique_ptr<InputChannel> mServerChannel, mClientChannel;      InputWindowInfo mInfo;      std::mutex mLock;      std::condition_variable mSetInputWindowsFinishedCondition; @@ -336,7 +336,7 @@ TEST_F(InputFlingerServiceTest, InputWindow_SetInputWindows) {   *  Test InputFlinger service interface registerInputChannel   */  TEST_F(InputFlingerServiceTest, InputWindow_RegisterInputChannel) { -    std::shared_ptr<InputChannel> serverChannel, clientChannel; +    std::unique_ptr<InputChannel> serverChannel, clientChannel;      InputChannel::openInputChannelPair("testchannels", serverChannel, clientChannel);      mService->registerInputChannel(*serverChannel); @@ -355,7 +355,7 @@ TEST_F(InputFlingerServiceTest, InputWindow_RegisterInputChannel) {   *  Test InputFlinger service interface registerInputChannel with invalid cases   */  TEST_F(InputFlingerServiceTest, InputWindow_RegisterInputChannelInvalid) { -    std::shared_ptr<InputChannel> serverChannel, clientChannel; +    std::unique_ptr<InputChannel> serverChannel, clientChannel;      InputChannel::openInputChannelPair("testchannels", serverChannel, clientChannel);      std::vector<::android::InputChannel> channels;  |