Catch potential SecurityException in app deserializer

Close #1146
This commit is contained in:
MM20 2024-12-04 18:56:36 +01:00
parent 0413cb8ff6
commit 37db43405f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -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<LauncherApps>()!!
val userManager = context.getSystemService<UserManager>()!!
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<LauncherApps>()!!
val userManager = context.getSystemService<UserManager>()!!
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) {