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

Commit 9eb635c4 authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Use cached keyguard flags during relaunch." into oc-dev

parents f18c5862 081554b2
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -915,7 +915,11 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        }
        }
        if (mPendingRelaunchCount > 0) {
        if (mPendingRelaunchCount > 0) {
            mPendingRelaunchCount--;
            mPendingRelaunchCount--;
        } else {
            // Update keyguard flags upon finishing relaunch.
            checkKeyguardFlagsChanged();
        }
        }

        updateAllDrawn();
        updateAllDrawn();
    }
    }


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


    boolean containsDismissKeyguardWindow() {
    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--) {
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
                return true;
                return true;
@@ -1514,11 +1524,19 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
    }
    }


    boolean containsShowWhenLockedWindow() {
    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--) {
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
            if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
                return true;
                return true;
            }
            }
        }
        }

        return false;
        return false;
    }
    }


+30 −1
Original line number Original line 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_REVERSE_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
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;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;

/**
/**
 * Tests for the {@link AppWindowToken} class.
 * 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.
        // Can specify orientation if the current orientation candidate is orientation behind.
        assertEquals(SCREEN_ORIENTATION_LANDSCAPE, token.getOrientation(SCREEN_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());
    }
}
}