Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c83a7fd6 authored by Your Name's avatar Your Name
Browse files

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
parent 3e2a850f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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" />

+0 −2
Original line number Diff line number Diff line
@@ -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")
+33 −17
Original line number Diff line number Diff line
@@ -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,6 +51,7 @@ class ScreenLockRule : TestRule {
            } finally {
                removeScreenLock()
                revertLockOnPowerButton()
                verifyKeyguardDismissed()
            }
        }
    }
@@ -61,6 +65,7 @@ class ScreenLockRule : TestRule {
    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)
@@ -90,14 +95,25 @@ class ScreenLockRule : TestRule {
    }

    private fun removeScreenLock() {
        lockPatternUtils.setLockCredential(
        var lockCredentialUnset = 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)
                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() {