Loading tests/TrustTests/AndroidManifest.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,9 @@ <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> <uses-permission android:name="android.permission.CONTROL_KEYGUARD" /> <uses-permission android:name="android.permission.CONTROL_KEYGUARD" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> <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.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.PROVIDE_TRUST_AGENT" /> <uses-permission android:name="android.permission.TRUST_LISTENER" /> <uses-permission android:name="android.permission.TRUST_LISTENER" /> Loading tests/TrustTests/src/android/trust/test/LockUserTest.kt +0 −2 Original line number Original line Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.util.Log import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat import org.junit.Ignore import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.rules.RuleChain import org.junit.rules.RuleChain Loading @@ -49,7 +48,6 @@ class LockUserTest { .around(lockStateTrackingRule) .around(lockStateTrackingRule) .around(trustAgentRule) .around(trustAgentRule) @Ignore("Causes issues with subsequent tests") // TODO: Enable test @Test @Test fun lockUser_locksTheDevice() { fun lockUser_locksTheDevice() { Log.i(TAG, "Locking user") Log.i(TAG, "Locking user") Loading tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt +33 −17 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.content.Context import android.util.Log import android.util.Log import android.view.WindowManagerGlobal import android.view.WindowManagerGlobal import androidx.test.core.app.ApplicationProvider.getApplicationContext 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.LockPatternUtils import com.android.internal.widget.LockscreenCredential import com.android.internal.widget.LockscreenCredential import com.google.common.truth.Truth.assertWithMessage import com.google.common.truth.Truth.assertWithMessage Loading @@ -32,6 +34,7 @@ import org.junit.runners.model.Statement */ */ class ScreenLockRule : TestRule { class ScreenLockRule : TestRule { private val context: Context = getApplicationContext() private val context: Context = getApplicationContext() private val uiDevice = UiDevice.getInstance(getInstrumentation()) private val windowManager = WindowManagerGlobal.getWindowManagerService() private val windowManager = WindowManagerGlobal.getWindowManagerService() private val lockPatternUtils = LockPatternUtils(context) private val lockPatternUtils = LockPatternUtils(context) private var instantLockSavedValue = false private var instantLockSavedValue = false Loading @@ -48,6 +51,7 @@ class ScreenLockRule : TestRule { } finally { } finally { removeScreenLock() removeScreenLock() revertLockOnPowerButton() revertLockOnPowerButton() verifyKeyguardDismissed() } } } } } } Loading @@ -61,6 +65,7 @@ class ScreenLockRule : TestRule { private fun verifyKeyguardDismissed() { private fun verifyKeyguardDismissed() { val maxWaits = 30 val maxWaits = 30 var waitCount = 0 var waitCount = 0 while (windowManager.isKeyguardLocked && waitCount < maxWaits) { while (windowManager.isKeyguardLocked && waitCount < maxWaits) { Log.i(TAG, "Keyguard still showing; attempting to dismiss and wait 50ms ($waitCount)") Log.i(TAG, "Keyguard still showing; attempting to dismiss and wait 50ms ($waitCount)") windowManager.dismissKeyguard(null, null) windowManager.dismissKeyguard(null, null) Loading Loading @@ -90,14 +95,25 @@ class ScreenLockRule : TestRule { } } private fun removeScreenLock() { private fun removeScreenLock() { lockPatternUtils.setLockCredential( var lockCredentialUnset = lockPatternUtils.setLockCredential( LockscreenCredential.createNone(), LockscreenCredential.createNone(), LockscreenCredential.createPin(PIN), LockscreenCredential.createPin(PIN), context.userId context.userId) ) Thread.sleep(100) Log.i(TAG, "Device PIN cleared; waiting 50 ms then dismissing Keyguard") assertWithMessage("Lock screen credential should be unset") Thread.sleep(50) .that(lockCredentialUnset) windowManager.dismissKeyguard(null, null) .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() { private fun revertLockOnPowerButton() { Loading Loading
tests/TrustTests/AndroidManifest.xml +2 −0 Original line number Original line Diff line number Diff line Loading @@ -23,7 +23,9 @@ <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> <uses-permission android:name="android.permission.BIND_DEVICE_ADMIN" /> <uses-permission android:name="android.permission.CONTROL_KEYGUARD" /> <uses-permission android:name="android.permission.CONTROL_KEYGUARD" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> <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.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.PROVIDE_TRUST_AGENT" /> <uses-permission android:name="android.permission.TRUST_LISTENER" /> <uses-permission android:name="android.permission.TRUST_LISTENER" /> Loading
tests/TrustTests/src/android/trust/test/LockUserTest.kt +0 −2 Original line number Original line Diff line number Diff line Loading @@ -25,7 +25,6 @@ import android.util.Log import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat import org.junit.Ignore import org.junit.Rule import org.junit.Rule import org.junit.Test import org.junit.Test import org.junit.rules.RuleChain import org.junit.rules.RuleChain Loading @@ -49,7 +48,6 @@ class LockUserTest { .around(lockStateTrackingRule) .around(lockStateTrackingRule) .around(trustAgentRule) .around(trustAgentRule) @Ignore("Causes issues with subsequent tests") // TODO: Enable test @Test @Test fun lockUser_locksTheDevice() { fun lockUser_locksTheDevice() { Log.i(TAG, "Locking user") Log.i(TAG, "Locking user") Loading
tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt +33 −17 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,8 @@ import android.content.Context import android.util.Log import android.util.Log import android.view.WindowManagerGlobal import android.view.WindowManagerGlobal import androidx.test.core.app.ApplicationProvider.getApplicationContext 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.LockPatternUtils import com.android.internal.widget.LockscreenCredential import com.android.internal.widget.LockscreenCredential import com.google.common.truth.Truth.assertWithMessage import com.google.common.truth.Truth.assertWithMessage Loading @@ -32,6 +34,7 @@ import org.junit.runners.model.Statement */ */ class ScreenLockRule : TestRule { class ScreenLockRule : TestRule { private val context: Context = getApplicationContext() private val context: Context = getApplicationContext() private val uiDevice = UiDevice.getInstance(getInstrumentation()) private val windowManager = WindowManagerGlobal.getWindowManagerService() private val windowManager = WindowManagerGlobal.getWindowManagerService() private val lockPatternUtils = LockPatternUtils(context) private val lockPatternUtils = LockPatternUtils(context) private var instantLockSavedValue = false private var instantLockSavedValue = false Loading @@ -48,6 +51,7 @@ class ScreenLockRule : TestRule { } finally { } finally { removeScreenLock() removeScreenLock() revertLockOnPowerButton() revertLockOnPowerButton() verifyKeyguardDismissed() } } } } } } Loading @@ -61,6 +65,7 @@ class ScreenLockRule : TestRule { private fun verifyKeyguardDismissed() { private fun verifyKeyguardDismissed() { val maxWaits = 30 val maxWaits = 30 var waitCount = 0 var waitCount = 0 while (windowManager.isKeyguardLocked && waitCount < maxWaits) { while (windowManager.isKeyguardLocked && waitCount < maxWaits) { Log.i(TAG, "Keyguard still showing; attempting to dismiss and wait 50ms ($waitCount)") Log.i(TAG, "Keyguard still showing; attempting to dismiss and wait 50ms ($waitCount)") windowManager.dismissKeyguard(null, null) windowManager.dismissKeyguard(null, null) Loading Loading @@ -90,14 +95,25 @@ class ScreenLockRule : TestRule { } } private fun removeScreenLock() { private fun removeScreenLock() { lockPatternUtils.setLockCredential( var lockCredentialUnset = lockPatternUtils.setLockCredential( LockscreenCredential.createNone(), LockscreenCredential.createNone(), LockscreenCredential.createPin(PIN), LockscreenCredential.createPin(PIN), context.userId context.userId) ) Thread.sleep(100) Log.i(TAG, "Device PIN cleared; waiting 50 ms then dismissing Keyguard") assertWithMessage("Lock screen credential should be unset") Thread.sleep(50) .that(lockCredentialUnset) windowManager.dismissKeyguard(null, null) .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() { private fun revertLockOnPowerButton() { Loading