• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 com.android.pixel.tests;
18 
19 import android.os.SystemClock;
20 import android.support.test.uiautomator.By;
21 import android.support.test.uiautomator.Until;
22 
23 import androidx.test.ext.junit.runners.AndroidJUnit4;
24 
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @RunWith(AndroidJUnit4.class)
30 public class AppLaunchLockTest extends PixelAppCompatTestBase {
31     private static final int LAUNCH_TIME_MS = 30000; // 30 seconds
32     private static final long WAIT_ONE_SECOND_IN_MS = 1000;
33     private static final String DISMISS_KEYGUARD = "wm dismiss-keyguard";
34 
35     @Test
testLockDevice()36     public void testLockDevice() throws Exception {
37         // Launch the 3P app
38         getDeviceUtils().launchApp(getPackage());
39 
40         // Wait for the 3P app to appear
41         getUiDevice().wait(Until.hasObject(By.pkg(getPackage()).depth(0)), LAUNCH_TIME_MS);
42         getUiDevice().waitForIdle();
43         Assert.assertTrue(
44                 "3P app main page should show up",
45                 getUiDevice().hasObject(By.pkg(getPackage()).depth(0)));
46 
47         if (getUiDevice().isScreenOn()) {
48             getUiDevice().sleep();
49             SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
50         }
51         getDeviceUtils().takeScreenshot(getPackage(), "sleep_device");
52         Assert.assertFalse("The screen should be off", getUiDevice().isScreenOn());
53 
54         getUiDevice().wakeUp();
55         SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
56         getDeviceUtils().takeScreenshot(getPackage(), "wake_up_device");
57         Assert.assertTrue("The screen should be off", getUiDevice().isScreenOn());
58         Assert.assertTrue("The keyguard should show up", getKeyguardManager().isKeyguardLocked());
59 
60         getUiDevice().executeShellCommand(DISMISS_KEYGUARD);
61         SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
62         getDeviceUtils().takeScreenshot(getPackage(), "dismiss_keyguard");
63         getUiDevice().wait(Until.hasObject(By.pkg(getPackage()).depth(0)), LAUNCH_TIME_MS);
64         Assert.assertFalse(
65                 "The keyguard should be dismissed", getKeyguardManager().isKeyguardLocked());
66         Assert.assertTrue(
67                 "3P app main page should show up after unlocking the screen",
68                 getUiDevice().hasObject(By.pkg(getPackage()).depth(0)));
69     }
70 }
71