aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-11-03 09:06:17 +0100
committerHarsh Shandilya <me@msfjarvis.dev>2021-03-20 22:26:19 +0530
commit0e9843ccba9fefabcb33e81ea13756bbbf74506e (patch)
tree43d6aa60f70bae1a67f3ae7577ab7a9f581d1523 /app/src
parent2494a159890950359fdfac4aad2260662acadfaf (diff)
Make autofill-parser API explicit and refactor (#1182)
(cherry picked from commit 73648b39d02086d1b964a89e049fe2c4ae3c33fc)
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt17
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt2
2 files changed, 9 insertions, 10 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt
index ec3d2b77..c186ecd8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt
@@ -37,8 +37,7 @@ class AutofillResponseBuilder(form: FillableForm) {
private val clientState = form.toClientState()
// We do not offer save when the only relevant field is a username field or there is no field.
- private val scenarioSupportsSave =
- scenario.fieldsToSave.minus(listOfNotNull(scenario.username)).isNotEmpty()
+ private val scenarioSupportsSave = scenario.hasPasswordFieldsToSave
private val canBeSaved = saveFlags != null && scenarioSupportsSave
private fun makePlaceholderDataset(
@@ -54,14 +53,14 @@ class AutofillResponseBuilder(form: FillableForm) {
}
private fun makeMatchDataset(context: Context, file: File): Dataset? {
- if (scenario.fieldsToFillOn(AutofillAction.Match).isEmpty()) return null
+ if (scenario.hasFieldsToFillOn(AutofillAction.Match)) return null
val remoteView = makeFillMatchRemoteView(context, file, formOrigin)
val intentSender = AutofillDecryptActivity.makeDecryptFileIntentSender(file, context)
return makePlaceholderDataset(remoteView, intentSender, AutofillAction.Match)
}
private fun makeSearchDataset(context: Context): Dataset? {
- if (scenario.fieldsToFillOn(AutofillAction.Search).isEmpty()) return null
+ if (scenario.hasFieldsToFillOn(AutofillAction.Search)) return null
val remoteView = makeSearchAndFillRemoteView(context, formOrigin)
val intentSender =
AutofillFilterView.makeMatchAndDecryptFileIntentSender(context, formOrigin)
@@ -69,14 +68,14 @@ class AutofillResponseBuilder(form: FillableForm) {
}
private fun makeGenerateDataset(context: Context): Dataset? {
- if (scenario.fieldsToFillOn(AutofillAction.Generate).isEmpty()) return null
+ if (scenario.hasFieldsToFillOn(AutofillAction.Generate)) return null
val remoteView = makeGenerateAndFillRemoteView(context, formOrigin)
val intentSender = AutofillSaveActivity.makeSaveIntentSender(context, null, formOrigin)
return makePlaceholderDataset(remoteView, intentSender, AutofillAction.Generate)
}
private fun makeFillOtpFromSmsDataset(context: Context): Dataset? {
- if (scenario.fieldsToFillOn(AutofillAction.FillOtpFromSms).isEmpty()) return null
+ if (scenario.hasFieldsToFillOn(AutofillAction.FillOtpFromSms)) return null
if (!AutofillSmsActivity.shouldOfferFillFromSms(context)) return null
val remoteView = makeFillOtpFromSmsRemoteView(context, formOrigin)
val intentSender = AutofillSmsActivity.makeFillOtpFromSmsIntentSender(context)
@@ -115,10 +114,10 @@ class AutofillResponseBuilder(form: FillableForm) {
private fun makeSaveInfo(): SaveInfo? {
if (!canBeSaved) return null
check(saveFlags != null)
- val idsToSave = scenario.fieldsToSave.map { it.autofillId }.toTypedArray()
+ val idsToSave = scenario.fieldsToSave.toTypedArray()
if (idsToSave.isEmpty()) return null
var saveDataTypes = SaveInfo.SAVE_DATA_TYPE_PASSWORD
- if (scenario.username != null) {
+ if (scenario.hasUsername) {
saveDataTypes = saveDataTypes or SaveInfo.SAVE_DATA_TYPE_USERNAME
}
return SaveInfo.Builder(saveDataTypes, idsToSave).run {
@@ -179,7 +178,7 @@ class AutofillResponseBuilder(form: FillableForm) {
action: AutofillAction
): Dataset {
val remoteView = makePlaceholderRemoteView(context)
- val scenario = AutofillScenario.fromBundle(clientState)
+ val scenario = AutofillScenario.fromClientState(clientState)
// Before Android P, Datasets used for fill-in had to come with a RemoteViews, even
// though they are never shown.
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt
index ecec6747..cfa33f11 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt
@@ -102,7 +102,7 @@ class OreoAutofillService : AutofillService() {
callback.onFailure(getString(R.string.oreo_autofill_save_internal_error))
return
}
- val scenario = AutofillScenario.fromBundle(clientState)?.recoverNodes(structure) ?: run {
+ val scenario = AutofillScenario.fromClientState(clientState)?.recoverNodes(structure) ?: run {
e { "Failed to recover client state or nodes from client state" }
callback.onFailure(getString(R.string.oreo_autofill_save_internal_error))
return