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

Commit ae73ba4c authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not always skip preparing window to display when already visible.

The window flag FLAG_TURN_SCREEN_ON relies on this method to properly
flag the screen to turn on. An optimization was put in place to skip
this method when the window was already visible. As a result, we would
skip turning the screen on if the activity was recreated.

This changelist addresses this issue by causing this method to execute
always if the flag is set.

Change-Id: I82c05c66136f7cc252b8d574d305809d455732ce
Fixes: 37432034
Test: bit FrameworksServicesTests:com.android.server.wm.WindowStateTests#testPrepareWindowToDisplayDuringRelayout
Test: go/wm-smoke
parent 0b1b1c43
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -2202,18 +2202,30 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
    }

    void prepareWindowToDisplayDuringRelayout(MergedConfiguration mergedConfiguration) {
    void prepareWindowToDisplayDuringRelayout(MergedConfiguration mergedConfiguration,
            boolean wasVisible) {
        // We need to turn on screen regardless of visibility.
        if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
            if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
            mTurnOnScreen = true;
        }

        // If we were already visible, skip rest of preparation.
        if (wasVisible) {
            if (DEBUG_VISIBILITY) Slog.v(TAG,
                    "Already visible and does not turn on screen, skip preparing: " + this);
            return;
        }

        if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
                == SOFT_INPUT_ADJUST_RESIZE) {
            mLayoutNeeded = true;
        }

        if (isDrawnLw() && mService.okToDisplay()) {
            mWinAnimator.applyEnterAnimationLocked();
        }
        if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
            if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
            mTurnOnScreen = true;
        }

        if (isConfigChanged()) {
            final Configuration globalConfig = mService.mRoot.getConfiguration();
            final Configuration overrideConfig = getMergedOverrideConfiguration();
@@ -4348,9 +4360,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mLastVisibleLayoutRotation = getDisplayContent().getRotation();

        mWinAnimator.mEnteringAnimation = true;
        if (!wasVisible) {
            prepareWindowToDisplayDuringRelayout(mergedConfiguration);
        }

        prepareWindowToDisplayDuringRelayout(mergedConfiguration, wasVisible);

        if ((attrChanges & FORMAT_CHANGED) != 0) {
            // If the format can't be changed in place, preserve the old surface until the app draws
            // on the new one. This prevents blinking when we change elevation of freeform and
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.wm;

import android.util.MergedConfiguration;
import android.view.WindowManager;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -204,4 +206,20 @@ public class WindowStateTests extends WindowTestsBase {
        assertEquals(mediaChild, windows.pollFirst());
        assertTrue(windows.isEmpty());
    }

    @Test
    public void testPrepareWindowToDisplayDuringRelayout() throws Exception {
        testPrepareWindowToDisplayDuringRelayout(false /*wasVisible*/);
        testPrepareWindowToDisplayDuringRelayout(true /*wasVisible*/);
    }

    private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) {
        final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
        root.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
        root.mTurnOnScreen = false;

        root.prepareWindowToDisplayDuringRelayout(new MergedConfiguration(),
                wasVisible /*wasVisible*/);
        assertTrue(root.mTurnOnScreen);
    }
}