• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package android.server.wm;
18 
19 import static android.server.wm.UiDeviceUtils.pressBackButton;
20 import static android.server.wm.app.Components.DISMISS_KEYGUARD_ACTIVITY;
21 import static android.view.Display.DEFAULT_DISPLAY;
22 
23 import static org.junit.Assume.assumeTrue;
24 
25 import android.platform.test.annotations.Presubmit;
26 import android.server.wm.WindowManagerState.DisplayContent;
27 import android.util.Size;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 
32 /**
33  * Display tests that require a keyguard.
34  *
35  * <p>Build/Install/Run:
36  *     atest CtsWindowManagerDeviceTestCases:MultiDisplayKeyguardTests
37  */
38 @Presubmit
39 @android.server.wm.annotation.Group3
40 public class MultiDisplayKeyguardTests extends MultiDisplayTestBase {
41 
42     @Before
43     @Override
setUp()44     public void setUp() throws Exception {
45         super.setUp();
46 
47         assumeTrue(supportsMultiDisplay());
48         assumeTrue(supportsInsecureLock());
49     }
50 
51     /**
52      * Tests whether a FLAG_DISMISS_KEYGUARD activity on a secondary display is visible (for an
53      * insecure keyguard).
54      */
55     @Test
testDismissKeyguardActivity_secondaryDisplay()56     public void testDismissKeyguardActivity_secondaryDisplay() {
57         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
58         final DisplayContent newDisplay = createManagedVirtualDisplaySession().createDisplay();
59 
60         lockScreenSession.gotoKeyguard();
61         mWmState.assertKeyguardShowingAndNotOccluded();
62         launchActivityOnDisplay(DISMISS_KEYGUARD_ACTIVITY, newDisplay.mId);
63         mWmState.waitForKeyguardShowingAndNotOccluded();
64         mWmState.assertKeyguardShowingAndNotOccluded();
65         mWmState.assertVisibility(DISMISS_KEYGUARD_ACTIVITY, true);
66     }
67 
68     /**
69      * Tests keyguard dialog shows on secondary display.
70      */
71     @Test
testShowKeyguardDialogOnSecondaryDisplay()72     public void testShowKeyguardDialogOnSecondaryDisplay() {
73         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
74         final DisplayContent publicDisplay = createManagedVirtualDisplaySession()
75                 .setPublicDisplay(true)
76                 .createDisplay();
77 
78         lockScreenSession.gotoKeyguard();
79         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
80 
81         // Keyguard dialog mustn't be removed when press back key
82         pressBackButton();
83         mWmState.computeState();
84         mWmState.assertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
85     }
86 
87     /**
88      * Tests keyguard dialog should exist after secondary display changed.
89      */
90     @Test
testShowKeyguardDialogSecondaryDisplayChange()91     public void testShowKeyguardDialogSecondaryDisplayChange() {
92         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
93         final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
94 
95         final DisplayContent publicDisplay = virtualDisplaySession
96                 .setPublicDisplay(true)
97                 .createDisplay();
98 
99         lockScreenSession.gotoKeyguard();
100         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
101 
102         // By default, a Presentation object should be dismissed if the DisplayMetrics changed.
103         // But this rule should not apply to KeyguardPresentation.
104         virtualDisplaySession.resizeDisplay();
105         mWmState.computeState();
106         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
107     }
108 
109     /**
110      * Tests keyguard dialog should exist after default display changed.
111      */
112     @Test
testShowKeyguardDialogDefaultDisplayChange()113     public void testShowKeyguardDialogDefaultDisplayChange() {
114         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
115         final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
116         final DisplayMetricsSession displayMetricsSession =
117                 createManagedDisplayMetricsSession(DEFAULT_DISPLAY);
118 
119         // Use simulate display instead of virtual display, because VirtualDisplayActivity will
120         // relaunch after configuration change.
121         final DisplayContent publicDisplay = virtualDisplaySession
122                 .setSimulateDisplay(true)
123                 .createDisplay();
124 
125         lockScreenSession.gotoKeyguard();
126         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
127 
128         // Unlock then lock again, to ensure the display metrics has updated.
129         lockScreenSession.wakeUpDevice().unlockDevice();
130         // Overriding the display metrics on the default display should not affect Keyguard to show
131         // on secondary display.
132         final ReportedDisplayMetrics originalDisplayMetrics =
133                 displayMetricsSession.getInitialDisplayMetrics();
134         final Size overrideSize = new Size(
135                 (int) (originalDisplayMetrics.physicalSize.getWidth() * 1.5),
136                 (int) (originalDisplayMetrics.physicalSize.getHeight() * 1.5));
137         final Integer overrideDensity = (int) (originalDisplayMetrics.physicalDensity * 1.1);
138         displayMetricsSession.overrideDisplayMetrics(overrideSize, overrideDensity);
139 
140         lockScreenSession.gotoKeyguard();
141         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
142     }
143 
144     /**
145      * Tests keyguard dialog cannot be shown on private display.
146      */
147     @Test
testNoKeyguardDialogOnPrivateDisplay()148     public void testNoKeyguardDialogOnPrivateDisplay() {
149         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
150         final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
151 
152         final DisplayContent privateDisplay =
153                 virtualDisplaySession.setPublicDisplay(false).createDisplay();
154         final DisplayContent publicDisplay =
155                 virtualDisplaySession.setPublicDisplay(true).createDisplay();
156 
157         lockScreenSession.gotoKeyguard();
158         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(publicDisplay.mId);
159         mWmState.assertKeyguardGoneOnSecondaryDisplay(privateDisplay.mId);
160     }
161 
162     @Test
testUnlockScreen_secondDisplayChanged_dismissesKeyguardOnUnlock()163     public void testUnlockScreen_secondDisplayChanged_dismissesKeyguardOnUnlock() {
164         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
165         final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
166         lockScreenSession.setLockCredential();
167 
168         // Create second screen
169         final DisplayContent secondDisplay = virtualDisplaySession
170                 .setPublicDisplay(true)
171                 .createDisplay();
172         final int secondDisplayId = secondDisplay.mId;
173 
174         // Lock screen. Keyguard should be shown on the second display
175         lockScreenSession.gotoKeyguard();
176         mWmState.assertKeyguardShowingAndNotOccluded();
177         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(secondDisplayId);
178 
179         // Change second display. Keyguard should still be shown on the second display
180         virtualDisplaySession.resizeDisplay();
181         mWmState.computeState();
182         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(secondDisplayId);
183 
184         // Unlock device. Keyguard should be dismissed on the second display
185         lockScreenSession.unlockDevice();
186         lockScreenSession.enterAndConfirmLockCredential();
187         mWmState.waitAndAssertKeyguardGone();
188         mWmState.waitAndAssertKeyguardGoneOnSecondaryDisplay(secondDisplayId);
189     }
190 
191     @Test
testUnlockScreen_decoredSystemDisplayChanged_dismissesKeyguardOnUnlock()192     public void testUnlockScreen_decoredSystemDisplayChanged_dismissesKeyguardOnUnlock() {
193         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
194         final VirtualDisplaySession virtualDisplaySession = createManagedVirtualDisplaySession();
195         lockScreenSession.setLockCredential();
196 
197         // Create decored system screen
198         final DisplayContent decoredSystemDisplay = virtualDisplaySession
199                 .setSimulateDisplay(true)
200                 .setShowSystemDecorations(true)
201                 .createDisplay();
202         final int decoredSystemDisplayId = decoredSystemDisplay.mId;
203 
204         // Lock screen. Keyguard should be shown on the decored system display
205         lockScreenSession.gotoKeyguard();
206         mWmState.assertKeyguardShowingAndNotOccluded();
207         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(decoredSystemDisplayId);
208 
209         // Resize decored display. Keyguard should still be shown on the decored system display
210         final ReportedDisplayMetrics displayMetrics =
211                 ReportedDisplayMetrics.getDisplayMetrics(decoredSystemDisplayId);
212         final Size overrideSize = new Size(
213                 (int) (displayMetrics.physicalSize.getWidth() * 0.5),
214                 (int) (displayMetrics.physicalSize.getHeight() * 0.5));
215         final DisplayMetricsSession displayMetricsSession =
216                 createManagedDisplayMetricsSession(decoredSystemDisplayId);
217         displayMetricsSession.overrideDisplayMetrics(overrideSize, displayMetrics.physicalDensity);
218         mWmState.computeState();
219         mWmState.waitAndAssertKeyguardShownOnSecondaryDisplay(decoredSystemDisplayId);
220 
221         // Unlock device. Keyguard should be dismissed on the decored system display
222         lockScreenSession.unlockDevice();
223         lockScreenSession.enterAndConfirmLockCredential();
224         mWmState.waitAndAssertKeyguardGone();
225         mWmState.waitAndAssertKeyguardGoneOnSecondaryDisplay(decoredSystemDisplayId);
226     }
227 }
228