Catch security exception

This commit is contained in:
MM20 2023-08-27 12:29:12 +02:00
parent ac29dd512c
commit b65ef71c3c
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 11 additions and 4 deletions

View File

@ -47,5 +47,6 @@ dependencies {
implementation(project(":core:permissions")) implementation(project(":core:permissions"))
implementation(project(":core:base")) implementation(project(":core:base"))
implementation(project(":core:ktx")) implementation(project(":core:ktx"))
implementation(project(":core:crashreporter"))
} }

View File

@ -12,6 +12,7 @@ import android.os.Process
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import de.mm20.launcher2.appshortcuts.R import de.mm20.launcher2.appshortcuts.R
import de.mm20.launcher2.crashreporter.CrashReporter
import de.mm20.launcher2.icons.* import de.mm20.launcher2.icons.*
import de.mm20.launcher2.ktx.getSerialNumber import de.mm20.launcher2.ktx.getSerialNumber
import de.mm20.launcher2.ktx.isAtLeastApiLevel import de.mm20.launcher2.ktx.isAtLeastApiLevel
@ -93,10 +94,15 @@ data class LauncherShortcut(
): LauncherIcon? { ): LauncherIcon? {
val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps val launcherApps = context.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
val icon = withContext(Dispatchers.IO) { val icon = withContext(Dispatchers.IO) {
launcherApps.getShortcutIconDrawable( try {
launcherShortcut, launcherApps.getShortcutIconDrawable(
context.resources.displayMetrics.densityDpi launcherShortcut,
) context.resources.displayMetrics.densityDpi
)
} catch (e: SecurityException) {
CrashReporter.logException(e)
null
}
} ?: return null } ?: return null
if (icon is AdaptiveIconDrawable) { if (icon is AdaptiveIconDrawable) {
if (themed && isAtLeastApiLevel(33) && icon.monochrome != null) { if (themed && isAtLeastApiLevel(33) && icon.monochrome != null) {