diff options
author | Fabian Henneke <FabianHenneke@users.noreply.github.com> | 2020-11-03 09:06:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-03 13:36:17 +0530 |
commit | 73648b39d02086d1b964a89e049fe2c4ae3c33fc (patch) | |
tree | 0f978f7ba87df9d4d2068887570ee5ad784a157e /app | |
parent | 1d13a1fbd6580c0d28c90579ade96e0a93e17c92 (diff) |
Make autofill-parser API explicit and refactor (#1182)
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillResponseBuilder.kt | 17 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/oreo/OreoAutofillService.kt | 2 |
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 2c62f935..1bee8c05 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 @@ -38,8 +38,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 makeIntentDataset( @@ -63,14 +62,14 @@ class AutofillResponseBuilder(form: FillableForm) { } private fun makeMatchDataset(context: Context, file: File, imeSpec: InlinePresentationSpec?): Dataset? { - if (scenario.fieldsToFillOn(AutofillAction.Match).isEmpty()) return null + if (scenario.hasFieldsToFillOn(AutofillAction.Match)) return null val metadata = makeFillMatchMetadata(context, file) val intentSender = AutofillDecryptActivity.makeDecryptFileIntentSender(file, context) return makeIntentDataset(context, AutofillAction.Match, intentSender, metadata, imeSpec) } private fun makeSearchDataset(context: Context, imeSpec: InlinePresentationSpec?): Dataset? { - if (scenario.fieldsToFillOn(AutofillAction.Search).isEmpty()) return null + if (scenario.hasFieldsToFillOn(AutofillAction.Search)) return null val metadata = makeSearchAndFillMetadata(context) val intentSender = AutofillFilterView.makeMatchAndDecryptFileIntentSender(context, formOrigin) @@ -78,14 +77,14 @@ class AutofillResponseBuilder(form: FillableForm) { } private fun makeGenerateDataset(context: Context, imeSpec: InlinePresentationSpec?): Dataset? { - if (scenario.fieldsToFillOn(AutofillAction.Generate).isEmpty()) return null + if (scenario.hasFieldsToFillOn(AutofillAction.Generate)) return null val metadata = makeGenerateAndFillMetadata(context) val intentSender = AutofillSaveActivity.makeSaveIntentSender(context, null, formOrigin) return makeIntentDataset(context, AutofillAction.Generate, intentSender, metadata, imeSpec) } private fun makeFillOtpFromSmsDataset(context: Context, imeSpec: InlinePresentationSpec?): Dataset? { - if (scenario.fieldsToFillOn(AutofillAction.FillOtpFromSms).isEmpty()) return null + if (scenario.hasFieldsToFillOn(AutofillAction.FillOtpFromSms)) return null if (!AutofillSmsActivity.shouldOfferFillFromSms(context)) return null val metadata = makeFillOtpFromSmsMetadata(context) val intentSender = AutofillSmsActivity.makeFillOtpFromSmsIntentSender(context) @@ -131,10 +130,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 { @@ -202,7 +201,7 @@ class AutofillResponseBuilder(form: FillableForm) { clientState: Bundle, action: AutofillAction ): Dataset { - 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 rarely shown. // FIXME: We should clone the original dataset here and add the credentials to be filled 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 10831cc5..61844039 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 @@ -108,7 +108,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 |