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

Commit 987ce859 authored by Helen Qin's avatar Helen Qin
Browse files

Remove the passkey education screen.

Test: local verification
Bug: 326109674
Change-Id: Iaccc756bee7a7ad63ff00d393258ef0e936e5998
parent 12e867a9
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ import com.android.credentialmanager.createflow.isFlowAutoSelectable
class CredentialManagerRepo(
    private val context: Context,
    intent: Intent,
    userConfigRepo: UserConfigRepo,
    isNewActivity: Boolean,
) {
    val requestInfo: RequestInfo?
@@ -124,7 +123,6 @@ class CredentialManagerRepo(

        initialUiState = when (requestInfo?.type) {
            RequestInfo.TYPE_CREATE -> {
                val isPasskeyFirstUse = userConfigRepo.getIsPasskeyFirstUse()
                val providerEnableListUiState = getCreateProviderEnableListInitialUiState()
                val providerDisableListUiState = getCreateProviderDisableListInitialUiState()
                val requestDisplayInfoUiState =
@@ -137,8 +135,6 @@ class CredentialManagerRepo(
                    defaultProviderIdsSetByUser =
                    requestDisplayInfoUiState.userSetDefaultProviderIds,
                    requestDisplayInfo = requestDisplayInfoUiState,
                    isOnPasskeyIntroStateAlready = false,
                    isPasskeyFirstUse = isPasskeyFirstUse,
                )!!
                val isFlowAutoSelectable = isFlowAutoSelectable(createCredentialUiState)
                UiState(
+4 −12
Original line number Diff line number Diff line
@@ -61,9 +61,7 @@ class CredentialSelectorActivity : ComponentActivity() {
            if (isCancellationRequest && !shouldShowCancellationUi) {
                return
            }
            val userConfigRepo = UserConfigRepo(this)
            val credManRepo = CredentialManagerRepo(
                this, intent, userConfigRepo, isNewActivity = true)
            val credManRepo = CredentialManagerRepo(this, intent, isNewActivity = true)

            val backPressedCallback = object : OnBackPressedCallback(
                true // default to enabled
@@ -78,10 +76,7 @@ class CredentialSelectorActivity : ComponentActivity() {

            setContent {
                PlatformTheme {
                    CredentialManagerBottomSheet(
                        credManRepo,
                        userConfigRepo
                    )
                    CredentialManagerBottomSheet(credManRepo)
                }
            }
        } catch (e: Exception) {
@@ -103,9 +98,7 @@ class CredentialSelectorActivity : ComponentActivity() {
                    return
                }
            } else {
                val userConfigRepo = UserConfigRepo(this)
                val credManRepo = CredentialManagerRepo(
                    this, intent, userConfigRepo, isNewActivity = false)
                val credManRepo = CredentialManagerRepo(this, intent, isNewActivity = false)
                viewModel.onNewCredentialManagerRepo(credManRepo)
            }
        } catch (e: Exception) {
@@ -147,10 +140,9 @@ class CredentialSelectorActivity : ComponentActivity() {
    @Composable
    private fun CredentialManagerBottomSheet(
        credManRepo: CredentialManagerRepo,
        userConfigRepo: UserConfigRepo,
    ) {
        val viewModel: CredentialSelectorViewModel = viewModel {
            CredentialSelectorViewModel(credManRepo, userConfigRepo)
            CredentialSelectorViewModel(credManRepo)
        }
        val launcher = rememberLauncherForActivityResult(
            StartBalIntentSenderForResultContract()
+0 −54
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import com.android.credentialmanager.common.DialogState
import com.android.credentialmanager.common.ProviderActivityResult
import com.android.credentialmanager.common.ProviderActivityState
import com.android.credentialmanager.createflow.ActiveEntry
import com.android.credentialmanager.createflow.isFlowAutoSelectable
import com.android.credentialmanager.createflow.CreateCredentialUiState
import com.android.credentialmanager.createflow.CreateScreenState
import com.android.credentialmanager.getflow.GetCredentialUiState
@@ -63,7 +62,6 @@ data class CancelUiRequestState(

class CredentialSelectorViewModel(
    private var credManRepo: CredentialManagerRepo,
    private val userConfigRepo: UserConfigRepo,
) : ViewModel() {
    var uiState by mutableStateOf(credManRepo.initState())
        private set
@@ -266,42 +264,6 @@ class CredentialSelectorViewModel(
    /**************************************************************************/
    /*****                     Create Flow Callbacks                      *****/
    /**************************************************************************/
    fun createFlowOnConfirmIntro() {
        userConfigRepo.setIsPasskeyFirstUse(false)
        val prevUiState = uiState.createCredentialUiState
        if (prevUiState == null) {
            Log.d(Constants.LOG_TAG, "Encountered unexpected null create ui state")
            onInternalError()
            return
        }
        val newScreenState = CreateFlowUtils.toCreateScreenState(
            createOptionSize = prevUiState.sortedCreateOptionsPairs.size,
            isOnPasskeyIntroStateAlready = true,
            requestDisplayInfo = prevUiState.requestDisplayInfo,
            remoteEntry = prevUiState.remoteEntry,
            isPasskeyFirstUse = true,
        )
        if (newScreenState == null) {
            Log.d(Constants.LOG_TAG, "Unexpected: couldn't resolve new screen state")
            onInternalError()
            return
        }
        val newCreateCredentialUiState = prevUiState.copy(
            currentScreenState = newScreenState,
        )
        val isFlowAutoSelectable = isFlowAutoSelectable(newCreateCredentialUiState)
        uiState = uiState.copy(
            createCredentialUiState = newCreateCredentialUiState,
            isAutoSelectFlow = isFlowAutoSelectable,
            providerActivityState =
            if (isFlowAutoSelectable) ProviderActivityState.READY_TO_LAUNCH
            else ProviderActivityState.NOT_APPLICABLE,
            selectedEntry =
            if (isFlowAutoSelectable) newCreateCredentialUiState.activeEntry?.activeEntryInfo
            else null,
        )
    }

    fun createFlowOnMoreOptionsSelectedOnCreationSelection() {
        uiState = uiState.copy(
            createCredentialUiState = uiState.createCredentialUiState?.copy(
@@ -318,14 +280,6 @@ class CredentialSelectorViewModel(
        )
    }

    fun createFlowOnBackPasskeyIntroButtonSelected() {
        uiState = uiState.copy(
            createCredentialUiState = uiState.createCredentialUiState?.copy(
                currentScreenState = CreateScreenState.PASSKEY_INTRO,
            )
        )
    }

    fun createFlowOnEntrySelectedFromMoreOptionScreen(activeEntry: ActiveEntry) {
        uiState = uiState.copy(
            createCredentialUiState = uiState.createCredentialUiState?.copy(
@@ -348,14 +302,6 @@ class CredentialSelectorViewModel(
        uiState = uiState.copy(dialogState = DialogState.CANCELED_FOR_SETTINGS)
    }

    fun createFlowOnLearnMore() {
        uiState = uiState.copy(
            createCredentialUiState = uiState.createCredentialUiState?.copy(
                currentScreenState = CreateScreenState.MORE_ABOUT_PASSKEYS_INTRO,
            )
        )
    }

    fun createFlowOnUseOnceSelected() {
        uiState = uiState.copy(
            createCredentialUiState = uiState.createCredentialUiState?.copy(
+3 −14
Original line number Diff line number Diff line
@@ -342,8 +342,6 @@ class CreateFlowUtils {
            defaultProviderIdPreferredByApp: String?,
            defaultProviderIdsSetByUser: Set<String>,
            requestDisplayInfo: RequestDisplayInfo,
            isOnPasskeyIntroStateAlready: Boolean,
            isPasskeyFirstUse: Boolean,
        ): CreateCredentialUiState? {
            var remoteEntry: RemoteInfo? = null
            var remoteEntryProvider: EnabledProviderInfo? = null
@@ -392,11 +390,8 @@ class CreateFlowUtils {
            val defaultProvider = defaultProviderPreferredByApp ?: defaultProviderSetByUser
            val initialScreenState = toCreateScreenState(
                createOptionSize = createOptionsPairs.size,
                isOnPasskeyIntroStateAlready = isOnPasskeyIntroStateAlready,
                requestDisplayInfo = requestDisplayInfo,
                remoteEntry = remoteEntry,
                isPasskeyFirstUse = isPasskeyFirstUse
            ) ?: return null
            )
            val sortedCreateOptionsPairs = createOptionsPairs.sortedWith(
                compareByDescending { it.first.lastUsedTime }
            )
@@ -419,15 +414,9 @@ class CreateFlowUtils {

        fun toCreateScreenState(
            createOptionSize: Int,
            isOnPasskeyIntroStateAlready: Boolean,
            requestDisplayInfo: RequestDisplayInfo,
            remoteEntry: RemoteInfo?,
            isPasskeyFirstUse: Boolean,
        ): CreateScreenState? {
            return if (isPasskeyFirstUse && requestDisplayInfo.type == CredentialType.PASSKEY &&
                !isOnPasskeyIntroStateAlready) {
                CreateScreenState.PASSKEY_INTRO
            } else if (createOptionSize == 0 && remoteEntry != null) {
        ): CreateScreenState {
            return if (createOptionSize == 0 && remoteEntry != null) {
                CreateScreenState.EXTERNAL_ONLY_SELECTION
            } else {
                CreateScreenState.CREATION_OPTION_SELECTION
+0 −44
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.credentialmanager

import android.content.Context
import android.content.SharedPreferences

class UserConfigRepo(context: Context) {
    val sharedPreferences: SharedPreferences = context.getSharedPreferences(
        context.packageName, Context.MODE_PRIVATE)

    fun setIsPasskeyFirstUse(
        isFirstUse: Boolean
    ) {
        sharedPreferences.edit().apply {
            putBoolean(IS_PASSKEY_FIRST_USE, isFirstUse)
            apply()
        }
    }

    fun getIsPasskeyFirstUse(): Boolean {
        return sharedPreferences.getBoolean(IS_PASSKEY_FIRST_USE, true)
    }

    companion object {
        // This first use value only applies to passkeys, not related with if generally
        // credential manager is first use or not
        const val IS_PASSKEY_FIRST_USE = "is_passkey_first_use"
    }
}
Loading