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

Commit fc9878c1 authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "Add traces for waitForAllWindowsDrawn logic" into tm-qpr-dev

parents f02c3268 b922dbed
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -329,6 +329,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static public final String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot";
    static public final String SYSTEM_DIALOG_REASON_GESTURE_NAV = "gestureNav";

    public static final String TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD = "waitForAllWindowsDrawn";

    private static final String TALKBACK_LABEL = "TalkBack";

    private static final int POWER_BUTTON_SUPPRESSION_DELAY_DEFAULT_MILLIS = 800;
@@ -4724,10 +4726,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {

        // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
        // as well as enabling the orientation change logic/sensor.
        Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD, /* cookie= */ 0);
        mWindowManagerInternal.waitForAllWindowsDrawn(() -> {
            if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for every display");
            mHandler.sendMessage(mHandler.obtainMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE,
                    INVALID_DISPLAY, 0));

            Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER,
                    TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD, /* cookie= */ 0);
            }, WAITING_FOR_DRAWN_TIMEOUT, INVALID_DISPLAY);
    }

@@ -4783,10 +4790,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        } else {
            mScreenOnListeners.put(displayId, screenOnListener);

            Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                    TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD, /* cookie= */ 0);
            mWindowManagerInternal.waitForAllWindowsDrawn(() -> {
                if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display: " + displayId);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE,
                        displayId, 0));

                Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER,
                        TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD, /* cookie= */ 0);
            }, WAITING_FOR_DRAWN_TIMEOUT, displayId);
        }
    }
+37 −2
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
import static com.android.internal.util.LatencyTracker.ACTION_ROTATE_SCREEN;
import static com.android.server.LockGuard.INDEX_WINDOW;
import static com.android.server.LockGuard.installLock;
import static com.android.server.policy.PhoneWindowManager.TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD;
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.ActivityTaskManagerService.POWER_MODE_REASON_CHANGE_DISPLAY;
import static com.android.server.wm.DisplayContent.IME_TARGET_CONTROL;
@@ -355,6 +356,7 @@ import java.util.function.Supplier;
public class WindowManagerService extends IWindowManager.Stub
        implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowManagerService" : TAG_WM;
    private static final int TRACE_MAX_SECTION_NAME_LENGTH = 127;

    static final int LAYOUT_REPEAT_THRESHOLD = 4;

@@ -5442,10 +5444,15 @@ public class WindowManagerService extends IWindowManager.Stub

                case WAITING_FOR_DRAWN_TIMEOUT: {
                    Runnable callback = null;
                    final WindowContainer container = (WindowContainer) msg.obj;
                    final WindowContainer<?> container = (WindowContainer<?>) msg.obj;
                    synchronized (mGlobalLock) {
                        ProtoLog.w(WM_ERROR, "Timeout waiting for drawn: undrawn=%s",
                                container.mWaitingForDrawn);
                        if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
                            for (int i = 0; i < container.mWaitingForDrawn.size(); i++) {
                                traceEndWaitingForWindowDrawn(container.mWaitingForDrawn.get(i));
                            }
                        }
                        container.mWaitingForDrawn.clear();
                        callback = mWaitingForDrawnCallbacks.remove(container);
                    }
@@ -6052,10 +6059,16 @@ public class WindowManagerService extends IWindowManager.Stub
                    // Window has been removed or hidden; no draw will now happen, so stop waiting.
                    ProtoLog.w(WM_DEBUG_SCREEN_ON, "Aborted waiting for drawn: %s", win);
                    container.mWaitingForDrawn.remove(win);
                    if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
                        traceEndWaitingForWindowDrawn(win);
                    }
                } else if (win.hasDrawn()) {
                    // Window is now drawn (and shown).
                    ProtoLog.d(WM_DEBUG_SCREEN_ON, "Window drawn win=%s", win);
                    container.mWaitingForDrawn.remove(win);
                    if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
                        traceEndWaitingForWindowDrawn(win);
                    }
                }
            }
            if (container.mWaitingForDrawn.isEmpty()) {
@@ -6066,6 +6079,22 @@ public class WindowManagerService extends IWindowManager.Stub
        });
    }

    private void traceStartWaitingForWindowDrawn(WindowState window) {
        final String traceName = TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD + "#"
                + window.getWindowTag();
        final String shortenedTraceName = traceName.substring(0, Math.min(
                TRACE_MAX_SECTION_NAME_LENGTH, traceName.length()));
        Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, shortenedTraceName, /* cookie= */ 0);
    }

    private void traceEndWaitingForWindowDrawn(WindowState window) {
        final String traceName = TRACE_WAIT_FOR_ALL_WINDOWS_DRAWN_METHOD + "#"
                + window.getWindowTag();
        final String shortenedTraceName = traceName.substring(0, Math.min(
                TRACE_MAX_SECTION_NAME_LENGTH, traceName.length()));
        Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, shortenedTraceName, /* cookie= */ 0);
    }

    void requestTraversal() {
        mWindowPlacerLocked.requestTraversal();
    }
@@ -7800,7 +7829,7 @@ public class WindowManagerService extends IWindowManager.Stub

        @Override
        public void waitForAllWindowsDrawn(Runnable callback, long timeout, int displayId) {
            final WindowContainer container = displayId == INVALID_DISPLAY
            final WindowContainer<?> container = displayId == INVALID_DISPLAY
                    ? mRoot : mRoot.getDisplayContent(displayId);
            if (container == null) {
                // The waiting container doesn't exist, no need to wait to run the callback. Run and
@@ -7816,6 +7845,12 @@ public class WindowManagerService extends IWindowManager.Stub
                if (container.mWaitingForDrawn.isEmpty()) {
                    allWindowsDrawn = true;
                } else {
                    if (Trace.isTagEnabled(TRACE_TAG_WINDOW_MANAGER)) {
                        for (int i = 0; i < container.mWaitingForDrawn.size(); i++) {
                            traceStartWaitingForWindowDrawn(container.mWaitingForDrawn.get(i));
                        }
                    }

                    mWaitingForDrawnCallbacks.put(container, callback);
                    mH.sendNewMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, container, timeout);
                    checkDrawnWindowsLocked();