• 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 = 15000; // 15 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         launchAndWaitAppOpen(LAUNCH_TIME_MS);
38 
39         if (getUiDevice().isScreenOn()) {
40             getUiDevice().sleep();
41             SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
42         }
43         getDeviceUtils().takeScreenshot(getPackage(), "sleep_device");
44         Assert.assertFalse("The screen should be off", getUiDevice().isScreenOn());
45 
46         getUiDevice().wakeUp();
47         SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
48         getDeviceUtils().takeScreenshot(getPackage(), "wake_up_device");
49         Assert.assertTrue("The screen should be off", getUiDevice().isScreenOn());
50         Assert.assertTrue("The keyguard should show up", getKeyguardManager().isKeyguardLocked());
51 
52         getUiDevice().executeShellCommand(DISMISS_KEYGUARD);
53         SystemClock.sleep(WAIT_ONE_SECOND_IN_MS);
54         getDeviceUtils().takeScreenshot(getPackage(), "dismiss_keyguard");
55         getUiDevice().wait(Until.hasObject(By.pkg(getPackage()).depth(0)), LAUNCH_TIME_MS);
56         Assert.assertFalse(
57                 "The keyguard should be dismissed", getKeyguardManager().isKeyguardLocked());
58         Assert.assertTrue(
59                 "3P app main page should show up after unlocking the screen",
60                 getUiDevice().hasObject(By.pkg(getPackage()).depth(0)));
61     }
62 }
63