Merge "Convert the create password requestInfo from real requestInfo and display the email and password"

This commit is contained in:
Qinmei Du
2022-11-17 04:48:14 +00:00
committed by Android (Google) Code Review
5 changed files with 51 additions and 29 deletions

View File

@@ -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"
)
}

View File

@@ -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()

View File

@@ -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)
)
}
}
}
)

View File

@@ -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 {

View File

@@ -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,
)