Loading packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt +0 −4 Original line number Diff line number Diff line Loading @@ -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? Loading Loading @@ -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 = Loading @@ -137,8 +135,6 @@ class CredentialManagerRepo( defaultProviderIdsSetByUser = requestDisplayInfoUiState.userSetDefaultProviderIds, requestDisplayInfo = requestDisplayInfoUiState, isOnPasskeyIntroStateAlready = false, isPasskeyFirstUse = isPasskeyFirstUse, )!! val isFlowAutoSelectable = isFlowAutoSelectable(createCredentialUiState) UiState( Loading packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +4 −12 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -78,10 +76,7 @@ class CredentialSelectorActivity : ComponentActivity() { setContent { PlatformTheme { CredentialManagerBottomSheet( credManRepo, userConfigRepo ) CredentialManagerBottomSheet(credManRepo) } } } catch (e: Exception) { Loading @@ -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) { Loading Loading @@ -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() Loading packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt +0 −54 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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( Loading @@ -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( Loading @@ -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( Loading packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt +3 −14 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } ) Loading @@ -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 Loading packages/CredentialManager/src/com/android/credentialmanager/UserConfigRepo.ktdeleted 100644 → 0 +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
packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt +0 −4 Original line number Diff line number Diff line Loading @@ -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? Loading Loading @@ -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 = Loading @@ -137,8 +135,6 @@ class CredentialManagerRepo( defaultProviderIdsSetByUser = requestDisplayInfoUiState.userSetDefaultProviderIds, requestDisplayInfo = requestDisplayInfoUiState, isOnPasskeyIntroStateAlready = false, isPasskeyFirstUse = isPasskeyFirstUse, )!! val isFlowAutoSelectable = isFlowAutoSelectable(createCredentialUiState) UiState( Loading
packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +4 −12 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -78,10 +76,7 @@ class CredentialSelectorActivity : ComponentActivity() { setContent { PlatformTheme { CredentialManagerBottomSheet( credManRepo, userConfigRepo ) CredentialManagerBottomSheet(credManRepo) } } } catch (e: Exception) { Loading @@ -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) { Loading Loading @@ -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() Loading
packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorViewModel.kt +0 −54 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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( Loading @@ -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( Loading @@ -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( Loading
packages/CredentialManager/src/com/android/credentialmanager/DataConverter.kt +3 −14 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } ) Loading @@ -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 Loading
packages/CredentialManager/src/com/android/credentialmanager/UserConfigRepo.ktdeleted 100644 → 0 +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" } }