• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.WindowManagerState.STATE_STOPPED;
20 import static android.server.wm.WindowManagerState.TRANSIT_ACTIVITY_OPEN;
21 import static android.server.wm.WindowManagerState.TRANSIT_KEYGUARD_GOING_AWAY;
22 import static android.server.wm.WindowManagerState.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
23 import static android.server.wm.WindowManagerState.TRANSIT_KEYGUARD_OCCLUDE;
24 import static android.server.wm.WindowManagerState.TRANSIT_KEYGUARD_UNOCCLUDE;
25 import static android.server.wm.app.Components.DISABLE_PREVIEW_ACTIVITY;
26 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY;
27 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY;
28 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY;
29 import static android.server.wm.app.Components.SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY;
30 import static android.server.wm.app.Components.WALLPAPAER_ACTIVITY;
31 
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertTrue;
34 import static org.junit.Assume.assumeFalse;
35 import static org.junit.Assume.assumeTrue;
36 
37 import android.platform.test.annotations.Presubmit;
38 
39 import org.junit.Before;
40 import org.junit.Test;
41 
42 import java.util.Arrays;
43 import java.util.List;
44 
45 /**
46  * Build/Install/Run:
47  *     atest CtsWindowManagerDeviceTestCases:KeyguardTransitionTests
48  */
49 @Presubmit
50 @android.server.wm.annotation.Group2
51 public class KeyguardTransitionTests extends ActivityManagerTestBase {
52 
53     @Before
54     @Override
setUp()55     public void setUp() throws Exception {
56         super.setUp();
57         assumeFalse(ENABLE_SHELL_TRANSITIONS);
58         assumeTrue(supportsInsecureLock());
59         assumeFalse(isUiModeLockedToVrHeadset());
60     }
61 
62     @Test
testUnlock()63     public void testUnlock() {
64         List<String> expectedTransitionList = Arrays.asList(TRANSIT_KEYGUARD_GOING_AWAY,
65                 TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER);
66         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
67         launchActivity(DISABLE_PREVIEW_ACTIVITY);
68         lockScreenSession.gotoKeyguard().unlockDevice();
69         mWmState.computeState(DISABLE_PREVIEW_ACTIVITY);
70         // The AOSP flow is checking if the current transit is TRANSIT_KEYGUARD_GOING_AWAY and
71         // if the visible apps have FLAG_SHOW_WALLPAPER and if both conditions are true the transit
72         // will be changed to TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER. For multiple screen devices,
73         // both conditions are true, because the launcher is visible and has this flag.
74         assertTrue("Picked wrong transition",
75                 expectedTransitionList.contains(mWmState.getDefaultDisplayLastTransition()));
76     }
77 
78     @Test
testUnlockWallpaper()79     public void testUnlockWallpaper() {
80         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
81         launchActivity(WALLPAPAER_ACTIVITY);
82         lockScreenSession.gotoKeyguard().unlockDevice();
83         mWmState.computeState(WALLPAPAER_ACTIVITY);
84         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER,
85                 mWmState.getDefaultDisplayLastTransition());
86     }
87 
88     @Test
testOcclude()89     public void testOcclude() {
90         createManagedLockScreenSession().gotoKeyguard();
91         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
92         mWmState.computeState(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
93         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
94                 mWmState.getDefaultDisplayLastTransition());
95     }
96 
97     @Test
testUnocclude()98     public void testUnocclude() {
99         createManagedLockScreenSession().gotoKeyguard();
100         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
101         launchActivity(DISABLE_PREVIEW_ACTIVITY);
102         mWmState.waitForKeyguardShowingAndNotOccluded();
103         mWmState.computeState();
104         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_UNOCCLUDE,
105                 mWmState.getDefaultDisplayLastTransition());
106     }
107 
108     @Test
testDismissKeyguard()109     public void testDismissKeyguard() {
110         createManagedLockScreenSession().gotoKeyguard();
111         launchActivityWithDismissKeyguard(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
112         mWmState.computeState(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
113         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY,
114                 mWmState.getDefaultDisplayLastTransition());
115     }
116 
117     @Test
testNewActivityDuringOccluded()118     public void testNewActivityDuringOccluded() {
119         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
120         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
121         lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
122         launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
123         mWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
124         assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
125                 mWmState.getDefaultDisplayLastTransition());
126     }
127 
128     @Test
testNewDismissKeyguardActivityDuringOccluded()129     public void testNewDismissKeyguardActivityDuringOccluded() {
130         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
131         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
132         lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
133         launchActivityWithDismissKeyguard(
134                 SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
135         mWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
136         assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
137                 mWmState.getDefaultDisplayLastTransition());
138     }
139 
140     @Test
testOccludeManifestAttr()141     public void testOccludeManifestAttr() {
142         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
143         lockScreenSession.gotoKeyguard();
144         separateTestJournal();
145         launchActivity(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
146         mWmState.computeState(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
147         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
148                 mWmState.getDefaultDisplayLastTransition());
149         assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
150     }
151 
152     @Test
testOccludeAttrRemove()153     public void testOccludeAttrRemove() {
154         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
155         lockScreenSession.gotoKeyguard();
156         separateTestJournal();
157         launchActivity(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
158         mWmState.computeState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
159         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
160                 mWmState.getDefaultDisplayLastTransition());
161         assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
162 
163         // Waiting for the standard keyguard since
164         // {@link SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY} called
165         // {@link Activity#showWhenLocked(boolean)} and removed the attribute.
166         lockScreenSession.gotoKeyguard();
167         separateTestJournal();
168         // Waiting for {@link SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY} stopped since it
169         // already lost show-when-locked attribute.
170         launchActivityNoWait(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
171         mWmState.waitForActivityState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY,
172                 STATE_STOPPED);
173         assertSingleStartAndStop(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
174     }
175 
176     @Test
testNewActivityDuringOccludedWithAttr()177     public void testNewActivityDuringOccludedWithAttr() {
178         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
179         launchActivityInFullscreen(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
180         lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
181         launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
182         mWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
183         assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
184                 mWmState.getDefaultDisplayLastTransition());
185     }
186 }
187