• 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.Assume.assumeFalse;
34 import static org.junit.Assume.assumeTrue;
35 
36 import android.platform.test.annotations.Presubmit;
37 
38 import org.junit.Before;
39 import org.junit.Test;
40 
41 /**
42  * Build/Install/Run:
43  *     atest CtsWindowManagerDeviceTestCases:KeyguardTransitionTests
44  */
45 @Presubmit
46 @android.server.wm.annotation.Group2
47 public class KeyguardTransitionTests extends ActivityManagerTestBase {
48 
49     @Before
50     @Override
setUp()51     public void setUp() throws Exception {
52         super.setUp();
53 
54         assumeTrue(supportsInsecureLock());
55         assumeFalse(isUiModeLockedToVrHeadset());
56     }
57 
58     @Test
testUnlock()59     public void testUnlock() {
60         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
61         launchActivity(DISABLE_PREVIEW_ACTIVITY);
62         lockScreenSession.gotoKeyguard().unlockDevice();
63         mWmState.computeState(DISABLE_PREVIEW_ACTIVITY);
64         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY,
65                 mWmState.getDefaultDisplayLastTransition());
66     }
67 
68     @Test
testUnlockWallpaper()69     public void testUnlockWallpaper() {
70         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
71         launchActivity(WALLPAPAER_ACTIVITY);
72         lockScreenSession.gotoKeyguard().unlockDevice();
73         mWmState.computeState(WALLPAPAER_ACTIVITY);
74         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER,
75                 mWmState.getDefaultDisplayLastTransition());
76     }
77 
78     @Test
testOcclude()79     public void testOcclude() {
80         createManagedLockScreenSession().gotoKeyguard();
81         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
82         mWmState.computeState(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
83         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
84                 mWmState.getDefaultDisplayLastTransition());
85     }
86 
87     @Test
testUnocclude()88     public void testUnocclude() {
89         createManagedLockScreenSession().gotoKeyguard();
90         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
91         launchActivity(DISABLE_PREVIEW_ACTIVITY);
92         mWmState.waitForKeyguardShowingAndNotOccluded();
93         mWmState.computeState();
94         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_UNOCCLUDE,
95                 mWmState.getDefaultDisplayLastTransition());
96     }
97 
98     @Test
testNewActivityDuringOccluded()99     public void testNewActivityDuringOccluded() {
100         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
101         launchActivity(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
102         lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_NO_PREVIEW_ACTIVITY);
103         launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
104         mWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
105         assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
106                 mWmState.getDefaultDisplayLastTransition());
107     }
108 
109     @Test
testOccludeManifestAttr()110     public void testOccludeManifestAttr() {
111         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
112         lockScreenSession.gotoKeyguard();
113         separateTestJournal();
114         launchActivity(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
115         mWmState.computeState(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
116         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
117                 mWmState.getDefaultDisplayLastTransition());
118         assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
119     }
120 
121     @Test
testOccludeAttrRemove()122     public void testOccludeAttrRemove() {
123         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
124         lockScreenSession.gotoKeyguard();
125         separateTestJournal();
126         launchActivity(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
127         mWmState.computeState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
128         assertEquals("Picked wrong transition", TRANSIT_KEYGUARD_OCCLUDE,
129                 mWmState.getDefaultDisplayLastTransition());
130         assertSingleLaunch(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
131 
132         // Waiting for the standard keyguard since
133         // {@link SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY} called
134         // {@link Activity#showWhenLocked(boolean)} and removed the attribute.
135         lockScreenSession.gotoKeyguard();
136         separateTestJournal();
137         // Waiting for {@link SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY} stopped since it
138         // already lost show-when-locked attribute.
139         launchActivityNoWait(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
140         mWmState.waitForActivityState(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY,
141                 STATE_STOPPED);
142         assertSingleStartAndStop(SHOW_WHEN_LOCKED_ATTR_REMOVE_ATTR_NO_PREVIEW_ACTIVITY);
143     }
144 
145     @Test
testNewActivityDuringOccludedWithAttr()146     public void testNewActivityDuringOccludedWithAttr() {
147         final LockScreenSession lockScreenSession = createManagedLockScreenSession();
148         launchActivity(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
149         lockScreenSession.gotoKeyguard(SHOW_WHEN_LOCKED_ATTR_NO_PREVIEW_ACTIVITY);
150         launchActivity(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
151         mWmState.computeState(SHOW_WHEN_LOCKED_WITH_DIALOG_NO_PREVIEW_ACTIVITY);
152         assertEquals("Picked wrong transition", TRANSIT_ACTIVITY_OPEN,
153                 mWmState.getDefaultDisplayLastTransition());
154     }
155 }
156