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

Commit d06e606b authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Do not retry taking screenshots

We are holding the activity manager lock during a sleep() :-(, which
is a really really bad idea, and leads to delays in certain cases.

Bug: 28026841
Change-Id: I0855350ee429907e4597e5813c7e4fefd889319d
parent b2005a02
Loading
Loading
Loading
Loading
+136 −158
Original line number Diff line number Diff line
@@ -6024,7 +6024,6 @@ public class WindowManagerService extends IWindowManager.Stub
            minLayer = Integer.MAX_VALUE;
        }

        int retryCount = 0;
        WindowState appWin = null;

        boolean appIsImTarget;
@@ -6038,17 +6037,6 @@ public class WindowManagerService extends IWindowManager.Stub
        final int aboveAppLayer = (mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1)
                * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;

        while (true) {
            if (retryCount++ > 0) {
                // Reset max/min layers on retries so we don't accidentally take a screenshot of a
                // layer based on the previous try.
                maxLayer = 0;
                minLayer = Integer.MAX_VALUE;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
        synchronized(mWindowMap) {
            // Figure out the part of the screen that is actually the app.
            appWin = null;
@@ -6131,19 +6119,12 @@ public class WindowManagerService extends IWindowManager.Stub
            }

            if (!screenshotReady) {
                    if (retryCount > MAX_SCREENSHOT_RETRIES) {
                        Slog.i(TAG_WM, "Screenshot max retries " + retryCount + " of " + appToken +
                Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken +
                        " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" +
                        appWin.mWinAnimator.mDrawState)));
                return null;
            }

                    // Delay and hope that window gets drawn.
                    if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot: No image ready for " + appToken
                            + ", " + appWin + " drawState=" + appWin.mWinAnimator.mDrawState);
                    continue;
                }

            // Screenshot is ready to be taken. Everything from here below will continue
            // through the bottom of the loop and return a value. We only stay in the loop
            // because we don't want to release the mWindowMap lock until the screenshot is
@@ -6224,9 +6205,6 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

            break;
        }

        if (DEBUG_SCREENSHOT) {
            // TEST IF IT's ALL BLACK
            int[] buffer = new int[bm.getWidth() * bm.getHeight()];