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

Commit 7f1fa997 authored by chaviw's avatar chaviw
Browse files

Don't take screenshot when no WSA surfaces are visible.

Currently screenshots are taken even when no WSA surfaces are visible.
This results in black screenshots geting taken and later used to show in
recents. Restore previous behavior where screenshots are not taken for
apps that don't have any WSA surfaces visible.

Test: Enter split screen. Put an app in the secondary screen. Exit
split screen and enter recents. App that was secondary should now contain
a correct screenshot instead of displaying a black screenshot.

Change-Id: I1417afa0bf6602f3ca7ed55e96fc94bce5f5b4fe
parent 7b9a2c76
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -223,6 +223,27 @@ class TaskSnapshotController {
            return null;
        }

        if (top.hasCommittedReparentToAnimationLeash()) {
            if (DEBUG_SCREENSHOT) {
                Slog.w(TAG_WM, "Failed to take screenshot. App is animating " + top);
            }
            return null;
        }

        final boolean hasVisibleChild = top.forAllWindows(
                // Ensure at least one window for the top app is visible before attempting to take
                // a screenshot. Visible here means that the WSA surface is shown and has an alpha
                // greater than 0.
                ws -> ws.mWinAnimator != null && ws.mWinAnimator.getShown()
                        && ws.mWinAnimator.mLastAlpha > 0f, true);

        if (!hasVisibleChild) {
            if (DEBUG_SCREENSHOT) {
                Slog.w(TAG_WM, "Failed to take screenshot. No visible windows for " + task);
            }
            return null;
        }

        final boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
        final float scaleFraction = isLowRamDevice ? REDUCED_SCALE : 1f;
        task.getBounds(mTmpRect);
@@ -233,7 +254,7 @@ class TaskSnapshotController {

        if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
            if (DEBUG_SCREENSHOT) {
                Slog.w(TAG_WM, "Failed to take screenshot");
                Slog.w(TAG_WM, "Failed to take screenshot for " + task);
            }
            return null;
        }
+18 −0
Original line number Diff line number Diff line
@@ -100,6 +100,12 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    /** Total number of elements in this subtree, including our own hierarchy element. */
    private int mTreeWeight = 1;

    /**
     * Indicates whether we are animating and have committed the transaction to reparent our 
     * surface to the animation leash
     */
    private boolean mCommittedReparentToAnimationLeash;

    WindowContainer(WindowManagerService service) {
        mService = service;
        mPendingTransaction = service.mTransactionFactory.make();
@@ -1025,11 +1031,23 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     */
    void prepareSurfaces() {
        SurfaceControl.mergeToGlobalTransaction(getPendingTransaction());

        // If a leash has been set when the transaction was committed, then the leash reparent has
        // been committed.
        mCommittedReparentToAnimationLeash = mSurfaceAnimator.hasLeash();
        for (int i = 0; i < mChildren.size(); i++) {
            mChildren.get(i).prepareSurfaces();
        }
    }

    /**
     * @return true if the reparent to animation leash transaction has been committed, false
     * otherwise.
     */
    boolean hasCommittedReparentToAnimationLeash() {
        return mCommittedReparentToAnimationLeash;
    }

    /**
     * Trigger a call to prepareSurfaces from the animation thread, such that
     * mPendingTransaction will be applied.