Skip to content

Commit c1b4af3

Browse files
author
Anton Ivanov
committed
Ensure libgui classes that are held by sp<> are only constructed with sp<>::make.
Exception is SurfaceComposerClient, which is widely references in vendor code. Test: presubmit Flag: EXEMPT refactor Bug: 393217449 Change-Id: Ib1039a1f7bc5676d32a4067361f131fc79efad4d
1 parent 4a95d2d commit c1b4af3

4 files changed

Lines changed: 18 additions & 10 deletions

File tree

libs/gui/include/gui/BufferQueueProducer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class BufferQueueProducer : public BnGraphicBufferProducer {
3636
public:
3737
friend class BufferQueue; // Needed to access binderDied
3838

39-
explicit BufferQueueProducer(const sp<BufferQueueCore>& core,
40-
bool consumerIsSurfaceFlinger = false);
4139
~BufferQueueProducer() override;
4240

4341
// requestBuffer returns the GraphicBuffer for slot N.
@@ -219,6 +217,9 @@ class BufferQueueProducer : public BnGraphicBufferProducer {
219217
#endif
220218

221219
protected:
220+
explicit BufferQueueProducer(const sp<BufferQueueCore>& core,
221+
bool consumerIsSurfaceFlinger = false);
222+
friend class sp<BufferQueueProducer>;
222223
// see IGraphicsBufferProducer::setMaxDequeuedBufferCount, but with the ability to retrieve the
223224
// total maximum buffer count for the buffer queue (dequeued AND acquired)
224225
status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers, int* maxBufferCount);

libs/gui/include/gui/Choreographer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class Choreographer : public DisplayEventDispatcher, public MessageHandler {
7979
};
8080
static Context gChoreographers;
8181

82-
explicit Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle = nullptr)
83-
EXCLUDES(gChoreographers.lock);
8482
void postFrameCallbackDelayed(AChoreographer_frameCallback cb,
8583
AChoreographer_frameCallback64 cb64,
8684
AChoreographer_vsyncCallback vsyncCallback, void* data,
@@ -113,6 +111,10 @@ class Choreographer : public DisplayEventDispatcher, public MessageHandler {
113111

114112
private:
115113
Choreographer(const Choreographer&) = delete;
114+
explicit Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle = nullptr)
115+
EXCLUDES(gChoreographers.lock);
116+
friend class sp<Choreographer>;
117+
friend AChoreographer* AChoreographer_create();
116118

117119
void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count,
118120
VsyncEventData vsyncEventData) override;

libs/gui/include/gui/DisplayEventDispatcher.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride;
2323

2424
class DisplayEventDispatcher : public LooperCallback {
2525
public:
26-
explicit DisplayEventDispatcher(const sp<Looper>& looper,
27-
gui::ISurfaceComposer::VsyncSource vsyncSource =
28-
gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp,
29-
EventRegistrationFlags eventRegistration = {},
30-
const sp<IBinder>& layerHandle = nullptr);
31-
3226
status_t initialize();
3327
void dispose();
3428
status_t scheduleVsync();
@@ -38,6 +32,14 @@ class DisplayEventDispatcher : public LooperCallback {
3832
status_t getLatestVsyncEventData(ParcelableVsyncEventData* outVsyncEventData) const;
3933

4034
protected:
35+
explicit DisplayEventDispatcher(const sp<Looper>& looper,
36+
gui::ISurfaceComposer::VsyncSource vsyncSource =
37+
gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp,
38+
EventRegistrationFlags eventRegistration = {},
39+
const sp<IBinder>& layerHandle = nullptr);
40+
41+
friend class sp<DisplayEventDispatcher>;
42+
4143
virtual ~DisplayEventDispatcher() = default;
4244

4345
private:

libs/gui/include/gui/WindowInfosListenerReporter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class WindowInfosListenerReporter : public gui::BnWindowInfosListener {
4040
void reconnect(const sp<gui::ISurfaceComposer>&);
4141

4242
private:
43+
WindowInfosListenerReporter() = default;
44+
friend class sp<WindowInfosListenerReporter>;
45+
4346
std::mutex mListenersMutex;
4447
std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>>
4548
mWindowInfosListeners GUARDED_BY(mListenersMutex);

0 commit comments

Comments
 (0)