From c980c898de8417e16942741d469ebef8532b822a Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 28 May 2024 15:11:50 +0530 Subject: chore: reformat with trailing commas changes --- .../autofillparser/AutofillFormParser.kt | 12 ++-- .../autofillparser/AutofillHelper.kt | 4 +- .../autofillparser/AutofillScenario.kt | 28 ++++----- .../autofillparser/AutofillStrategyDsl.kt | 44 ++++++------- .../autofillparser/FeatureAndTrustDetection.kt | 23 +++---- .../autofillparser/FormField.kt | 72 ++++------------------ .../autofillparser/PublicSuffixListCache.kt | 4 +- 7 files changed, 67 insertions(+), 120 deletions(-) (limited to 'autofill-parser/src/main/java/com/github') 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 badaabcb..89359057 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 @@ -47,7 +47,7 @@ public sealed class FormOrigin(public open val identifier: String) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { context.packageManager.getApplicationInfo( identifier, - ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()) + ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()), ) } else { context.packageManager.getApplicationInfo(identifier, PackageManager.GET_META_DATA) @@ -74,7 +74,7 @@ private class AutofillFormParser( context: Context, structure: AssistStructure, isManualRequest: Boolean, - private val customSuffixes: Sequence + private val customSuffixes: Sequence, ) { companion object { @@ -136,7 +136,7 @@ private class AutofillFormParser( autofillStrategy.match( relevantFields, singleOriginMode = trustedBrowserInfo?.multiOriginMethod == BrowserMultiOriginMethod.None, - isManualRequest = isManualRequest + isManualRequest = isManualRequest, ) private fun trackOrigin(node: AssistStructure.ViewNode) { @@ -187,7 +187,7 @@ private class AutofillFormParser( // situation is uncertain and Autofill should not be offered. webOriginToFormOrigin( context, - scenario.allFields.map { it.webOrigin }.toSet().singleOrNull() ?: return null + scenario.allFields.map { it.webOrigin }.toSet().singleOrNull() ?: return null, ) } } @@ -206,7 +206,7 @@ private constructor( public val formOrigin: FormOrigin, public val scenario: AutofillScenario, public val ignoredIds: List, - public val saveFlags: Int? + public val saveFlags: Int?, ) { public companion object { /** Returns a [FillableForm] if a login form could be detected in [structure]. */ @@ -222,7 +222,7 @@ private constructor( form.formOrigin, form.scenario.map { it.autofillId }, form.ignoredIds, - form.saveFlags + form.saveFlags, ) } } 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 b12fd9c1..f08f3172 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 @@ -57,7 +57,7 @@ public fun computeCertificatesHash(context: Context, appPackage: String): String if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { context.packageManager.getPackageInfo( appPackage, - PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong()) + PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong()), ) } else { context.packageManager.getPackageInfo(appPackage, PackageManager.GET_SIGNING_CERTIFICATES) @@ -121,7 +121,7 @@ private fun visitViewNodes(structure: AssistStructure, block: (AssistStructure.V private fun visitViewNode( node: AssistStructure.ViewNode, - block: (AssistStructure.ViewNode) -> Unit + block: (AssistStructure.ViewNode) -> Unit, ) { block(node) for (i in 0 until node.childCount) { 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 c7bd99fc..9c32d62f 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 @@ -21,7 +21,7 @@ public enum class AutofillAction { Match, Search, Generate, - FillOtpFromSms + FillOtpFromSms, } /** @@ -46,8 +46,8 @@ public sealed class AutofillScenario { "Use `fromClientState` instead.", ReplaceWith( "fromClientState(clientState)", - "com.github.androidpasswordstore.autofillparser.AutofillScenario.Companion.fromClientState" - ) + "com.github.androidpasswordstore.autofillparser.AutofillScenario.Companion.fromClientState", + ), ) public fun fromBundle(clientState: Bundle): AutofillScenario? { return fromClientState(clientState) @@ -61,7 +61,7 @@ public sealed class AutofillScenario { BundleCompat.getParcelable( clientState, BUNDLE_KEY_USERNAME_ID, - AutofillId::class.java + AutofillId::class.java, ) fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME) otp = BundleCompat.getParcelable(clientState, BUNDLE_KEY_OTP_ID, AutofillId::class.java) @@ -69,21 +69,21 @@ public sealed class AutofillScenario { BundleCompat.getParcelableArrayList( clientState, BUNDLE_KEY_CURRENT_PASSWORD_IDS, - AutofillId::class.java + AutofillId::class.java, ) ?: emptyList() ) newPassword.addAll( BundleCompat.getParcelableArrayList( clientState, BUNDLE_KEY_NEW_PASSWORD_IDS, - AutofillId::class.java + AutofillId::class.java, ) ?: emptyList() ) genericPassword.addAll( BundleCompat.getParcelableArrayList( clientState, BUNDLE_KEY_GENERIC_PASSWORD_IDS, - AutofillId::class.java + AutofillId::class.java, ) ?: emptyList() ) } @@ -114,14 +114,14 @@ public sealed class AutofillScenario { fillUsername = fillUsername, otp = otp, currentPassword = currentPassword, - newPassword = newPassword + newPassword = newPassword, ) } else { GenericAutofillScenario( username = username, fillUsername = fillUsername, otp = otp, - genericPassword = genericPassword + genericPassword = genericPassword, ) } } @@ -193,7 +193,7 @@ internal data class ClassifiedAutofillScenario( override val fillUsername: Boolean, override val otp: T?, val currentPassword: List, - val newPassword: List + val newPassword: List, ) : AutofillScenario() { override val allPasswordFields @@ -217,7 +217,7 @@ internal data class GenericAutofillScenario( override val username: T?, override val fillUsername: Boolean, override val otp: T?, - val genericPassword: List + val genericPassword: List, ) : AutofillScenario() { override val allPasswordFields @@ -254,7 +254,7 @@ internal fun AutofillScenario.passesOriginCheck(singleOriginMode: Boo public fun Dataset.Builder.fillWith( scenario: AutofillScenario, action: AutofillAction, - credentials: Credentials? + credentials: Credentials?, ) { val credentialsToFill = credentials ?: Credentials("USERNAME", "PASSWORD", "OTP") for (field in scenario.fieldsToFillOn(action)) { @@ -303,7 +303,7 @@ internal fun AutofillScenario.toBundle(): Bundle = putParcelable(AutofillScenario.BUNDLE_KEY_OTP_ID, otp) putParcelableArrayList( AutofillScenario.BUNDLE_KEY_CURRENT_PASSWORD_IDS, - ArrayList(currentPassword) + ArrayList(currentPassword), ) putParcelableArrayList(AutofillScenario.BUNDLE_KEY_NEW_PASSWORD_IDS, ArrayList(newPassword)) } @@ -315,7 +315,7 @@ internal fun AutofillScenario.toBundle(): Bundle = putParcelable(AutofillScenario.BUNDLE_KEY_OTP_ID, otp) putParcelableArrayList( AutofillScenario.BUNDLE_KEY_GENERIC_PASSWORD_IDS, - ArrayList(genericPassword) + ArrayList(genericPassword), ) } } 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 04e8d98c..6cd6afc7 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 @@ -75,7 +75,7 @@ internal interface FieldMatcher { @RequiresApi(Build.VERSION_CODES.O) internal class SingleFieldMatcher( private val take: (FormField, List) -> Boolean, - private val tieBreakers: List<(FormField, List) -> Boolean> + private val tieBreakers: List<(FormField, List) -> Boolean>, ) : FieldMatcher { @AutofillDsl @@ -100,7 +100,7 @@ internal class SingleFieldMatcher( fun build() = SingleFieldMatcher( takeSingle ?: throw IllegalArgumentException("Every block needs a take{Single,Pair} block"), - tieBreakersSingle + tieBreakersSingle, ) } @@ -139,7 +139,7 @@ internal class SingleFieldMatcher( @RequiresApi(Build.VERSION_CODES.O) private class PairOfFieldsMatcher( private val take: (Pair, List) -> Boolean, - private val tieBreakers: List<(Pair, List) -> Boolean> + private val tieBreakers: List<(Pair, List) -> Boolean>, ) : FieldMatcher { override fun match(fields: List, alreadyMatched: List): List? { @@ -180,14 +180,14 @@ private constructor( private val matchers: List, private val applyInSingleOriginMode: Boolean, private val applyOnManualRequestOnly: Boolean, - private val name: String + private val name: String, ) { data class AutofillRuleMatcher( val type: FillableFieldType, val matcher: FieldMatcher, val optional: Boolean, - val matchHidden: Boolean + val matchHidden: Boolean, ) enum class FillableFieldType { @@ -201,7 +201,7 @@ private constructor( @AutofillDsl class Builder( private val applyInSingleOriginMode: Boolean, - private val applyOnManualRequestOnly: Boolean + private val applyOnManualRequestOnly: Boolean, ) { companion object { @@ -215,7 +215,7 @@ private constructor( fun username( optional: Boolean = false, matchHidden: Boolean = false, - block: SingleFieldMatcher.Builder.() -> Unit + block: SingleFieldMatcher.Builder.() -> Unit, ) { require(matchers.none { it.type == FillableFieldType.Username }) { "Every rule block can only have at most one username block" @@ -225,7 +225,7 @@ private constructor( type = FillableFieldType.Username, matcher = SingleFieldMatcher.Builder().apply(block).build(), optional = optional, - matchHidden = matchHidden + matchHidden = matchHidden, ) ) } @@ -239,7 +239,7 @@ private constructor( type = FillableFieldType.Otp, matcher = SingleFieldMatcher.Builder().apply(block).build(), optional = optional, - matchHidden = false + matchHidden = false, ) ) } @@ -247,7 +247,7 @@ private constructor( fun currentPassword( optional: Boolean = false, matchHidden: Boolean = false, - block: FieldMatcher.Builder.() -> Unit + block: FieldMatcher.Builder.() -> Unit, ) { require(matchers.none { it.type == FillableFieldType.GenericPassword }) { "Every rule block can only have either genericPassword or {current,new}Password blocks" @@ -257,7 +257,7 @@ private constructor( type = FillableFieldType.CurrentPassword, matcher = FieldMatcher.Builder().apply(block).build(), optional = optional, - matchHidden = matchHidden + matchHidden = matchHidden, ) ) } @@ -271,7 +271,7 @@ private constructor( type = FillableFieldType.NewPassword, matcher = FieldMatcher.Builder().apply(block).build(), optional = optional, - matchHidden = false + matchHidden = false, ) ) } @@ -279,11 +279,7 @@ private constructor( fun genericPassword(optional: Boolean = false, block: FieldMatcher.Builder.() -> Unit) { require( matchers.none { - it.type in - listOf( - FillableFieldType.CurrentPassword, - FillableFieldType.NewPassword, - ) + it.type in listOf(FillableFieldType.CurrentPassword, FillableFieldType.NewPassword) } ) { "Every rule block can only have either genericPassword or {current,new}Password blocks" @@ -293,7 +289,7 @@ private constructor( type = FillableFieldType.GenericPassword, matcher = FieldMatcher.Builder().apply(block).build(), optional = optional, - matchHidden = false + matchHidden = false, ) ) } @@ -314,7 +310,7 @@ private constructor( matchers, applyInSingleOriginMode, applyOnManualRequestOnly, - name ?: "Rule #$ruleId" + name ?: "Rule #$ruleId", ) .also { ruleId++ } } @@ -325,7 +321,7 @@ private constructor( allUsername: List, allOtp: List, singleOriginMode: Boolean, - isManualRequest: Boolean + isManualRequest: Boolean, ): AutofillScenario? { if (singleOriginMode && !applyInSingleOriginMode) { logcat { "$name: Skipped in single origin mode" } @@ -399,12 +395,12 @@ internal class AutofillStrategy private constructor(private val rules: List Unit + block: AutofillRule.Builder.() -> Unit, ) { rules.add( AutofillRule.Builder( applyInSingleOriginMode = applyInSingleOriginMode, - applyOnManualRequestOnly = applyOnManualRequestOnly + applyOnManualRequestOnly = applyOnManualRequestOnly, ) .apply(block) .build() @@ -417,7 +413,7 @@ internal class AutofillStrategy private constructor(private val rules: List, singleOriginMode: Boolean, - isManualRequest: Boolean + isManualRequest: Boolean, ): AutofillScenario? { val possiblePasswordFields = fields.filter { it.passwordCertainty >= CertaintyLevel.Possible } logcat { "Possible password fields: ${possiblePasswordFields.size}" } @@ -433,7 +429,7 @@ internal class AutofillStrategy private constructor(private val rules: List= Build.VERSION_CODES.TIRAMISU) { context.packageManager.queryIntentActivities( testWebIntent, - ResolveInfoFlags.of(PackageManager.MATCH_ALL.toLong()) + ResolveInfoFlags.of(PackageManager.MATCH_ALL.toLong()), ) } else { context.packageManager.queryIntentActivities(testWebIntent, PackageManager.MATCH_ALL) 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 4d4dd218..5bcc7479 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 @@ -17,7 +17,7 @@ internal enum class CertaintyLevel { Impossible, Possible, Likely, - Certain + Certain, } /** @@ -29,31 +29,19 @@ internal class FormField( node: AssistStructure.ViewNode, private val index: Int, passDownWebViewOrigins: Boolean, - passedDownWebOrigin: String? = null + passedDownWebOrigin: String? = null, ) { companion object { private val HINTS_USERNAME = - listOf( - HintConstants.AUTOFILL_HINT_USERNAME, - HintConstants.AUTOFILL_HINT_NEW_USERNAME, - ) - private val HINTS_NEW_PASSWORD = - listOf( - HintConstants.AUTOFILL_HINT_NEW_PASSWORD, - ) + listOf(HintConstants.AUTOFILL_HINT_USERNAME, HintConstants.AUTOFILL_HINT_NEW_USERNAME) + private val HINTS_NEW_PASSWORD = listOf(HintConstants.AUTOFILL_HINT_NEW_PASSWORD) private val HINTS_PASSWORD = HINTS_NEW_PASSWORD + - listOf( - HintConstants.AUTOFILL_HINT_PASSWORD, - HintConstants.AUTOFILL_HINT_WIFI_PASSWORD, - ) + listOf(HintConstants.AUTOFILL_HINT_PASSWORD, HintConstants.AUTOFILL_HINT_WIFI_PASSWORD) private val HINTS_OTP = - listOf( - HintConstants.AUTOFILL_HINT_SMS_OTP, - HintConstants.AUTOFILL_HINT_2FA_APP_OTP, - ) + listOf(HintConstants.AUTOFILL_HINT_SMS_OTP, HintConstants.AUTOFILL_HINT_2FA_APP_OTP) @Suppress("DEPRECATION") private val HINTS_FILLABLE = @@ -93,21 +81,9 @@ internal class FormField( } } - private val HTML_INPUT_FIELD_TYPES_USERNAME = - listOf( - "email", - "tel", - "text", - ) - private val HTML_INPUT_FIELD_TYPES_PASSWORD = - listOf( - "password", - ) - private val HTML_INPUT_FIELD_TYPES_OTP = - listOf( - "tel", - "text", - ) + private val HTML_INPUT_FIELD_TYPES_USERNAME = listOf("email", "tel", "text") + private val HTML_INPUT_FIELD_TYPES_PASSWORD = listOf("password") + private val HTML_INPUT_FIELD_TYPES_OTP = listOf("tel", "text") private val HTML_INPUT_FIELD_TYPES_FILLABLE = (HTML_INPUT_FIELD_TYPES_USERNAME + HTML_INPUT_FIELD_TYPES_PASSWORD + @@ -128,33 +104,11 @@ internal class FormField( "captcha", "postal", // Prevent postal code fields from being mistaken for OTP fields ) - private val PASSWORD_HEURISTIC_TERMS = - listOf( - "pass", - "pswd", - "pwd", - ) + private val PASSWORD_HEURISTIC_TERMS = listOf("pass", "pswd", "pwd") private val USERNAME_HEURISTIC_TERMS = - listOf( - "alias", - "benutzername", - "e-mail", - "email", - "mail", - "login", - "user", - ) - private val OTP_HEURISTIC_TERMS = - listOf( - "einmal", - "otp", - "challenge", - "verification", - ) - private val OTP_WEAK_HEURISTIC_TERMS = - listOf( - "code", - ) + listOf("alias", "benutzername", "e-mail", "email", "mail", "login", "user") + private val OTP_HEURISTIC_TERMS = listOf("einmal", "otp", "challenge", "verification") + private val OTP_WEAK_HEURISTIC_TERMS = listOf("code") } private val List.anyMatchesFieldInfo diff --git a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt index 706aa6c5..64fb854f 100644 --- a/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt +++ b/autofill-parser/src/main/java/com/github/androidpasswordstore/autofillparser/PublicSuffixListCache.kt @@ -39,7 +39,7 @@ public fun cachePublicSuffixList(context: Context) { internal fun getPublicSuffixPlusOne( context: Context, domain: String, - customSuffixes: Sequence + customSuffixes: Sequence, ) = runBlocking { // We only feed valid domain names which are not IP addresses into getPublicSuffixPlusOne. // We do not check whether the domain actually exists (actually, not even whether its TLD @@ -77,7 +77,7 @@ private fun getSuffixPlusUpToOne(domain: String, suffix: String): String? { private suspend fun getCanonicalSuffix( context: Context, domain: String, - customSuffixes: Sequence + customSuffixes: Sequence, ): String { val publicSuffixList = PublicSuffixListCache.getOrCachePublicSuffixList(context) val publicSuffixPlusOne = -- cgit v1.2.3