From ca9c951a536e9ccd2bf3e8f0e2e0a48992d0d655 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Thu, 2 Jul 2020 13:49:32 +0200 Subject: Fill OTP fields with SMS codes (#900) * Fill OTP fields with SMS codes * Allow SMS OTP fill also for web origins * Introduce free and nonFree build variants * Fix up workflow * Improve layout and feature detection * Workflow changes * Add Changelog entry * github: update release workflow for nonFree/Free split Signed-off-by: Harsh Shandilya * Switch to lifecycleScope * github: make snapshot deploy free variant Signed-off-by: Harsh Shandilya Co-authored-by: Harsh Shandilya --- app/src/main/AndroidManifest.xml | 5 ++ .../zeapo/pwdstore/autofill/oreo/AutofillHelper.kt | 9 +++- .../pwdstore/autofill/oreo/AutofillScenario.kt | 7 ++- .../java/com/zeapo/pwdstore/autofill/oreo/Form.kt | 13 +++++ app/src/main/res/drawable/ic_autofill_sms.xml | 10 ++++ .../main/res/layout/activity_oreo_autofill_sms.xml | 61 ++++++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_autofill_sms.xml create mode 100644 app/src/main/res/layout/activity_oreo_autofill_sms.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2098abc9..40bcb481 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -138,6 +138,11 @@ + { AutofillAction.Match -> passwordFieldsToFillOnMatch + listOfNotNull(otp) AutofillAction.Search -> passwordFieldsToFillOnSearch + listOfNotNull(otp) AutofillAction.Generate -> passwordFieldsToFillOnGenerate + AutofillAction.FillOtpFromSms -> listOfNotNull(otp) } return when { + action == AutofillAction.FillOtpFromSms -> { + // When filling from an SMS, we cannot get any data other than the OTP itself. + credentialFieldsToFill + } credentialFieldsToFill.isNotEmpty() -> { // If the current action would fill into any password field, we also fill into the // username field if possible. diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/Form.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/Form.kt index 210fefab..e4ae1f75 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/Form.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/Form.kt @@ -25,6 +25,7 @@ import com.zeapo.pwdstore.autofill.oreo.ui.AutofillDecryptActivity import com.zeapo.pwdstore.autofill.oreo.ui.AutofillFilterView import com.zeapo.pwdstore.autofill.oreo.ui.AutofillPublisherChangedActivity import com.zeapo.pwdstore.autofill.oreo.ui.AutofillSaveActivity +import com.zeapo.pwdstore.autofill.oreo.ui.AutofillSmsActivity import java.io.File /** @@ -285,6 +286,14 @@ class FillableForm private constructor( return makePlaceholderDataset(remoteView, intentSender, AutofillAction.Generate) } + private fun makeFillOtpFromSmsDataset(context: Context): Dataset? { + if (scenario.fieldsToFillOn(AutofillAction.FillOtpFromSms).isEmpty()) return null + if (!AutofillSmsActivity.shouldOfferFillFromSms(context)) return null + val remoteView = makeFillOtpFromSmsRemoteView(context, formOrigin) + val intentSender = AutofillSmsActivity.makeFillOtpFromSmsIntentSender(context) + return makePlaceholderDataset(remoteView, intentSender, AutofillAction.FillOtpFromSms) + } + private fun makePublisherChangedDataset( context: Context, publisherChangedException: AutofillPublisherChangedException @@ -341,6 +350,10 @@ class FillableForm private constructor( hasDataset = true addDataset(it) } + makeFillOtpFromSmsDataset(context)?.let { + hasDataset = true + addDataset(it) + } if (!hasDataset) return null makeSaveInfo()?.let { setSaveInfo(it) } setClientState(clientState) diff --git a/app/src/main/res/drawable/ic_autofill_sms.xml b/app/src/main/res/drawable/ic_autofill_sms.xml new file mode 100644 index 00000000..e58c33c4 --- /dev/null +++ b/app/src/main/res/drawable/ic_autofill_sms.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_oreo_autofill_sms.xml b/app/src/main/res/layout/activity_oreo_autofill_sms.xml new file mode 100644 index 00000000..608727d0 --- /dev/null +++ b/app/src/main/res/layout/activity_oreo_autofill_sms.xml @@ -0,0 +1,61 @@ + + + + + + + + + + +