From e414291e50d03eba961f9d7791e347524f6e3918 Mon Sep 17 00:00:00 2001 From: Piyush Bhardwaj <162677885+Piyu-Pika@users.noreply.github.com> Date: Sat, 9 May 2026 17:40:30 +0530 Subject: [PATCH] Handle invalid profile lock/unlock targets without crashing (#1897) --- .../mm20/launcher2/profiles/ProfileManager.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/profiles/src/main/java/de/mm20/launcher2/profiles/ProfileManager.kt b/core/profiles/src/main/java/de/mm20/launcher2/profiles/ProfileManager.kt index a692f0fe5..641184905 100644 --- a/core/profiles/src/main/java/de/mm20/launcher2/profiles/ProfileManager.kt +++ b/core/profiles/src/main/java/de/mm20/launcher2/profiles/ProfileManager.kt @@ -8,6 +8,7 @@ import android.content.pm.LauncherApps import android.os.Process import android.os.UserHandle import android.os.UserManager +import android.util.Log import androidx.annotation.RequiresApi import androidx.core.content.getSystemService import de.mm20.launcher2.ktx.isAtLeastApiLevel @@ -35,6 +36,10 @@ class ProfileManager( private val context: Context, private val permissionsManager: PermissionsManager, ) { + private companion object { + private const val TAG = "ProfileManager" + } + private val mutex = Mutex() private val userManager = context.getSystemService()!! @@ -166,12 +171,20 @@ class ProfileManager( @RequiresApi(28) fun unlockProfile(profile: Profile) { - userManager.requestQuietModeEnabled(false, profile.userHandle) + try { + userManager.requestQuietModeEnabled(false, profile.userHandle) + } catch (e: IllegalArgumentException) { + Log.w(TAG, "Unable to unlock profile ${profile.serial}", e) + } } @RequiresApi(28) fun lockProfile(profile: Profile) { - userManager.requestQuietModeEnabled(true, profile.userHandle) + try { + userManager.requestQuietModeEnabled(true, profile.userHandle) + } catch (e: IllegalArgumentException) { + Log.w(TAG, "Unable to lock profile ${profile.serial}", e) + } } -} \ No newline at end of file +}