Loading packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt +15 −0 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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) } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/supervision/SupervisionIntentProviderTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ class SupervisionIntentProviderTest { assertThat(intent).isNull() } @Test fun getConfirmSupervisionCredentialsIntent_unresolvedIntent() { mockPackageManager.stub { on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn Loading @@ -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 { Loading Loading @@ -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" } Loading Loading
packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt +15 −0 Original line number Diff line number Diff line Loading @@ -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), Loading Loading @@ -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) } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/supervision/SupervisionIntentProviderTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -137,6 +137,7 @@ class SupervisionIntentProviderTest { assertThat(intent).isNull() } @Test fun getConfirmSupervisionCredentialsIntent_unresolvedIntent() { mockPackageManager.stub { on { queryIntentActivitiesAsUser(any<Intent>(), any<Int>(), any<Int>()) } doReturn Loading @@ -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 { Loading Loading @@ -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" } Loading