From 6d0bff144c35c9f2c73f34065e972b3f48a34241 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 23 Jul 2022 03:15:29 +0530 Subject: [PATCH] Begin cleaning up Detekt warnings (#2027) --- .../autofill/oreo/ui/AutofillSmsActivity.kt | 3 +- .../ui/autofill/AutofillDecryptActivity.kt | 4 +-- .../ui/autofill/AutofillFilterView.kt | 4 +-- .../AutofillPublisherChangedActivity.kt | 4 +-- .../ui/autofill/AutofillSaveActivity.kt | 3 +- .../ui/crypto/BasePgpActivity.kt | 2 +- .../ui/crypto/PasswordCreationActivity.kt | 2 +- .../ui/proxy/ProxySelectorActivity.kt | 2 +- .../ui/settings/AutofillSettings.kt | 8 ++--- .../ui/settings/GeneralSettings.kt | 2 +- .../passwordstore/ui/settings/MiscSettings.kt | 2 +- .../ui/settings/RepositorySettings.kt | 2 +- .../autofill/Api30AutofillResponseBuilder.kt | 2 +- .../util/autofill/AutofillPreferences.kt | 3 +- .../util/autofill/AutofillResponseBuilder.kt | 6 ++-- .../util/autofill/AutofillViewUtils.kt | 4 +-- .../util/extensions/AndroidExtensions.kt | 2 +- .../app/passwordstore/util/git/sshj/SshKey.kt | 6 ++-- .../util/services/ClipboardService.kt | 12 +++---- .../util/services/OreoAutofillService.kt | 6 ++-- .../util/services/PasswordExportService.kt | 4 +-- .../util/shortcuts/ShortcutHandler.kt | 8 ++--- .../autofill/oreo/ui/AutofillSmsActivity.kt | 2 +- .../autofillparser/AutofillFormParser.kt | 4 +-- .../autofillparser/AutofillHelper.kt | 13 +++---- .../autofillparser/AutofillScenario.kt | 20 +++++------ .../autofillparser/AutofillStrategy.kt | 3 +- .../autofillparser/AutofillStrategyDsl.kt | 13 +++---- .../FeatureAndTrustDetection.kt | 15 ++++---- .../autofillparser/FormField.kt | 6 ++-- .../autofillparser/PublicSuffixListCache.kt | 2 +- .../util/coroutines/RunSuspendCatching.kt | 6 ++-- detekt-baselines/app.xml | 35 ------------------- detekt-baselines/autofill-parser.xml | 21 ----------- detekt-baselines/coroutine-utils.xml | 5 +-- 35 files changed, 96 insertions(+), 140 deletions(-) diff --git a/app/src/free/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt b/app/src/free/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt index 19ebfe55..71cd28a8 100644 --- a/app/src/free/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt +++ b/app/src/free/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt @@ -6,10 +6,11 @@ package app.passwordstore.autofill.oreo.ui import android.content.Context import android.content.IntentSender +import android.os.Build import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @Suppress("UNUSED_PARAMETER") class AutofillSmsActivity : AppCompatActivity() { diff --git a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt index acc8958a..e8e1f565 100644 --- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt @@ -38,7 +38,7 @@ import kotlinx.coroutines.withContext import logcat.LogPriority.ERROR import logcat.logcat -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @AndroidEntryPoint class AutofillDecryptActivity : AppCompatActivity() { @@ -67,7 +67,7 @@ class AutofillDecryptActivity : AppCompatActivity() { context, decryptFileRequestCode++, intent, - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE } else { PendingIntent.FLAG_CANCEL_CURRENT diff --git a/app/src/main/java/app/passwordstore/ui/autofill/AutofillFilterView.kt b/app/src/main/java/app/passwordstore/ui/autofill/AutofillFilterView.kt index 66927ca3..8825bc58 100644 --- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillFilterView.kt +++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillFilterView.kt @@ -41,7 +41,7 @@ import dagger.hilt.android.AndroidEntryPoint import logcat.LogPriority.ERROR import logcat.logcat -@TargetApi(26) +@TargetApi(Build.VERSION_CODES.O) @AndroidEntryPoint class AutofillFilterView : AppCompatActivity() { @@ -71,7 +71,7 @@ class AutofillFilterView : AppCompatActivity() { context, matchAndDecryptFileRequestCode++, intent, - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE } else { PendingIntent.FLAG_CANCEL_CURRENT diff --git a/app/src/main/java/app/passwordstore/ui/autofill/AutofillPublisherChangedActivity.kt b/app/src/main/java/app/passwordstore/ui/autofill/AutofillPublisherChangedActivity.kt index ac85a92a..6d348a23 100644 --- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillPublisherChangedActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillPublisherChangedActivity.kt @@ -33,7 +33,7 @@ import com.github.michaelbull.result.runCatching import logcat.LogPriority.ERROR import logcat.logcat -@TargetApi(26) +@TargetApi(Build.VERSION_CODES.O) class AutofillPublisherChangedActivity : AppCompatActivity() { companion object { @@ -57,7 +57,7 @@ class AutofillPublisherChangedActivity : AppCompatActivity() { context, publisherChangedRequestCode++, intent, - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE } else { PendingIntent.FLAG_CANCEL_CURRENT diff --git a/app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt b/app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt index 6f3a6462..801b9627 100644 --- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt @@ -8,6 +8,7 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.content.IntentSender +import android.os.Build import android.os.Bundle import android.view.autofill.AutofillManager import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult @@ -28,7 +29,7 @@ import java.io.File import logcat.LogPriority.ERROR import logcat.logcat -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @AndroidEntryPoint class AutofillSaveActivity : AppCompatActivity() { diff --git a/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt index fa85ffdd..c769e334 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt @@ -95,7 +95,7 @@ open class BasePgpActivity : AppCompatActivity() { action = ClipboardService.ACTION_START putExtra(ClipboardService.EXTRA_NOTIFICATION_TIME, clearAfter) } - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startForegroundService(service) } else { startService(service) diff --git a/app/src/main/java/app/passwordstore/ui/crypto/PasswordCreationActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/PasswordCreationActivity.kt index 8fee21b4..2e3e48a9 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/PasswordCreationActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/PasswordCreationActivity.kt @@ -105,7 +105,7 @@ class PasswordCreationActivity : BasePgpActivity() { return@registerForActivityResult } val bitmap = - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, imageUri)) .copy(Bitmap.Config.ARGB_8888, true) } else { diff --git a/app/src/main/java/app/passwordstore/ui/proxy/ProxySelectorActivity.kt b/app/src/main/java/app/passwordstore/ui/proxy/ProxySelectorActivity.kt index 9243a7f5..f7833a1c 100644 --- a/app/src/main/java/app/passwordstore/ui/proxy/ProxySelectorActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/proxy/ProxySelectorActivity.kt @@ -62,7 +62,7 @@ class ProxySelectorActivity : AppCompatActivity() { } private fun isNumericAddress(text: CharSequence): Boolean { - return if (Build.VERSION.SDK_INT >= 29) { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { InetAddresses.isNumericAddress(text as String) } else { @Suppress("DEPRECATION") Patterns.IP_ADDRESS.matcher(text).matches() diff --git a/app/src/main/java/app/passwordstore/ui/settings/AutofillSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/AutofillSettings.kt index 64ca531b..403c342d 100644 --- a/app/src/main/java/app/passwordstore/ui/settings/AutofillSettings.kt +++ b/app/src/main/java/app/passwordstore/ui/settings/AutofillSettings.kt @@ -35,11 +35,11 @@ class AutofillSettings(private val activity: FragmentActivity) : SettingsProvide private val isAutofillServiceEnabled: Boolean get() { - if (Build.VERSION.SDK_INT < 26) return false + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false return activity.autofillManager?.hasEnabledAutofillServices() == true } - @RequiresApi(26) + @RequiresApi(Build.VERSION_CODES.O) private fun showAutofillDialog(pref: SwitchPreference) { val observer = LifecycleEventObserver { _, event -> when (event) { @@ -95,10 +95,10 @@ class AutofillSettings(private val activity: FragmentActivity) : SettingsProvide builder.apply { switch(PreferenceKeys.AUTOFILL_ENABLE) { titleRes = R.string.pref_autofill_enable_title - visible = Build.VERSION.SDK_INT >= 26 + visible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O defaultValue = isAutofillServiceEnabled onClick { - if (Build.VERSION.SDK_INT < 26) return@onClick true + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return@onClick true if (isAutofillServiceEnabled) { activity.autofillManager?.disableAutofillServices() } else { diff --git a/app/src/main/java/app/passwordstore/ui/settings/GeneralSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/GeneralSettings.kt index b0c28455..a06a1dc8 100644 --- a/app/src/main/java/app/passwordstore/ui/settings/GeneralSettings.kt +++ b/app/src/main/java/app/passwordstore/ui/settings/GeneralSettings.kt @@ -97,7 +97,7 @@ class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider } } } - if (Build.VERSION.SDK_INT >= 25) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { activity.getSystemService()?.apply { removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList()) } diff --git a/app/src/main/java/app/passwordstore/ui/settings/MiscSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/MiscSettings.kt index 250af493..35f63e5b 100644 --- a/app/src/main/java/app/passwordstore/ui/settings/MiscSettings.kt +++ b/app/src/main/java/app/passwordstore/ui/settings/MiscSettings.kt @@ -47,7 +47,7 @@ class MiscSettings(activity: FragmentActivity) : SettingsProvider { putExtra("uri", uri) } - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { activity.startForegroundService(service) } else { activity.startService(service) diff --git a/app/src/main/java/app/passwordstore/ui/settings/RepositorySettings.kt b/app/src/main/java/app/passwordstore/ui/settings/RepositorySettings.kt index d57a1d36..060f7c93 100644 --- a/app/src/main/java/app/passwordstore/ui/settings/RepositorySettings.kt +++ b/app/src/main/java/app/passwordstore/ui/settings/RepositorySettings.kt @@ -166,7 +166,7 @@ class RepositorySettings(private val activity: FragmentActivity) : SettingsProvi } .onFailure { it.message?.let { message -> activity.snackbar(message = message) } } - if (Build.VERSION.SDK_INT >= 25) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { activity.getSystemService()?.apply { removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList()) } diff --git a/app/src/main/java/app/passwordstore/util/autofill/Api30AutofillResponseBuilder.kt b/app/src/main/java/app/passwordstore/util/autofill/Api30AutofillResponseBuilder.kt index 997e27b4..2fcb1f61 100644 --- a/app/src/main/java/app/passwordstore/util/autofill/Api30AutofillResponseBuilder.kt +++ b/app/src/main/java/app/passwordstore/util/autofill/Api30AutofillResponseBuilder.kt @@ -34,7 +34,7 @@ import logcat.asLog import logcat.logcat /** Implements [AutofillResponseBuilder]'s methods for API 30 and above */ -@RequiresApi(30) +@RequiresApi(Build.VERSION_CODES.R) class Api30AutofillResponseBuilder @AssistedInject constructor( diff --git a/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt b/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt index d99ba7a2..ba3e5079 100644 --- a/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt +++ b/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt @@ -5,6 +5,7 @@ package app.passwordstore.util.autofill import android.content.Context +import android.os.Build import androidx.annotation.RequiresApi import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.util.extensions.getString @@ -102,7 +103,7 @@ enum class DirectoryStructure(val value: String) { ?: file.nameWithoutExtension } - @RequiresApi(26) + @RequiresApi(Build.VERSION_CODES.O) fun getSaveFolderName(sanitizedIdentifier: String, username: String?) = when (this) { EncryptedUsername -> "/" diff --git a/app/src/main/java/app/passwordstore/util/autofill/AutofillResponseBuilder.kt b/app/src/main/java/app/passwordstore/util/autofill/AutofillResponseBuilder.kt index a198297c..2b2154c0 100644 --- a/app/src/main/java/app/passwordstore/util/autofill/AutofillResponseBuilder.kt +++ b/app/src/main/java/app/passwordstore/util/autofill/AutofillResponseBuilder.kt @@ -32,7 +32,7 @@ import logcat.LogPriority.ERROR import logcat.asLog import logcat.logcat -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) class AutofillResponseBuilder @AssistedInject constructor( @@ -167,7 +167,7 @@ constructor( addDataset(it) } if (datasetCount == 0) return null - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { setHeader( makeRemoteView( context, @@ -210,7 +210,7 @@ constructor( // fill-in dataset without any visual representation. This causes it to be missing from // the Autofill suggestions shown after the user clears the filled out form fields. val builder = - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { Dataset.Builder() } else { @Suppress("DEPRECATION") Dataset.Builder(makeRemoteView(context, makeEmptyMetadata())) diff --git a/app/src/main/java/app/passwordstore/util/autofill/AutofillViewUtils.kt b/app/src/main/java/app/passwordstore/util/autofill/AutofillViewUtils.kt index 9bf2cc8d..75d9efc6 100644 --- a/app/src/main/java/app/passwordstore/util/autofill/AutofillViewUtils.kt +++ b/app/src/main/java/app/passwordstore/util/autofill/AutofillViewUtils.kt @@ -47,7 +47,7 @@ fun makeInlinePresentation( imeSpec: InlinePresentationSpec, metadata: DatasetMetadata ): InlinePresentation? { - if (Build.VERSION.SDK_INT < 30) return null + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return null if (UiVersions.INLINE_UI_VERSION_1 !in UiVersions.getVersions(imeSpec.style)) return null @@ -56,7 +56,7 @@ fun makeInlinePresentation( context, 0, Intent(context, PasswordStore::class.java), - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_MUTABLE } else { 0 diff --git a/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt b/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt index 948d3827..2c9dbc9f 100644 --- a/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt +++ b/app/src/main/java/app/passwordstore/util/extensions/AndroidExtensions.kt @@ -40,7 +40,7 @@ import logcat.logcat /** Get an instance of [AutofillManager]. Only available on Android Oreo and above */ val Context.autofillManager: AutofillManager? - @RequiresApi(26) get() = getSystemService() + @RequiresApi(Build.VERSION_CODES.O) get() = getSystemService() /** Get an instance of [ClipboardManager] */ val Context.clipboard diff --git a/app/src/main/java/app/passwordstore/util/git/sshj/SshKey.kt b/app/src/main/java/app/passwordstore/util/git/sshj/SshKey.kt index 15753da9..bfdf5a51 100644 --- a/app/src/main/java/app/passwordstore/util/git/sshj/SshKey.kt +++ b/app/src/main/java/app/passwordstore/util/git/sshj/SshKey.kt @@ -120,7 +120,7 @@ object SshKey { context.sharedPrefs.edit { putString(PreferenceKeys.GIT_REMOTE_KEY_TYPE, value?.value) } private val isStrongBoxSupported by unsafeLazy { - if (Build.VERSION.SDK_INT >= 28) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) context.packageManager.hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE) else false } @@ -162,7 +162,7 @@ object SshKey { setKeySize(256) setAlgorithmParameterSpec(java.security.spec.ECGenParameterSpec("secp256r1")) setDigests(KeyProperties.DIGEST_SHA256) - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { setIsStrongBoxBacked(isStrongBoxSupported) } } @@ -285,7 +285,7 @@ object SshKey { apply(algorithm.applyToSpec) if (requireAuthentication) { setUserAuthenticationRequired(true) - if (Build.VERSION.SDK_INT >= 30) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { setUserAuthenticationParameters(30, KeyProperties.AUTH_DEVICE_CREDENTIAL) } else { @Suppress("DEPRECATION") setUserAuthenticationValidityDurationSeconds(30) diff --git a/app/src/main/java/app/passwordstore/util/services/ClipboardService.kt b/app/src/main/java/app/passwordstore/util/services/ClipboardService.kt index c56c319b..76128a50 100644 --- a/app/src/main/java/app/passwordstore/util/services/ClipboardService.kt +++ b/app/src/main/java/app/passwordstore/util/services/ClipboardService.kt @@ -120,12 +120,12 @@ class ClipboardService : Service() { val clearTimeMs = clearTime * 1000L val clearIntent = Intent(this, ClipboardService::class.java).apply { action = ACTION_CLEAR } val pendingIntent = - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { PendingIntent.getForegroundService( this, 0, clearIntent, - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE } else { PendingIntent.FLAG_UPDATE_CURRENT @@ -136,7 +136,7 @@ class ClipboardService : Service() { this, 0, clearIntent, - if (Build.VERSION.SDK_INT >= 31) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE } else { PendingIntent.FLAG_UPDATE_CURRENT @@ -144,7 +144,7 @@ class ClipboardService : Service() { ) } val notification = - if (Build.VERSION.SDK_INT <= 23) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) { createNotificationApi23(pendingIntent) } else { createNotificationApi24(pendingIntent, clearTimeMs) @@ -165,7 +165,7 @@ class ClipboardService : Service() { .build() } - @RequiresApi(24) + @RequiresApi(Build.VERSION_CODES.N) private fun createNotificationApi24( pendingIntent: PendingIntent, clearTimeMs: Long @@ -184,7 +184,7 @@ class ClipboardService : Service() { } private fun createNotificationChannel() { - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val serviceChannel = NotificationChannel( CHANNEL_ID, diff --git a/app/src/main/java/app/passwordstore/util/services/OreoAutofillService.kt b/app/src/main/java/app/passwordstore/util/services/OreoAutofillService.kt index 54cbb3b5..fca44be2 100644 --- a/app/src/main/java/app/passwordstore/util/services/OreoAutofillService.kt +++ b/app/src/main/java/app/passwordstore/util/services/OreoAutofillService.kt @@ -37,7 +37,7 @@ import javax.inject.Inject import logcat.LogPriority.ERROR import logcat.logcat -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @AndroidEntryPoint class OreoAutofillService : AutofillService() { @@ -78,7 +78,7 @@ class OreoAutofillService : AutofillService() { return } if (structure.activityComponent.packageName in DENYLISTED_PACKAGES) { - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { callback.onSuccess( FillResponse.Builder().run { disableAutofill(DISABLE_AUTOFILL_DURATION_MS) @@ -102,7 +102,7 @@ class OreoAutofillService : AutofillService() { callback.onSuccess(null) return } - if (Build.VERSION.SDK_INT >= 30) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { api30ResponseBuilderFactory .create(formToFill) .fillCredentials(this, request.inlineSuggestionsRequest, callback) diff --git a/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt b/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt index 4d587621..5bbeba50 100644 --- a/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt +++ b/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt @@ -66,7 +66,7 @@ class PasswordExportService : Service() { logcat { "Copying ${repositoryDirectory.path} to $targetDirectory" } val dateString = - if (Build.VERSION.SDK_INT >= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) } else { String.format("%tFT%= 26) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val serviceChannel = NotificationChannel( CHANNEL_ID, diff --git a/app/src/main/java/app/passwordstore/util/shortcuts/ShortcutHandler.kt b/app/src/main/java/app/passwordstore/util/shortcuts/ShortcutHandler.kt index 03d14b9c..6e58f446 100644 --- a/app/src/main/java/app/passwordstore/util/shortcuts/ShortcutHandler.kt +++ b/app/src/main/java/app/passwordstore/util/shortcuts/ShortcutHandler.kt @@ -42,7 +42,7 @@ constructor( * [MAX_SHORTCUT_COUNT] and older items are removed by a simple LRU sweep. */ fun addDynamicShortcut(item: PasswordItem, intent: Intent) { - if (Build.VERSION.SDK_INT < 25) return + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return val shortcutManager: ShortcutManager = context.getSystemService() ?: return val shortcut = buildShortcut(item, intent) val shortcuts = shortcutManager.dynamicShortcuts @@ -67,7 +67,7 @@ constructor( * a no-op if the user's default launcher does not support pinned shortcuts. */ fun addPinnedShortcut(item: PasswordItem, intent: Intent) { - if (Build.VERSION.SDK_INT < 26) return + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return val shortcutManager: ShortcutManager = context.getSystemService() ?: return if (!shortcutManager.isRequestPinShortcutSupported) { logcat { "addPinnedShortcut: pin shortcuts unsupported" } @@ -78,7 +78,7 @@ constructor( } /** Creates a [ShortcutInfo] from [item] and assigns [intent] to it. */ - @RequiresApi(25) + @RequiresApi(Build.VERSION_CODES.N_MR1) private fun buildShortcut(item: PasswordItem, intent: Intent): ShortcutInfo { return ShortcutInfo.Builder(context, item.fullPathToParent) .setShortLabel(item.toString()) @@ -93,7 +93,7 @@ constructor( * data, which ensures that the get/set dance in [addDynamicShortcut] does not cause invalidation * of icon assets, resulting in invisible icons in all but the newest launcher shortcut. */ - @RequiresApi(25) + @RequiresApi(Build.VERSION_CODES.N_MR1) private fun rebuildShortcut(shortcut: ShortcutInfo): ShortcutInfo { // Non-null assertions are fine since we know these values aren't null. return ShortcutInfo.Builder(context, shortcut.id) diff --git a/app/src/nonFree/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt b/app/src/nonFree/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt index 884d621a..bcd467ee 100644 --- a/app/src/nonFree/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt +++ b/app/src/nonFree/java/app/passwordstore/autofill/oreo/ui/AutofillSmsActivity.kt @@ -52,7 +52,7 @@ suspend fun Task.suspendableAwait() = } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) class AutofillSmsActivity : AppCompatActivity() { companion object { 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 952bc3f0..fc1fcca3 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 @@ -69,7 +69,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(26) +@RequiresApi(Build.VERSION_CODES.O) private class AutofillFormParser( context: Context, structure: AssistStructure, @@ -200,7 +200,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(26) +@RequiresApi(Build.VERSION_CODES.O) 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 7e5a3d33..0b4f491d 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 @@ -52,7 +52,7 @@ public fun computeCertificatesHash(context: Context, appPackage: String): String val signaturesOld = context.packageManager.getPackageInfo(appPackage, PackageManager.GET_SIGNATURES).signatures val stableHashOld = stableHash(signaturesOld.map { it.toByteArray() }) - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { val info = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { context.packageManager.getPackageInfo( @@ -79,14 +79,15 @@ public fun computeCertificatesHash(context: Context, appPackage: String): String * its `webDomain` and `webScheme`, if available. */ internal val AssistStructure.ViewNode.webOrigin: String? - @RequiresApi(26) + @RequiresApi(Build.VERSION_CODES.O) get() = webDomain?.let { domain -> - val scheme = (if (Build.VERSION.SDK_INT >= 28) webScheme else null) ?: "https" + val scheme = + (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) webScheme else null) ?: "https" "$scheme://$domain" } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) public class FixedSaveCallback(context: Context, private val callback: SaveCallback) { private val applicationContext = context.applicationContext @@ -102,7 +103,7 @@ public class FixedSaveCallback(context: Context, private val callback: SaveCallb } public fun onSuccess(intentSender: IntentSender) { - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { callback.onSuccess(intentSender) } else { callback.onSuccess() @@ -129,7 +130,7 @@ private fun visitViewNode( } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) 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 d2a95b40..4f14907c 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 @@ -30,7 +30,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(26) +@RequiresApi(Build.VERSION_CODES.O) public sealed class AutofillScenario { public companion object { @@ -185,7 +185,7 @@ public sealed class AutofillScenario { get() = username != null } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal data class ClassifiedAutofillScenario( override val username: T?, override val fillUsername: Boolean, @@ -206,7 +206,7 @@ internal data class ClassifiedAutofillScenario( get() = newPassword.ifEmpty { currentPassword } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal data class GenericAutofillScenario( override val username: T?, override val fillUsername: Boolean, @@ -226,7 +226,7 @@ internal data class GenericAutofillScenario( get() = genericPassword } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal fun AutofillScenario.passesOriginCheck(singleOriginMode: Boolean): Boolean { return if (singleOriginMode) { // In single origin mode, only the browsers URL bar (which is never filled) should have @@ -239,7 +239,7 @@ internal fun AutofillScenario.passesOriginCheck(singleOriginMode: Boo } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @JvmName("fillWithAutofillId") public fun Dataset.Builder.fillWith( scenario: AutofillScenario, @@ -262,7 +262,7 @@ public fun Dataset.Builder.fillWith( } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal inline fun AutofillScenario.map( transform: (T) -> S ): AutofillScenario { @@ -282,7 +282,7 @@ internal inline fun AutofillScenario.map( return builder.build() } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) @JvmName("toBundleAutofillId") internal fun AutofillScenario.toBundle(): Bundle = when (this) { @@ -311,7 +311,7 @@ internal fun AutofillScenario.toBundle(): Bundle = } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) public fun AutofillScenario.recoverNodes( structure: AssistStructure ): AutofillScenario? { @@ -319,13 +319,13 @@ public fun AutofillScenario.recoverNodes( } public val AutofillScenario.usernameValue: String? - @RequiresApi(26) + @RequiresApi(Build.VERSION_CODES.O) get() { val value = username?.autofillValue ?: return null return if (value.isText) value.textValue.toString() else null } public val AutofillScenario.passwordValue: String? - @RequiresApi(26) + @RequiresApi(Build.VERSION_CODES.O) 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 93355a94..7303efc5 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,6 +4,7 @@ */ 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 @@ -21,7 +22,7 @@ private inline fun Pair.none(predicate: T.() -> Boolean) = * The strategy used to detect [AutofillScenario] s; expressed using the DSL implemented in * [AutofillDsl]. */ -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) 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 8295a7f4..35006468 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,13 +4,14 @@ */ 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(26) +@RequiresApi(Build.VERSION_CODES.O) internal interface FieldMatcher { fun match(fields: List, alreadyMatched: List): List? @@ -71,7 +72,7 @@ internal interface FieldMatcher { } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal class SingleFieldMatcher( private val take: (FormField, List) -> Boolean, private val tieBreakers: List<(FormField, List) -> Boolean> @@ -135,7 +136,7 @@ internal class SingleFieldMatcher( } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) private class PairOfFieldsMatcher( private val take: (Pair, List) -> Boolean, private val tieBreakers: List<(Pair, List) -> Boolean> @@ -173,7 +174,7 @@ private class PairOfFieldsMatcher( } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal class AutofillRule private constructor( private val matchers: List, @@ -381,7 +382,7 @@ private constructor( } } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal class AutofillStrategy private constructor(private val rules: List) { @AutofillDsl @@ -434,6 +435,6 @@ internal class AutofillStrategy private constructor(private val rules: List 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 7c4d0c2e..a4d9752f 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 @@ -143,7 +143,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(26) +@RequiresApi(Build.VERSION_CODES.O) private val BROWSER_SAVE_FLAG = mapOf( "com.duckduckgo.mobile.android" to 0, @@ -157,7 +157,7 @@ private val BROWSER_SAVE_FLAG = "com.opera.touch" to 0, ) -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) private val BROWSER_SAVE_FLAG_IF_NO_ACCESSIBILITY = mapOf( "com.android.chrome" to SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE, @@ -177,7 +177,7 @@ private fun isNoAccessibilityServiceEnabled(context: Context): Boolean { .isNullOrEmpty() } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) private fun getBrowserSaveFlag(context: Context, appPackage: String): Int? = BROWSER_SAVE_FLAG[appPackage] ?: BROWSER_SAVE_FLAG_IF_NO_ACCESSIBILITY[appPackage]?.takeIf { @@ -189,7 +189,7 @@ internal data class BrowserAutofillSupportInfo( val saveFlags: Int? ) -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal fun getBrowserAutofillSupportInfoIfTrusted( context: Context, appPackage: String @@ -215,7 +215,7 @@ public enum class BrowserAutofillSupportLevel { GeneralFillAndSave, } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) private fun getBrowserAutofillSupportLevel( context: Context, appPackage: String @@ -237,12 +237,13 @@ private fun getBrowserAutofillSupportLevel( // 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 < 28 + supportLevel != BrowserAutofillSupportLevel.GeneralFillAndSave && + Build.VERSION.SDK_INT < Build.VERSION_CODES.P } ?: BrowserAutofillSupportLevel.None } -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) public fun getInstalledBrowsersWithAutofillSupportLevel( context: Context ): List> { 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 36734064..96813be5 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,6 +5,7 @@ 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 @@ -23,7 +24,7 @@ internal enum class CertaintyLevel { * Represents a single potentially fillable or saveable field together with all meta data extracted * from its [AssistStructure.ViewNode]. */ -@RequiresApi(26) +@RequiresApi(Build.VERSION_CODES.O) internal class FormField( node: AssistStructure.ViewNode, private val index: Int, @@ -113,7 +114,8 @@ internal class FormField( .toSet() .toList() - @RequiresApi(26) private fun isSupportedHint(hint: String?) = hint in HINTS_FILLABLE + @RequiresApi(Build.VERSION_CODES.O) + private fun isSupportedHint(hint: String?) = hint in HINTS_FILLABLE private val EXCLUDED_TERMS = listOf( "url_bar", // Chrome/Edge/Firefox address bar 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 2a35e8c7..706aa6c5 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 @@ -53,7 +53,7 @@ internal fun getPublicSuffixPlusOne( } private fun isNumericAddress(domain: String): Boolean { - return if (Build.VERSION.SDK_INT >= 29) { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { InetAddresses.isNumericAddress(domain) } else { @Suppress("DEPRECATION") Patterns.IP_ADDRESS.matcher(domain).matches() diff --git a/coroutine-utils/src/main/kotlin/app/passwordstore/util/coroutines/RunSuspendCatching.kt b/coroutine-utils/src/main/kotlin/app/passwordstore/util/coroutines/RunSuspendCatching.kt index c650c14b..677c2bc3 100644 --- a/coroutine-utils/src/main/kotlin/app/passwordstore/util/coroutines/RunSuspendCatching.kt +++ b/coroutine-utils/src/main/kotlin/app/passwordstore/util/coroutines/RunSuspendCatching.kt @@ -22,8 +22,9 @@ public suspend inline fun runSuspendCatching(block: () -> V): Result T.runSuspendCatching( return try { Ok(block()) + } catch (e: CancellationException) { + throw e } catch (e: Throwable) { - if (e is CancellationException) throw e Err(e) } } diff --git a/detekt-baselines/app.xml b/detekt-baselines/app.xml index be37b720..a82c325e 100644 --- a/detekt-baselines/app.xml +++ b/detekt-baselines/app.xml @@ -35,59 +35,28 @@ LongMethod:RepositorySettings.kt$RepositorySettings$override fun provideSettings(builder: PreferenceScreen.Builder) LoopWithTooManyJumpStatements:AutofillMatcher.kt$AutofillMatcher.Companion$for ((key, value) in prefs.all) { if (!key.startsWith(PREFERENCE_PREFIX_MATCHES)) continue // We know that preferences starting with `PREFERENCE_PREFIX_MATCHES` were // created with `putStringSet`. @Suppress("UNCHECKED_CAST") val oldMatches = value as? Set<String> if (oldMatches == null) { logcat(WARN) { "Failed to read matches for $key" } continue } // Delete all matches for file locations that are going to be overwritten, then // transfer matches over to the files at their new locations. val newMatches = oldMatches .asSequence() .minus(deletePathList) .minus(oldNewPathMap.values) .map { match -> val newPath = oldNewPathMap[match] ?: return@map match logcat { "Updating match for $key: $match --> $newPath" } newPath } .toSet() if (newMatches != oldMatches) prefs.edit { putStringSet(key, newMatches) } } LoopWithTooManyJumpStatements:ErrorMessages.kt$ErrorMessages$while (cause.cause != null) { if (cause is GitException) break val nextCause = cause.cause!! if (nextCause is RemoteException) break cause = nextCause } - MagicNumber:Api30AutofillResponseBuilder.kt$Api30AutofillResponseBuilder$30 - MagicNumber:AutofillDecryptActivity.kt$AutofillDecryptActivity$26 - MagicNumber:AutofillDecryptActivity.kt$AutofillDecryptActivity.Companion$31 - MagicNumber:AutofillFilterView.kt$AutofillFilterView$26 - MagicNumber:AutofillFilterView.kt$AutofillFilterView.Companion$31 - MagicNumber:AutofillPreferences.kt$DirectoryStructure$26 - MagicNumber:AutofillPublisherChangedActivity.kt$AutofillPublisherChangedActivity$26 - MagicNumber:AutofillPublisherChangedActivity.kt$AutofillPublisherChangedActivity.Companion$31 - MagicNumber:AutofillResponseBuilder.kt$AutofillResponseBuilder$26 - MagicNumber:AutofillResponseBuilder.kt$AutofillResponseBuilder$28 - MagicNumber:AutofillResponseBuilder.kt$AutofillResponseBuilder.Companion$28 - MagicNumber:AutofillSaveActivity.kt$AutofillSaveActivity$26 - MagicNumber:AutofillSettings.kt$AutofillSettings$26 - MagicNumber:AutofillViewUtils.kt$30 - MagicNumber:AutofillViewUtils.kt$31 - MagicNumber:BasePgpActivity.kt$BasePgpActivity$26 MagicNumber:BasePgpActivity.kt$BasePgpActivity$45 MagicNumber:ClipboardService.kt$ClipboardService$1000 MagicNumber:ClipboardService.kt$ClipboardService$1000L - MagicNumber:ClipboardService.kt$ClipboardService$23 - MagicNumber:ClipboardService.kt$ClipboardService$24 - MagicNumber:ClipboardService.kt$ClipboardService$26 - MagicNumber:ClipboardService.kt$ClipboardService$31 MagicNumber:ClipboardService.kt$ClipboardService$45 MagicNumber:ClipboardService.kt$ClipboardService$500 MagicNumber:DicewareModule.kt$DicewareModule$6 MagicNumber:DicewarePasswordGeneratorDialogFragment.kt$DicewarePasswordGeneratorDialogFragment$5 MagicNumber:Extensions.kt$1000 - MagicNumber:GeneralSettings.kt$GeneralSettings$25 MagicNumber:GitConfigActivity.kt$GitConfigActivity$0.5f MagicNumber:GitConfigActivity.kt$GitConfigActivity$500 MagicNumber:GitConfigActivity.kt$GitConfigActivity$8 MagicNumber:GitLogAdapter.kt$8 MagicNumber:GitServerConfigActivity.kt$GitServerConfigActivity$500 MagicNumber:LaunchActivity.kt$LaunchActivity$500L - MagicNumber:OreoAutofillService.kt$OreoAutofillService$26 - MagicNumber:OreoAutofillService.kt$OreoAutofillService$28 - MagicNumber:OreoAutofillService.kt$OreoAutofillService$30 - MagicNumber:PasswordCreationActivity.kt$PasswordCreationActivity$28 MagicNumber:PasswordExportService.kt$PasswordExportService$1024 - MagicNumber:PasswordExportService.kt$PasswordExportService$26 MagicNumber:PasswordGeneratorDialogFragment.kt$PasswordGeneratorDialogFragment$20 MagicNumber:PasswordItemRecyclerAdapter.kt$PasswordItemRecyclerAdapter.PasswordItemViewHolder$0.7f - MagicNumber:ProxySelectorActivity.kt$ProxySelectorActivity$29 MagicNumber:ProxySelectorActivity.kt$ProxySelectorActivity$500 - MagicNumber:RepositorySettings.kt$RepositorySettings$25 - MagicNumber:ShortcutHandler.kt$ShortcutHandler$25 - MagicNumber:ShortcutHandler.kt$ShortcutHandler$26 MagicNumber:SshKey.kt$SshKey$100_000 MagicNumber:SshKey.kt$SshKey$15 MagicNumber:SshKey.kt$SshKey$30 MagicNumber:SshKey.kt$SshKey.Algorithm.Ecdsa$256 - MagicNumber:SshKey.kt$SshKey.Algorithm.Ecdsa$28 MagicNumber:SshKey.kt$SshKey.Algorithm.Rsa$3072 MagicNumber:SshjSessionFactory.kt$SshjSession$22 MagicNumber:UriTotpFinder.kt$UriTotpFinder$30 @@ -124,9 +93,7 @@ ThrowsCount:GitCommandExecutor.kt$GitCommandExecutor$suspend fun execute(): Result<Unit, Throwable> ThrowsCount:SshKey.kt$SshKey$fun import(uri: Uri) TooManyFunctions:PasswordStore.kt$PasswordStore : BaseGitActivity - TooManyFunctions:SearchableRepositoryViewModel.kt$SearchableRepositoryViewModel : AndroidViewModel TooManyFunctions:SshjConfig.kt$AbstractLogger : Logger - TooManyFunctions:SshjConfig.kt$LogcatLoggerFactory$LogcatLogger : AbstractLogger TopLevelPropertyNaming:AutofillMatcher.kt$private const val PREFERENCES_AUTOFILL_APP_MATCHES = "oreo_autofill_app_matches" TopLevelPropertyNaming:AutofillMatcher.kt$private const val PREFERENCES_AUTOFILL_WEB_MATCHES = "oreo_autofill_web_matches" TopLevelPropertyNaming:Extensions.kt$/** The default OpenPGP provider for the app */ const val OPENPGP_PROVIDER = "org.sufficientlysecure.keychain" @@ -134,8 +101,6 @@ TopLevelPropertyNaming:SshKey.kt$private const val ANDROIDX_SECURITY_KEYSET_PREF_NAME = "androidx_sshkey_keyset_prefs" TopLevelPropertyNaming:SshKey.kt$private const val KEYSTORE_ALIAS = "sshkey" TopLevelPropertyNaming:SshKey.kt$private const val PROVIDER_ANDROID_KEY_STORE = "AndroidKeyStore" - UnusedPrivateMember:PasswordStore.kt$PasswordStore$private val directorySelectAction = registerForActivityResult(StartActivityForResult()) { result -> if (result.resultCode == RESULT_OK) { checkLocalRepository() } } - UnusedPrivateMember:PasswordStore.kt$PasswordStore$private val storagePermissionRequest = registerForActivityResult(RequestPermission()) { granted -> if (granted) checkLocalRepository() } UseCheckOrError:CredentialFinder.kt$CredentialFinder$throw IllegalStateException("Only SshKey and Password connection mode ask for passwords") UseCheckOrError:FragmentViewBindingDelegate.kt$FragmentViewBindingDelegate$throw IllegalStateException( "Should not attempt to get bindings when Fragment views are destroyed." ) UseCheckOrError:GitOperation.kt$GitOperation$throw IllegalStateException("Biometric authentication failures should be ignored") diff --git a/detekt-baselines/autofill-parser.xml b/detekt-baselines/autofill-parser.xml index a7726c93..83f3316f 100644 --- a/detekt-baselines/autofill-parser.xml +++ b/detekt-baselines/autofill-parser.xml @@ -11,30 +11,9 @@ LoopWithTooManyJumpStatements:AutofillStrategyDsl.kt$PairOfFieldsMatcher$for ((i, tieBreaker) in tieBreakers.withIndex()) { val new = current.filter { tieBreaker(it, alreadyMatched) } if (new.isEmpty()) { logcat { "Tie breaker #${i + 1}: Didn't match any pair of fields; skipping" } continue } // and return if the available options have been narrowed to a single field. if (new.size == 1) { logcat { "Tie breaker #${i + 1}: Success" } current = new break } logcat { "Tie breaker #${i + 1}: Matched ${new.size} pairs of fields; continuing" } current = new } LoopWithTooManyJumpStatements:AutofillStrategyDsl.kt$SingleFieldMatcher$for ((i, tieBreaker) in tieBreakers.withIndex()) { // Successively filter matched fields via tie breakers... val new = current.filter { tieBreaker(it, alreadyMatched) } // skipping those tie breakers that are not satisfied for any remaining field... if (new.isEmpty()) { logcat { "Tie breaker #${i + 1}: Didn't match any field; skipping" } continue } // and return if the available options have been narrowed to a single field. if (new.size == 1) { logcat { "Tie breaker #${i + 1}: Success" } current = new break } logcat { "Tie breaker #${i + 1}: Matched ${new.size} fields; continuing" } current = new } LoopWithTooManyJumpStatements:ByteArray.kt$while (true) { val byte0 = if (expectDot) { expectDot = false '.'.code.toByte() } else { labels[currentLabelIndex][currentLabelByteIndex] and BITMASK } val byte1 = this[start + publicSuffixByteIndex] and BITMASK // Compare the bytes. Note that the file stores UTF-8 encoded bytes, so we must compare // the // unsigned bytes. compareResult = (byte0.toUByte() - byte1.toUByte()).toInt() if (compareResult != 0) { break } publicSuffixByteIndex++ currentLabelByteIndex++ if (publicSuffixByteIndex == publicSuffixLength) { break } if (labels[currentLabelIndex].size == currentLabelByteIndex) { // We've exhausted our current label. Either there are more labels to compare, in // which // case we expect a dot as the next character. Otherwise, we've checked all our // labels. if (currentLabelIndex == labels.size - 1) { break } else { currentLabelIndex++ currentLabelByteIndex = -1 expectDot = true } } } - MagicNumber:AutofillFormParser.kt$AutofillFormParser$26 - MagicNumber:AutofillFormParser.kt$FillableForm$26 - MagicNumber:AutofillHelper.kt$26 - MagicNumber:AutofillHelper.kt$28 - MagicNumber:AutofillHelper.kt$FixedSaveCallback$26 - MagicNumber:AutofillHelper.kt$FixedSaveCallback$28 MagicNumber:AutofillHelper.kt$FixedSaveCallback$29 - MagicNumber:AutofillScenario.kt$26 MagicNumber:AutofillScenario.kt$4 MagicNumber:AutofillScenario.kt$5 - MagicNumber:AutofillScenario.kt$AutofillScenario$26 - MagicNumber:AutofillScenario.kt$ClassifiedAutofillScenario$26 - MagicNumber:AutofillScenario.kt$GenericAutofillScenario$26 - MagicNumber:AutofillStrategyDsl.kt$26 - MagicNumber:AutofillStrategyDsl.kt$AutofillRule$26 - MagicNumber:AutofillStrategyDsl.kt$AutofillStrategy$26 - MagicNumber:AutofillStrategyDsl.kt$FieldMatcher$26 - MagicNumber:AutofillStrategyDsl.kt$PairOfFieldsMatcher$26 - MagicNumber:AutofillStrategyDsl.kt$SingleFieldMatcher$26 - MagicNumber:FeatureAndTrustDetection.kt$26 - MagicNumber:FeatureAndTrustDetection.kt$28 - MagicNumber:FormField.kt$FormField$26 - MagicNumber:FormField.kt$FormField.Companion$26 - MagicNumber:PublicSuffixListCache.kt$29 MaxLineLength:FeatureAndTrustDetection.kt$/* In order to add a new browser, do the following: 1. Obtain the .apk from a trusted source. For example, download it from the Play Store on your phone and use adb pull to get it onto your computer. We will assume that it is called browser.apk. 2. Run aapt dump badging browser.apk | grep package: | grep -Eo " name='[a-zA-Z0-9_\.]*" | cut -c8- to obtain the package name (actually, the application ID) of the app in the .apk. 3. Run apksigner verify --print-certs browser.apk | grep "#1 certificate SHA-256" | grep -Eo "[a-f0-9]{64}" | tr -d '\n' | xxd -r -p | base64 to calculate the hash of browser.apk's first signing certificate. Note: This will only work if the apk has a single signing certificate. Apps with multiple signers are very rare, so there is probably no need to add them. Refer to computeCertificatesHash to learn how the hash would be computed in this case. 4. Verify the package name and the hash, for example by asking other people to repeat the steps above. 5. Add an entry with the browser apps's package name and the hash to TRUSTED_BROWSER_CERTIFICATE_HASH. 6. Optionally, try adding the browser's package name to BROWSERS_WITH_SAVE_SUPPORT and check whether a save request to Password Store is triggered when you submit a registration form. 7. Optionally, try adding the browser's package name to BROWSERS_WITH_MULTI_ORIGIN_SUPPORT and check whether it correctly distinguishes web origins even if iframes are present on the page. You can use https://fabianhenneke.github.io/Android-Password-Store/ as a test form. */ MaxLineLength:FormField.kt$FormField$"\"$hint\", \"$fieldId\"${if (isFocused) ", focused" else ""}${if (isVisible) ", visible" else ""}, $webOrigin, $htmlAttributesDebug, $autofillHints" ReturnCount:AutofillFormParser.kt$AutofillFormParser$private fun determineFormOrigin(context: Context): FormOrigin? diff --git a/detekt-baselines/coroutine-utils.xml b/detekt-baselines/coroutine-utils.xml index 1d920d34..6d7bc820 100644 --- a/detekt-baselines/coroutine-utils.xml +++ b/detekt-baselines/coroutine-utils.xml @@ -1,8 +1,9 @@ - + + TooGenericExceptionCaught:RunSuspendCatching.kt$e: Throwable + - InstanceOfCheckForException:RunSuspendCatching.kt$e is CancellationException TooGenericExceptionCaught:RunSuspendCatching.kt$e: Throwable