Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc333972 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Return error when trying to disconnect twice" into oc-dev

parents 5330710a 3e198b2b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -487,6 +487,7 @@ public:
    // is considered a no-op.
    //
    // Return of a value other than NO_ERROR means an error has occurred:
    // * NO_INIT - the producer is not connected
    // * BAD_VALUE - one of the following has occurred:
    //             * the api specified does not match the one that was connected
    //             * api was out of range (see above).
+4 −1
Original line number Diff line number Diff line
@@ -1267,7 +1267,10 @@ status_t BufferQueueProducer::disconnect(int api, DisconnectMode mode) {
                    mCore->mSidebandStream.clear();
                    mCore->mDequeueCondition.broadcast();
                    listener = mCore->mConsumerListener;
                } else if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) {
                } else if (mCore->mConnectedApi == BufferQueueCore::NO_CONNECTED_API) {
                    BQ_LOGE("disconnect: not connected (req=%d)", api);
                    status = NO_INIT;
                } else {
                    BQ_LOGE("disconnect: still connected to another API "
                            "(cur=%d req=%d)", mCore->mConnectedApi, api);
                    status = BAD_VALUE;
+17 −0
Original line number Diff line number Diff line
@@ -1181,4 +1181,21 @@ TEST_F(BufferQueueTest, TestStaleBufferHandleSentAfterDisconnect) {
    ASSERT_NE(nullptr, item.mGraphicBuffer.get());
}

TEST_F(BufferQueueTest, TestProducerConnectDisconnect) {
    createBufferQueue();
    sp<DummyConsumer> dc(new DummyConsumer);
    ASSERT_EQ(OK, mConsumer->consumerConnect(dc, true));
    IGraphicBufferProducer::QueueBufferOutput output;
    sp<IProducerListener> dummyListener(new DummyProducerListener);
    ASSERT_EQ(NO_INIT, mProducer->disconnect(NATIVE_WINDOW_API_CPU));
    ASSERT_EQ(OK, mProducer->connect(
            dummyListener, NATIVE_WINDOW_API_CPU, true, &output));
    ASSERT_EQ(BAD_VALUE, mProducer->connect(
            dummyListener, NATIVE_WINDOW_API_MEDIA, true, &output));

    ASSERT_EQ(BAD_VALUE, mProducer->disconnect(NATIVE_WINDOW_API_MEDIA));
    ASSERT_EQ(OK, mProducer->disconnect(NATIVE_WINDOW_API_CPU));
    ASSERT_EQ(NO_INIT, mProducer->disconnect(NATIVE_WINDOW_API_CPU));
}

} // namespace android
+3 −1
Original line number Diff line number Diff line
@@ -450,7 +450,9 @@ status_t BufferHubQueueProducer::disconnect(int api, DisconnectMode /*mode*/) {

  std::unique_lock<std::mutex> lock(core_->mutex_);

  if (api != core_->connected_api_) {
  if (BufferHubQueueCore::kNoConnectedApi == core_->connected_api_) {
    return NO_INIT;
  } else if (api != core_->connected_api_) {
    return BAD_VALUE;
  }