1 /* 2 * Copyright (C) 2021 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.car.cts.builtin.app; 18 19 import static android.server.wm.UiDeviceUtils.pressUnlockButton; 20 import static android.view.Display.DEFAULT_DISPLAY; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import static org.junit.Assume.assumeTrue; 25 26 import android.car.builtin.app.KeyguardManagerHelper; 27 import android.server.wm.ActivityManagerTestBase; 28 29 import androidx.test.runner.AndroidJUnit4; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 35 @RunWith(AndroidJUnit4.class) 36 public final class KeyguardManagerHelperTest extends ActivityManagerTestBase { 37 38 private static final String TAG = KeyguardManagerHelperTest.class.getSimpleName(); 39 40 @Before 41 @Override setUp()42 public void setUp() throws Exception { 43 super.setUp(); 44 assumeTrue(supportsSecureLock()); 45 } 46 47 @Test testIsKeyguardLocked()48 public void testIsKeyguardLocked() throws Exception { 49 try (LockScreenSession lockScreenSession = createManagedLockScreenSession()) { 50 lockScreenSession.setLockCredential().gotoKeyguard(); 51 assertThat(KeyguardManagerHelper.isKeyguardLocked()).isTrue(); 52 53 unlockDevice(); 54 lockScreenSession.enterAndConfirmLockCredential(); 55 mWmState.waitAndAssertKeyguardGone(); 56 assertThat(KeyguardManagerHelper.isKeyguardLocked()).isFalse(); 57 } 58 } 59 unlockDevice()60 private void unlockDevice() { 61 touchAndCancelOnDisplayCenterSync(DEFAULT_DISPLAY); 62 pressUnlockButton(); 63 } 64 } 65