summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt33
1 files changed, 24 insertions, 9 deletions
diff --git a/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt b/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt
index f29bb8a..b44e96e 100644
--- a/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt
+++ b/core/src/main/java/foundation/e/advancedprivacy/data/repositories/AppListsRepository.kt
@@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.withContext
class AppListsRepository(
private val permissionsModule: IPermissionsPrivacyModule,
@@ -179,20 +180,24 @@ class AppListsRepository(
} else test(app)
}
- fun applyForHiddenApps(app: ApplicationDescription, action: (ApplicationDescription) -> Unit) {
+ fun getRealApps(app: ApplicationDescription): List<ApplicationDescription> {
+ return when (app) {
+ dummySystemApp -> getHiddenSystemApps()
+ dummyCompatibilityApp -> getCompatibilityApps()
+ else -> listOf(app)
+ }
+ }
+
+ suspend fun applyForHiddenApps(app: ApplicationDescription, action: suspend (ApplicationDescription) -> Unit) {
mapReduceForHiddenApps(app = app, map = action, reduce = {})
}
- fun <T, R> mapReduceForHiddenApps(
+ suspend fun <T, R> mapReduceForHiddenApps(
app: ApplicationDescription,
- map: (ApplicationDescription) -> T,
- reduce: (List<T>) -> R
+ map: suspend (ApplicationDescription) -> T,
+ reduce: suspend (List<T>) -> R
): R {
- return if (app == dummySystemApp) {
- reduce(getHiddenSystemApps().map(map))
- } else if (app == dummyCompatibilityApp) {
- reduce(getCompatibilityApps().map(map))
- } else reduce(listOf(map(app)))
+ return reduce(getRealApps(app).map { map(it) })
}
private var appsByUid = mapOf<Int, ApplicationDescription>()
@@ -214,6 +219,16 @@ class AppListsRepository(
}
}
+ suspend fun getDisplayableApp(apId: String): ApplicationDescription? = withContext(Dispatchers.IO) {
+ getApp(apId)?.let { app ->
+ when {
+ app in getCompatibilityApps() -> dummyCompatibilityApp
+ app in getHiddenSystemApps() -> dummySystemApp
+ else -> app
+ }
+ }
+ }
+
private val allProfilesAppDescriptions = MutableStateFlow(
Triple(
emptyList<ApplicationDescription>(),