summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Your Name <jacobhobbie@google.com> 2022-03-08 23:18:23 +0000
committer Your Name <jacobhobbie@google.com> 2022-03-09 19:20:26 +0000
commitc83a7fd623c008e282bb323aaf75d734e94e1c4e (patch)
tree99f75ec0a167fdc1642219fa07639eaa4d454dbc
parent3e2a850fa69cb3d9b7c36e7c5bee177825c20f6c (diff)
Enable lockUserTest
Code such that after lockUserTest is run, we assert that the keyguard was successfully dismissed so that the device can return to it's pretest state. All tests run in <5s now. Test: atest TrustTests --iterations Bug: 221155933 Change-Id: I20bf7671f8deeb6c70a977e7c2fc7cbc5395fe4b
-rw-r--r--tests/TrustTests/AndroidManifest.xml2
-rw-r--r--tests/TrustTests/src/android/trust/test/LockUserTest.kt2
-rw-r--r--tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt50
3 files changed, 35 insertions, 19 deletions
diff --git a/tests/TrustTests/AndroidManifest.xml b/tests/TrustTests/AndroidManifest.xml
index c94152da2bf6..68bc1f69628f 100644
--- a/tests/TrustTests/AndroidManifest.xml
+++ b/tests/TrustTests/AndroidManifest.xml
@@ -23,7 +23,9 @@
<uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" />
<uses-permission android:name="android.permission.CONTROL_KEYGUARD" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
+ <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+ <uses-permission android:name="android.permission.MANAGE_USERS" />
<uses-permission android:name="android.permission.PROVIDE_TRUST_AGENT" />
<uses-permission android:name="android.permission.TRUST_LISTENER" />
diff --git a/tests/TrustTests/src/android/trust/test/LockUserTest.kt b/tests/TrustTests/src/android/trust/test/LockUserTest.kt
index 83fc28fee818..8f200a64450e 100644
--- a/tests/TrustTests/src/android/trust/test/LockUserTest.kt
+++ b/tests/TrustTests/src/android/trust/test/LockUserTest.kt
@@ -25,7 +25,6 @@ import android.util.Log
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
-import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
@@ -49,7 +48,6 @@ class LockUserTest {
.around(lockStateTrackingRule)
.around(trustAgentRule)
- @Ignore("Causes issues with subsequent tests") // TODO: Enable test
@Test
fun lockUser_locksTheDevice() {
Log.i(TAG, "Locking user")
diff --git a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
index bc100ba03639..006525d857ac 100644
--- a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
+++ b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
@@ -20,6 +20,8 @@ import android.content.Context
import android.util.Log
import android.view.WindowManagerGlobal
import androidx.test.core.app.ApplicationProvider.getApplicationContext
+import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
+import androidx.test.uiautomator.UiDevice
import com.android.internal.widget.LockPatternUtils
import com.android.internal.widget.LockscreenCredential
import com.google.common.truth.Truth.assertWithMessage
@@ -32,6 +34,7 @@ import org.junit.runners.model.Statement
*/
class ScreenLockRule : TestRule {
private val context: Context = getApplicationContext()
+ private val uiDevice = UiDevice.getInstance(getInstrumentation())
private val windowManager = WindowManagerGlobal.getWindowManagerService()
private val lockPatternUtils = LockPatternUtils(context)
private var instantLockSavedValue = false
@@ -48,19 +51,21 @@ class ScreenLockRule : TestRule {
} finally {
removeScreenLock()
revertLockOnPowerButton()
+ verifyKeyguardDismissed()
}
}
}
private fun verifyNoScreenLockAlreadySet() {
assertWithMessage("Screen Lock must not already be set on device")
- .that(lockPatternUtils.isSecure(context.userId))
- .isFalse()
+ .that(lockPatternUtils.isSecure(context.userId))
+ .isFalse()
}
private fun verifyKeyguardDismissed() {
val maxWaits = 30
var waitCount = 0
+
while (windowManager.isKeyguardLocked && waitCount < maxWaits) {
Log.i(TAG, "Keyguard still showing; attempting to dismiss and wait 50ms ($waitCount)")
windowManager.dismissKeyguard(null, null)
@@ -68,19 +73,19 @@ class ScreenLockRule : TestRule {
waitCount++
}
assertWithMessage("Keyguard should be unlocked")
- .that(windowManager.isKeyguardLocked)
- .isFalse()
+ .that(windowManager.isKeyguardLocked)
+ .isFalse()
}
private fun setScreenLock() {
lockPatternUtils.setLockCredential(
- LockscreenCredential.createPin(PIN),
- LockscreenCredential.createNone(),
- context.userId
+ LockscreenCredential.createPin(PIN),
+ LockscreenCredential.createNone(),
+ context.userId
)
assertWithMessage("Screen Lock should now be set")
- .that(lockPatternUtils.isSecure(context.userId))
- .isTrue()
+ .that(lockPatternUtils.isSecure(context.userId))
+ .isTrue()
Log.i(TAG, "Device PIN set to $PIN")
}
@@ -90,14 +95,25 @@ class ScreenLockRule : TestRule {
}
private fun removeScreenLock() {
- lockPatternUtils.setLockCredential(
- LockscreenCredential.createNone(),
- LockscreenCredential.createPin(PIN),
- context.userId
- )
- Log.i(TAG, "Device PIN cleared; waiting 50 ms then dismissing Keyguard")
- Thread.sleep(50)
- windowManager.dismissKeyguard(null, null)
+ var lockCredentialUnset = lockPatternUtils.setLockCredential(
+ LockscreenCredential.createNone(),
+ LockscreenCredential.createPin(PIN),
+ context.userId)
+ Thread.sleep(100)
+ assertWithMessage("Lock screen credential should be unset")
+ .that(lockCredentialUnset)
+ .isTrue()
+
+ lockPatternUtils.setLockScreenDisabled(true, context.userId)
+ Thread.sleep(100)
+ assertWithMessage("Lockscreen needs to be disabled")
+ .that(lockPatternUtils.isLockScreenDisabled(context.userId))
+ .isTrue()
+
+ // this is here because somehow it helps the keyguard not get stuck
+ uiDevice.sleep()
+ Thread.sleep(500) // delay added to avoid initiating camera by double clicking power
+ uiDevice.wakeUp()
}
private fun revertLockOnPowerButton() {