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

Commit dc152770 authored by Qinmei Du's avatar Qinmei Du Committed by Android (Google) Code Review
Browse files

Merge "Convert the create password requestInfo from real requestInfo and...

Merge "Convert the create password requestInfo from real requestInfo and display the email and password"
parents 48030f33 71e87df4
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -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"
    )
  }

+4 −4
Original line number Diff line number Diff line
@@ -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()
+22 −12
Original line number Diff line number Diff line
@@ -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() {
        // 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.userName,
            text = requestDisplayInfo.title,
            style = MaterialTheme.typography.titleLarge,
            modifier = Modifier.padding(top = 16.dp)
          )
          Text(
          text = requestDisplayInfo.displayName,
            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)
          )
        }
      }
    }
  )
+3 −3
Original line number Diff line number Diff line
@@ -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 {
+2 −2
Original line number Diff line number Diff line
@@ -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,
)