diff --git a/data/applications/src/main/java/de/mm20/launcher2/applications/AppSerialization.kt b/data/applications/src/main/java/de/mm20/launcher2/applications/AppSerialization.kt index c4a8b938..d2ed66e8 100644 --- a/data/applications/src/main/java/de/mm20/launcher2/applications/AppSerialization.kt +++ b/data/applications/src/main/java/de/mm20/launcher2/applications/AppSerialization.kt @@ -43,33 +43,36 @@ class LauncherAppSerializer : SearchableSerializer { class LauncherAppDeserializer(val context: Context) : SearchableDeserializer { override suspend fun deserialize(serialized: String): SavableSearchable? { - val json = JSONObject(serialized) - val launcherApps = context.getSystemService()!! - val userManager = context.getSystemService()!! - val userSerial = json.optLong("user") - val user = userManager.getUserForSerialNumber(userSerial) ?: return null - - val pkg = json.getString("package") - val activity = json.getString("activity") - - val componentName = ComponentName(pkg, activity) - - if (isAtLeastApiLevel(35)) { - val launcherUser = launcherApps.getLauncherUserInfo(user) ?: return null - if (launcherUser.userType == UserManager.USER_TYPE_PROFILE_PRIVATE && userManager.isQuietModeEnabled(user)) { - return LockedPrivateProfileApp( - label = context.getString(R.string.app_label_locked_profile), - componentName = componentName, - user = user, - userSerialNumber = userSerial - ) - } - } - - val intent = Intent().also { - it.component = componentName - } try { + val json = JSONObject(serialized) + val launcherApps = context.getSystemService()!! + val userManager = context.getSystemService()!! + val userSerial = json.optLong("user") + val user = userManager.getUserForSerialNumber(userSerial) ?: return null + + val pkg = json.getString("package") + val activity = json.getString("activity") + + val componentName = ComponentName(pkg, activity) + + if (isAtLeastApiLevel(35)) { + val launcherUser = launcherApps.getLauncherUserInfo(user) ?: return null + if (launcherUser.userType == UserManager.USER_TYPE_PROFILE_PRIVATE && userManager.isQuietModeEnabled( + user + ) + ) { + return LockedPrivateProfileApp( + label = context.getString(R.string.app_label_locked_profile), + componentName = componentName, + user = user, + userSerialNumber = userSerial + ) + } + } + + val intent = Intent().also { + it.component = componentName + } val launcherActivityInfo = launcherApps.resolveActivity(intent, user) ?: return null return LauncherApp(context, launcherActivityInfo) } catch (e: SecurityException) {