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

Commit 081554b2 authored by Bryce Lee's avatar Bryce Lee
Browse files

Use cached keyguard flags during relaunch.

It is possible for the display to be unfrozen before an
AppWindowToken is finished relaunching. This allows for other window
containers (such as the StatusBar) to influence the rotation when
unfreezing.

This changelist prevents the cached keyguard flag values for the
AppWindowToken when relaunching. This prevents incorrect values from
being reported during transient relaunch window states.

Fixes: 38262879
Test: bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests#testKeyguardFlagsDuringRelaunch

Change-Id: I2aa23ac282cf7626bb187c6cd1a4a3524f788877
parent fc6e6d13
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -913,7 +913,11 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        }
        if (mPendingRelaunchCount > 0) {
            mPendingRelaunchCount--;
        } else {
            // Update keyguard flags upon finishing relaunch.
            checkKeyguardFlagsChanged();
        }

        updateAllDrawn();
    }

@@ -1501,6 +1505,12 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
    }

    boolean containsDismissKeyguardWindow() {
        // Window state is transient during relaunch. We are not guaranteed to be frozen during the
        // entirety of the relaunch.
        if (isRelaunching()) {
            return mLastContainsDismissKeyguardWindow;
        }

        for (int i = mChildren.size() - 1; i >= 0; i--) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
                return true;
@@ -1510,11 +1520,19 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
    }

    boolean containsShowWhenLockedWindow() {
        // When we are relaunching, it is possible for us to be unfrozen before our previous
        // windows have been added back. Using the cached value ensures that our previous
        // showWhenLocked preference is honored until relaunching is complete.
        if (isRelaunching()) {
            return mLastContainsShowWhenLockedWindow;
        }

        for (int i = mChildren.size() - 1; i >= 0; i--) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
                return true;
            }
        }

        return false;
    }

+30 −1
Original line number Diff line number Diff line
@@ -30,13 +30,15 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * Tests for the {@link AppWindowToken} class.
 *
@@ -184,4 +186,31 @@ public class AppWindowTokenTests extends WindowTestsBase {
        // Can specify orientation if the current orientation candidate is orientation behind.
        assertEquals(SCREEN_ORIENTATION_LANDSCAPE, token.getOrientation(SCREEN_ORIENTATION_BEHIND));
    }

    @Test
    public void testKeyguardFlagsDuringRelaunch() throws Exception {
        final WindowTestUtils.TestAppWindowToken token =
                new WindowTestUtils.TestAppWindowToken(mDisplayContent);
        final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(
                TYPE_BASE_APPLICATION);
        attrs.flags |= FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD;
        attrs.setTitle("AppWindow");
        final WindowTestUtils.TestWindowState appWindow = createWindowState(attrs, token);

        // Add window with show when locked flag
        token.addWindow(appWindow);
        assertTrue(token.containsShowWhenLockedWindow() && token.containsDismissKeyguardWindow());

        // Start relaunching
        token.startRelaunching();
        assertTrue(token.containsShowWhenLockedWindow() && token.containsDismissKeyguardWindow());

        // Remove window and make sure that we still report back flag
        token.removeChild(appWindow);
        assertTrue(token.containsShowWhenLockedWindow() && token.containsDismissKeyguardWindow());

        // Finish relaunching and ensure flag is now not reported
        token.finishRelaunching();
        assertFalse(token.containsShowWhenLockedWindow() || token.containsDismissKeyguardWindow());
    }
}