diff options
| author | 2022-11-16 18:40:27 +0000 | |
|---|---|---|
| committer | 2022-11-16 19:16:56 +0000 | |
| commit | 71e87df405da1657d57f6fa5ccaf928295b6491c (patch) | |
| tree | 2271683b391a14e352bdd4c2707ddf42f2054ca9 | |
| parent | d08a3d764c063097965d172e4d0bfcb560ca126b (diff) | |
Convert the create password requestInfo from real requestInfo and display the email and password
screenshot:https://screenshot.googleplex.com/BmjfD7JRC6Zsv6Q
Test: deployed locally
Bug: 253157211
Change-Id: Ief8fd7a8173b9494216ae5cd49702b1338314ef0
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt | 28 | ||||
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt | 8 | ||||
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt (renamed from packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt) | 34 | ||||
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt (renamed from packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyViewModel.kt) | 6 | ||||
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt | 4 |
5 files changed, 51 insertions, 29 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt index 8bd7cf03008b..b848a47f37de 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt @@ -38,12 +38,15 @@ import android.os.Binder import android.os.Bundle import android.os.ResultReceiver import com.android.credentialmanager.createflow.ActiveEntry -import com.android.credentialmanager.createflow.CreatePasskeyUiState +import com.android.credentialmanager.createflow.CreateCredentialUiState import com.android.credentialmanager.createflow.CreateScreenState import com.android.credentialmanager.createflow.EnabledProviderInfo import com.android.credentialmanager.createflow.RequestDisplayInfo import com.android.credentialmanager.getflow.GetCredentialUiState import com.android.credentialmanager.getflow.GetScreenState +import com.android.credentialmanager.jetpack.developer.CreateCredentialRequest.Companion.createFrom +import com.android.credentialmanager.jetpack.developer.CreatePasswordRequest +import com.android.credentialmanager.jetpack.developer.CreatePasswordRequest.Companion.toBundle import com.android.credentialmanager.jetpack.developer.PublicKeyCredential.Companion.TYPE_PUBLIC_KEY_CREDENTIAL // Consider repo per screen, similar to view model? @@ -123,7 +126,7 @@ class CredentialManagerRepo( ) } - fun createPasskeyInitialUiState(): CreatePasskeyUiState { + fun createCredentialInitialUiState(): CreateCredentialUiState { val providerEnabledList = CreateFlowUtils.toEnabledProviderList( // Handle runtime cast error providerEnabledList as List<CreateCredentialProviderData>, context) @@ -135,13 +138,22 @@ class CredentialManagerRepo( providerEnabledList.forEach{providerInfo -> providerInfo.createOptions = providerInfo.createOptions.sortedWith(compareBy { it.lastUsedTimeMillis }).reversed() if (providerInfo.isDefault) {hasDefault = true; defaultProvider = providerInfo} } - // TODO: covert from real requestInfo - val requestDisplayInfo = RequestDisplayInfo( + // TODO: covert from real requestInfo for create passkey + var requestDisplayInfo = RequestDisplayInfo( "Elisa Beckett", "beckett-bakert@gmail.com", TYPE_PUBLIC_KEY_CREDENTIAL, "tribank") - return CreatePasskeyUiState( + val createCredentialRequest = requestInfo.createCredentialRequest + val createCredentialRequestJetpack = createCredentialRequest?.let { createFrom(it) } + if (createCredentialRequestJetpack is CreatePasswordRequest) { + requestDisplayInfo = RequestDisplayInfo( + createCredentialRequestJetpack.id, + createCredentialRequestJetpack.password, + TYPE_PASSWORD_CREDENTIAL, + "tribank") + } + return CreateCredentialUiState( enabledProviders = providerEnabledList, disabledProviders = providerDisabledList, if (hasDefault) @@ -388,15 +400,15 @@ class CredentialManagerRepo( } private fun testCreateRequestInfo(): RequestInfo { - val data = Bundle() + val data = toBundle("beckett-bakert@gmail.com", "password123") return RequestInfo.newCreateRequestInfo( Binder(), CreateCredentialRequest( - TYPE_PUBLIC_KEY_CREDENTIAL, + TYPE_PASSWORD_CREDENTIAL, data ), /*isFirstUsage=*/false, - "tribank.us" + "tribank" ) } diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt index 78edaa936bcd..1041a33333b3 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt @@ -28,8 +28,8 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.android.credentialmanager.common.DialogType import com.android.credentialmanager.common.DialogResult import com.android.credentialmanager.common.ResultState -import com.android.credentialmanager.createflow.CreatePasskeyScreen -import com.android.credentialmanager.createflow.CreatePasskeyViewModel +import com.android.credentialmanager.createflow.CreateCredentialScreen +import com.android.credentialmanager.createflow.CreateCredentialViewModel import com.android.credentialmanager.getflow.GetCredentialScreen import com.android.credentialmanager.getflow.GetCredentialViewModel import com.android.credentialmanager.ui.theme.CredentialSelectorTheme @@ -63,12 +63,12 @@ class CredentialSelectorActivity : ComponentActivity() { val dialogType = DialogType.toDialogType(operationType) when (dialogType) { DialogType.CREATE_PASSKEY -> { - val viewModel: CreatePasskeyViewModel = viewModel() + val viewModel: CreateCredentialViewModel = viewModel() viewModel.observeDialogResult().observe( this@CredentialSelectorActivity, onCancel ) - CreatePasskeyScreen(viewModel = viewModel) + CreateCredentialScreen(viewModel = viewModel) } DialogType.GET_CREDENTIALS -> { val viewModel: GetCredentialViewModel = viewModel() diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt index 8a1f83d2cb77..dbb33c8233dd 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt @@ -48,8 +48,8 @@ import com.android.credentialmanager.jetpack.developer.PublicKeyCredential.Compa @OptIn(ExperimentalMaterial3Api::class) @Composable -fun CreatePasskeyScreen( - viewModel: CreatePasskeyViewModel, +fun CreateCredentialScreen( + viewModel: CreateCredentialViewModel, ) { val state = rememberModalBottomSheetState( initialValue = ModalBottomSheetValue.Expanded, @@ -510,16 +510,26 @@ fun PrimaryCreateOptionRow( shape = EntryShape.FullRoundedCorner, label = { Column() { - Text( - text = requestDisplayInfo.userName, - style = MaterialTheme.typography.titleLarge, - modifier = Modifier.padding(top = 16.dp) - ) - Text( - text = requestDisplayInfo.displayName, - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.padding(bottom = 16.dp) - ) + // TODO: Add the function to hide/view password when the type is create password + if (requestDisplayInfo.type == TYPE_PUBLIC_KEY_CREDENTIAL || + requestDisplayInfo.type == TYPE_PASSWORD_CREDENTIAL) { + Text( + text = requestDisplayInfo.title, + style = MaterialTheme.typography.titleLarge, + modifier = Modifier.padding(top = 16.dp) + ) + Text( + text = requestDisplayInfo.subtitle, + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.padding(bottom = 16.dp) + ) + } else { + Text( + text = requestDisplayInfo.subtitle, + style = MaterialTheme.typography.titleLarge, + modifier = Modifier.padding(top = 16.dp, bottom = 16.dp) + ) + } } } ) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyViewModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt index af74b8ea4de1..6be019fa0882 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyViewModel.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialViewModel.kt @@ -27,7 +27,7 @@ import com.android.credentialmanager.CredentialManagerRepo import com.android.credentialmanager.common.DialogResult import com.android.credentialmanager.common.ResultState -data class CreatePasskeyUiState( +data class CreateCredentialUiState( val enabledProviders: List<EnabledProviderInfo>, val disabledProviders: List<DisabledProviderInfo>? = null, val currentScreenState: CreateScreenState, @@ -35,11 +35,11 @@ data class CreatePasskeyUiState( val activeEntry: ActiveEntry? = null, ) -class CreatePasskeyViewModel( +class CreateCredentialViewModel( credManRepo: CredentialManagerRepo = CredentialManagerRepo.getInstance() ) : ViewModel() { - var uiState by mutableStateOf(credManRepo.createPasskeyInitialUiState()) + var uiState by mutableStateOf(credManRepo.createCredentialInitialUiState()) private set val dialogResult: MutableLiveData<DialogResult> by lazy { diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt index 123c3d454905..1ab234a0e0bc 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateModel.kt @@ -62,8 +62,8 @@ class RemoteInfo( ) : EntryInfo(entryKey, entrySubkey) data class RequestDisplayInfo( - val userName: String, - val displayName: String, + val title: String, + val subtitle: String, val type: String, val appDomainName: String, ) |