mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
Add AutofillSaveItem and related Intent helpers (#895)
This commit is contained in:
parent
c82406b599
commit
27c93d26e5
2 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
package com.x8bit.bitwarden.data.autofill.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Represents raw data from a user completing a form and deciding to save that data to their vault
|
||||
* via the autofill framework.
|
||||
*/
|
||||
sealed class AutofillSaveItem : Parcelable {
|
||||
|
||||
/**
|
||||
* Data for a card item.
|
||||
*
|
||||
* @property number The actual card number (if applicable).
|
||||
* @property expirationMonth The expiration month in string form (if applicable).
|
||||
* @property expirationYear The expiration year in string form (if applicable).
|
||||
* @property securityCode The security code for the card (if applicable).
|
||||
*/
|
||||
@Parcelize
|
||||
data class Card(
|
||||
val number: String?,
|
||||
val expirationMonth: String?,
|
||||
val expirationYear: String?,
|
||||
val securityCode: String?,
|
||||
) : AutofillSaveItem()
|
||||
|
||||
/**
|
||||
* Data for a login item.
|
||||
*
|
||||
* @property username The username/email for the login (if applicable).
|
||||
* @property password The password for the login (if applicable).
|
||||
* @property uri The URI associated with the login (if applicable).
|
||||
*/
|
||||
@Parcelize
|
||||
data class Login(
|
||||
val username: String?,
|
||||
val password: String?,
|
||||
val uri: String?,
|
||||
) : AutofillSaveItem()
|
||||
}
|
|
@ -11,11 +11,14 @@ import android.service.autofill.Dataset
|
|||
import android.view.autofill.AutofillManager
|
||||
import com.x8bit.bitwarden.AutofillTotpCopyActivity
|
||||
import com.x8bit.bitwarden.MainActivity
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSaveItem
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillTotpCopyData
|
||||
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||
import com.x8bit.bitwarden.data.platform.util.getSafeParcelableExtra
|
||||
|
||||
private const val AUTOFILL_SAVE_ITEM_DATA_KEY = "autofill-save-item-data"
|
||||
private const val AUTOFILL_SELECTION_DATA_KEY = "autofill-selection-data"
|
||||
private const val AUTOFILL_TOTP_COPY_DATA_KEY = "autofill-totp-copy-data"
|
||||
|
||||
|
@ -72,6 +75,22 @@ fun createTotpCopyIntentSender(
|
|||
.intentSender
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [Intent] in order to start the cipher saving process during the autofill flow.
|
||||
*/
|
||||
fun createAutofillSavedItemIntent(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
autofillSaveItem: AutofillSaveItem,
|
||||
): Intent =
|
||||
Intent(
|
||||
autofillAppInfo.context,
|
||||
MainActivity::class.java,
|
||||
)
|
||||
.apply {
|
||||
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
putExtra(AUTOFILL_SAVE_ITEM_DATA_KEY, autofillSaveItem)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an [Intent] in order to specify that there is a successful selection during a manual
|
||||
* autofill process.
|
||||
|
@ -91,6 +110,13 @@ fun createAutofillSelectionResultIntent(
|
|||
fun Intent.getAutofillAssistStructureOrNull(): AssistStructure? =
|
||||
this.getSafeParcelableExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE)
|
||||
|
||||
/**
|
||||
* Checks if the given [Intent] contains an [AutofillSaveItem] related to an ongoing save item
|
||||
* process.
|
||||
*/
|
||||
fun Intent.getAutofillSaveItemOrNull(): AutofillSaveItem? =
|
||||
this.getSafeParcelableExtra(AUTOFILL_SAVE_ITEM_DATA_KEY)
|
||||
|
||||
/**
|
||||
* Checks if the given [Intent] contains data about an ongoing manual autofill selection process.
|
||||
* The [AutofillSelectionData] will be returned when present.
|
||||
|
|
Loading…
Reference in a new issue