diff options
Diffstat (limited to 'autofill-parser/src/main')
4 files changed, 63 insertions, 9 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 78af009d..952bc3f0 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 @@ -7,7 +7,9 @@ package com.github.androidpasswordstore.autofillparser import android.app.assist.AssistStructure import android.content.Context import android.content.pm.PackageManager +import android.content.pm.PackageManager.ApplicationInfoFlags import android.net.Uri +import android.os.Build import android.os.Bundle import android.view.autofill.AutofillId import androidx.annotation.RequiresApi @@ -41,7 +43,15 @@ public sealed class FormOrigin(public open val identifier: String) { is Web -> identifier is App -> { val info = - context.packageManager.getApplicationInfo(identifier, PackageManager.GET_META_DATA) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.packageManager.getApplicationInfo( + identifier, + ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()) + ) + } else { + @Suppress("DEPRECATION") + context.packageManager.getApplicationInfo(identifier, PackageManager.GET_META_DATA) + } val label = context.packageManager.getApplicationLabel(info) if (untrusted) "“$label”" else "$label" } 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 5874bf77..7e5a3d33 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 @@ -54,7 +54,15 @@ public fun computeCertificatesHash(context: Context, appPackage: String): String val stableHashOld = stableHash(signaturesOld.map { it.toByteArray() }) if (Build.VERSION.SDK_INT >= 28) { val info = - context.packageManager.getPackageInfo(appPackage, PackageManager.GET_SIGNING_CERTIFICATES) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.packageManager.getPackageInfo( + appPackage, + PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong()) + ) + } else { + @Suppress("DEPRECATION") + context.packageManager.getPackageInfo(appPackage, PackageManager.GET_SIGNING_CERTIFICATES) + } val signaturesNew = info.signingInfo.signingCertificateHistory ?: info.signingInfo.apkContentsSigners val stableHashNew = stableHash(signaturesNew.map { it.toByteArray() }) 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 7476f56c..d2a95b40 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,8 +5,11 @@ package com.github.androidpasswordstore.autofillparser import android.app.assist.AssistStructure +import android.os.Build import android.os.Bundle +import android.os.Parcelable import android.service.autofill.Dataset +import android.service.autofill.Field import android.view.autofill.AutofillId import android.view.autofill.AutofillValue import androidx.annotation.RequiresApi @@ -54,17 +57,19 @@ public sealed class AutofillScenario<out T : Any> { return try { Builder<AutofillId>() .apply { - username = clientState.getParcelable(BUNDLE_KEY_USERNAME_ID) + username = clientState.getParcelableCompat(BUNDLE_KEY_USERNAME_ID) fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME) - otp = clientState.getParcelable(BUNDLE_KEY_OTP_ID) + otp = clientState.getParcelableCompat(BUNDLE_KEY_OTP_ID) currentPassword.addAll( - clientState.getParcelableArrayList(BUNDLE_KEY_CURRENT_PASSWORD_IDS) ?: emptyList() + clientState.getParcelableArrayListCompat(BUNDLE_KEY_CURRENT_PASSWORD_IDS) + ?: emptyList() ) newPassword.addAll( - clientState.getParcelableArrayList(BUNDLE_KEY_NEW_PASSWORD_IDS) ?: emptyList() + clientState.getParcelableArrayListCompat(BUNDLE_KEY_NEW_PASSWORD_IDS) ?: emptyList() ) genericPassword.addAll( - clientState.getParcelableArrayList(BUNDLE_KEY_GENERIC_PASSWORD_IDS) ?: emptyList() + clientState.getParcelableArrayListCompat(BUNDLE_KEY_GENERIC_PASSWORD_IDS) + ?: emptyList() ) } .build() @@ -73,6 +78,24 @@ public sealed class AutofillScenario<out T : Any> { null } } + + private inline fun <reified T> Bundle.getParcelableCompat(key: String): T? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelable(key, T::class.java) + } else { + @Suppress("DEPRECATION") getParcelable(key) + } + } + + private inline fun <reified T : Parcelable> Bundle.getParcelableArrayListCompat( + key: String + ): ArrayList<T>? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableArrayList(key, T::class.java) + } else { + @Suppress("DEPRECATION") getParcelableArrayList(key) + } + } } internal class Builder<T : Any> { @@ -231,7 +254,11 @@ public fun Dataset.Builder.fillWith( scenario.otp -> credentialsToFill.otp else -> credentialsToFill.password } - setValue(field, AutofillValue.forText(value)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + setField(field, Field.Builder().setValue(AutofillValue.forText(value)).build()) + } else { + @Suppress("DEPRECATION") setValue(field, AutofillValue.forText(value)) + } } } 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 58f400ef..7c4d0c2e 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 @@ -7,6 +7,7 @@ package com.github.androidpasswordstore.autofillparser import android.content.Context import android.content.Intent import android.content.pm.PackageManager +import android.content.pm.PackageManager.ResolveInfoFlags import android.net.Uri import android.os.Build import android.provider.Settings @@ -247,7 +248,15 @@ public fun getInstalledBrowsersWithAutofillSupportLevel( ): List<Pair<String, BrowserAutofillSupportLevel>> { val testWebIntent = Intent(Intent.ACTION_VIEW).apply { data = Uri.parse("https://example.org") } val installedBrowsers = - context.packageManager.queryIntentActivities(testWebIntent, PackageManager.MATCH_ALL) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.packageManager.queryIntentActivities( + testWebIntent, + ResolveInfoFlags.of(PackageManager.MATCH_ALL.toLong()) + ) + } else { + @Suppress("DEPRECATION") + context.packageManager.queryIntentActivities(testWebIntent, PackageManager.MATCH_ALL) + } return installedBrowsers .map { it to getBrowserAutofillSupportLevel(context, it.activityInfo.packageName) } .filter { it.first.isDefault || it.second != BrowserAutofillSupportLevel.None } |