From a2a54921f37409c4603b0233ca006a3e307d3297 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 13 Sep 2024 11:34:28 +0200 Subject: [PATCH] Android 15 strict mode update for unsafe intents (#1582) * Android 15 strict mode update for unsafe intents * Use AndroidApiVersion API * Update AndroidApiVersion API with new versions Rename T to Tiramisu * Ktlint warning fix --------- Co-authored-by: Honza --- .../zcash/crash/android/internal/local/Components.kt | 4 ++-- .../zcash/spackle/process/VersionCodeCompatTest.kt | 2 +- .../co/electriccoin/zcash/spackle/AndroidApiVersion.kt | 8 +++++++- .../co/electriccoin/zcash/spackle/ClipboardManagerUtil.kt | 4 ++-- .../co/electriccoin/zcash/spackle/PackageManagerCompat.kt | 4 ++-- .../co/electriccoin/zcash/spackle/StrictModeCompat.kt | 3 +++ .../spackle/process/AbstractProcessNameContentProvider.kt | 2 +- .../zcash/spackle/process/ProcessNameCompat.kt | 2 +- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crash-android-lib/src/androidTest/kotlin/co/electriccoin/zcash/crash/android/internal/local/Components.kt b/crash-android-lib/src/androidTest/kotlin/co/electriccoin/zcash/crash/android/internal/local/Components.kt index 74c13221..fcb6378d 100644 --- a/crash-android-lib/src/androidTest/kotlin/co/electriccoin/zcash/crash/android/internal/local/Components.kt +++ b/crash-android-lib/src/androidTest/kotlin/co/electriccoin/zcash/crash/android/internal/local/Components.kt @@ -26,7 +26,7 @@ class Components { } private fun PackageManager.getProviderInfoCompat(componentName: ComponentName) = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { getProviderInfo(componentName, PackageManager.ComponentInfoFlags.of(0)) } else { @Suppress("Deprecation") @@ -34,7 +34,7 @@ private fun PackageManager.getProviderInfoCompat(componentName: ComponentName) = } private fun PackageManager.getReceiverInfoCompat(componentName: ComponentName) = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { getReceiverInfo(componentName, PackageManager.ComponentInfoFlags.of(0)) } else { @Suppress("Deprecation") diff --git a/spackle-android-lib/src/androidTest/java/co/electriccoin/zcash/spackle/process/VersionCodeCompatTest.kt b/spackle-android-lib/src/androidTest/java/co/electriccoin/zcash/spackle/process/VersionCodeCompatTest.kt index 3a2f8a96..710daffa 100644 --- a/spackle-android-lib/src/androidTest/java/co/electriccoin/zcash/spackle/process/VersionCodeCompatTest.kt +++ b/spackle-android-lib/src/androidTest/java/co/electriccoin/zcash/spackle/process/VersionCodeCompatTest.kt @@ -17,7 +17,7 @@ class VersionCodeCompatTest { PackageInfo().apply { @Suppress("Deprecation") versionCode = expectedVersionCode.toInt() - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { longVersionCode = expectedVersionCode } } diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/AndroidApiVersion.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/AndroidApiVersion.kt index 681eb24d..41761047 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/AndroidApiVersion.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/AndroidApiVersion.kt @@ -46,7 +46,13 @@ object AndroidApiVersion { val isAtLeastS = isAtLeast(Build.VERSION_CODES.S) @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU) - val isAtLeastT = isAtLeast(Build.VERSION_CODES.TIRAMISU) + val isAtLeastTiramisu = isAtLeast(Build.VERSION_CODES.TIRAMISU) + + @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + val isAtLeastUpsideDownCake = isAtLeast(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + + @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.VANILLA_ICE_CREAM) + val isAtLeastVanillaIceCream = isAtLeast(Build.VERSION_CODES.VANILLA_ICE_CREAM) val isPreview = 0 != Build.VERSION.PREVIEW_SDK_INT } diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/ClipboardManagerUtil.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/ClipboardManagerUtil.kt index 767cad5b..945508a2 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/ClipboardManagerUtil.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/ClipboardManagerUtil.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking object ClipboardManagerUtil { private val extraIsSensitive: String get() = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { ClipDescription.EXTRA_IS_SENSITIVE } else { "android.content.extra.IS_SENSITIVE" @@ -32,7 +32,7 @@ object ClipboardManagerUtil { putBoolean(extraIsSensitive, true) } } - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { // API 33 and later implement their system Toast UI. clipboardManager.setPrimaryClip(data) } else { diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/PackageManagerCompat.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/PackageManagerCompat.kt index e6097249..30bac722 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/PackageManagerCompat.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/PackageManagerCompat.kt @@ -11,7 +11,7 @@ fun PackageManager.getPackageInfoCompat( packageName: String, flags: Long ): PackageInfo = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { getPackageInfoTPlus(packageName, flags) } else { getPackageInfoLegacy(packageName, flags) @@ -21,7 +21,7 @@ suspend fun PackageManager.getPackageInfoCompatSuspend( packageName: String, flags: Long ): PackageInfo = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { withContext(Dispatchers.IO) { getPackageInfoTPlus(packageName, flags) } } else { withContext(Dispatchers.IO) { getPackageInfoLegacy(packageName, flags) } diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/StrictModeCompat.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/StrictModeCompat.kt index 9d29b453..f4c1126e 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/StrictModeCompat.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/StrictModeCompat.kt @@ -26,6 +26,9 @@ object StrictModeCompat { // Don't enable missing network tags, because those are noisy. StrictMode.setVmPolicy( StrictMode.VmPolicy.Builder().apply { + if (AndroidApiVersion.isAtLeastS) { + detectUnsafeIntentLaunch() + } detectActivityLeaks() detectCleartextNetwork() detectContentUriWithoutPermission() diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/AbstractProcessNameContentProvider.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/AbstractProcessNameContentProvider.kt index 04ef4784..52f0e680 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/AbstractProcessNameContentProvider.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/AbstractProcessNameContentProvider.kt @@ -27,7 +27,7 @@ open class AbstractProcessNameContentProvider : ContentProvider() { super.attachInfo(context, info) val processName: String = - if (AndroidApiVersion.isAtLeastT) { + if (AndroidApiVersion.isAtLeastTiramisu) { getProcessNameTPlus() } else if (AndroidApiVersion.isAtLeastP) { getProcessNamePPlus() diff --git a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/ProcessNameCompat.kt b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/ProcessNameCompat.kt index f7cfb15d..27df8a9d 100644 --- a/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/ProcessNameCompat.kt +++ b/spackle-android-lib/src/main/kotlin/co/electriccoin/zcash/spackle/process/ProcessNameCompat.kt @@ -55,7 +55,7 @@ object ProcessNameCompat { * due to some race conditions in Android. */ private fun searchForProcessName(context: Context): String? { - return if (AndroidApiVersion.isAtLeastT) { + return if (AndroidApiVersion.isAtLeastTiramisu) { getProcessNameTPlus() } else if (AndroidApiVersion.isAtLeastP) { getProcessNamePPlus()