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 <rychnovsky.honza@gmail.com>
This commit is contained in:
parent
b8ae29a17f
commit
a2a54921f3
|
@ -26,7 +26,7 @@ class Components {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PackageManager.getProviderInfoCompat(componentName: ComponentName) =
|
private fun PackageManager.getProviderInfoCompat(componentName: ComponentName) =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
getProviderInfo(componentName, PackageManager.ComponentInfoFlags.of(0))
|
getProviderInfo(componentName, PackageManager.ComponentInfoFlags.of(0))
|
||||||
} else {
|
} else {
|
||||||
@Suppress("Deprecation")
|
@Suppress("Deprecation")
|
||||||
|
@ -34,7 +34,7 @@ private fun PackageManager.getProviderInfoCompat(componentName: ComponentName) =
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun PackageManager.getReceiverInfoCompat(componentName: ComponentName) =
|
private fun PackageManager.getReceiverInfoCompat(componentName: ComponentName) =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
getReceiverInfo(componentName, PackageManager.ComponentInfoFlags.of(0))
|
getReceiverInfo(componentName, PackageManager.ComponentInfoFlags.of(0))
|
||||||
} else {
|
} else {
|
||||||
@Suppress("Deprecation")
|
@Suppress("Deprecation")
|
||||||
|
|
|
@ -17,7 +17,7 @@ class VersionCodeCompatTest {
|
||||||
PackageInfo().apply {
|
PackageInfo().apply {
|
||||||
@Suppress("Deprecation")
|
@Suppress("Deprecation")
|
||||||
versionCode = expectedVersionCode.toInt()
|
versionCode = expectedVersionCode.toInt()
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
longVersionCode = expectedVersionCode
|
longVersionCode = expectedVersionCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,13 @@ object AndroidApiVersion {
|
||||||
val isAtLeastS = isAtLeast(Build.VERSION_CODES.S)
|
val isAtLeastS = isAtLeast(Build.VERSION_CODES.S)
|
||||||
|
|
||||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
|
@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
|
val isPreview = 0 != Build.VERSION.PREVIEW_SDK_INT
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import kotlinx.coroutines.runBlocking
|
||||||
object ClipboardManagerUtil {
|
object ClipboardManagerUtil {
|
||||||
private val extraIsSensitive: String
|
private val extraIsSensitive: String
|
||||||
get() =
|
get() =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
ClipDescription.EXTRA_IS_SENSITIVE
|
ClipDescription.EXTRA_IS_SENSITIVE
|
||||||
} else {
|
} else {
|
||||||
"android.content.extra.IS_SENSITIVE"
|
"android.content.extra.IS_SENSITIVE"
|
||||||
|
@ -32,7 +32,7 @@ object ClipboardManagerUtil {
|
||||||
putBoolean(extraIsSensitive, true)
|
putBoolean(extraIsSensitive, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
// API 33 and later implement their system Toast UI.
|
// API 33 and later implement their system Toast UI.
|
||||||
clipboardManager.setPrimaryClip(data)
|
clipboardManager.setPrimaryClip(data)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,7 +11,7 @@ fun PackageManager.getPackageInfoCompat(
|
||||||
packageName: String,
|
packageName: String,
|
||||||
flags: Long
|
flags: Long
|
||||||
): PackageInfo =
|
): PackageInfo =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
getPackageInfoTPlus(packageName, flags)
|
getPackageInfoTPlus(packageName, flags)
|
||||||
} else {
|
} else {
|
||||||
getPackageInfoLegacy(packageName, flags)
|
getPackageInfoLegacy(packageName, flags)
|
||||||
|
@ -21,7 +21,7 @@ suspend fun PackageManager.getPackageInfoCompatSuspend(
|
||||||
packageName: String,
|
packageName: String,
|
||||||
flags: Long
|
flags: Long
|
||||||
): PackageInfo =
|
): PackageInfo =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
withContext(Dispatchers.IO) { getPackageInfoTPlus(packageName, flags) }
|
withContext(Dispatchers.IO) { getPackageInfoTPlus(packageName, flags) }
|
||||||
} else {
|
} else {
|
||||||
withContext(Dispatchers.IO) { getPackageInfoLegacy(packageName, flags) }
|
withContext(Dispatchers.IO) { getPackageInfoLegacy(packageName, flags) }
|
||||||
|
|
|
@ -26,6 +26,9 @@ object StrictModeCompat {
|
||||||
// Don't enable missing network tags, because those are noisy.
|
// Don't enable missing network tags, because those are noisy.
|
||||||
StrictMode.setVmPolicy(
|
StrictMode.setVmPolicy(
|
||||||
StrictMode.VmPolicy.Builder().apply {
|
StrictMode.VmPolicy.Builder().apply {
|
||||||
|
if (AndroidApiVersion.isAtLeastS) {
|
||||||
|
detectUnsafeIntentLaunch()
|
||||||
|
}
|
||||||
detectActivityLeaks()
|
detectActivityLeaks()
|
||||||
detectCleartextNetwork()
|
detectCleartextNetwork()
|
||||||
detectContentUriWithoutPermission()
|
detectContentUriWithoutPermission()
|
||||||
|
|
|
@ -27,7 +27,7 @@ open class AbstractProcessNameContentProvider : ContentProvider() {
|
||||||
super.attachInfo(context, info)
|
super.attachInfo(context, info)
|
||||||
|
|
||||||
val processName: String =
|
val processName: String =
|
||||||
if (AndroidApiVersion.isAtLeastT) {
|
if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
getProcessNameTPlus()
|
getProcessNameTPlus()
|
||||||
} else if (AndroidApiVersion.isAtLeastP) {
|
} else if (AndroidApiVersion.isAtLeastP) {
|
||||||
getProcessNamePPlus()
|
getProcessNamePPlus()
|
||||||
|
|
|
@ -55,7 +55,7 @@ object ProcessNameCompat {
|
||||||
* due to some race conditions in Android.
|
* due to some race conditions in Android.
|
||||||
*/
|
*/
|
||||||
private fun searchForProcessName(context: Context): String? {
|
private fun searchForProcessName(context: Context): String? {
|
||||||
return if (AndroidApiVersion.isAtLeastT) {
|
return if (AndroidApiVersion.isAtLeastTiramisu) {
|
||||||
getProcessNameTPlus()
|
getProcessNameTPlus()
|
||||||
} else if (AndroidApiVersion.isAtLeastP) {
|
} else if (AndroidApiVersion.isAtLeastP) {
|
||||||
getProcessNamePPlus()
|
getProcessNamePPlus()
|
||||||
|
|
Loading…
Reference in New Issue