user launcher profilemanager

This commit is contained in:
MM20
2026-07-04 20:35:37 +02:00
parent 069aa1796a
commit 10516ef9a9
4 changed files with 39 additions and 19 deletions

View File

@@ -50,6 +50,7 @@ dependencies {
implementation(libs.coil.core)
implementation(project(":core:base"))
implementation(project(":core:profiles"))
implementation(project(":data:database"))
implementation(project(":core:ktx"))
implementation(project(":core:preferences"))

View File

@@ -1,14 +1,15 @@
package de.mm20.launcher2.searchactions.actions
import android.content.Context
import android.os.UserHandle
import android.os.UserManager
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.profiles.Profile
import de.mm20.launcher2.profiles.ProfileManager
data class PrivateSpaceLockAction(
override val label: String,
val isLocked: Boolean,
val userHandle: UserHandle,
val profile: Profile,
val profileManager: ProfileManager,
) : SearchAction {
override val icon = SearchActionIcon.PrivateSpace
override val iconColor = 0
@@ -16,8 +17,11 @@ data class PrivateSpaceLockAction(
override fun start(context: Context) {
if (isAtLeastApiLevel(28)) {
context.getSystemService(UserManager::class.java)
?.requestQuietModeEnabled(!isLocked, userHandle)
if (isLocked) {
profileManager.unlockProfile(profile)
} else {
profileManager.lockProfile(profile)
}
}
}
}

View File

@@ -1,19 +1,23 @@
package de.mm20.launcher2.searchactions.builders
import android.content.Context
import android.content.pm.LauncherApps
import android.os.UserManager
import de.mm20.launcher2.ktx.isAtLeastApiLevel
import de.mm20.launcher2.profiles.Profile
import de.mm20.launcher2.profiles.ProfileManager
import de.mm20.launcher2.search.ResultScore
import de.mm20.launcher2.searchactions.R
import de.mm20.launcher2.searchactions.TextClassificationResult
import de.mm20.launcher2.searchactions.actions.PrivateSpaceLockAction
import de.mm20.launcher2.searchactions.actions.SearchAction
import de.mm20.launcher2.searchactions.actions.SearchActionIcon
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
class PrivateSpaceLockActionBuilder(
override val label: String,
) : SearchActionBuilder {
) : SearchActionBuilder, KoinComponent {
private val profileManager: ProfileManager by inject()
constructor(context: Context) : this(context.getString(R.string.search_query_private_space))
@@ -23,6 +27,9 @@ class PrivateSpaceLockActionBuilder(
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction? {
if (!isAtLeastApiLevel(35)) return null
val privateProfile = profileManager.getProfile(Profile.Type.Private) ?: return null
val profileState = profileManager.getProfileStateOnce(privateProfile) ?: return null
val keyword = context.getString(R.string.search_query_private_space).lowercase()
val score = ResultScore.from(
query = classifiedQuery.text.lowercase(),
@@ -30,21 +37,14 @@ class PrivateSpaceLockActionBuilder(
)
if (score.score < 0.8f) return null
val launcherApps = context.getSystemService(LauncherApps::class.java) ?: return null
val userManager = context.getSystemService(UserManager::class.java) ?: return null
val privateHandle = launcherApps.profiles.firstOrNull {
launcherApps.getLauncherUserInfo(it)?.userType == UserManager.USER_TYPE_PROFILE_PRIVATE
} ?: return null
val isLocked = !userManager.isUserUnlocked(privateHandle)
return PrivateSpaceLockAction(
label = context.getString(
if (isLocked) R.string.search_action_private_space_unlock
if (profileState.locked) R.string.search_action_private_space_unlock
else R.string.search_action_private_space_lock
),
isLocked = isLocked,
userHandle = privateHandle,
isLocked = profileState.locked,
profile = privateProfile,
profileManager = profileManager,
)
}
}