From e595f0c7fcdea72bcbed55336151f75e8ca4c0b9 Mon Sep 17 00:00:00 2001 From: Phie Date: Thu, 18 Nov 2021 14:10:48 +0100 Subject: use blockable list provided by tracker module --- .../e/privacycentralapp/DependencyContainer.kt | 2 +- .../domain/usecases/AppListUseCase.kt | 33 ++++++++++++++++++++++ .../features/trackers/TrackersFeature.kt | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt index 1553b52..102d970 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt @@ -80,7 +80,7 @@ class DependencyContainer constructor(val app: Application) { private val ipScramblingStateUseCase by lazy { IpScramblingStateUseCase(ipScramblerModule, permissionsModule, appDesc, localStateRepository, GlobalScope) } - private val appListUseCase = AppListUseCase(permissionsModule, GlobalScope) + private val appListUseCase = AppListUseCase(permissionsModule, blockTrackersPrivacyModule, GlobalScope) private val trackersStatisticsUseCase by lazy { TrackersStatisticsUseCase(trackTrackersPrivacyModule) diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/AppListUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/AppListUseCase.kt index 57168c5..a72360e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/AppListUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/AppListUseCase.kt @@ -20,6 +20,7 @@ package foundation.e.privacycentralapp.domain.usecases import android.Manifest import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription +import foundation.e.trackerfilter.api.BlockTrackersPrivacyModule import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -27,6 +28,7 @@ import kotlinx.coroutines.launch class AppListUseCase( private val permissionsModule: PermissionsPrivacyModule, + private val blockTrackersPrivacyModule: BlockTrackersPrivacyModule, private val corouteineScope: CoroutineScope ) { @@ -45,6 +47,37 @@ class AppListUseCase( return _installedAppsUsingInternet } + fun getBlockableApps(): Flow> { + corouteineScope.launch { + _installedAppsUsingInternet.value = getBlockableAppsList() + } + return _installedAppsUsingInternet + } + + private fun getBlockableAppsList(): List { + return blockTrackersPrivacyModule.getBlockableApps() + .filter { + permissionsModule.getPermissions(it.packageName) + .contains(Manifest.permission.INTERNET) + }.map { + it.icon = permissionsModule.getApplicationIcon(it.packageName) + it + }.sortedWith(object : Comparator { + override fun compare( + p0: ApplicationDescription?, + p1: ApplicationDescription? + ): Int { + return if (p0?.icon != null && p1?.icon != null) { + p0.label.toString().compareTo(p1.label.toString()) + } else if (p0?.icon == null) { + 1 + } else { + -1 + } + } + }) + } + private fun getInstalledAppsUsingInternetList(): List { return permissionsModule.getInstalledApplications() .filter { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt index 9bd2c7a..4728158 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt @@ -130,7 +130,7 @@ class TrackersFeature( ) ) }, - appListUseCase.getInstalledAppsUsingInternet().map { apps -> + appListUseCase.getBlockableApps().map { apps -> Effect.AvailableAppsListEffect(apps) } ) -- cgit v1.2.1