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

Commit a7055cda authored by Clara Thomas's avatar Clara Thomas Committed by Android (Google) Code Review
Browse files

Merge "Add force confirm option for ConfirmSupervisionCredentials intent" into main

parents 4335b396 81383cef
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ object SupervisionIntentProvider {
    private const val SETTINGS_PKG: String = "com.android.settings"
    private const val ACTION_CONFIRM_SUPERVISION_CREDENTIALS =
        "android.app.supervision.action.CONFIRM_SUPERVISION_CREDENTIALS"
    private const val EXTRA_FORCE_CONFIRMATION = "force_confirmation"

    enum class PinRecoveryAction(val action: String) {
        SET(ACTION_SETUP_PIN_RECOVERY),
@@ -96,4 +97,18 @@ object SupervisionIntentProvider {
            context.packageManager.queryIntentActivitiesAsUser(intent, 0, context.userId)
        return if (activities.isNotEmpty()) intent else null
    }

    /**
     * Returns an [Intent] to confirm supervision credentials or null if the intent is not
     * resolvable.
     *
     * If [forceConfirm], user will be prompted to confirm supervision credentials regardless of
     * whether there is an active authentication session (i.e. if the supervision credentials have
     * been recently confirmed for some other purpose).
     */
    @JvmStatic
    fun getConfirmSupervisionCredentialsIntent(context: Context, forceConfirm: Boolean): Intent? {
        return getConfirmSupervisionCredentialsIntent(context)
            ?.putExtra(EXTRA_FORCE_CONFIRMATION, forceConfirm)
    }
}
+36 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ class SupervisionIntentProviderTest {
        assertThat(intent).isNull()
    }

    @Test
    fun getConfirmSupervisionCredentialsIntent_unresolvedIntent() {
        mockPackageManager.stub {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
@@ -148,6 +149,22 @@ class SupervisionIntentProviderTest {
        assertThat(intent).isNull()
    }

    @Test
    fun getConfirmSupervisionCredentialsIntent_forceConfirm_unresolvedIntent() {
        mockPackageManager.stub {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
                emptyList<ResolveInfo>()
        }

        val intent =
            SupervisionIntentProvider.getConfirmSupervisionCredentialsIntent(
                context = context,
                forceConfirm = true,
            )

        assertThat(intent).isNull()
    }

    @Test
    fun getPinRecoveryIntent_setup_resolvedIntent() {
        mockRoleManager.stub {
@@ -276,6 +293,25 @@ class SupervisionIntentProviderTest {
        assertThat(intent?.`package`).isEqualTo("com.android.settings")
    }

    @Test
    fun getConfirmSupervisionCredentialsIntent_forceConfirm_resolvedIntent() {
        mockPackageManager.stub {
            on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn
                listOf(ResolveInfo())
        }

        val intent =
            SupervisionIntentProvider.getConfirmSupervisionCredentialsIntent(
                context = context,
                forceConfirm = true,
            )
        assertThat(intent).isNotNull()
        assertThat(intent?.action)
            .isEqualTo("android.app.supervision.action.CONFIRM_SUPERVISION_CREDENTIALS")
        assertThat(intent?.`package`).isEqualTo("com.android.settings")
        assertThat(intent?.extras?.getBoolean("force_confirmation")).isTrue()
    }

    private companion object {
        const val SUPERVISION_APP_PACKAGE = "app.supervision"
    }