diff options
Diffstat (limited to 'app/src/main/java')
9 files changed, 64 insertions, 31 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt index a44a00a..2e24d4c 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt @@ -43,7 +43,6 @@ import foundation.e.privacycentralapp.features.trackers.apptrackers.AppTrackersV import foundation.e.privacymodules.fakelocation.FakeLocationModule import foundation.e.privacymodules.ipscrambler.IpScramblerModule import foundation.e.privacymodules.ipscramblermodule.IIpScramblerModule -import foundation.e.privacymodules.location.IFakeLocationModule import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription import foundation.e.privacymodules.trackers.api.BlockTrackersPrivacyModule @@ -98,7 +97,7 @@ class DependencyContainer(val app: Application) { } val trackersStateUseCase by lazy { - TrackersStateUseCase(blockTrackersPrivacyModule, trackTrackersPrivacyModule, permissionsModule, localStateRepository, trackersRepository, appListsRepository, GlobalScope) + TrackersStateUseCase(blockTrackersPrivacyModule, trackTrackersPrivacyModule, localStateRepository, trackersRepository, appListsRepository, GlobalScope) } private val fakeLocationStateUseCase by lazy { diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt index 1f23516..d6af1e0 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/AppListsRepository.kt @@ -36,6 +36,10 @@ class AppListsRepository( private val context: Context, private val coroutineScope: CoroutineScope ) { + companion object { + private const val settingsPackageName = "com.android.settings" + } + val dummySystemApp = ApplicationDescription( packageName = "foundation.e.dummysystemapp", uid = -1, @@ -96,7 +100,9 @@ class AppListsRepository( } private fun isNotHiddenSystemApp(app: ApplicationInfo, launcherApps: List<String>): Boolean { - if (app.hasFlag(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) { + if (app.packageName == settingsPackageName) { + return false + } else if (app.hasFlag(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) { return true } else if (!app.hasFlag(ApplicationInfo.FLAG_SYSTEM)) { return true diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt index 2b2c1dd..b5310e1 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/TrackersRepository.kt @@ -20,7 +20,7 @@ package foundation.e.privacycentralapp.data.repositories import android.content.Context import android.util.Log import com.google.gson.Gson -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.Tracker import retrofit2.Retrofit import retrofit2.converter.scalars.ScalarsConverterFactory import retrofit2.http.GET diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt index 6417fce..10c1ad0 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt @@ -22,17 +22,15 @@ import foundation.e.privacycentralapp.data.repositories.LocalStateRepository import foundation.e.privacycentralapp.data.repositories.TrackersRepository import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription -import foundation.e.privacymodules.trackers.IBlockTrackersPrivacyModule -import foundation.e.privacymodules.trackers.ITrackTrackersPrivacyModule -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.IBlockTrackersPrivacyModule +import foundation.e.privacymodules.trackers.api.ITrackTrackersPrivacyModule +import foundation.e.privacymodules.trackers.api.Tracker import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch class TrackersStateUseCase( private val blockTrackersPrivacyModule: IBlockTrackersPrivacyModule, private val trackersPrivacyModule: ITrackTrackersPrivacyModule, - private val permissionsPrivacyModule: PermissionsPrivacyModule, private val localStateRepository: LocalStateRepository, private val trackersRepository: TrackersRepository, private val appListsRepository: AppListsRepository, @@ -65,13 +63,8 @@ class TrackersStateUseCase( return appListsRepository.getApplicationDescription(appUid) } - fun isWhitelisted(appUid: Int): Boolean { - return if (appUid == appListsRepository.dummySystemApp.uid) { - appListsRepository.getHiddenSystemApps().any { - blockTrackersPrivacyModule.isWhitelisted(it.uid) - } - } else blockTrackersPrivacyModule.isWhitelisted(appUid) - } + fun isWhitelisted(appUid: Int) + = isWhitelisted(appUid, appListsRepository, blockTrackersPrivacyModule) fun getTrackersWhitelistIds(appUid: Int): List<String> { return if (appUid == appListsRepository.dummySystemApp.uid) { @@ -114,3 +107,16 @@ class TrackersStateUseCase( trackersPrivacyModule.start(trackersRepository.trackers, enableNotification = false) } } + + +fun isWhitelisted( + appUid: Int, + appListsRepository: AppListsRepository, + blockTrackersPrivacyModule: IBlockTrackersPrivacyModule +): Boolean { + return if (appUid == appListsRepository.dummySystemApp.uid) { + appListsRepository.getHiddenSystemApps().any { + blockTrackersPrivacyModule.isWhitelisted(it.uid) + } + } else blockTrackersPrivacyModule.isWhitelisted(appUid) +} 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 5abe0b8..52e0bad 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,15 +18,16 @@ 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 import foundation.e.privacycentralapp.domain.entities.AppWithCounts import foundation.e.privacycentralapp.domain.entities.TrackersPeriodicStatistics import foundation.e.privacymodules.permissions.data.ApplicationDescription -import foundation.e.privacymodules.trackers.IBlockTrackersPrivacyModule -import foundation.e.privacymodules.trackers.ITrackTrackersPrivacyModule -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.IBlockTrackersPrivacyModule +import foundation.e.privacymodules.trackers.api.ITrackTrackersPrivacyModule +import foundation.e.privacymodules.trackers.api.Tracker import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow @@ -172,24 +173,45 @@ class TrackersStatisticsUseCase( .map { apps -> val callsByApp = trackTrackersPrivacyModule.getPastDayTrackersCallsByApps() apps.map { app -> - val (blockedLeaks, leaks) = callsByApp.getOrDefault(app.uid, 0 to 0) AppWithCounts( app = app, isWhitelisted = !blockTrackersPrivacyModule.isBlockingEnabled() || - blockTrackersPrivacyModule.isWhitelisted(app.uid), - trackersCount = appListsRepository.foldForHiddenSystemApp(app.uid) { - trackersCounts.getOrDefault(it, 0) + isWhitelisted(app.uid, appListsRepository, blockTrackersPrivacyModule), + trackersCount = if (app.uid == appListsRepository.dummySystemApp.uid) { + getHiddenSystemAppsTrackersCount() + } else { + trackersCounts.getOrDefault(app.uid, 0) }, - whiteListedTrackersCount = appListsRepository.foldForHiddenSystemApp(app.uid) { - blockTrackersPrivacyModule.getWhiteList(it).size + whiteListedTrackersCount = if (app.uid == appListsRepository.dummySystemApp.uid) { + getHiddenSystemAppWhitelistedTrackersCount() + } else { + blockTrackersPrivacyModule.getWhiteList(app.uid).size }, - blockedLeaks = blockedLeaks, - leaks = leaks + blockedLeaks = appListsRepository.foldForHiddenSystemApp(app.uid) { + appUid -> callsByApp.getOrDefault(appUid, 0 to 0).first + }, + leaks = appListsRepository.foldForHiddenSystemApp(app.uid) { + appUid -> callsByApp.getOrDefault(appUid, 0 to 0).second + } ) }.sortedWith(mostLeakedAppsComparator) } } + 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/domain/usecases/UpdateWidgetUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/UpdateWidgetUseCase.kt index dab0b18..f70065c 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/UpdateWidgetUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/UpdateWidgetUseCase.kt @@ -18,7 +18,7 @@ package foundation.e.privacycentralapp.domain.usecases import foundation.e.privacycentralapp.data.repositories.LocalStateRepository -import foundation.e.privacymodules.trackers.ITrackTrackersPrivacyModule +import foundation.e.privacymodules.trackers.api.ITrackTrackersPrivacyModule class UpdateWidgetUseCase( private val localStateRepository: LocalStateRepository, 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 9a294e2..230f872 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 @@ -18,7 +18,7 @@ package foundation.e.privacycentralapp.features.trackers.apptrackers import foundation.e.privacymodules.permissions.data.ApplicationDescription -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.Tracker data class AppTrackersState( val appDesc: ApplicationDescription? = null, 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 bc591bf..c20ec7c 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 @@ -23,7 +23,7 @@ import androidx.lifecycle.viewModelScope import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase import foundation.e.privacycentralapp.domain.usecases.TrackersStateUseCase import foundation.e.privacycentralapp.domain.usecases.TrackersStatisticsUseCase -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.Tracker import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt index 02a274a..197f13f 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/ToggleTrackersAdapter.kt @@ -27,7 +27,7 @@ import android.widget.TextView import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import foundation.e.privacycentralapp.R -import foundation.e.privacymodules.trackers.Tracker +import foundation.e.privacymodules.trackers.api.Tracker class ToggleTrackersAdapter( private val itemsLayout: Int, |