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

Commit ccf93234 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add SurfaceView callback event logs" into main

parents 995f91ad 771ec0b5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@ option java_package android.view
# following other view events defined in system/logging/logcat/event.logtags
# ViewRoot Draw Events
60004 viewroot_draw_event (window|3),(event|3)
# SurfaceView Events
60005 surfaceview_layout (window|3),(format|1),(width|1),(height|1),(z|1),(sizeFrom|3),(attached|1),(lifecycleStrategy|1),(viewVisible|1)
60006 surfaceview_callback (window|3),(callback|3)


# NOTE - the range 1000000-2000000 is reserved for partners and others who
+40 −4
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.SystemClock;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.EventLog;
import android.util.Log;
import android.view.SurfaceControl.Transaction;
import android.view.accessibility.AccessibilityNodeInfo;
@@ -163,6 +164,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    private static final boolean DEBUG_POSITION = false;

    private static final long FORWARD_BACK_KEY_TOLERANCE_MS = 100;
    private static final int LOGTAG_SURFACEVIEW_LAYOUT = 60005;
    private static final int LOGTAG_SURFACEVIEW_CALLBACK = 60006;

    @UnsupportedAppUsage(
            maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
@@ -320,6 +323,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    private final ConcurrentLinkedQueue<WindowManager.LayoutParams> mEmbeddedWindowParams =
            new ConcurrentLinkedQueue<>();

    private String mTag = TAG;

    private final ISurfaceControlViewHostParent mSurfaceControlViewHostParent =
            new ISurfaceControlViewHostParent.Stub() {
        @Override
@@ -418,13 +423,26 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        updateSurface();
    }

    private void setTag() {
        String windowName = "";
        ViewRootImpl viewRoot = getViewRootImpl();
        if (viewRoot != null) {
            // strip package name
            final String[] split = viewRoot.mWindowAttributes.getTitle().toString().split("\\.");
            if (split.length > 0) {
                windowName =  " " + split[split.length - 1];
            }
        }

        mTag = "SV[" + System.identityHashCode(this) + windowName + "]";
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        setTag();
        getViewRootImpl().addSurfaceChangedCallback(this);
        mWindowStopped = false;

        mViewVisibility = getVisibility() == VISIBLE;
        updateRequestedVisibility();

@@ -1146,13 +1164,22 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                    + " format=" + formatChanged + " size=" + sizeChanged
                    + " visible=" + visibleChanged + " alpha=" + alphaChanged
                    + " hint=" + hintChanged
                    + " visible=" + visibleChanged
                    + " left=" + (mWindowSpaceLeft != mLocation[0])
                    + " top=" + (mWindowSpaceTop != mLocation[1])
                    + " z=" + relativeZChanged
                    + " attached=" + mAttachedToWindow
                    + " lifecycleStrategy=" + surfaceLifecycleStrategyChanged);

            if (creating || formatChanged || sizeChanged  || visibleChanged
                    || layoutSizeChanged ||  relativeZChanged || !mAttachedToWindow
                    || surfaceLifecycleStrategyChanged ) {
                EventLog.writeEvent(LOGTAG_SURFACEVIEW_LAYOUT,
                        mTag, mRequestedFormat, myWidth, myHeight, mRequestedSubLayer,
                        (mRequestedWidth > 0 ? "setFixedSize" : "layout"),
                        (mAttachedToWindow ? 1 : 0),
                        mRequestedSurfaceLifecycleStrategy, (mRequestedVisible ? 1 : 0));
            }

            try {
                mVisible = mRequestedVisible;
                mWindowSpaceLeft = mLocation[0];
@@ -1235,6 +1262,8 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                            mIsCreating = true;
                            if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
                                    + "visibleChanged -- surfaceCreated");
                            EventLog.writeEvent(LOGTAG_SURFACEVIEW_CALLBACK, mTag,
                                "surfaceCreated");
                            callbacks = getSurfaceCallbacks();
                            for (SurfaceHolder.Callback c : callbacks) {
                                c.surfaceCreated(mSurfaceHolder);
@@ -1245,6 +1274,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                            if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
                                    + "surfaceChanged -- format=" + mFormat
                                    + " w=" + myWidth + " h=" + myHeight);
                            EventLog.writeEvent(LOGTAG_SURFACEVIEW_CALLBACK, mTag,
                                    "surfaceChanged -- format=" + mFormat
                                    + " w=" + myWidth + " h=" + myHeight);
                            if (callbacks == null) {
                                callbacks = getSurfaceCallbacks();
                            }
@@ -1256,6 +1288,9 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                            if (DEBUG) {
                                Log.i(TAG, System.identityHashCode(this) + " surfaceRedrawNeeded");
                            }
                            EventLog.writeEvent(LOGTAG_SURFACEVIEW_CALLBACK, mTag,
                                "surfaceRedrawNeeded");

                            if (callbacks == null) {
                                callbacks = getSurfaceCallbacks();
                            }
@@ -1337,7 +1372,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall

    private void redrawNeededAsync(SurfaceHolder.Callback[] callbacks,
            Runnable callbacksCollected) {
        SurfaceCallbackHelper sch = new SurfaceCallbackHelper(callbacksCollected);
        SurfaceCallbackHelper sch = new SurfaceCallbackHelper(callbacksCollected, mTag);
        sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks);
    }

@@ -2100,6 +2135,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        if (mSurface.isValid()) {
            if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
                    + "surfaceDestroyed");
            EventLog.writeEvent(LOGTAG_SURFACEVIEW_CALLBACK, mTag, "surfaceDestroyed");
            SurfaceHolder.Callback[] callbacks = getSurfaceCallbacks();
            for (SurfaceHolder.Callback c : callbacks) {
                c.surfaceDestroyed(mSurfaceHolder);
+16 −2
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@

package com.android.internal.view;

import android.os.RemoteException;
import android.view.Surface;
import android.util.EventLog;
import android.view.SurfaceHolder;

public class SurfaceCallbackHelper {
    private static final int LOGTAG_SURFACEVIEW_CALLBACK = 60006;
    private final String mTag;
    private boolean mSurfaceRedrawImplemented;
    Runnable mRunnable;

    int mFinishDrawingCollected = 0;
@@ -35,12 +37,23 @@ public class SurfaceCallbackHelper {
                        return;
                    }
                    mRunnable.run();
                    if (mSurfaceRedrawImplemented && mTag != null) {
                        EventLog.writeEvent(LOGTAG_SURFACEVIEW_CALLBACK, mTag,
                                "surfaceRedrawNeeded implemented");
                    }
                }
            }
    };

    public SurfaceCallbackHelper(Runnable callbacksCollected) {
        // skip logging surfaceRedrawNeeded calls
        this(callbacksCollected, null);
    }

    public SurfaceCallbackHelper(Runnable callbacksCollected, String tag) {
        mRunnable = callbacksCollected;
        mTag = tag;
        mSurfaceRedrawImplemented = false;
    }

    public void dispatchSurfaceRedrawNeededAsync(SurfaceHolder holder, SurfaceHolder.Callback callbacks[]) {
@@ -58,6 +71,7 @@ public class SurfaceCallbackHelper {
            if (c instanceof SurfaceHolder.Callback2) {
                ((SurfaceHolder.Callback2) c).surfaceRedrawNeededAsync(
                        holder, mFinishDrawingRunnable);
                mSurfaceRedrawImplemented = true;
            } else {
                mFinishDrawingRunnable.run();
            }