summaryrefslogtreecommitdiff
path: root/autofill-parser/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'autofill-parser/src/main')
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillFormParser.kt5
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillHelper.kt6
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt21
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategy.kt3
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt13
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FeatureAndTrustDetection.kt15
-rw-r--r--autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FormField.kt6
7 files changed, 31 insertions, 38 deletions
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillFormParser.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillFormParser.kt
index e7b04f56..78af009d 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillFormParser.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillFormParser.kt
@@ -8,7 +8,6 @@ import android.app.assist.AssistStructure
import android.content.Context
import android.content.pm.PackageManager
import android.net.Uri
-import android.os.Build
import android.os.Bundle
import android.view.autofill.AutofillId
import androidx.annotation.RequiresApi
@@ -60,7 +59,7 @@ public sealed class FormOrigin(public open val identifier: String) {
/**
* Manages the detection of fields to fill in an [AssistStructure] and determines the [FormOrigin].
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private class AutofillFormParser(
context: Context,
structure: AssistStructure,
@@ -191,7 +190,7 @@ public data class Credentials(val username: String?, val password: String?, val
* Represents a collection of fields in a specific app that can be filled or saved. This is the
* entry point to all fill and save features.
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
public class FillableForm
private constructor(
public val formOrigin: FormOrigin,
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillHelper.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillHelper.kt
index e8f661ef..5874bf77 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillHelper.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillHelper.kt
@@ -71,14 +71,14 @@ public fun computeCertificatesHash(context: Context, appPackage: String): String
* its `webDomain` and `webScheme`, if available.
*/
internal val AssistStructure.ViewNode.webOrigin: String?
- @RequiresApi(Build.VERSION_CODES.O)
+ @RequiresApi(26)
get() =
webDomain?.let { domain ->
val scheme = (if (Build.VERSION.SDK_INT >= 28) webScheme else null) ?: "https"
"$scheme://$domain"
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
public class FixedSaveCallback(context: Context, private val callback: SaveCallback) {
private val applicationContext = context.applicationContext
@@ -121,7 +121,7 @@ private fun visitViewNode(
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal fun AssistStructure.findNodeByAutofillId(
autofillId: AutofillId
): AssistStructure.ViewNode? {
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt
index 33a2a3fd..7476f56c 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillScenario.kt
@@ -5,7 +5,6 @@
package com.github.androidpasswordstore.autofillparser
import android.app.assist.AssistStructure
-import android.os.Build
import android.os.Bundle
import android.service.autofill.Dataset
import android.view.autofill.AutofillId
@@ -28,7 +27,7 @@ public enum class AutofillAction {
* [FormField], [AssistStructure.ViewNode] or [AutofillId], depending on how much metadata about the
* field is needed and available in the particular situation.
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
public sealed class AutofillScenario<out T : Any> {
public companion object {
@@ -163,7 +162,7 @@ public sealed class AutofillScenario<out T : Any> {
get() = username != null
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal data class ClassifiedAutofillScenario<T : Any>(
override val username: T?,
override val fillUsername: Boolean,
@@ -184,7 +183,7 @@ internal data class ClassifiedAutofillScenario<T : Any>(
get() = newPassword.ifEmpty { currentPassword }
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal data class GenericAutofillScenario<T : Any>(
override val username: T?,
override val fillUsername: Boolean,
@@ -204,7 +203,7 @@ internal data class GenericAutofillScenario<T : Any>(
get() = genericPassword
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal fun AutofillScenario<FormField>.passesOriginCheck(singleOriginMode: Boolean): Boolean {
return if (singleOriginMode) {
// In single origin mode, only the browsers URL bar (which is never filled) should have
@@ -217,7 +216,7 @@ internal fun AutofillScenario<FormField>.passesOriginCheck(singleOriginMode: Boo
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
@JvmName("fillWithAutofillId")
public fun Dataset.Builder.fillWith(
scenario: AutofillScenario<AutofillId>,
@@ -236,7 +235,7 @@ public fun Dataset.Builder.fillWith(
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal inline fun <T : Any, S : Any> AutofillScenario<T>.map(
transform: (T) -> S
): AutofillScenario<S> {
@@ -256,7 +255,7 @@ internal inline fun <T : Any, S : Any> AutofillScenario<T>.map(
return builder.build()
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
@JvmName("toBundleAutofillId")
internal fun AutofillScenario<AutofillId>.toBundle(): Bundle =
when (this) {
@@ -285,7 +284,7 @@ internal fun AutofillScenario<AutofillId>.toBundle(): Bundle =
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
public fun AutofillScenario<AutofillId>.recoverNodes(
structure: AssistStructure
): AutofillScenario<AssistStructure.ViewNode>? {
@@ -293,13 +292,13 @@ public fun AutofillScenario<AutofillId>.recoverNodes(
}
public val AutofillScenario<AssistStructure.ViewNode>.usernameValue: String?
- @RequiresApi(Build.VERSION_CODES.O)
+ @RequiresApi(26)
get() {
val value = username?.autofillValue ?: return null
return if (value.isText) value.textValue.toString() else null
}
public val AutofillScenario<AssistStructure.ViewNode>.passwordValue: String?
- @RequiresApi(Build.VERSION_CODES.O)
+ @RequiresApi(26)
get() {
val distinctValues =
passwordFieldsToSave
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategy.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategy.kt
index 7303efc5..93355a94 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategy.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategy.kt
@@ -4,7 +4,6 @@
*/
package com.github.androidpasswordstore.autofillparser
-import android.os.Build
import androidx.annotation.RequiresApi
import com.github.androidpasswordstore.autofillparser.CertaintyLevel.Certain
import com.github.androidpasswordstore.autofillparser.CertaintyLevel.Likely
@@ -22,7 +21,7 @@ private inline fun <T> Pair<T, T>.none(predicate: T.() -> Boolean) =
* The strategy used to detect [AutofillScenario] s; expressed using the DSL implemented in
* [AutofillDsl].
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal val autofillStrategy = strategy {
// Match two new password fields, an optional current password field right below or above, and
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
index 35006468..8295a7f4 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/AutofillStrategyDsl.kt
@@ -4,14 +4,13 @@
*/
package com.github.androidpasswordstore.autofillparser
-import android.os.Build
import androidx.annotation.RequiresApi
import logcat.LogPriority.WARN
import logcat.logcat
@DslMarker internal annotation class AutofillDsl
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal interface FieldMatcher {
fun match(fields: List<FormField>, alreadyMatched: List<FormField>): List<FormField>?
@@ -72,7 +71,7 @@ internal interface FieldMatcher {
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal class SingleFieldMatcher(
private val take: (FormField, List<FormField>) -> Boolean,
private val tieBreakers: List<(FormField, List<FormField>) -> Boolean>
@@ -136,7 +135,7 @@ internal class SingleFieldMatcher(
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private class PairOfFieldsMatcher(
private val take: (Pair<FormField, FormField>, List<FormField>) -> Boolean,
private val tieBreakers: List<(Pair<FormField, FormField>, List<FormField>) -> Boolean>
@@ -174,7 +173,7 @@ private class PairOfFieldsMatcher(
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal class AutofillRule
private constructor(
private val matchers: List<AutofillRuleMatcher>,
@@ -382,7 +381,7 @@ private constructor(
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal class AutofillStrategy private constructor(private val rules: List<AutofillRule>) {
@AutofillDsl
@@ -435,6 +434,6 @@ internal class AutofillStrategy private constructor(private val rules: List<Auto
}
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal fun strategy(block: AutofillStrategy.Builder.() -> Unit) =
AutofillStrategy.Builder().apply(block).build()
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FeatureAndTrustDetection.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FeatureAndTrustDetection.kt
index 2556a2f6..66332a4f 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FeatureAndTrustDetection.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FeatureAndTrustDetection.kt
@@ -142,7 +142,7 @@ private fun getBrowserMultiOriginMethod(appPackage: String): BrowserMultiOriginM
* Some browsers may not issue save requests automatically and thus need
* `FLAG_SAVE_ON_ALL_VIEW_INVISIBLE` to be set.
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private val BROWSER_SAVE_FLAG =
mapOf(
"com.duckduckgo.mobile.android" to 0,
@@ -156,7 +156,7 @@ private val BROWSER_SAVE_FLAG =
"com.opera.touch" to 0,
)
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private val BROWSER_SAVE_FLAG_IF_NO_ACCESSIBILITY =
mapOf(
"com.android.chrome" to SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE,
@@ -176,7 +176,7 @@ private fun isNoAccessibilityServiceEnabled(context: Context): Boolean {
.isNullOrEmpty()
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private fun getBrowserSaveFlag(context: Context, appPackage: String): Int? =
BROWSER_SAVE_FLAG[appPackage]
?: BROWSER_SAVE_FLAG_IF_NO_ACCESSIBILITY[appPackage]?.takeIf {
@@ -188,7 +188,7 @@ internal data class BrowserAutofillSupportInfo(
val saveFlags: Int?
)
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal fun getBrowserAutofillSupportInfoIfTrusted(
context: Context,
appPackage: String
@@ -214,7 +214,7 @@ public enum class BrowserAutofillSupportLevel {
GeneralFillAndSave,
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
private fun getBrowserAutofillSupportLevel(
context: Context,
appPackage: String
@@ -234,13 +234,12 @@ private fun getBrowserAutofillSupportLevel(
// (compatibility mode is only available on Android Pie and higher). Since all known browsers
// with native Autofill support offer full save support as well, we reuse the list of those
// browsers here.
- supportLevel != BrowserAutofillSupportLevel.GeneralFillAndSave &&
- Build.VERSION.SDK_INT < Build.VERSION_CODES.P
+ supportLevel != BrowserAutofillSupportLevel.GeneralFillAndSave && Build.VERSION.SDK_INT < 28
}
?: BrowserAutofillSupportLevel.None
}
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
public fun getInstalledBrowsersWithAutofillSupportLevel(
context: Context
): List<Pair<String, BrowserAutofillSupportLevel>> {
diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FormField.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FormField.kt
index 96813be5..36734064 100644
--- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FormField.kt
+++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/FormField.kt
@@ -5,7 +5,6 @@
package com.github.androidpasswordstore.autofillparser
import android.app.assist.AssistStructure
-import android.os.Build
import android.text.InputType
import android.view.View
import android.view.autofill.AutofillId
@@ -24,7 +23,7 @@ internal enum class CertaintyLevel {
* Represents a single potentially fillable or saveable field together with all meta data extracted
* from its [AssistStructure.ViewNode].
*/
-@RequiresApi(Build.VERSION_CODES.O)
+@RequiresApi(26)
internal class FormField(
node: AssistStructure.ViewNode,
private val index: Int,
@@ -114,8 +113,7 @@ internal class FormField(
.toSet()
.toList()
- @RequiresApi(Build.VERSION_CODES.O)
- private fun isSupportedHint(hint: String?) = hint in HINTS_FILLABLE
+ @RequiresApi(26) private fun isSupportedHint(hint: String?) = hint in HINTS_FILLABLE
private val EXCLUDED_TERMS =
listOf(
"url_bar", // Chrome/Edge/Firefox address bar