From 2e897cc8af4234abc4e3f5c3448e1fd7b2b8a1bd Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Tue, 5 Dec 2023 08:17:01 +0000 Subject: 1203 trackers oriented view --- .../data/repositories/AppListsRepository.kt | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'core/src') 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 { + 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 mapReduceForHiddenApps( + suspend fun mapReduceForHiddenApps( app: ApplicationDescription, - map: (ApplicationDescription) -> T, - reduce: (List) -> R + map: suspend (ApplicationDescription) -> T, + reduce: suspend (List) -> 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() @@ -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(), -- cgit v1.2.1