diff options
| author | 2022-10-11 17:03:47 +0000 | |
|---|---|---|
| committer | 2022-10-12 22:31:05 +0000 | |
| commit | 1b7bc2b052a7ea508d26a9638193fcfe2bf56a92 (patch) | |
| tree | 4cfdc19239cf97e2d34e172f34669988d12a21c7 | |
| parent | 6f245890af08ebce746d5f66b66d5ceb32219689 (diff) | |
Parse the provider and request data from the intent.
Usage of these values will be added next.
Test: deployed locally
Bug: 247855226
Change-Id: Id9bace68064feb925ddbaf9a9cb7995ee6e4c237
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt | 91 | ||||
| -rw-r--r-- | packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt | 2 |
2 files changed, 89 insertions, 4 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt index 59186336056e..46bf19c64759 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt @@ -1,6 +1,14 @@ 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 { diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt index 5cd6a13a377a..98c824cb77fc 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt @@ -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" |