summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt11
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/oreo/Form.kt18
2 files changed, 17 insertions, 12 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
index b22833a5..1b0ff35d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt
@@ -11,6 +11,9 @@ import androidx.core.content.edit
import com.github.ajalt.timberkt.Timber.e
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.w
+import com.github.michaelbull.result.Err
+import com.github.michaelbull.result.Ok
+import com.github.michaelbull.result.Result
import com.zeapo.pwdstore.R
import java.io.File
@@ -94,18 +97,18 @@ class AutofillMatcher {
* first time the user associated an entry with it, an [AutofillPublisherChangedException]
* will be thrown.
*/
- fun getMatchesFor(context: Context, formOrigin: FormOrigin): List<File> {
+ fun getMatchesFor(context: Context, formOrigin: FormOrigin): Result<List<File>, AutofillPublisherChangedException> {
if (hasFormOriginHashChanged(context, formOrigin)) {
- throw AutofillPublisherChangedException(formOrigin)
+ return Err(AutofillPublisherChangedException(formOrigin))
}
val matchPreferences = context.matchPreferences(formOrigin)
val matchedFiles =
matchPreferences.getStringSet(matchesKey(formOrigin), emptySet())!!.map { File(it) }
- return matchedFiles.filter { it.exists() }.also { validFiles ->
+ return Ok(matchedFiles.filter { it.exists() }.also { validFiles ->
matchPreferences.edit {
putStringSet(matchesKey(formOrigin), validFiles.map { it.absolutePath }.toSet())
}
- }
+ })
}
fun clearMatchesFor(context: Context, formOrigin: FormOrigin) {
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 85164f8f..5d24c882 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
@@ -21,6 +21,7 @@ import androidx.annotation.RequiresApi
import androidx.core.os.bundleOf
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
+import com.github.michaelbull.result.fold
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillDecryptActivity
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillFilterView
import com.zeapo.pwdstore.autofill.oreo.ui.AutofillPublisherChangedActivity
@@ -369,13 +370,14 @@ class FillableForm private constructor(
* Creates and returns a suitable [FillResponse] to the Autofill framework.
*/
fun fillCredentials(context: Context, callback: FillCallback) {
- val matchedFiles = try {
- AutofillMatcher.getMatchesFor(context, formOrigin)
- } catch (publisherChangedException: AutofillPublisherChangedException) {
- e(publisherChangedException)
- callback.onSuccess(makePublisherChangedResponse(context, publisherChangedException))
- return
- }
- callback.onSuccess(makeFillResponse(context, matchedFiles))
+ AutofillMatcher.getMatchesFor(context, formOrigin).fold(
+ success = { matchedFiles ->
+ callback.onSuccess(makeFillResponse(context, matchedFiles))
+ },
+ failure = { e ->
+ e(e)
+ callback.onSuccess(makePublisherChangedResponse(context, e))
+ }
+ )
}
}