From 421dfd5842d44a77883fac7ad2781c363e77aed3 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Tue, 22 Sep 2020 18:11:45 +0000 Subject: Convert SurfaceControl parceling to SAFE_PARCEL Test: Existing tests Change-Id: I7618f9677e538fca90ae5cfb0693e5926701f564 --- libs/gui/SurfaceControl.cpp | 49 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'libs/gui/SurfaceControl.cpp') diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index 8dcb71bcfc..0246b7315e 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -169,42 +169,35 @@ void SurfaceControl::setTransformHint(uint32_t hint) { mTransformHint = hint; } -void SurfaceControl::writeToParcel(Parcel* parcel) -{ - parcel->writeStrongBinder(ISurfaceComposerClient::asBinder(mClient->getClient())); - parcel->writeStrongBinder(mHandle); - parcel->writeStrongBinder(IGraphicBufferProducer::asBinder(mGraphicBufferProducer)); - parcel->writeUint32(mTransformHint); +status_t SurfaceControl::writeToParcel(Parcel& parcel) { + SAFE_PARCEL(parcel.writeStrongBinder, ISurfaceComposerClient::asBinder(mClient->getClient())); + SAFE_PARCEL(parcel.writeStrongBinder, mHandle); + SAFE_PARCEL(parcel.writeStrongBinder, IGraphicBufferProducer::asBinder(mGraphicBufferProducer)); + SAFE_PARCEL(parcel.writeUint32, mTransformHint); + + return NO_ERROR; } -sp SurfaceControl::readFromParcel(const Parcel* parcel) { - bool invalidParcel = false; - status_t status; +status_t SurfaceControl::readFromParcel(const Parcel& parcel, + sp* outSurfaceControl) { sp client; - if ((status = parcel->readStrongBinder(&client)) != OK) { - ALOGE("Failed to read client: %s", statusToString(status).c_str()); - invalidParcel = true; - } sp handle; - if ((status = parcel->readStrongBinder(&handle)) != OK) { - ALOGE("Failed to read handle: %s", statusToString(status).c_str()); - invalidParcel = true; - } sp gbp; - if ((status = parcel->readNullableStrongBinder(&gbp)) != OK) { - ALOGE("Failed to read gbp: %s", statusToString(status).c_str()); - invalidParcel = true; - } - uint32_t transformHint = parcel->readUint32(); + uint32_t transformHint; + + SAFE_PARCEL(parcel.readStrongBinder, &client); + SAFE_PARCEL(parcel.readStrongBinder, &handle); + SAFE_PARCEL(parcel.readNullableStrongBinder, &gbp); + SAFE_PARCEL(parcel.readUint32, &transformHint); - if (invalidParcel) { - return nullptr; - } // We aren't the original owner of the surface. - return new SurfaceControl(new SurfaceComposerClient( - interface_cast(client)), - handle.get(), interface_cast(gbp), + *outSurfaceControl = + new SurfaceControl(new SurfaceComposerClient( + interface_cast(client)), + handle.get(), interface_cast(gbp), transformHint); + + return NO_ERROR; } // ---------------------------------------------------------------------------- -- cgit v1.2.3-59-g8ed1b