summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Reema Bajwa <reemabajwa@google.com> 2022-12-08 20:04:20 +0000
committer Reema Bajwa <reemabajwa@google.com> 2022-12-13 01:29:05 +0000
commite4374aaf2d2cc133e2432f85c615efa5fabd0a5c (patch)
tree2c0c67cfd6348a437c43789db4f20085ff2bc5f3
parent9a512e9c887b3e57a12266291c4e7b4d0d96dc7d (diff)
Copy over slice parsing from jetpack
Test: Built & deployed locally Change-Id: Ibc07a3db7dffd412d24c2fbc619b127870b7ee89
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt65
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt61
2 files changed, 76 insertions, 50 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
index 1693eb629b1b..47b5af0d7fe6 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
@@ -16,8 +16,8 @@
package com.android.credentialmanager.jetpack.provider
+import android.app.PendingIntent
import android.app.slice.Slice
-import android.credentials.ui.Entry
import android.graphics.drawable.Icon
/**
@@ -32,38 +32,57 @@ class CredentialEntryUi(
val userDisplayName: CharSequence?,
val entryIcon: Icon?,
val lastUsedTimeMillis: Long?,
+ // TODO: Remove note
val note: CharSequence?,
) {
companion object {
+ // Copied over from jetpack
+ const val SLICE_HINT_TYPE_DISPLAY_NAME =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_TYPE_DISPLAY_NAME"
+ const val SLICE_HINT_USERNAME =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_USER_NAME"
+ const val SLICE_HINT_DISPLAYNAME =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_CREDENTIAL_TYPE_DISPLAY_NAME"
+ const val SLICE_HINT_LAST_USED_TIME_MILLIS =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_LAST_USED_TIME_MILLIS"
+ const val SLICE_HINT_ICON =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_PROFILE_ICON"
+ const val SLICE_HINT_PENDING_INTENT =
+ "androidx.credentials.provider.credentialEntry.SLICE_HINT_PENDING_INTENT"
+
+ /**
+ * Returns an instance of [CredentialEntryUi] derived from a [Slice] object.
+ *
+ * @param slice the [Slice] object constructed through jetpack library
+ */
+ @JvmStatic
fun fromSlice(slice: Slice): CredentialEntryUi {
- var credentialType = slice.spec!!.type
- var credentialTypeDisplayName: CharSequence? = null
- var userName: CharSequence? = null
- var userDisplayName: CharSequence? = null
- var entryIcon: Icon? = null
- var lastUsedTimeMillis: Long? = null
+ var username: CharSequence? = null
+ var displayName: CharSequence = ""
+ var icon: Icon? = null
+ var pendingIntent: PendingIntent? = null
+ var lastUsedTimeMillis: Long = 0
var note: CharSequence? = null
+ var typeDisplayName: CharSequence = ""
- val items = slice.items
- items.forEach {
- if (it.hasHint(Entry.HINT_CREDENTIAL_TYPE_DISPLAY_NAME)) {
- credentialTypeDisplayName = it.text
- } else if (it.hasHint(Entry.HINT_USER_NAME)) {
- userName = it.text
- } else if (it.hasHint(Entry.HINT_PASSKEY_USER_DISPLAY_NAME)) {
- userDisplayName = it.text
- } else if (it.hasHint(Entry.HINT_PROFILE_ICON)) {
- entryIcon = it.icon
- } else if (it.hasHint(Entry.HINT_LAST_USED_TIME_MILLIS)) {
+ slice.items.forEach {
+ if (it.hasHint(SLICE_HINT_TYPE_DISPLAY_NAME)) {
+ typeDisplayName = it.text
+ } else if (it.hasHint(SLICE_HINT_USERNAME)) {
+ username = it.text
+ } else if (it.hasHint(SLICE_HINT_DISPLAYNAME)) {
+ displayName = it.text
+ } else if (it.hasHint(SLICE_HINT_ICON)) {
+ icon = it.icon
+ } else if (it.hasHint(SLICE_HINT_PENDING_INTENT)) {
+ pendingIntent = it.action
+ } else if (it.hasHint(SLICE_HINT_LAST_USED_TIME_MILLIS)) {
lastUsedTimeMillis = it.long
- } else if (it.hasHint(Entry.HINT_NOTE)) {
- note = it.text
}
}
-
return CredentialEntryUi(
- credentialType, credentialTypeDisplayName!!, userName!!, userDisplayName, entryIcon,
- lastUsedTimeMillis, note,
+ slice.spec!!.type, typeDisplayName, username!!, displayName, icon,
+ lastUsedTimeMillis, note,
)
}
}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
index bcc05315cfc0..313f0f97e246 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
@@ -16,8 +16,8 @@
package com.android.credentialmanager.jetpack.provider
+import android.app.PendingIntent
import android.app.slice.Slice
-import android.credentials.ui.Entry
import android.graphics.drawable.Icon
/**
@@ -35,38 +35,45 @@ class SaveEntryUi(
val lastUsedTimeMillis: Long?,
) {
companion object {
- fun fromSlice(slice: Slice): SaveEntryUi {
- var userProviderAccountName: CharSequence? = null
- var credentialTypeIcon: Icon? = null
- var profileIcon: Icon? = null
- var passwordCount: Int? = null
- var passkeyCount: Int? = null
- var totalCredentialCount: Int? = null
- var lastUsedTimeMillis: Long? = null
+ const val SLICE_HINT_ACCOUNT_NAME =
+ "androidx.credentials.provider.createEntry.SLICE_HINT_USER_PROVIDER_ACCOUNT_NAME"
+ const val SLICE_HINT_ICON =
+ "androidx.credentials.provider.createEntry.SLICE_HINT_PROFILE_ICON"
+ const val SLICE_HINT_CREDENTIAL_COUNT_INFORMATION =
+ "androidx.credentials.provider.createEntry.SLICE_HINT_CREDENTIAL_COUNT_INFORMATION"
+ const val SLICE_HINT_LAST_USED_TIME_MILLIS =
+ "androidx.credentials.provider.createEntry.SLICE_HINT_LAST_USED_TIME_MILLIS"
+ const val SLICE_HINT_PENDING_INTENT =
+ "androidx.credentials.provider.createEntry.SLICE_HINT_PENDING_INTENT"
+ /**
+ * Returns an instance of [SaveEntryUi] derived from a [Slice] object.
+ *
+ * @param slice the [Slice] object constructed through the jetpack library
+ */
+ @JvmStatic
+ fun fromSlice(slice: Slice): SaveEntryUi {
+ var accountName: CharSequence? = null
+ var icon: Icon? = null
+ var pendingIntent: PendingIntent? = null
+ var lastUsedTimeMillis: Long = 0
- val items = slice.items
- items.forEach {
- if (it.hasHint(Entry.HINT_USER_PROVIDER_ACCOUNT_NAME)) {
- userProviderAccountName = it.text
- } else if (it.hasHint(Entry.HINT_CREDENTIAL_TYPE_ICON)) {
- credentialTypeIcon = it.icon
- } else if (it.hasHint(Entry.HINT_PROFILE_ICON)) {
- profileIcon = it.icon
- } else if (it.hasHint(Entry.HINT_PASSWORD_COUNT)) {
- passwordCount = it.int
- } else if (it.hasHint(Entry.HINT_PASSKEY_COUNT)) {
- passkeyCount = it.int
- } else if (it.hasHint(Entry.HINT_TOTAL_CREDENTIAL_COUNT)) {
- totalCredentialCount = it.int
- } else if (it.hasHint(Entry.HINT_LAST_USED_TIME_MILLIS)) {
+ slice.items.forEach {
+ if (it.hasHint(SLICE_HINT_ACCOUNT_NAME)) {
+ accountName = it.text
+ } else if (it.hasHint(SLICE_HINT_ICON)) {
+ icon = it.icon
+ } else if (it.hasHint(SLICE_HINT_PENDING_INTENT)) {
+ pendingIntent = it.action
+ } else if (it.hasHint(SLICE_HINT_LAST_USED_TIME_MILLIS)) {
lastUsedTimeMillis = it.long
}
}
- // TODO: fail NPE more elegantly.
+
return SaveEntryUi(
- userProviderAccountName!!, credentialTypeIcon, profileIcon,
- passwordCount, passkeyCount, totalCredentialCount, lastUsedTimeMillis,
+ // TODO: Add count parsing
+ accountName!!, icon, icon,
+ 0, 0, 0, lastUsedTimeMillis,
)
}
}