diff options
author | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-03-21 08:58:41 +0100 |
---|---|---|
committer | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-03-21 08:58:41 +0100 |
commit | a7cc29a6d52ce7b622fb6f5c961865f1e207252d (patch) | |
tree | c20885f4686362a3ed80110f59820ffadb511738 /app/src | |
parent | bb103aa91e24d2b17875b496e17807ebd50aeb24 (diff) |
Attach system apps to a dummy system app instead of settings app.
Diffstat (limited to 'app/src')
4 files changed, 49 insertions, 34 deletions
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<List<ApplicationDescription>> { 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<Tracker>) : Effect() @@ -127,37 +127,38 @@ class AppTrackersFeature( }, actor = { state, action -> when (action) { - is Action.InitAction -> { - val appDesc = - trackersStateUseCase.getApplicationDescription(action.packageName) - merge<Effect>( - flow { + is Action.InitAction -> + trackersStateUseCase + .getApplicationDescription(action.packageName)?.let { appDesc -> + merge<Effect>( + 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 { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f774249..30f017c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,9 @@ <resources> <string name="app_name">PrivacyCentralApp</string> + <!-- Commons --> + <string name="dummy_system_app_label">System</string> + <!-- Dashboard --> <string name="dashboard_title">Quick Privacy</string> <string name="dashboard_state_title_on">Your online privacy is protected</string> @@ -75,6 +78,7 @@ <string name="apptrackers_no_trackers_yet_block_on">No trackers were detected yet. All future trackers will be blocked.</string> <string name="apptrackers_error_quickprivacy_disabled">Enable Quick Privacy to be able to activate/deactivate trackers.</string> <string name="apptrackers_trackers_count_summary">%1$d blocked trackers out of %2$d detected trackers</string> + <string name="apptrackers_error_no_app">App not installed.</string> <!-- --> <string name="quick_protection_info">Quick protection enables these settings when turned on</string> |