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

Commit 4cca0014 authored by Helen Qin's avatar Helen Qin Committed by Android (Google) Code Review
Browse files

Merge "Parse the provider and request data from the intent."

parents 9cbc89c2 1b7bc2b0
Loading
Loading
Loading
Loading
+88 −3
Original line number Diff line number Diff line
package com.android.credentialmanager

import android.app.slice.Slice
import android.app.slice.SliceSpec
import android.content.Context
import android.content.Intent
import android.credentials.ui.Entry
import android.credentials.ui.ProviderData
import android.credentials.ui.RequestInfo
import android.graphics.drawable.Icon
import android.os.Binder
import com.android.credentialmanager.createflow.CreateOptionInfo
import com.android.credentialmanager.createflow.CreatePasskeyUiState
import com.android.credentialmanager.createflow.CreateScreenState
@@ -11,8 +19,82 @@ import com.android.credentialmanager.getflow.GetScreenState

// Consider repo per screen, similar to view model?
class CredentialManagerRepo(
  private val context: Context
  private val context: Context,
  intent: Intent,
) {
  private val requestInfo: RequestInfo
  private val providerList: List<ProviderData>

  init {
    requestInfo = intent.extras?.getParcelable(
      RequestInfo.EXTRA_REQUEST_INFO,
      RequestInfo::class.java
    ) ?: RequestInfo(
      Binder(),
      RequestInfo.TYPE_CREATE,
      /*isFirstUsage=*/false
    )

    providerList = intent.extras?.getParcelableArrayList(
      ProviderData.EXTRA_PROVIDER_DATA_LIST,
      ProviderData::class.java
    ) ?: testProviderList()
  }

  private fun testProviderList(): List<ProviderData> {
    return listOf(
      ProviderData(
        "com.google",
        listOf<Entry>(
          newEntry(1, "elisa.beckett@gmail.com", "Elisa Backett"),
          newEntry(2, "elisa.work@google.com", "Elisa Backett Work"),
        ),
        listOf<Entry>(
          newEntry(3, "Go to Settings", ""),
          newEntry(4, "Switch Account", ""),
        ),
        null
      ),
      ProviderData(
        "com.dashlane",
        listOf<Entry>(
          newEntry(5, "elisa.beckett@dashlane.com", "Elisa Backett"),
          newEntry(6, "elisa.work@dashlane.com", "Elisa Backett Work"),
        ),
        listOf<Entry>(
          newEntry(7, "Manage Accounts", "Manage your accounts in the dashlane app"),
        ),
        null
      ),
      ProviderData(
        "com.lastpass",
        listOf<Entry>(
          newEntry(8, "elisa.beckett@lastpass.com", "Elisa Backett"),
        ),
        listOf<Entry>(),
        null
      )

    )
  }

  private fun newEntry(id: Int, title: String, subtitle: String): Entry {
    val slice = Slice.Builder(
      Entry.CREDENTIAL_MANAGER_ENTRY_URI, SliceSpec(Entry.VERSION, 1)
    )
      .addText(title, null, listOf(Entry.HINT_TITLE))
      .addText(subtitle, null, listOf(Entry.HINT_SUBTITLE))
      .addIcon(
        Icon.createWithResource(context, R.drawable.ic_passkey),
        null,
        listOf(Entry.HINT_ICON))
      .build()
    return Entry(
      id,
      slice
    )
  }

  private fun getCredentialProviderList():
    List<com.android.credentialmanager.getflow.ProviderInfo> {
      return listOf(
@@ -140,8 +222,11 @@ class CredentialManagerRepo(
  companion object {
    lateinit var repo: CredentialManagerRepo

    fun setup(context: Context) {
      repo = CredentialManagerRepo(context)
    fun setup(
      context: Context,
      intent: Intent,
    ) {
      repo = CredentialManagerRepo(context, intent)
    }

    fun getInstance(): CredentialManagerRepo {
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ import com.android.credentialmanager.ui.theme.CredentialSelectorTheme
class CredentialSelectorActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    CredentialManagerRepo.setup(this)
    CredentialManagerRepo.setup(this, intent)
    val startDestination = intent.extras?.getString(
      "start_destination",
      "CREATE_PASSKEY"