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

Commit 41bd44e6 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Automerger Merge Worker
Browse files

Merge "Pass in callsite of SurfaceControl constructor explicitly (1/3)" into rvc-dev am: 37cf2279

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11920862

Change-Id: I19b6f83b3777bfeccbe90f1c531efcc59e41f54e
parents 11d419a3 37cf2279
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5151,7 +5151,7 @@ package android.view {
  }

  public final class SurfaceControl implements android.os.Parcelable {
    ctor public SurfaceControl(@NonNull android.view.SurfaceControl);
    ctor public SurfaceControl(@NonNull android.view.SurfaceControl, @NonNull String);
    method public static long acquireFrameRateFlexibilityToken();
    method public boolean isSameSurface(@NonNull android.view.SurfaceControl);
    method public static void releaseFrameRateFlexibilityToken(long);
+7 −0
Original line number Diff line number Diff line
@@ -1918,9 +1918,16 @@ public final class StrictMode {
    }

    private static class AndroidCloseGuardReporter implements CloseGuard.Reporter {

        @Override
        public void report(String message, Throwable allocationSite) {
            onVmPolicyViolation(new LeakedClosableViolation(message, allocationSite));
        }

        @Override
        public void report(String message) {
            onVmPolicyViolation(new LeakedClosableViolation(message));
        }
    }

    /** Called from Parcel.writeNoException() */
+5 −0
Original line number Diff line number Diff line
@@ -21,4 +21,9 @@ public final class LeakedClosableViolation extends Violation {
        super(message);
        initCause(allocationSite);
    }

    /** @hide */
    public LeakedClosableViolation(String message) {
        super(message);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class InsetsSourceControl implements Parcelable {
    public InsetsSourceControl(InsetsSourceControl other) {
        mType = other.mType;
        if (other.mLeash != null) {
            mLeash = new SurfaceControl(other.mLeash);
            mLeash = new SurfaceControl(other.mLeash, "InsetsSourceControl");
        } else {
            mLeash = null;
        }
+29 −13
Original line number Diff line number Diff line
@@ -499,14 +499,12 @@ public final class SurfaceControl implements Parcelable {
    private static final int INTERNAL_DATASPACE_DISPLAY_P3 = 143261696;
    private static final int INTERNAL_DATASPACE_SCRGB = 411107328;

    private void assignNativeObject(long nativeObject) {
    private void assignNativeObject(long nativeObject, String callsite) {
        if (mNativeObject != 0) {
            release();
        }
        if (nativeObject != 0) {
            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "closeGuard");
            mCloseGuard.open("release");
            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
            mCloseGuard.openWithCallSite("release", callsite);
        }
        mNativeObject = nativeObject;
        mNativeHandle = mNativeObject != 0 ? nativeGetHandle(nativeObject) : 0;
@@ -515,12 +513,12 @@ public final class SurfaceControl implements Parcelable {
    /**
     * @hide
     */
    public void copyFrom(@NonNull SurfaceControl other) {
    public void copyFrom(@NonNull SurfaceControl other, String callsite) {
        mName = other.mName;
        mWidth = other.mWidth;
        mHeight = other.mHeight;
        mLocalOwnerView = other.mLocalOwnerView;
        assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject));
        assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject), callsite);
    }

    /**
@@ -621,6 +619,7 @@ public final class SurfaceControl implements Parcelable {
        private WeakReference<View> mLocalOwnerView;
        private SurfaceControl mParent;
        private SparseIntArray mMetadata;
        private String mCallsite = "SurfaceControl.Builder";

        /**
         * Begin building a SurfaceControl with a given {@link SurfaceSession}.
@@ -654,7 +653,7 @@ public final class SurfaceControl implements Parcelable {
            }
            return new SurfaceControl(
                    mSession, mName, mWidth, mHeight, mFormat, mFlags, mParent, mMetadata,
                    mLocalOwnerView);
                    mLocalOwnerView, mCallsite);
        }

        /**
@@ -912,6 +911,18 @@ public final class SurfaceControl implements Parcelable {
            return this;
        }

        /**
         * Sets the callsite this SurfaceControl is constructed from.
         *
         * @param callsite String uniquely identifying callsite that created this object. Used for
         *                 leakage tracking.
         * @hide
         */
        public Builder setCallsite(String callsite) {
            mCallsite = callsite;
            return this;
        }

        private Builder setFlags(int flags, int mask) {
            mFlags = (mFlags & ~mask) | flags;
            return this;
@@ -943,10 +954,13 @@ public final class SurfaceControl implements Parcelable {
     * @param h        The surface initial height.
     * @param flags    The surface creation flags.
     * @param metadata Initial metadata.
     * @param callsite String uniquely identifying callsite that created this object. Used for
     *                 leakage tracking.
     * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
     */
    private SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags,
            SurfaceControl parent, SparseIntArray metadata, WeakReference<View> localOwnerView)
            SurfaceControl parent, SparseIntArray metadata, WeakReference<View> localOwnerView,
            String callsite)
                    throws OutOfResourcesException, IllegalArgumentException {
        if (name == null) {
            throw new IllegalArgumentException("name must not be null");
@@ -978,18 +992,20 @@ public final class SurfaceControl implements Parcelable {
                    "Couldn't allocate SurfaceControl native object");
        }
        mNativeHandle = nativeGetHandle(mNativeObject);
        mCloseGuard.open("release");
        mCloseGuard.openWithCallSite("release", callsite);
    }

    /**
     * Copy constructor. Creates a new native object pointing to the same surface as {@code other}.
     *
     * @param other The object to copy the surface from.
     * @param callsite String uniquely identifying callsite that created this object. Used for
     *                 leakage tracking.
     * @hide
     */
    @TestApi
    public SurfaceControl(@NonNull SurfaceControl other) {
        copyFrom(other);
    public SurfaceControl(@NonNull SurfaceControl other, @NonNull String callsite) {
        copyFrom(other, callsite);
    }

    private SurfaceControl(Parcel in) {
@@ -1015,7 +1031,7 @@ public final class SurfaceControl implements Parcelable {
        if (in.readInt() != 0) {
            object = nativeReadFromParcel(in);
        }
        assignNativeObject(object);
        assignNativeObject(object, "readFromParcel");
    }

    @Override
@@ -2209,7 +2225,7 @@ public final class SurfaceControl implements Parcelable {
    public static SurfaceControl mirrorSurface(SurfaceControl mirrorOf) {
        long nativeObj = nativeMirrorSurface(mirrorOf.mNativeObject);
        SurfaceControl sc = new SurfaceControl();
        sc.assignNativeObject(nativeObj);
        sc.assignNativeObject(nativeObj, "mirrorSurface");
        return sc;
    }

Loading