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

Commit cbd40e68 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Only clear SurfaceControl.Transaction when parcelling as a return value

Fix this by have writeToParcel respect PARCELABLE_WRITE_RETURN_VALUE.

Fixes: b/185178151
Test: go/wm-smoke

Change-Id: Ic146d1bbb9a68be6c4f4fea10c65f81b1b36d760
parent 9ad3b820
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeApplyTransaction(long transactionObj, boolean sync);
    private static native void nativeMergeTransaction(long transactionObj,
            long otherTransactionObj);
    private static native void nativeClearTransaction(long transactionObj);
    private static native void nativeSetAnimationTransaction(long transactionObj);
    private static native void nativeSetEarlyWakeupStart(long transactionObj);
    private static native void nativeSetEarlyWakeupEnd(long transactionObj);
@@ -2603,6 +2604,19 @@ public final class SurfaceControl implements Parcelable {
            apply(false);
        }

        /**
         * Clear the transaction object, without applying it.
         *
         * @hide
         */
        public void clear() {
            mResizedSurfaces.clear();
            mReparentedSurfaces.clear();
            if (mNativeObject != 0) {
                nativeClearTransaction(mNativeObject);
            }
        }

        /**
         * Release the native transaction object, without applying it.
         */
@@ -3428,10 +3442,14 @@ public final class SurfaceControl implements Parcelable {
        public void writeToParcel(@NonNull Parcel dest, @WriteFlags int flags) {
            if (mNativeObject == 0) {
                dest.writeInt(0);
            } else {
                dest.writeInt(1);
                return;
            }

            dest.writeInt(1);
            nativeWriteTransactionToParcel(mNativeObject, dest);
            if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
                nativeClearTransaction(mNativeObject);
            }
        }

        private void readFromParcel(Parcel in) {
+4 −1
Original line number Diff line number Diff line
@@ -3901,7 +3901,10 @@ public final class ViewRootImpl implements ViewParent,
            mDrawsNeededToReport = 0;
            mWindowSession.finishDrawing(mWindow, mSurfaceChangedTransaction);
        } catch (RemoteException e) {
            // Have fun!
            Log.e(mTag, "Unable to report draw finished", e);
            mSurfaceChangedTransaction.apply();
        } finally {
            mSurfaceChangedTransaction.clear();
        }
    }

+9 −0
Original line number Diff line number Diff line
@@ -1570,6 +1570,13 @@ static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nati
            reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
    if (self != nullptr) {
        self->writeToParcel(parcel);
    }
}

static void nativeClearTransaction(JNIEnv* env, jclass clazz, jlong nativeObject) {
    SurfaceComposerClient::Transaction* const self =
            reinterpret_cast<SurfaceComposerClient::Transaction*>(nativeObject);
    if (self != nullptr) {
        self->clear();
    }
}
@@ -1890,6 +1897,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeReadTransactionFromParcel },
    {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
            (void*)nativeWriteTransactionToParcel },
    {"nativeClearTransaction", "(J)V",
            (void*)nativeClearTransaction },
    {"nativeMirrorSurface", "(J)J",
            (void*)nativeMirrorSurface },
    {"nativeSetGlobalShadowSettings", "([F[FFFF)V",