From fc06e0142613e80440e08b956e0717f05a78104c Mon Sep 17 00:00:00 2001 From: Andy <72276976+andy-math@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:48:46 +0800 Subject: [PATCH] FIX: getActivityList crash on some profile --- .../main/java/com/oasisfeng/island/util/Users.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/shared/src/main/java/com/oasisfeng/island/util/Users.kt b/shared/src/main/java/com/oasisfeng/island/util/Users.kt index ec9d1f56..628b547d 100644 --- a/shared/src/main/java/com/oasisfeng/island/util/Users.kt +++ b/shared/src/main/java/com/oasisfeng/island/util/Users.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE +import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherApps import android.graphics.drawable.Drawable import android.os.Build.VERSION.SDK_INT @@ -78,11 +79,19 @@ class Users : PseudoContentProvider() { val uiModule = Modules.getMainLaunchActivity(context).packageName val la = context.getSystemService()!! val activityInOwner = la.getActivityList(uiModule, CURRENT)[0].name - for (profile in profiles.drop(1)/* skip parent */) - for (activity in la.getActivityList(uiModule, profile)) + for (profile in profiles.drop(1)/* skip parent */) { + val activityList: List + try { + activityList = la.getActivityList(uiModule, profile) + } catch (e: SecurityException) { + Log.w(TAG, "Skip profile ${profile.toId()} (most probably not normal profile)") + continue + } + for (activity in activityList) // Separate "Island Settings" launcher activity is enabled, only if profile is managed by Island. if (activity.name == activityInOwner) Log.i(TAG, "Profile not managed by Island: ${profile.toId()}") else profilesByIsland.add(profile).also { Log.i(TAG, "Profile managed by Island: ${profile.toId()}") } + } } else for (user in profiles.drop(1)/* skip parent */) if (user != CURRENT) Log.w(TAG, "Skip sibling profile (may not managed by Island): ${user.toId()}") else profilesByIsland.add(user).also { Log.i(TAG, "Profile managed by Island: ${user.toId()}") }