summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorPhie <phie@phie.ovh>2021-11-18 14:10:48 +0100
committerPhie <phie@phie.ovh>2021-11-18 14:10:48 +0100
commite595f0c7fcdea72bcbed55336151f75e8ca4c0b9 (patch)
tree4e1f26d768494d16f64e65c5a7b08fd5dc161674 /app/src
parent14e92a27713801c9e38d3421211399b50abf7db2 (diff)
use blockable list provided by tracker module
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt2
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/AppListUseCase.kt33
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFeature.kt2
3 files changed, 35 insertions, 2 deletions
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<List<ApplicationDescription>> {
+ corouteineScope.launch {
+ _installedAppsUsingInternet.value = getBlockableAppsList()
+ }
+ return _installedAppsUsingInternet
+ }
+
+ private fun getBlockableAppsList(): List<ApplicationDescription> {
+ return blockTrackersPrivacyModule.getBlockableApps()
+ .filter {
+ permissionsModule.getPermissions(it.packageName)
+ .contains(Manifest.permission.INTERNET)
+ }.map {
+ it.icon = permissionsModule.getApplicationIcon(it.packageName)
+ it
+ }.sortedWith(object : Comparator<ApplicationDescription> {
+ 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<ApplicationDescription> {
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)
}
)