Fix SecurityException

Fix #301
This commit is contained in:
MM20 2023-08-26 22:28:16 +02:00
parent 8ace6562cb
commit 28384972d5
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 16 additions and 4 deletions

View File

@ -113,7 +113,11 @@ internal class AppRepositoryImpl(
}, Handler(Looper.getMainLooper()))
val apps = profiles.map { p ->
launcherApps.getActivityList(null, p).mapNotNull { getApplication(it, p) }
try {
launcherApps.getActivityList(null, p).mapNotNull { getApplication(it, p) }
} catch (e: SecurityException) {
emptyList()
}
}.flatten()
installedApps.value = apps
}
@ -127,7 +131,11 @@ internal class AppRepositoryImpl(
if (packageName == context.packageName) return emptyList()
return profiles.map { p ->
launcherApps.getActivityList(packageName, p).mapNotNull { getApplication(it, p) }
try {
launcherApps.getActivityList(packageName, p).mapNotNull { getApplication(it, p) }
} catch (e: SecurityException) {
emptyList()
}
}.flatten()
}

View File

@ -36,8 +36,12 @@ class LauncherAppDeserializer(val context: Context) : SearchableDeserializer {
val intent = Intent().also {
it.component = ComponentName(pkg, json.getString("activity"))
}
val launcherActivityInfo = launcherApps.resolveActivity(intent, user) ?: return null
return LauncherApp(context, launcherActivityInfo)
try {
val launcherActivityInfo = launcherApps.resolveActivity(intent, user) ?: return null
return LauncherApp(context, launcherActivityInfo)
} catch (e: SecurityException) {
return null
}
}
}