Surface: Add force disconnection method.
Add a new method forceScopedDisconnect to Surface. This will
be used by the framework to force disconnection at times where
the underlying GraphicBufferProducer may be about to be reused.
This is scoped by PID to avoid conflicting with remote producers.
Bug: 30236166
Change-Id: I857216483c0b550f240b3baea41977cbc58a67ed
diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h
index 82bc121..cc5c536 100644
--- a/include/gui/BufferQueueCore.h
+++ b/include/gui/BufferQueueCore.h
@@ -182,6 +182,8 @@
// to this BufferQueue. It defaults to NO_CONNECTED_API, and gets updated
// by the connect and disconnect methods.
int mConnectedApi;
+ // PID of the process which last successfully called connect(...)
+ pid_t mConnectedPid;
// mConnectedProducerToken is used to set a binder death notification on
// the producer.
diff --git a/include/gui/BufferQueueProducer.h b/include/gui/BufferQueueProducer.h
index 838632c..8f613ee 100644
--- a/include/gui/BufferQueueProducer.h
+++ b/include/gui/BufferQueueProducer.h
@@ -135,15 +135,8 @@
virtual status_t connect(const sp<IProducerListener>& listener,
int api, bool producerControlledByApp, QueueBufferOutput* output);
- // disconnect attempts to disconnect a producer API from the BufferQueue.
- // Calling this method will cause any subsequent calls to other
- // IGraphicBufferProducer methods to fail except for getAllocator and connect.
- // Successfully calling connect after this will allow the other methods to
- // succeed again.
- //
- // This method will fail if the the BufferQueue is not currently
- // connected to the specified producer API.
- virtual status_t disconnect(int api);
+ // See IGraphicBufferProducer::disconnect
+ virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api);
// Attaches a sideband buffer stream to the IGraphicBufferProducer.
//
diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h
index c62bc58..bf427fe 100644
--- a/include/gui/IGraphicBufferProducer.h
+++ b/include/gui/IGraphicBufferProducer.h
@@ -458,17 +458,24 @@
virtual status_t connect(const sp<IProducerListener>& listener,
int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
+ enum class DisconnectMode {
+ // Disconnect only the specified API.
+ Api,
+ // Disconnect any API originally connected from the process calling disconnect.
+ AllLocal
+ };
+
// disconnect attempts to disconnect a client API from the
// IGraphicBufferProducer. Calling this method will cause any subsequent
// calls to other IGraphicBufferProducer methods to fail except for
// getAllocator and connect. Successfully calling connect after this will
// allow the other methods to succeed again.
//
- // This method will fail if the the IGraphicBufferProducer is not currently
- // connected to the specified client API.
- //
// The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
//
+ // Alternatively if mode is AllLocal, then the API value is ignored, and any API
+ // connected from the same PID calling disconnect will be disconnected.
+ //
// Disconnecting from an abandoned IGraphicBufferProducer is legal and
// is considered a no-op.
//
@@ -477,7 +484,7 @@
// * the api specified does not match the one that was connected
// * api was out of range (see above).
// * DEAD_OBJECT - the token is hosted by an already-dead process
- virtual status_t disconnect(int api) = 0;
+ virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0;
// Attaches a sideband buffer stream to the IGraphicBufferProducer.
//
diff --git a/include/gui/Surface.h b/include/gui/Surface.h
index 8177ec6..f4a22cb 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -203,7 +203,6 @@
virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
virtual int connect(int api);
- virtual int disconnect(int api);
virtual int setBufferCount(int bufferCount);
virtual int setBuffersDimensions(uint32_t width, uint32_t height);
virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
@@ -217,6 +216,10 @@
virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
public:
+ virtual int disconnect(int api,
+ IGraphicBufferProducer::DisconnectMode mode =
+ IGraphicBufferProducer::DisconnectMode::Api);
+
virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
virtual int setAsyncMode(bool async);
virtual int setSharedBufferMode(bool sharedBufferMode);