From 81793808b9347a52dd979e4b3d5d9d10fc8c4915 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Thu, 13 Feb 2025 22:57:24 -0800 Subject: Harden construction sites of android::StrongPointer. Bug: 393217449 Test: presubmit Flag: EXEMPT_refactor Change-Id: Icf703aed608531e9b302b299481af00a52074731 --- libs/gui/SurfaceComposerClient.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'libs/gui/SurfaceComposerClient.cpp') diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 852885be61..de3f9ccd14 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -123,7 +123,7 @@ bool ComposerService::connectLocked() { explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { } }; - mDeathObserver = new DeathObserver(*const_cast(this)); + mDeathObserver = sp::make(*const_cast(this)); IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver); return true; } @@ -170,7 +170,7 @@ bool ComposerServiceAIDL::connectLocked() { explicit DeathObserver(ComposerServiceAIDL& mgr) : mComposerService(mgr) {} }; - mDeathObserver = new DeathObserver(*const_cast(this)); + mDeathObserver = sp::make(*const_cast(this)); IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver); return true; } @@ -202,7 +202,7 @@ public: DefaultComposerClient& dc = DefaultComposerClient::getInstance(); Mutex::Autolock _l(dc.mLock); if (dc.mClient == nullptr) { - dc.mClient = new SurfaceComposerClient; + dc.mClient = sp::make(); } return dc.mClient; } @@ -399,7 +399,7 @@ void TransactionCompletedListener::setInstance(const sp TransactionCompletedListener::getInstance() { std::lock_guard lock(sListenerInstanceMutex); if (sInstance == nullptr) { - sInstance = new TransactionCompletedListener; + sInstance = sp::make(); } return sInstance; } @@ -677,7 +677,7 @@ void TransactionCompletedListener::removeReleaseBufferCallback( SurfaceComposerClient::PresentationCallbackRAII::PresentationCallbackRAII( TransactionCompletedListener* tcl, int id) { - mTcl = tcl; + mTcl = sp::fromExisting(tcl); mId = id; } @@ -691,7 +691,7 @@ TransactionCompletedListener::addTrustedPresentationCallback(TrustedPresentation std::scoped_lock lock(mMutex); mTrustedPresentationCallbacks[id] = std::tuple(tpc, context); - return new SurfaceComposerClient::PresentationCallbackRAII(this, id); + return sp::make(this, id); } void TransactionCompletedListener::clearTrustedPresentationCallback(int id) { @@ -743,7 +743,7 @@ void removeDeadBufferCallback(void* /*context*/, uint64_t graphicBufferId); */ class BufferCache : public Singleton { public: - BufferCache() : token(new BBinder()) {} + BufferCache() : token(sp::make()) {} sp getToken() { return IInterface::asBinder(TransactionCompletedListener::getIInstance()); @@ -1357,7 +1357,7 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay return binderStatus; } -sp SurfaceComposerClient::Transaction::sApplyToken = new BBinder(); +sp SurfaceComposerClient::Transaction::sApplyToken = sp::make(); std::mutex SurfaceComposerClient::Transaction::sApplyTokenMutex; @@ -2695,9 +2695,10 @@ status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32 } ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err)); if (err == NO_ERROR) { - *outSurface = new SurfaceControl(this, result.handle, result.layerId, - toString(result.layerName), w, h, format, - result.transformHint, flags); + *outSurface = sp::make(sp::fromExisting(this), + result.handle, result.layerId, + toString(result.layerName), w, h, format, + result.transformHint, flags); } } return err; @@ -2713,7 +2714,8 @@ sp SurfaceComposerClient::mirrorSurface(SurfaceControl* mirrorFr const binder::Status status = mClient->mirrorSurface(mirrorFromHandle, &result); const status_t err = statusTFromBinderStatus(status); if (err == NO_ERROR) { - return new SurfaceControl(this, result.handle, result.layerId, toString(result.layerName)); + return sp::make(sp::fromExisting(this), + result.handle, result.layerId, toString(result.layerName)); } return nullptr; } @@ -2723,7 +2725,8 @@ sp SurfaceComposerClient::mirrorDisplay(DisplayId displayId) { const binder::Status status = mClient->mirrorDisplay(displayId.value, &result); const status_t err = statusTFromBinderStatus(status); if (err == NO_ERROR) { - return new SurfaceControl(this, result.handle, result.layerId, toString(result.layerName)); + return sp::make(sp::fromExisting(this), + result.handle, result.layerId, toString(result.layerName)); } return nullptr; } -- cgit v1.2.3-59-g8ed1b