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

Commit e39501e7 authored by Pascal Mütschard's avatar Pascal Mütschard Committed by Android (Google) Code Review
Browse files

Merge "Tie the jank listener lifetime to the registration." into main

parents 7acbff03 d9dd4341
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -594,6 +594,7 @@ public final class SurfaceControl implements Parcelable {

        private final Runnable mFreeNativeResources;
        private boolean mRemoved = false;
        private OnJankDataListener mListener;

        private OnJankDataListenerRegistration() {
            mNativeObject = 0;
@@ -604,6 +605,8 @@ public final class SurfaceControl implements Parcelable {
            mNativeObject = nativeCreateJankDataListenerWrapper(surface.mNativeObject, listener);
            mFreeNativeResources = (mNativeObject == 0) ? () -> {} :
                    sRegistry.registerNativeAllocation(this, mNativeObject);
            // Make sure the listener doesn't get GCed as long as the registration is alive.
            mListener = listener;
        }

        /**
@@ -643,6 +646,7 @@ public final class SurfaceControl implements Parcelable {
            if (!mRemoved) {
                removeAfter(0);
            }
            mListener = null;
            mFreeNativeResources.run();
        }
    }