diff options
Diffstat (limited to 'app')
4 files changed, 40 insertions, 36 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt index 52e0bad..0a47bc5 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStatisticsUseCase.kt @@ -18,7 +18,6 @@ package foundation.e.privacycentralapp.domain.usecases import android.content.res.Resources -import android.util.Log import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.common.throttleFirst import foundation.e.privacycentralapp.data.repositories.AppListsRepository @@ -156,6 +155,28 @@ class TrackersStatisticsUseCase( return trackers.sortedBy { it.label.lowercase() } } + fun getTrackersWithWhiteList(appUid: Int): List<Pair<Tracker, Boolean>> { + val trackers: List<Tracker> + val whiteListedTrackersIds: Set<String> + if (appUid == appListsRepository.dummySystemApp.uid) { + val hiddenApps = appListsRepository.getHiddenSystemApps() + trackers = trackTrackersPrivacyModule.getTrackers(hiddenApps.map { it.uid }) + + whiteListedTrackersIds = hiddenApps.fold(HashSet<String>()) { acc, app -> + acc.addAll(blockTrackersPrivacyModule.getWhiteList(app.uid).map { it.id }) + acc + } + + } else { + trackers = trackTrackersPrivacyModule.getTrackersForApp(appUid) + whiteListedTrackersIds = blockTrackersPrivacyModule.getWhiteList(appUid) + .map { it.id }.toSet() + } + + return trackers.sortedBy { it.label.lowercase() }.map { tracker -> tracker to whiteListedTrackersIds.any { tracker.id == it }} + } + + fun getCalls(appUid: Int): Pair<Int, Int> { return if (appUid == appListsRepository.dummySystemApp.uid) { appListsRepository.getHiddenSystemApps().map { @@ -168,6 +189,8 @@ class TrackersStatisticsUseCase( fun getAppsWithCounts(): Flow<List<AppWithCounts>> { val trackersCounts = trackTrackersPrivacyModule.getTrackersCountByApp() + val hiddenAppsTrackersWithWhiteList = + getTrackersWithWhiteList(appListsRepository.dummySystemApp.uid) return appListsRepository.getVisibleApps() .map { apps -> @@ -178,12 +201,12 @@ class TrackersStatisticsUseCase( isWhitelisted = !blockTrackersPrivacyModule.isBlockingEnabled() || isWhitelisted(app.uid, appListsRepository, blockTrackersPrivacyModule), trackersCount = if (app.uid == appListsRepository.dummySystemApp.uid) { - getHiddenSystemAppsTrackersCount() + hiddenAppsTrackersWithWhiteList.size } else { trackersCounts.getOrDefault(app.uid, 0) }, whiteListedTrackersCount = if (app.uid == appListsRepository.dummySystemApp.uid) { - getHiddenSystemAppWhitelistedTrackersCount() + hiddenAppsTrackersWithWhiteList.count { it.second } } else { blockTrackersPrivacyModule.getWhiteList(app.uid).size }, @@ -198,20 +221,6 @@ class TrackersStatisticsUseCase( } } - private fun getHiddenSystemAppsTrackersCount(): Int { - return trackTrackersPrivacyModule.getTrackersCount( - appListsRepository.getHiddenSystemApps().map { it.uid } - ) - } - - private fun getHiddenSystemAppWhitelistedTrackersCount(): Int { - return appListsRepository.getHiddenSystemApps().fold(HashSet<String>()) { acc, app -> - acc.addAll(blockTrackersPrivacyModule.getWhiteList(app.uid).map { it.id }) - acc - }.size - } - - private val mostLeakedAppsComparator: Comparator<AppWithCounts> = Comparator { o1, o2 -> val leaks = o2.leaks - o1.leaks if (leaks != 0) leaks else { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt index 3d8f809..ae169b4 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt @@ -151,10 +151,10 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { binding.blockAllToggle.isChecked = state.isBlockingActivated - binding.trackersListTitle.isVisible = state.isBlockingActivated val trackersStatus = state.getTrackersStatus() if (!trackersStatus.isNullOrEmpty()) { + binding.trackersListTitle.isVisible = state.isBlockingActivated binding.trackers.isVisible = true binding.trackers.post { (binding.trackers.adapter as ToggleTrackersAdapter?)?.updateDataSet( @@ -164,6 +164,7 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { } binding.noTrackersYet.isVisible = false } else { + binding.trackersListTitle.isVisible = false binding.trackers.isVisible = false binding.noTrackersYet.isVisible = true binding.noTrackersYet.text = getString( diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt index 230f872..ffa1f36 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersState.kt @@ -23,23 +23,17 @@ import foundation.e.privacymodules.trackers.api.Tracker data class AppTrackersState( val appDesc: ApplicationDescription? = null, val isBlockingActivated: Boolean = false, - val trackers: List<Tracker>? = null, - val whitelist: List<String>? = null, + val trackersWithWhiteList: List<Pair<Tracker, Boolean>>? = null, val leaked: Int = 0, val blocked: Int = 0, val isQuickPrivacyEnabled: Boolean = false, val showQuickPrivacyDisabledMessage: Boolean = false, ) { - fun getTrackersStatus(): List<Pair<Tracker, Boolean>>? { - if (trackers != null && whitelist != null) { - return trackers.map { it to (it.id !in whitelist) } - } else { - return null - } - } + fun getTrackersStatus(): List<Pair<Tracker, Boolean>>? + = trackersWithWhiteList?.map { it.first to !it.second } - fun getTrackersCount() = trackers?.size ?: 0 + fun getTrackersCount() = trackersWithWhiteList?.size ?: 0 fun getBlockedTrackersCount(): Int = if (isQuickPrivacyEnabled && isBlockingActivated) - getTrackersCount() - (whitelist?.size ?: 0) + trackersWithWhiteList?.count { !it.second }?: 0 else 0 }
\ No newline at end of file diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt index c20ec7c..faa4e6b 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt @@ -54,9 +54,9 @@ class AppTrackersViewModel( init { viewModelScope.launch(Dispatchers.IO) { _state.update { it.copy( - appDesc = trackersStateUseCase.getApplicationDescription(appUid), - isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), - whitelist = trackersStateUseCase.getTrackersWhitelistIds(appUid), + appDesc = trackersStateUseCase.getApplicationDescription(appUid), + isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), ) } } } @@ -96,7 +96,7 @@ class AppTrackersViewModel( if (state.value.isBlockingActivated) { trackersStateUseCase.blockTracker(appUid, action.tracker, action.isBlocked) _state.update { it.copy( - whitelist = trackersStateUseCase.getTrackersWhitelistIds(appUid) + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid) ) } } } @@ -115,9 +115,9 @@ class AppTrackersViewModel( private fun fetchStatistics() { val (blocked, leaked) = trackersStatisticsUseCase.getCalls(appUid) return _state.update { s -> s.copy( - trackers = trackersStatisticsUseCase.getTrackers(appUid), - leaked = leaked, - blocked = blocked, + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), + leaked = leaked, + blocked = blocked, ) } } |