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

Commit 830249f3 authored by Ahan Wu's avatar Ahan Wu Committed by Wu Ahan
Browse files

Catch unexpected detached view while creating FrameTracker

Bug: 245083316
Test: atest FrameTrackerTest InteractionJankMonitorTest
Test: LatencyTrackerTest
Change-Id: I55941c78b7200bd70a4b30a29defc3c8306eead8
Merged-In: I55941c78b7200bd70a4b30a29defc3c8306eead8
parent bb103d52
Loading
Loading
Loading
Loading
+35 −2
Original line number Diff line number Diff line
@@ -431,6 +431,22 @@ public class InteractionJankMonitor {
    @VisibleForTesting
    public FrameTracker createFrameTracker(Configuration config, Session session) {
        final View view = config.mView;

        if (!config.hasValidView()) {
            boolean attached = false;
            boolean hasViewRoot = false;
            boolean hasRenderer = false;
            if (view != null) {
                attached = view.isAttachedToWindow();
                hasViewRoot = view.getViewRootImpl() != null;
                hasRenderer = view.getThreadedRenderer() != null;
            }
            Log.d(TAG, "create FrameTracker fails: view=" + view
                    + ", attached=" + attached + ", hasViewRoot=" + hasViewRoot
                    + ", hasRenderer=" + hasRenderer, new Throwable());
            return null;
        }

        final ThreadedRendererWrapper threadedRenderer =
                view == null ? null : new ThreadedRendererWrapper(view.getThreadedRenderer());
        final ViewRootWrapper viewRoot =
@@ -537,6 +553,7 @@ public class InteractionJankMonitor {

        // begin a new trace session.
        tracker = createFrameTracker(conf, new Session(cujType, conf.mTag));
        if (tracker == null) return false;
        putTracker(cujType, tracker);
        tracker.begin();

@@ -1054,9 +1071,19 @@ public class InteractionJankMonitor {
                    msg.append("Must pass in a valid surface control if only instrument surface; ");
                }
            } else {
                if (mView == null || !mView.isAttachedToWindow()) {
                if (!hasValidView()) {
                    shouldThrow = true;
                    msg.append("Null view or unattached view while instrumenting view; ");
                    boolean attached = false;
                    boolean hasViewRoot = false;
                    boolean hasRenderer = false;
                    if (mView != null) {
                        attached = mView.isAttachedToWindow();
                        hasViewRoot = mView.getViewRootImpl() != null;
                        hasRenderer = mView.getThreadedRenderer() != null;
                    }
                    String err = "invalid view: view=" + mView + ", attached=" + attached
                            + ", hasViewRoot=" + hasViewRoot + ", hasRenderer=" + hasRenderer;
                    msg.append(err);
                }
            }
            if (shouldThrow) {
@@ -1064,6 +1091,12 @@ public class InteractionJankMonitor {
            }
        }

        boolean hasValidView() {
            return mSurfaceOnly
                    || (mView != null && mView.isAttachedToWindow()
                    && mView.getViewRootImpl() != null && mView.getThreadedRenderer() != null);
        }

        /**
         * @return true if only instrumenting surface, false otherwise
         */