From 37db43405fd0535195d94a702bf65e838f7fc3df Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:56:36 +0100 Subject: [PATCH] Catch potential SecurityException in app deserializer Close #1146 --- .../applications/AppSerialization.kt | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) 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) {