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

Commit 1d26aaac authored by Sandy Pan's avatar Sandy Pan
Browse files

Fix supervisionPinRecovery flow to bypass the user restriction.

Context: "add/remove user" restriction is applied when supervision is enabled which prevents us from resetting the user. This change should fix the reset PIN flow, however will still investigate on better approach in b/407064075.

Bug: 417533273
Bug: 414457269
Flag: android.app.supervision.flags.enable_supervision_pin_recovery_screen
Test: tests/robotests/src/com/android/settings/supervision/SupervisionPinRecoveryActivityTest.kt
Change-Id: Ide5c0f8281a4a8937bd8e9632a576a2a51e974a8
parent 2a6c2260
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -95,8 +95,7 @@ class SupervisionPinRecoveryActivity : FragmentActivity() {
                SupervisionIntentProvider.PinRecoveryAction.VERIFY,
            )
        if (recoveryIntent != null) {
            val supervisionManager =
                applicationContext.getSystemService(SupervisionManager::class.java)
            val supervisionManager = getSystemService(SupervisionManager::class.java)
            val recoveryInfo = supervisionManager?.getSupervisionRecoveryInfo()

            recoveryIntent.apply {
@@ -146,8 +145,7 @@ class SupervisionPinRecoveryActivity : FragmentActivity() {
                            SupervisionIntentProvider.PinRecoveryAction.POST_SETUP_VERIFY,
                        )
                    if (postSetupVerifyIntent != null) {
                        val supervisionManager =
                            applicationContext.getSystemService(SupervisionManager::class.java)
                        val supervisionManager = getSystemService(SupervisionManager::class.java)
                        val recoveryInfo = supervisionManager?.getSupervisionRecoveryInfo()
                        postSetupVerifyIntent.apply {
                            // TODO(b/409805806): will use the parcelable once the system API is
@@ -176,8 +174,7 @@ class SupervisionPinRecoveryActivity : FragmentActivity() {
                ACTION_SETUP_VERIFIED,
                ACTION_POST_SETUP_VERIFY -> {
                    if (data != null) {
                        val supervisionManager =
                            applicationContext.getSystemService(SupervisionManager::class.java)
                        val supervisionManager = getSystemService(SupervisionManager::class.java)
                        // TODO(b/409805806): will directly get the parcelable from intent once the
                        // system API is available.
                        val recoveryInfo =
@@ -192,7 +189,7 @@ class SupervisionPinRecoveryActivity : FragmentActivity() {
                                    },
                                )
                            }
                        supervisionManager?.setSupervisionRecoveryInfo(recoveryInfo)
                        supervisionManager?.supervisionRecoveryInfo = recoveryInfo
                        handleSuccess()
                    } else {
                        handleError("Cannot save recovery info, no recovery info from result.")
@@ -263,9 +260,19 @@ class SupervisionPinRecoveryActivity : FragmentActivity() {
    )
    private fun resetSupervisionUser(): Boolean {
        val userManager = getSystemService(UserManager::class.java)
        val supervisionManager = getSystemService(SupervisionManager::class.java)
        val isSupervisionEnabled = supervisionManager.isSupervisionEnabled
        if (isSupervisionEnabled) {
            // Disables supervision temporally to allow user reset.
            supervisionManager.setSupervisionEnabled(false)
        }
        supervisingUserHandle?.let { userManager.removeUser(it) }
        val userInfo =
            userManager.createUser("Supervising", USER_TYPE_PROFILE_SUPERVISING, /* flags= */ 0)
        if (isSupervisionEnabled) {
            // Re-enables supervision after user reset.
            supervisionManager.setSupervisionEnabled(true)
        }
        if (userInfo != null) {
            return true
        } else {
+634 −42

File changed.

Preview size limit exceeded, changes collapsed.