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

Commit 73b931f4 authored by Winson Chung's avatar Winson Chung
Browse files

Add callsite info to SurfaceControlViewHost

- Add callsite info for tracking leaks in SCVH
- Use CloseGuard for tracking SCVH leakage

Bug: 266978825
Test: Presubmit
Change-Id: I0ba1a14cd4752699cbc24d17d10e977ceceece38
parent 3462f7a7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public abstract class InlineSuggestionRenderService extends Service {
                    PixelFormat.TRANSPARENT);

            final SurfaceControlViewHost host = new SurfaceControlViewHost(this, getDisplay(),
                    hostInputToken);
                    hostInputToken, "InlineSuggestionRenderService");
            host.setView(suggestionRoot, lp);

            // Set the suggestion view to be non-focusable so that if its background is set to a
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public abstract class GameSessionService extends Service {
        final Context windowContext = createWindowContext(display,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, /*options=*/ null);
        SurfaceControlViewHost surfaceControlViewHost =
                new SurfaceControlViewHost(windowContext, display, hostToken);
                new SurfaceControlViewHost(windowContext, display, hostToken, "GameSessionService");

        gameSession.attach(
                gameSessionController,
+1 −1
Original line number Diff line number Diff line
@@ -275,7 +275,7 @@ final class RemoteSelectionToolbar {
                    mHostInputToken, mTransferTouchListener);
            contentHolder.addView(mContentContainer);
            mSurfaceControlViewHost = new SurfaceControlViewHost(mContext, mContext.getDisplay(),
                    mHostInputToken);
                    mHostInputToken, "RemoteSelectionToolbar");
            mSurfaceControlViewHost.setView(contentHolder, mPopupWidth, mPopupHeight);
        }
        if (mSurfacePackage == null) {
+30 −3
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.view.accessibility.IAccessibilityEmbeddedConnection;
import android.window.ISurfaceSyncGroup;
import android.window.WindowTokenClient;

import dalvik.system.CloseGuard;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
@@ -51,6 +53,7 @@ import java.util.concurrent.TimeoutException;
public class SurfaceControlViewHost {
    private final static String TAG = "SurfaceControlViewHost";
    private final ViewRootImpl mViewRoot;
    private final CloseGuard mCloseGuard = CloseGuard.get();
    private WindowlessWindowManager mWm;

    private SurfaceControl mSurfaceControl;
@@ -292,9 +295,10 @@ public class SurfaceControlViewHost {

    /** @hide */
    public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d,
            @NonNull WindowlessWindowManager wwm) {
            @NonNull WindowlessWindowManager wwm, @NonNull String callsite) {
        mWm = wwm;
        mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout());
        mCloseGuard.openWithCallSite("release", callsite);
        addConfigCallback(c, d);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
@@ -316,15 +320,35 @@ public class SurfaceControlViewHost {
     */
    public SurfaceControlViewHost(@NonNull Context context, @NonNull Display display,
            @Nullable IBinder hostToken) {
        this(context, display, hostToken, "untracked");
    }

    /**
     * Construct a new SurfaceControlViewHost. The root Surface will be
     * allocated internally and is accessible via getSurfacePackage().
     *
     * The {@param hostToken} parameter, primarily used for ANR reporting,
     * must be obtained from whomever will be hosting the embedded hierarchy.
     * It's accessible from {@link SurfaceView#getHostToken}.
     *
     * @param context The Context object for your activity or application.
     * @param display The Display the hierarchy will be placed on.
     * @param hostToken The host token, as discussed above.
     * @param callsite The call site, used for tracking leakage of the host
     * @hide
     */
    public SurfaceControlViewHost(@NonNull Context context, @NonNull Display display,
            @Nullable IBinder hostToken, @NonNull String callsite) {
        mSurfaceControl = new SurfaceControl.Builder()
                .setContainerLayer()
                .setName("SurfaceControlViewHost")
                .setCallsite("SurfaceControlViewHost")
                .setCallsite("SurfaceControlViewHost[" + callsite + "]")
                .build();
        mWm = new WindowlessWindowManager(context.getResources().getConfiguration(),
                mSurfaceControl, hostToken);

        mViewRoot = new ViewRootImpl(context, display, mWm, new WindowlessWindowLayout());
        mCloseGuard.openWithCallSite("release", callsite);
        addConfigCallback(context, display);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
@@ -350,7 +374,9 @@ public class SurfaceControlViewHost {
        if (mReleased) {
            return;
        }
        Log.e(TAG, "SurfaceControlViewHost finalized without being released: " + this);
        if (mCloseGuard != null) {
            mCloseGuard.warnIfOpen();
        }
        // We aren't on the UI thread here so we need to pass false to doDie
        mViewRoot.die(false /* immediate */);
        WindowManagerGlobal.getInstance().removeWindowlessRoot(mViewRoot);
@@ -466,6 +492,7 @@ public class SurfaceControlViewHost {
        mViewRoot.die(true /* immediate */);
        WindowManagerGlobal.getInstance().removeWindowlessRoot(mViewRoot);
        mReleased = true;
        mCloseGuard.close();
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -333,7 +333,8 @@ public final class SplashScreenView extends FrameLayout {

                SurfaceControlViewHost viewHost = new SurfaceControlViewHost(viewContext,
                        viewContext.getDisplay(),
                        surfaceView.getHostToken());
                        surfaceView.getHostToken(),
                        "SplashScreenView");
                ImageView imageView = new ImageView(viewContext);
                imageView.setBackground(mIconDrawable);
                viewHost.setView(imageView, mIconSize, mIconSize);
Loading