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

Commit 3995a1f7 authored by Xiaomiao Zhang's avatar Xiaomiao Zhang Committed by Android (Google) Code Review
Browse files

Merge "Create a method to provide confirm supervision credentials intent in...

Merge "Create a method to provide confirm supervision credentials intent in SupervisionIntentProvider." into main
parents a4541604 d0417a03
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@ object SupervisionIntentProvider {
        "android.settings.supervision.action.SET_VERIFIED_PIN_RECOVERY"
    private const val ACTION_POST_SETUP_VERIFY_PIN_RECOVERY =
        "android.settings.supervision.action.POST_SETUP_VERIFY_PIN_RECOVERY"
    private const val SETTINGS_PKG: String = "com.android.settings"
    private const val ACTION_CONFIRM_SUPERVISION_CREDENTIALS =
        "android.app.supervision.action.CONFIRM_SUPERVISION_CREDENTIALS"

    enum class PinRecoveryAction(val action: String) {
        SET(ACTION_SETUP_PIN_RECOVERY),
@@ -74,4 +77,16 @@ 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.
     */
    @JvmStatic
    fun getConfirmSupervisionCredentialsIntent(context: Context): Intent? {
        val intent = Intent(ACTION_CONFIRM_SUPERVISION_CREDENTIALS).setPackage(SETTINGS_PKG)
        val activities =
            context.packageManager.queryIntentActivitiesAsUser(intent, 0, context.userId)
        return if (activities.isNotEmpty()) intent else null
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -129,6 +129,15 @@ class SupervisionIntentProviderTest {
        assertThat(intent).isNull()
    }

    fun getConfirmSupervisionCredentialsIntent_unresolvedIntent() {
        `when`(mockPackageManager.queryIntentActivitiesAsUser(any<Intent>(), anyInt(), anyInt()))
            .thenReturn(emptyList<ResolveInfo>())

        val intent = SupervisionIntentProvider.getConfirmSupervisionCredentialsIntent(context)

        assertThat(intent).isNull()
    }

    @Test
    fun getPinRecoveryIntent_setup_resolvedIntent() {
        `when`(mockSupervisionManager.activeSupervisionAppPackage)
@@ -223,6 +232,17 @@ class SupervisionIntentProviderTest {
        assertThat(intent?.`package`).isEqualTo(SUPERVISION_APP_PACKAGE)
    }

    fun getConfirmSupervisionCredentialsIntent_resolvedIntent() {
        `when`(mockPackageManager.queryIntentActivitiesAsUser(any<Intent>(), anyInt(), anyInt()))
            .thenReturn(listOf(ResolveInfo()))

        val intent = SupervisionIntentProvider.getConfirmSupervisionCredentialsIntent(context)
        assertThat(intent).isNotNull()
        assertThat(intent?.action)
            .isEqualTo("android.app.supervision.action.CONFIRM_SUPERVISION_CREDENTIALS")
        assertThat(intent?.`package`).isEqualTo("com.android.settings")
    }

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