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.am;
18 
19 import static android.server.am.Components.SHOW_WHEN_LOCKED_ACTIVITY;
20 import static android.server.am.Components.SHOW_WHEN_LOCKED_ATTR_ACTIVITY;
21 import static android.server.am.Components.SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY;
22 import static android.server.am.Components.SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY;
23 import static android.server.am.Components.TEST_ACTIVITY;
24 import static android.server.am.Components.WALLPAPAER_ACTIVITY;
25 import static android.server.am.WindowManagerState.TRANSIT_ACTIVITY_OPEN;
26 import static android.server.am.WindowManagerState.TRANSIT_KEYGUARD_GOING_AWAY;
27 import static android.server.am.WindowManagerState.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
28 import static android.server.am.WindowManagerState.TRANSIT_KEYGUARD_OCCLUDE;
29 import static android.server.am.WindowManagerState.TRANSIT_KEYGUARD_UNOCCLUDE;
30 
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assume.assumeFalse;
33 import static org.junit.Assume.assumeTrue;
34 
35 import org.junit.Before;
36 import org.junit.Test;
37 
38 /**
39  * Build/Install/Run:
40  *     atest CtsActivityManagerDeviceTestCases:KeyguardTransitionTests
41  */
42 public class KeyguardTransitionTests extends ActivityManagerTestBase {
43 
44     @Before
45     @Override
setUp()46     public void setUp() throws Exception {
47         super.setUp();
48 
49         assumeTrue(supportsInsecureLock());
50         assumeFalse(isUiModeLockedToVrHeadset());
51     }
52 
53     @Test
testUnlock()54     public void testUnlock() throws Exception {
55         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
56             launchActivity(TEST_ACTIVITY);
57             lockScreenSession.gotoKeyguard()
58                     .unlockDevice();
59             mAmWmState.computeState(TEST_ACTIVITY);
60             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY,
61                     mAmWmState.getWmState().getLastTransition());
62         }
63     }
64 
65     @Test
testUnlockWallpaper()66     public void testUnlockWallpaper() throws Exception {
67         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
68             launchActivity(WALLPAPAER_ACTIVITY);
69             lockScreenSession.gotoKeyguard()
70                     .unlockDevice();
71             mAmWmState.computeState(WALLPAPAER_ACTIVITY);
72             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER,
73                     mAmWmState.getWmState().getLastTransition());
74         }
75     }
76 
77     @Test
testOcclude()78     public void testOcclude() throws Exception {
79         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
80             lockScreenSession.gotoKeyguard();
81             launchActivity(SHOW_WHEN_LOCKED_ACTIVITY);
82             mAmWmState.computeState(SHOW_WHEN_LOCKED_ACTIVITY);
83             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
84                     mAmWmState.getWmState().getLastTransition());
85         }
86     }
87 
88     @Test
testUnocclude()89     public void testUnocclude() throws Exception {
90         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
91             lockScreenSession.gotoKeyguard();
92             launchActivity(SHOW_WHEN_LOCKED_ACTIVITY);
93             launchActivity(TEST_ACTIVITY);
94             mAmWmState.waitForKeyguardShowingAndNotOccluded();
95             mAmWmState.computeState(true);
96             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_UNOCCLUDE,
97                     mAmWmState.getWmState().getLastTransition());
98         }
99     }
100 
101     @Test
testNewActivityDuringOccluded()102     public void testNewActivityDuringOccluded() throws Exception {
103         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
104             launchActivity(SHOW_WHEN_LOCKED_ACTIVITY);
105             lockScreenSession.gotoKeyguard();
106             launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY);
107             mAmWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY);
108             assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
109                     mAmWmState.getWmState().getLastTransition());
110         }
111     }
112 
113     @Test
testOccludeManifestAttr()114     public void testOccludeManifestAttr() throws Exception {
115         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
116             lockScreenSession.gotoKeyguard();
117             final LogSeparator logSeparator = separateLogs();
118             launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY);
119             mAmWmState.computeState(SHOW_WHEN_LOCKED_ATTR_ACTIVITY);
120             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
121                     mAmWmState.getWmState().getLastTransition());
122             assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_ACTIVITY, logSeparator);
123         }
124     }
125 
126     @Test
testOccludeAttrRemove()127     public void testOccludeAttrRemove() throws Exception {
128         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
129             lockScreenSession.gotoKeyguard();
130             LogSeparator logSeparator = separateLogs();
131             launchActivity(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY);
132             mAmWmState.computeState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY);
133             assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
134                     mAmWmState.getWmState().getLastTransition());
135             assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY, logSeparator);
136 
137             lockScreenSession.gotoKeyguard();
138             logSeparator = separateLogs();
139             launchActivity(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY);
140             mAmWmState.computeState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY);
141             assertSingleStartAndStop(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_ACTIVITY, logSeparator);
142         }
143     }
144 
145     @Test
testNewActivityDuringOccludedWithAttr()146     public void testNewActivityDuringOccludedWithAttr() throws Exception {
147         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
148             launchActivity(SHOW_WHEN_LOCKED_ATTR_ACTIVITY);
149             lockScreenSession.gotoKeyguard();
150             launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY);
151             mAmWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_ACTIVITY);
152             assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
153                     mAmWmState.getWmState().getLastTransition());
154         }
155     }
156 }
157