Fixed possible crashes below U

This commit is contained in:
MrSluffy
2024-12-27 09:40:06 +08:00
parent 1bc5b0459c
commit 6033863bf8
2 changed files with 72 additions and 54 deletions

View File

@@ -77,6 +77,7 @@ open class SystemApiWrapper(context: Context?) : ApiWrapper(context) {
if (!enablePrivateSpace() || !LawnchairApp.isRecentsEnabled) {
return super.queryAllUsers()
}
return try {
val users = ArrayMap<UserHandle, UserIconInfo>()
mContext.getSystemService(UserManager::class.java)!!.userProfiles?.forEach { user ->
mContext.getSystemService(LauncherApps::class.java)!!.getLauncherUserInfo(user)?.apply {
@@ -94,17 +95,26 @@ open class SystemApiWrapper(context: Context?) : ApiWrapper(context) {
}
}
return users
} catch (t : Throwable) {
return super.queryAllUsers()
}
}
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
override fun getPreInstalledSystemPackages(user: UserHandle): List<String> =
override fun getPreInstalledSystemPackages(user: UserHandle): List<String> {
return try {
if (enablePrivateSpace() && privateSpaceSysAppsSeparation())
mContext
.getSystemService(LauncherApps::class.java)!!
.getPreInstalledSystemPackages(user)
else ArrayList()
} catch (t: Throwable) {
super.getPreInstalledSystemPackages(user)
}
}
override fun getAppMarketActivityIntent(packageName: String, user: UserHandle): Intent =
override fun getAppMarketActivityIntent(packageName: String, user: UserHandle): Intent {
return try {
if (
enablePrivateSpace() &&
(privateSpaceAppInstallerButton() || enablePrivateSpaceInstallShortcut())
@@ -126,6 +136,10 @@ open class SystemApiWrapper(context: Context?) : ApiWrapper(context) {
}
)
else super.getAppMarketActivityIntent(packageName, user)
} catch (t: Throwable) {
super.getAppMarketActivityIntent(packageName, user)
}
}
/** Returns an intent which can be used to open Private Space Settings. */
override fun getPrivateSpaceSettingsIntent(): Intent? =

View File

@@ -101,7 +101,8 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable {
isWork ? UserIconInfo.TYPE_WORK : UserIconInfo.TYPE_MAIN,
serial);
if (launcherApps != null && Utilities.ATLEAST_V) {
try {
if (Utilities.ATLEAST_U && launcherApps != null) {
LauncherUserInfo userInfo = launcherApps.getLauncherUserInfo(user);
if (userInfo != null) {
var userType = userInfo.getUserType();
@@ -115,6 +116,9 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable {
);
}
}
} catch (Throwable t) {
// Ignore
}
users.put(user, info);
}