From a7cc29a6d52ce7b622fb6f5c961865f1e207252d Mon Sep 17 00:00:00 2001 From: jacquarg Date: Mon, 21 Mar 2022 08:58:41 +0100 Subject: Attach system apps to a dummy system app instead of settings app. --- .../data/repositories/AppListsRepository.kt | 14 ++++- .../domain/usecases/TrackersStateUseCase.kt | 4 +- .../trackers/apptrackers/AppTrackersFeature.kt | 61 +++++++++++----------- 3 files changed, 45 insertions(+), 34 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') 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 3573d4f..5d25a82 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 @@ -22,6 +22,7 @@ import android.content.Context import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageManager +import foundation.e.privacycentralapp.R import foundation.e.privacymodules.permissions.PermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription import kotlinx.coroutines.CoroutineScope @@ -35,14 +36,19 @@ class AppListsRepository( private val context: Context, private val coroutineScope: CoroutineScope ) { - val dummySystemApp = permissionsModule.getApplicationDescription("com.android.settings") + val dummySystemApp = ApplicationDescription( + packageName = "foundation.e.dummysystemapp", + uid = -1, + label = context.getString(R.string.dummy_system_app_label), + icon = context.getDrawable(lineageos.platform.R.drawable.ic_android) + ) fun getVisibleApps(): Flow> { coroutineScope.launch { val (visible, hidden) = splitVisibleToHidden(getAppsUsingInternet()) appDescriptions.emit( Pair( - visible.map { permissionsModule.buildApplicationDescription(it, withIcon = true) }, + visible.map { permissionsModule.buildApplicationDescription(it, withIcon = true) } + dummySystemApp, hidden.map { permissionsModule.buildApplicationDescription(it, withIcon = false) }, ) ) @@ -53,6 +59,10 @@ class AppListsRepository( return appDescriptions.value.second } + fun getApplicationDescription(packageName: String): ApplicationDescription? { + return appDescriptions.value.first.find { it.packageName == packageName } + } + fun foldForHiddenSystemApp(appUid: Int, appValueGetter: (Int) -> Int): Int { return if (appUid == dummySystemApp.uid) { getHiddenSystemApps().fold(0) { acc, app -> 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 ecf2e7b..a589509 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 @@ -67,8 +67,8 @@ class TrackersStateUseCase( blockTrackersPrivacyModule.isWhiteListEmpty() } - fun getApplicationDescription(packageName: String): ApplicationDescription { - return permissionsPrivacyModule.getApplicationDescription(packageName) + fun getApplicationDescription(packageName: String): ApplicationDescription? { + return appListsRepository.getApplicationDescription(packageName) } fun isWhitelisted(appUid: Int): Boolean { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt index 790a5a0..270dfcb 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFeature.kt @@ -87,7 +87,7 @@ class AppTrackersFeature( sealed class Effect { object NoEffect : Effect() - data class ErrorEffect(val message: String) : Effect() + data class ErrorEffect(val message: Any) : Effect() data class SetAppEffect(val appDesc: ApplicationDescription) : Effect() data class AppTrackersBlockingActivatedEffect(val isBlockingActivated: Boolean) : Effect() data class AvailableTrackersListEffect(val trackers: List) : Effect() @@ -127,37 +127,38 @@ class AppTrackersFeature( }, actor = { state, action -> when (action) { - is Action.InitAction -> { - val appDesc = - trackersStateUseCase.getApplicationDescription(action.packageName) - merge( - flow { + is Action.InitAction -> + trackersStateUseCase + .getApplicationDescription(action.packageName)?.let { appDesc -> + merge( + flow { - emit(Effect.SetAppEffect(appDesc)) - emit( - Effect.AppTrackersBlockingActivatedEffect( - !trackersStateUseCase.isWhitelisted(appDesc.uid) - ) - ) - emit( - Effect.TrackersWhitelistUpdateEffect( - trackersStateUseCase.getTrackersWhitelistIds(appDesc.uid) - ) - ) - emit( - Effect.AvailableTrackersListEffect( - trackers = trackersStatisticsUseCase.getTrackers(appDesc.uid) - ) + emit(Effect.SetAppEffect(appDesc)) + emit( + Effect.AppTrackersBlockingActivatedEffect( + !trackersStateUseCase.isWhitelisted(appDesc.uid) + ) + ) + emit( + Effect.TrackersWhitelistUpdateEffect( + trackersStateUseCase.getTrackersWhitelistIds(appDesc.uid) + ) + ) + emit( + Effect.AvailableTrackersListEffect( + trackers = trackersStatisticsUseCase.getTrackers(appDesc.uid) + ) + ) + }, + trackersStatisticsUseCase.listenUpdates().map { + Effect.NewStatisticsAvailablesEffect + }, + getQuickPrivacyStateUseCase.quickPrivacyEnabledFlow.map { + Effect.QuickPrivacyUpdatedEffect(it) + } ) - }, - trackersStatisticsUseCase.listenUpdates().map { - Effect.NewStatisticsAvailablesEffect - }, - getQuickPrivacyStateUseCase.quickPrivacyEnabledFlow.map { - Effect.QuickPrivacyUpdatedEffect(it) - } - ) - } + } ?: flowOf(Effect.ErrorEffect(R.string.apptrackers_error_no_app)) + is Action.BlockAllToggleAction -> state.appDesc?.uid?.let { appUid -> flow { -- cgit v1.2.1