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 android.trust.test 18 19 import android.trust.BaseTrustAgentService 20 import android.trust.TrustTestActivity 21 import android.trust.test.lib.LockStateTrackingRule 22 import android.trust.test.lib.ScreenLockRule 23 import android.trust.test.lib.TrustAgentRule 24 import android.util.Log 25 import androidx.test.ext.junit.rules.ActivityScenarioRule 26 import androidx.test.ext.junit.runners.AndroidJUnit4 27 import org.junit.Rule 28 import org.junit.Test 29 import org.junit.rules.RuleChain 30 import org.junit.runner.RunWith 31 32 /** 33 * Test for testing lockUser. 34 * 35 * atest TrustTests:LockUserTest 36 */ 37 @RunWith(AndroidJUnit4::class) 38 class LockUserTest { 39 private val activityScenarioRule = ActivityScenarioRule(TrustTestActivity::class.java) 40 private val lockStateTrackingRule = LockStateTrackingRule() 41 private val trustAgentRule = TrustAgentRule<LockUserTrustAgent>() 42 43 @get:Rule 44 val rule: RuleChain = RuleChain 45 .outerRule(activityScenarioRule) 46 .around(ScreenLockRule()) 47 .around(lockStateTrackingRule) 48 .around(trustAgentRule) 49 50 @Test lockUser_locksTheDevicenull51 fun lockUser_locksTheDevice() { 52 Log.i(TAG, "Locking user") 53 trustAgentRule.agent.lockUser() 54 55 lockStateTrackingRule.assertLocked() 56 } 57 58 companion object { 59 private const val TAG = "LockUserTest" 60 } 61 } 62 63 class LockUserTrustAgent : BaseTrustAgentService() 64