catch android.os.DeadSystemException

This commit is contained in:
Milos Kozak 2023-05-09 11:56:39 +02:00
parent 62cea47d57
commit 7d307b267c

View file

@ -16,8 +16,12 @@ fun PackageManager.safeGetInstalledPackages(flags: Int): List<PackageInfo> =
* Safe version of queryBroadcastReceivers depending on Android version running * Safe version of queryBroadcastReceivers depending on Android version running
*/ */
fun PackageManager.safeQueryBroadcastReceivers(intent: Intent, flags: Int): List<ResolveInfo> = fun PackageManager.safeQueryBroadcastReceivers(intent: Intent, flags: Int): List<ResolveInfo> =
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(flags.toLong())) try {
else @Suppress("DEPRECATION") queryBroadcastReceivers(intent, flags) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) queryBroadcastReceivers(intent, PackageManager.ResolveInfoFlags.of(flags.toLong()))
else @Suppress("DEPRECATION") queryBroadcastReceivers(intent, flags)
} catch (ignored: Exception) {
emptyList()
}
/** /**
* Safe version of getPackageInfo depending on Android version running * Safe version of getPackageInfo depending on Android version running