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

Commit da12b32b authored by Craig Mautner's avatar Craig Mautner Committed by The Android Automerger
Browse files

Eliminate deferred surface destruction.

Removing the code that delays a surface destruction when
WindowManager.FLAG_KEEP_SURFACE_WHILE_ANIMATING is set. The lock
screen that continued to animate after destroySurfaceLocked is no
longer used and this code was causing problems.

Also mDrawState was being set to NO_SURFACE in destroySurfaceLocked
even if the surface ended up not being destroyed. Later when it was
reused the false value of mDrawState was messing things up.

The screen lock bug referenced below no longer levaes the user stuck
with a black lockscreen. However it occasionally powers back up in the
launcher screen rather than the lock screen.

Fixes bug 6485955.

Change-Id: I684104c7e7c39c161a5118aa890889fbae92e635
parent 56df8668
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -691,13 +691,6 @@ public interface WindowManager extends ViewManager {
         */
        public static final int FLAG_NEEDS_MENU_KEY = 0x08000000;

        /** Window flag: *sigh* The lock screen wants to continue running its
         * animation while it is fading.  A kind-of hack to allow this.  Maybe
         * in the future we just make this the default behavior.
         *
         * {@hide} */
        public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000;
        
        /** Window flag: special flag to limit the size of the window to be
         * original size ([320x480] x density). Used to create window for applications
         * running under compatibility mode.
+0 −1
Original line number Diff line number Diff line
@@ -117,7 +117,6 @@ public class KeyguardViewManager implements KeyguardWindowController {
            final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
            int flags = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
                    | WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING
                    | WindowManager.LayoutParams.FLAG_SLIPPERY
                    /*| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR*/ ;
+14 −32
Original line number Diff line number Diff line
@@ -1173,8 +1173,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (DEBUG_INPUT_METHOD) {
                Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
                if (!w.isVisibleOrAdding()) {
                    Slog.i(TAG, "  mSurface=" + w.mWinAnimator.mSurface + " reportDestroy="
                            + w.mWinAnimator.mReportDestroySurface
                    Slog.i(TAG, "  mSurface=" + w.mWinAnimator.mSurface
                            + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
                            + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden
                            + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
@@ -2651,7 +2650,7 @@ public class WindowManagerService extends IWindowManager.Stub
            int requestedHeight, int viewVisibility, int flags,
            Rect outFrame, Rect outContentInsets,
            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
        boolean displayed = false;
        boolean toBeDisplayed = false;
        boolean inTouchMode;
        boolean configChanged;
        boolean surfaceChanged = false;
@@ -2754,7 +2753,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            if (viewVisibility == View.VISIBLE &&
                    (win.mAppToken == null || !win.mAppToken.clientHidden)) {
                displayed = !win.isVisibleLw();
                toBeDisplayed = !win.isVisibleLw();
                if (win.mExiting) {
                    winAnimator.cancelExitAnimationForNextAnimationLocked();
                    win.mExiting = false;
@@ -2766,7 +2765,7 @@ public class WindowManagerService extends IWindowManager.Stub
                if (oldVisibility == View.GONE) {
                    winAnimator.mEnterAnimationPending = true;
                }
                if (displayed) {
                if (toBeDisplayed) {
                    if (win.isDrawnLw() && okToDisplay()) {
                        winAnimator.applyEnterAnimationLocked();
                    }
@@ -2792,7 +2791,7 @@ public class WindowManagerService extends IWindowManager.Stub
                if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
                    // To change the format, we need to re-build the surface.
                    winAnimator.destroySurfaceLocked();
                    displayed = true;
                    toBeDisplayed = true;
                    surfaceChanged = true;
                }
                try {
@@ -2802,8 +2801,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    Surface surface = winAnimator.createSurfaceLocked();
                    if (surface != null) {
                        outSurface.copyFrom(surface);
                        winAnimator.mReportDestroySurface = false;
                        winAnimator.mSurfacePendingDestroy = false;
                        if (SHOW_TRANSACTIONS) Slog.i(TAG,
                                "  OUT SURFACE " + outSurface + ": copied");
                    } else {
@@ -2820,7 +2817,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    Binder.restoreCallingIdentity(origId);
                    return 0;
                }
                if (displayed) {
                if (toBeDisplayed) {
                    focusMayChange = true;
                }
                if (win.mAttrs.type == TYPE_INPUT_METHOD
@@ -2845,11 +2842,10 @@ public class WindowManagerService extends IWindowManager.Stub
                winAnimator.mEnterAnimationPending = false;
                if (winAnimator.mSurface != null) {
                    if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
                            + ": mExiting=" + win.mExiting
                            + " mSurfacePendingDestroy=" + winAnimator.mSurfacePendingDestroy);
                            + ": mExiting=" + win.mExiting);
                    // If we are not currently running the exit animation, we
                    // need to see about starting one.
                    if (!win.mExiting || winAnimator.mSurfacePendingDestroy) {
                    if (!win.mExiting) {
                        surfaceChanged = true;
                        // Try starting an animation; if there isn't one, we
                        // can destroy the surface right away.
@@ -2857,7 +2853,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
                            transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
                        }
                        if (!winAnimator.mSurfacePendingDestroy && win.isWinVisibleLw() &&
                        if (win.isWinVisibleLw() &&
                                winAnimator.applyAnimationLocked(transit, false)) {
                            focusMayChange = true;
                            win.mExiting = true;
@@ -2880,22 +2876,8 @@ public class WindowManagerService extends IWindowManager.Stub
                    }
                }

                if (winAnimator.mSurface == null || (win.getAttrs().flags
                        & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0
                        || winAnimator.mSurfacePendingDestroy) {
                    // We could be called from a local process, which
                    // means outSurface holds its current surface.  Ensure the
                    // surface object is cleared, but we don't necessarily want
                    // it actually destroyed at this point.
                    winAnimator.mSurfacePendingDestroy = false;
                outSurface.release();
                if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
                } else if (winAnimator.mSurface != null) {
                    if (DEBUG_VISIBILITY) Slog.i(TAG,
                            "Keeping surface, will report destroy: " + win);
                    winAnimator.mReportDestroySurface = true;
                    outSurface.copyFrom(winAnimator.mSurface);
                }
            }

            if (focusMayChange) {
@@ -2912,7 +2894,7 @@ public class WindowManagerService extends IWindowManager.Stub
            boolean assignLayers = false;

            if (imMayMove) {
                if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
                if (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed) {
                    // Little hack here -- we -should- be able to rely on the
                    // function to return true if the IME has moved and needs
                    // its layer recomputed.  However, if the IME was hidden
@@ -2934,7 +2916,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            configChanged = updateOrientationFromAppTokensLocked(false);
            performLayoutAndPlaceSurfacesLocked();
            if (displayed && win.mIsWallpaper) {
            if (toBeDisplayed && win.mIsWallpaper) {
                updateWallpaperOffsetLocked(win, mAppDisplayWidth, mAppDisplayHeight, false);
            }
            if (win.mAppToken != null) {
@@ -2970,7 +2952,7 @@ public class WindowManagerService extends IWindowManager.Stub
        Binder.restoreCallingIdentity(origId);

        return (inTouchMode ? WindowManagerImpl.RELAYOUT_RES_IN_TOUCH_MODE : 0)
                | (displayed ? WindowManagerImpl.RELAYOUT_RES_FIRST_TIME : 0)
                | (toBeDisplayed ? WindowManagerImpl.RELAYOUT_RES_FIRST_TIME : 0)
                | (surfaceChanged ? WindowManagerImpl.RELAYOUT_RES_SURFACE_CHANGED : 0)
                | (animating ? WindowManagerImpl.RELAYOUT_RES_ANIMATING : 0);
    }
+1 −2
Original line number Diff line number Diff line
@@ -679,8 +679,7 @@ final class WindowState implements WindowManagerPolicy.WindowState {
     */
    boolean isVisibleOrAdding() {
        final AppWindowToken atoken = mAppToken;
        return ((mHasSurface && !mWinAnimator.mReportDestroySurface)
                        || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
        return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
                && mPolicyVisibility && !mAttachedHidden
                && (atoken == null || !atoken.hiddenRequested)
                && !mExiting && !mDestroying;
+2 −17
Original line number Diff line number Diff line
@@ -71,8 +71,6 @@ class WindowStateAnimator {

    Surface mSurface;
    Surface mPendingDestroySurface;
    boolean mReportDestroySurface;
    boolean mSurfacePendingDestroy;

    /**
     * Set when we have changed the size of the surface, to know that
@@ -561,8 +559,6 @@ class WindowStateAnimator {

    Surface createSurfaceLocked() {
        if (mSurface == null) {
            mReportDestroySurface = false;
            mSurfacePendingDestroy = false;
            if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
                    "createSurface " + this + ": mDrawState=DRAW_PENDING");
            mDrawState = DRAW_PENDING;
@@ -694,7 +690,6 @@ class WindowStateAnimator {
            mWin.mAppToken.startingDisplayed = false;
        }

        mDrawState = NO_SURFACE;
        if (mSurface != null) {

            int i = mWin.mChildWindows.size();
@@ -704,17 +699,6 @@ class WindowStateAnimator {
                c.mAttachedHidden = true;
            }

            if (mReportDestroySurface) {
                mReportDestroySurface = false;
                mSurfacePendingDestroy = true;
                try {
                    mWin.mClient.dispatchGetNewSurface();
                    // We'll really destroy on the next time around.
                    return;
                } catch (RemoteException e) {
                }
            }

            try {
                if (DEBUG_VISIBILITY) {
                    RuntimeException e = null;
@@ -760,6 +744,7 @@ class WindowStateAnimator {
            mSurfaceShown = false;
            mSurface = null;
            mWin.mHasSurface =false;
            mDrawState = NO_SURFACE;
        }
    }

@@ -1147,7 +1132,7 @@ class WindowStateAnimator {
            }
        } else {
            if (DEBUG_ANIM) {
                Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin);
                // Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin);
            }
            displayed = true;
        }