mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-11 23:04:32 +02:00
handle exception when acessing shortcuts
This commit is contained in:
parent
bf45b6602e
commit
c9ee2c6304
2 changed files with 15 additions and 10 deletions
|
@ -100,7 +100,7 @@ fun removeUnusedShortcuts(context: Context) {
|
||||||
},
|
},
|
||||||
profile
|
profile
|
||||||
)
|
)
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: Exception) {
|
||||||
// https://github.com/jrpie/launcher/issues/116
|
// https://github.com/jrpie/launcher/issues/116
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,15 +28,20 @@ class PinnedShortcutInfo(
|
||||||
fun getShortcutInfo(context: Context): ShortcutInfo? {
|
fun getShortcutInfo(context: Context): ShortcutInfo? {
|
||||||
val launcherApps = context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
|
val launcherApps = context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
|
|
||||||
return launcherApps.getShortcuts(
|
return try {
|
||||||
ShortcutQuery().apply {
|
launcherApps.getShortcuts(
|
||||||
setQueryFlags(ShortcutQuery.FLAG_MATCH_PINNED)
|
ShortcutQuery().apply {
|
||||||
setPackage(packageName)
|
setQueryFlags(ShortcutQuery.FLAG_MATCH_PINNED)
|
||||||
setActivity(ComponentName(packageName, activityName))
|
setPackage(packageName)
|
||||||
setShortcutIds(listOf(id))
|
setActivity(ComponentName(packageName, activityName))
|
||||||
},
|
setShortcutIds(listOf(id))
|
||||||
getUserFromId(user, context)
|
},
|
||||||
)?.firstOrNull()
|
getUserFromId(user, context)
|
||||||
|
)?.firstOrNull()
|
||||||
|
} catch(_: Exception) {
|
||||||
|
// can throw SecurityException or IllegalStateException when profile is locked
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
|
Loading…
Add table
Reference in a new issue