From f8d19823ea9be0c8700a69a215fac7d3af4d6d87 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Tue, 4 Oct 2022 08:34:34 +0200 Subject: 5561: display name of other VPNrunning always on. --- .../common/extensions/AnyExtension.kt | 6 --- .../data/repositories/LocalStateRepository.kt | 9 +++-- .../domain/usecases/GetQuickPrivacyStateUseCase.kt | 3 +- .../domain/usecases/IpScramblingStateUseCase.kt | 44 +++++++++++----------- .../features/dashboard/DashboardFragment.kt | 6 ++- .../features/dashboard/DashboardViewModel.kt | 8 +++- .../internetprivacy/InternetPrivacyFragment.kt | 3 +- .../internetprivacy/InternetPrivacyViewModel.kt | 10 ++++- .../trackers/apptrackers/AppTrackersFragment.kt | 3 +- .../trackers/apptrackers/AppTrackersViewModel.kt | 3 +- 10 files changed, 52 insertions(+), 43 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/extensions/AnyExtension.kt b/app/src/main/java/foundation/e/privacycentralapp/common/extensions/AnyExtension.kt index 5c73df9..71de99a 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/extensions/AnyExtension.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/extensions/AnyExtension.kt @@ -19,10 +19,4 @@ package foundation.e.privacycentralapp.common.extensions import android.content.Context -fun Any.toText(context: Context) = when (this) { - is Int -> context.getString(this) - is String -> this - else -> this.toString() -} - fun Int.dpToPxF(context: Context): Float = this.toFloat() * context.resources.displayMetrics.density diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt index 672f260..d39ee43 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt @@ -20,6 +20,7 @@ package foundation.e.privacycentralapp.data.repositories import android.content.Context import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode import foundation.e.privacycentralapp.domain.entities.LocationMode +import foundation.e.privacymodules.permissions.data.ApplicationDescription import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow @@ -51,12 +52,12 @@ class LocalStateRepository(context: Context) { return isFirstActivation } - private val _otherVpnRunning = MutableSharedFlow() - suspend fun emitOtherVpnRunning() { - _otherVpnRunning.emit(true) + private val _otherVpnRunning = MutableSharedFlow() + suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) { + _otherVpnRunning.emit(appDesc) } - val otherVpnRunning: SharedFlow = _otherVpnRunning + val otherVpnRunning: SharedFlow = _otherVpnRunning var quickPrivacyEnabledFlow: StateFlow = quickPrivacyEnabledMutableFlow diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt index e1f773f..688bdc4 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -22,6 +22,7 @@ import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode import foundation.e.privacycentralapp.domain.entities.LocationMode import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.domain.entities.TrackerMode +import foundation.e.privacymodules.permissions.data.ApplicationDescription import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow @@ -106,6 +107,6 @@ class GetQuickPrivacyStateUseCase( localStateRepository.setShowQuickPrivacyDisabledMessage(false) } - val otherVpnRunning: SharedFlow = localStateRepository.otherVpnRunning + val otherVpnRunning: SharedFlow = localStateRepository.otherVpnRunning } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt index 3320721..a0003eb 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt @@ -126,30 +126,32 @@ class IpScramblingStateUseCase( } private fun applySettings(isQuickPrivacyEnabled: Boolean, isIpScramblingEnabled: Boolean) { + val mode = localStateRepository.internetPrivacyMode.value when { - isQuickPrivacyEnabled && isIpScramblingEnabled -> when (localStateRepository.internetPrivacyMode.value) { - InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING -> { - var intent = ipScramblerModule.prepareAndroidVpn() - if (intent != null) { - permissionsPrivacyModule.setVpnPackageAuthorization(appDesc.packageName) - intent = ipScramblerModule.prepareAndroidVpn() - } - - if (intent != null) { - coroutineScope.launch { - localStateRepository.emitOtherVpnRunning() - } - localStateRepository.setIpScramblingSetting(enabled = false) - } else { - ipScramblerModule.start(enableNotification = false) - } - } - else -> {} + isQuickPrivacyEnabled && isIpScramblingEnabled && + mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> + applyStartIpScrambling() + + mode in setOf(InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING) -> + ipScramblerModule.stop() + else -> {} } - else -> when (localStateRepository.internetPrivacyMode.value) { - InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING -> ipScramblerModule.stop() - else -> {} + } + + private fun applyStartIpScrambling() { + ipScramblerModule.prepareAndroidVpn()?.let { + permissionsPrivacyModule.setVpnPackageAuthorization(appDesc.packageName) + permissionsPrivacyModule.getAlwaysOnVpnPackage() + }?.let { + coroutineScope.launch { + localStateRepository.emitOtherVpnRunning( + permissionsPrivacyModule.getApplicationDescription(packageName = it, withIcon = false) + ) } + localStateRepository.setIpScramblingSetting(enabled = false) + + }?: run { + ipScramblerModule.start(enableNotification = false) } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index 4d38ec8..21950a4 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -163,8 +163,10 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { } } is SingleEvent.ToastMessageSingleEvent -> - Toast.makeText(requireContext(), event.message, Toast.LENGTH_LONG) - .show() + Toast.makeText(requireContext(), + getString(event.message, *event.args.toTypedArray()), + Toast.LENGTH_LONG + ).show() } } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt index cd7e414..a2fca86 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt @@ -17,6 +17,7 @@ package foundation.e.privacycentralapp.features.dashboard +import androidx.annotation.StringRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import foundation.e.privacycentralapp.R @@ -77,7 +78,8 @@ class DashboardViewModel( }, getPrivacyStateUseCase.otherVpnRunning.map { _singleEvents.emit(SingleEvent.ToastMessageSingleEvent( - R.string.ipscrambling_error_always_on_vpn_already_running + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label?: "") )) } ).collect {} @@ -139,7 +141,9 @@ class DashboardViewModel( object NavigateToLocationSingleEvent : SingleEvent() object NavigateToPermissionsSingleEvent : SingleEvent() data class NavigateToAppDetailsEvent(val appDesc: ApplicationDescription) : SingleEvent() - data class ToastMessageSingleEvent(val message: Int) : SingleEvent() + data class ToastMessageSingleEvent( + @StringRes val message: Int, val args: List = emptyList() + ) : SingleEvent() } sealed class Action { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt index 749fae4..99aa217 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt @@ -33,7 +33,6 @@ import foundation.e.privacycentralapp.PrivacyCentralApplication import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.common.NavToolbarFragment import foundation.e.privacycentralapp.common.ToggleAppsAdapter -import foundation.e.privacycentralapp.common.extensions.toText import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar import foundation.e.privacycentralapp.common.setToolTipForAsterisk import foundation.e.privacycentralapp.databinding.FragmentInternetActivityPolicyBinding @@ -137,7 +136,7 @@ class InternetPrivacyFragment : NavToolbarFragment(R.layout.fragment_internet_ac viewModel.singleEvents.collect { event -> when (event) { is InternetPrivacyViewModel.SingleEvent.ErrorEvent -> { - displayToast(event.error.toText(requireContext())) + displayToast(getString(event.errorResId, *event.args.toTypedArray())) } } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt index ab5e24d..8bdb16e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt @@ -17,6 +17,7 @@ package foundation.e.privacycentralapp.features.internetprivacy +import androidx.annotation.StringRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import foundation.e.privacycentralapp.R @@ -108,7 +109,10 @@ class InternetPrivacyViewModel( launch { getQuickPrivacyStateUseCase.otherVpnRunning.collect { - _singleEvents.emit(SingleEvent.ErrorEvent(R.string.ipscrambling_error_always_on_vpn_already_running)) + _singleEvents.emit(SingleEvent.ErrorEvent( + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label?: "")) + ) _state.update { it.copy(forceRedraw = !it.forceRedraw)} } @@ -148,7 +152,9 @@ class InternetPrivacyViewModel( } sealed class SingleEvent { - data class ErrorEvent(val error: Any) : SingleEvent() + data class ErrorEvent( + @StringRes val errorResId: Int, val args: List = emptyList() + ): SingleEvent() } sealed class Action { 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 ae169b4..69e520c 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 @@ -36,7 +36,6 @@ import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.common.NavToolbarFragment import foundation.e.privacycentralapp.common.initQuickPrivacySnackbar import foundation.e.privacycentralapp.databinding.ApptrackersFragmentBinding -import foundation.e.privacycentralapp.common.extensions.toText import kotlinx.coroutines.launch class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { @@ -110,7 +109,7 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { viewModel.singleEvents.collect { event -> when (event) { is AppTrackersViewModel.SingleEvent.ErrorEvent -> - displayToast(event.error.toText(requireContext())) + displayToast(getString(event.errorResId)) is AppTrackersViewModel.SingleEvent.OpenUrl -> try { startActivity(Intent(Intent.ACTION_VIEW, event.url)) 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 faa4e6b..4a81b2c 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 @@ -18,6 +18,7 @@ package foundation.e.privacycentralapp.features.trackers.apptrackers import android.net.Uri +import androidx.annotation.StringRes import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import foundation.e.privacycentralapp.domain.usecases.GetQuickPrivacyStateUseCase @@ -123,7 +124,7 @@ class AppTrackersViewModel( sealed class SingleEvent { - data class ErrorEvent(val error: Any) : SingleEvent() + data class ErrorEvent(@StringRes val errorResId: Int) : SingleEvent() data class OpenUrl(val url: Uri) : SingleEvent() } -- cgit v1.2.1 From 5f02fd142ca438a48423340aeb9a36b017a6be83 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Fri, 7 Oct 2022 08:45:15 +0200 Subject: Fix lint. --- .../e/privacycentralapp/DependencyContainer.kt | 26 +++--- .../privacycentralapp/PrivacyCentralApplication.kt | 2 - .../e/privacycentralapp/UpdateTrackersWorker.kt | 5 +- .../e/privacycentralapp/common/TextViewHelpers.kt | 2 +- .../domain/entities/TrackerMode.kt | 2 +- .../domain/usecases/FakeLocationStateUseCase.kt | 19 ++--- .../domain/usecases/GetQuickPrivacyStateUseCase.kt | 1 - .../domain/usecases/IpScramblingStateUseCase.kt | 7 +- .../domain/usecases/TrackersStateUseCase.kt | 7 +- .../domain/usecases/TrackersStatisticsUseCase.kt | 10 +-- .../features/dashboard/DashboardFragment.kt | 15 ++-- .../features/dashboard/DashboardState.kt | 2 +- .../features/dashboard/DashboardViewModel.kt | 21 +++-- .../internetprivacy/InternetPrivacyState.kt | 2 +- .../internetprivacy/InternetPrivacyViewModel.kt | 51 ++++++------ .../features/location/FakeLocationFragment.kt | 14 ++-- .../features/location/FakeLocationState.kt | 2 +- .../features/location/FakeLocationViewModel.kt | 28 ++++--- .../features/trackers/TrackersState.kt | 2 +- .../features/trackers/TrackersViewModel.kt | 8 +- .../trackers/apptrackers/AppTrackersFragment.kt | 4 +- .../trackers/apptrackers/AppTrackersState.kt | 9 ++- .../trackers/apptrackers/AppTrackersViewModel.kt | 93 +++++++++++++--------- .../e/privacycentralapp/main/MainActivity.kt | 1 - .../e/privacycentralapp/widget/Widget.kt | 1 - .../e/privacycentralapp/widget/WidgetUI.kt | 7 +- 26 files changed, 187 insertions(+), 154 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt index 2e24d4c..670b81e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/DependencyContainer.kt @@ -106,15 +106,17 @@ class DependencyContainer(val app: Application) { ) } - val viewModelsFactory by lazy { ViewModelsFactory( - getQuickPrivacyStateUseCase = getQuickPrivacyStateUseCase, - trackersStatisticsUseCase = trackersStatisticsUseCase, - trackersStateUseCase = trackersStateUseCase, - fakeLocationStateUseCase = fakeLocationStateUseCase, - ipScramblerModule = ipScramblerModule, - ipScramblingStateUseCase = ipScramblingStateUseCase, - appListUseCase = appListUseCase - ) } + val viewModelsFactory by lazy { + ViewModelsFactory( + getQuickPrivacyStateUseCase = getQuickPrivacyStateUseCase, + trackersStatisticsUseCase = trackersStatisticsUseCase, + trackersStateUseCase = trackersStateUseCase, + fakeLocationStateUseCase = fakeLocationStateUseCase, + ipScramblerModule = ipScramblerModule, + ipScramblingStateUseCase = ipScramblingStateUseCase, + appListUseCase = appListUseCase + ) + } // Background fun initBackgroundSingletons() { @@ -140,15 +142,15 @@ class ViewModelsFactory( private val ipScramblerModule: IIpScramblerModule, private val ipScramblingStateUseCase: IpScramblingStateUseCase, private val appListUseCase: AppListUseCase -): ViewModelProvider.Factory { +) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class, extras: CreationExtras): T { return when (modelClass) { AppTrackersViewModel::class.java -> { val fallbackUid = android.os.Process.myPid() - val appUid = extras[DEFAULT_ARGS_KEY]?. - getInt(AppTrackersFragment.PARAM_APP_UID, fallbackUid)?: fallbackUid + val appUid = extras[DEFAULT_ARGS_KEY] + ?.getInt(AppTrackersFragment.PARAM_APP_UID, fallbackUid) ?: fallbackUid AppTrackersViewModel( appUid = appUid, diff --git a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt index b23be3d..28e96e0 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/PrivacyCentralApplication.kt @@ -19,14 +19,12 @@ package foundation.e.privacycentralapp import android.app.Application import com.mapbox.mapboxsdk.Mapbox -import kotlinx.coroutines.FlowPreview class PrivacyCentralApplication : Application() { // Initialize the dependency container. val dependencyContainer: DependencyContainer by lazy { DependencyContainer(this) } - override fun onCreate() { super.onCreate() Mapbox.getTelemetry()?.setUserTelemetryRequestState(false) diff --git a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt index c83d8f9..13511da 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt @@ -45,8 +45,9 @@ class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) fun periodicUpdate(context: Context) { val request = PeriodicWorkRequestBuilder( - 7, TimeUnit.DAYS) - .setConstraints(constraints).build() + 7, TimeUnit.DAYS + ) + .setConstraints(constraints).build() WorkManager.getInstance(context).enqueueUniquePeriodicWork( UpdateTrackersWorker::class.qualifiedName ?: "", diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt index 25a3633..d85f4a7 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -60,4 +60,4 @@ private fun asteriskAsInfoIconSpannable( } } return spannable -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt index ae70ba3..9f057be 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/TrackerMode.kt @@ -19,4 +19,4 @@ package foundation.e.privacycentralapp.domain.entities enum class TrackerMode { DENIED, CUSTOM, VULNERABLE -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt index 1426891..e9da855 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt @@ -67,8 +67,8 @@ class FakeLocationStateUseCase( get() = appContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager private fun hasAcquireLocationPermission(): Boolean { - return (appContext.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) - || permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true) + return (appContext.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) || + permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true) } private fun applySettings(isQuickPrivacyEnabled: Boolean, fakeLocation: Pair?, isSpecificLocation: Boolean = false) { @@ -85,8 +85,8 @@ class FakeLocationStateUseCase( } private fun hasAcquireMockLocationPermission(): Boolean { - return (permissionsModule.getAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION) == AppOpModes.ALLOWED) - || permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION, AppOpModes.ALLOWED) + return (permissionsModule.getAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION) == AppOpModes.ALLOWED) || + permissionsModule.setAppOpMode(appDesc, AppOpsManager.OPSTR_MOCK_LOCATION, AppOpModes.ALLOWED) } fun setSpecificLocation(latitude: Float, longitude: Float) { @@ -140,7 +140,8 @@ class FakeLocationStateUseCase( override fun onLocationChanged(location: Location) { currentLocation.update { previous -> if ((previous?.time ?: 0) + 1800 < location.time || - (previous?.accuracy ?: Float.MAX_VALUE) > location.accuracy) { + (previous?.accuracy ?: Float.MAX_VALUE) > location.accuracy + ) { location } else { previous @@ -193,10 +194,10 @@ class FakeLocationStateUseCase( ) - locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)?: - locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)?.let { - localListener.onLocationChanged(it) - } + locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) + ?: locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)?.let { + localListener.onLocationChanged(it) + } } catch (se: SecurityException) { Log.e(TAG, "Missing permission", se) } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt index 688bdc4..46e054e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -108,5 +108,4 @@ class GetQuickPrivacyStateUseCase( } val otherVpnRunning: SharedFlow = localStateRepository.otherVpnRunning - } diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt index a0003eb..947e8e9 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt @@ -129,13 +129,13 @@ class IpScramblingStateUseCase( val mode = localStateRepository.internetPrivacyMode.value when { isQuickPrivacyEnabled && isIpScramblingEnabled && - mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> + mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> applyStartIpScrambling() mode in setOf(InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING) -> ipScramblerModule.stop() else -> {} - } + } } private fun applyStartIpScrambling() { @@ -149,8 +149,7 @@ class IpScramblingStateUseCase( ) } localStateRepository.setIpScramblingSetting(enabled = false) - - }?: run { + } ?: run { ipScramblerModule.start(enableNotification = false) } } 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 10c1ad0..17e5096 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 @@ -20,7 +20,6 @@ package foundation.e.privacycentralapp.domain.usecases import foundation.e.privacycentralapp.data.repositories.AppListsRepository 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.api.IBlockTrackersPrivacyModule import foundation.e.privacymodules.trackers.api.ITrackTrackersPrivacyModule @@ -63,8 +62,9 @@ class TrackersStateUseCase( return appListsRepository.getApplicationDescription(appUid) } - fun isWhitelisted(appUid: Int) - = isWhitelisted(appUid, appListsRepository, blockTrackersPrivacyModule) + fun isWhitelisted(appUid: Int): Boolean { + return isWhitelisted(appUid, appListsRepository, blockTrackersPrivacyModule) + } fun getTrackersWhitelistIds(appUid: Int): List { return if (appUid == appListsRepository.dummySystemApp.uid) { @@ -108,7 +108,6 @@ class TrackersStateUseCase( } } - fun isWhitelisted( appUid: Int, appListsRepository: AppListsRepository, 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 0a47bc5..57ab1a4 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 @@ -166,17 +166,15 @@ class TrackersStatisticsUseCase( 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 }} + return trackers.sortedBy { it.label.lowercase() }.map { tracker -> tracker to whiteListedTrackersIds.any { tracker.id == it } } } - fun getCalls(appUid: Int): Pair { return if (appUid == appListsRepository.dummySystemApp.uid) { appListsRepository.getHiddenSystemApps().map { @@ -211,10 +209,12 @@ class TrackersStatisticsUseCase( blockTrackersPrivacyModule.getWhiteList(app.uid).size }, blockedLeaks = appListsRepository.foldForHiddenSystemApp(app.uid) { - appUid -> callsByApp.getOrDefault(appUid, 0 to 0).first + appUid -> + callsByApp.getOrDefault(appUid, 0 to 0).first }, leaks = appListsRepository.foldForHiddenSystemApp(app.uid) { - appUid -> callsByApp.getOrDefault(appUid, 0 to 0).second + appUid -> + callsByApp.getOrDefault(appUid, 0 to 0).second } ) }.sortedWith(mostLeakedAppsComparator) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index 21950a4..6cd259e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -163,7 +163,8 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { } } is SingleEvent.ToastMessageSingleEvent -> - Toast.makeText(requireContext(), + Toast.makeText( + requireContext(), getString(event.message, *event.args.toTypedArray()), Toast.LENGTH_LONG ).show() @@ -202,11 +203,13 @@ class DashboardFragment : NavToolbarFragment(R.layout.fragment_dashboard) { binding.togglePrivacyCentral.isChecked = state.quickPrivacyState.isEnabled() - binding.stateTrackers.text = getString(when(state.trackerMode) { - TrackerMode.DENIED -> R.string.dashboard_state_trackers_on - TrackerMode.VULNERABLE -> R.string.dashboard_state_trackers_off - TrackerMode.CUSTOM -> R.string.dashboard_state_trackers_custom - }) + binding.stateTrackers.text = getString( + when (state.trackerMode) { + TrackerMode.DENIED -> R.string.dashboard_state_trackers_on + TrackerMode.VULNERABLE -> R.string.dashboard_state_trackers_off + TrackerMode.CUSTOM -> R.string.dashboard_state_trackers_custom + } + ) binding.stateTrackers.setTextColor( getColor( requireContext(), diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt index fb00f07..04b7ae8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardState.kt @@ -33,4 +33,4 @@ data class DashboardState( val dayStatistics: List>? = null, val dayLabels: List? = null, val showQuickPrivacyDisabledMessage: Boolean = false -) \ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt index a2fca86..d7d74c6 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt @@ -77,10 +77,12 @@ class DashboardViewModel( _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, getPrivacyStateUseCase.otherVpnRunning.map { - _singleEvents.emit(SingleEvent.ToastMessageSingleEvent( - R.string.ipscrambling_error_always_on_vpn_already_running, - listOf(it.label?: "") - )) + _singleEvents.emit( + SingleEvent.ToastMessageSingleEvent( + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label ?: "") + ) + ) } ).collect {} } @@ -122,9 +124,11 @@ class DashboardViewModel( val isFirstActivation = getPrivacyStateUseCase.toggleReturnIsFirstActivation() fetchStatistics().first() - if (isFirstActivation) _singleEvents.emit(SingleEvent.ToastMessageSingleEvent( - message = R.string.dashboard_first_ipscrambling_activation - )) + if (isFirstActivation) _singleEvents.emit( + SingleEvent.ToastMessageSingleEvent( + message = R.string.dashboard_first_ipscrambling_activation + ) + ) } private suspend fun actionShowMostLeakedApp() = withContext(Dispatchers.IO) { @@ -142,7 +146,8 @@ class DashboardViewModel( object NavigateToPermissionsSingleEvent : SingleEvent() data class NavigateToAppDetailsEvent(val appDesc: ApplicationDescription) : SingleEvent() data class ToastMessageSingleEvent( - @StringRes val message: Int, val args: List = emptyList() + @StringRes val message: Int, + val args: List = emptyList() ) : SingleEvent() } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt index 25e911f..6991196 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyState.kt @@ -34,4 +34,4 @@ data class InternetPrivacyState( } val selectedLocationPosition get() = availableLocationIds.indexOf(selectedLocation) -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt index 8bdb16e..be6cd4d 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt @@ -55,20 +55,20 @@ class InternetPrivacyViewModel( private val _singleEvents = MutableSharedFlow() val singleEvents = _singleEvents.asSharedFlow() - - val availablesLocationsIds = listOf("", *ipScramblerModule.getAvailablesLocations().sorted().toTypedArray()) init { viewModelScope.launch(Dispatchers.IO) { - _state.update { it.copy( - mode = ipScramblingStateUseCase.internetPrivacyMode.value, - availableLocationIds = availablesLocationsIds, - selectedLocation = ipScramblerModule.exitCountry) } + _state.update { + it.copy( + mode = ipScramblingStateUseCase.internetPrivacyMode.value, + availableLocationIds = availablesLocationsIds, + selectedLocation = ipScramblerModule.exitCountry + ) + } } } - @OptIn(FlowPreview::class) suspend fun doOnStartedState() = withContext(Dispatchers.IO) { launch { @@ -77,23 +77,26 @@ class InternetPrivacyViewModel( _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, appListUseCase.getAppsUsingInternet().map { apps -> - _state.update { s -> s.copy( - availableApps = apps, - bypassTorApps = ipScramblingStateUseCase.bypassTorApps - ) } + _state.update { s -> + s.copy( + availableApps = apps, + bypassTorApps = ipScramblingStateUseCase.bypassTorApps + ) + } }, if (getQuickPrivacyStateUseCase.isQuickPrivacyEnabled) ipScramblingStateUseCase.internetPrivacyMode.map { _state.update { s -> s.copy(mode = it) } } else ipScramblingStateUseCase.configuredMode.map { - _state.update { s -> s.copy( - mode = if (it) InternetPrivacyMode.HIDE_IP - else InternetPrivacyMode.REAL_IP - ) } + _state.update { s -> + s.copy( + mode = if (it) InternetPrivacyMode.HIDE_IP + else InternetPrivacyMode.REAL_IP + ) + } } ).collect {} - } launch { @@ -109,12 +112,13 @@ class InternetPrivacyViewModel( launch { getQuickPrivacyStateUseCase.otherVpnRunning.collect { - _singleEvents.emit(SingleEvent.ErrorEvent( - R.string.ipscrambling_error_always_on_vpn_already_running, - listOf(it.label?: "")) + _singleEvents.emit( + SingleEvent.ErrorEvent( + R.string.ipscrambling_error_always_on_vpn_already_running, + listOf(it.label ?: "") + ) ) - _state.update { it.copy(forceRedraw = !it.forceRedraw)} - + _state.update { it.copy(forceRedraw = !it.forceRedraw) } } } } @@ -153,8 +157,9 @@ class InternetPrivacyViewModel( sealed class SingleEvent { data class ErrorEvent( - @StringRes val errorResId: Int, val args: List = emptyList() - ): SingleEvent() + @StringRes val errorResId: Int, + val args: List = emptyList() + ) : SingleEvent() } sealed class Action { diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt index 2e014e2..537d0b6 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt @@ -86,8 +86,8 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) private val locationPermissionRequest = registerForActivityResult( ActivityResultContracts.RequestMultiplePermissions() ) { permissions -> - if (permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) - || permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) + if (permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) || + permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) ) { viewModel.submitAction(Action.StartListeningLocation) } // TODO: else. @@ -167,10 +167,12 @@ class FakeLocationFragment : NavToolbarFragment(R.layout.fragment_fake_location) } is FakeLocationViewModel.SingleEvent.RequestLocationPermission -> { // TODO for standalone: rationale dialog - locationPermissionRequest.launch(arrayOf( - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION - )) + locationPermissionRequest.launch( + arrayOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + ) } is FakeLocationViewModel.SingleEvent.LocationUpdatedEvent -> { // Nothing here, another collect linked to mapbox view. diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt index c7bcd98..9513f77 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationState.kt @@ -27,4 +27,4 @@ data class FakeLocationState( val specificLongitude: Float? = null, val forceRefresh: Boolean = false, val showQuickPrivacyDisabledMessage: Boolean = false -) \ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt index afba3d0..8db3537 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationViewModel.kt @@ -58,28 +58,32 @@ class FakeLocationViewModel( launch { merge( fakeLocationStateUseCase.configuredLocationMode.map { (mode, lat, lon) -> - _state.update { s -> s.copy( - mode = mode, - specificLatitude = lat, - specificLongitude = lon - ) } + _state.update { s -> + s.copy( + mode = mode, + specificLatitude = lat, + specificLongitude = lon + ) + } }, getQuickPrivacyStateUseCase.showQuickPrivacyDisabledMessage.map { _state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) } }, specificLocationInputFlow .debounce(SET_SPECIFIC_LOCATION_DELAY).map { action -> - fakeLocationStateUseCase.setSpecificLocation(action.latitude, action.longitude) - } + fakeLocationStateUseCase.setSpecificLocation(action.latitude, action.longitude) + } ).collect {} } launch { fakeLocationStateUseCase.currentLocation.collect { location -> - _singleEvents.emit(SingleEvent.LocationUpdatedEvent( - mode = _state.value.mode, - location = location - )) + _singleEvents.emit( + SingleEvent.LocationUpdatedEvent( + mode = _state.value.mode, + location = location + ) + ) } } } @@ -110,7 +114,7 @@ class FakeLocationViewModel( sealed class SingleEvent { data class LocationUpdatedEvent(val mode: LocationMode, val location: Location?) : SingleEvent() - object RequestLocationPermission: SingleEvent() + object RequestLocationPermission : SingleEvent() data class ErrorEvent(val error: String) : SingleEvent() } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt index f51ff18..2437366 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersState.kt @@ -26,4 +26,4 @@ data class TrackersState( val yearStatistics: TrackersPeriodicStatistics? = null, val apps: List? = null, val showQuickPrivacyDisabledMessage: Boolean = false -) \ No newline at end of file +) diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt index f49152e..3869c39 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersViewModel.kt @@ -52,11 +52,13 @@ class TrackersViewModel( trackersStatisticsUseCase.listenUpdates().map { trackersStatisticsUseCase.getDayMonthYearStatistics() .let { (day, month, year) -> - _state.update { s -> s.copy( + _state.update { s -> + s.copy( dayStatistics = day, monthStatistics = month, yearStatistics = year - ) } + ) + } } }, trackersStatisticsUseCase.getAppsWithCounts().map { @@ -74,7 +76,7 @@ class TrackersViewModel( } } - suspend private fun actionClickApp(action: Action.ClickAppAction) { + private suspend fun actionClickApp(action: Action.ClickAppAction) { state.value.apps?.find { it.packageName == action.packageName }?.let { _singleEvents.emit(SingleEvent.OpenAppDetailsEvent(it)) } 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 69e520c..cd4f6b2 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 @@ -68,7 +68,8 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (arguments == null || - requireArguments().getInt(PARAM_APP_UID, Int.MIN_VALUE) == Int.MIN_VALUE) { + requireArguments().getInt(PARAM_APP_UID, Int.MIN_VALUE) == Int.MIN_VALUE + ) { activity?.supportFragmentManager?.popBackStack() } } @@ -150,7 +151,6 @@ class AppTrackersFragment : NavToolbarFragment(R.layout.apptrackers_fragment) { binding.blockAllToggle.isChecked = state.isBlockingActivated - val trackersStatus = state.getTrackersStatus() if (!trackersStatus.isNullOrEmpty()) { binding.trackersListTitle.isVisible = state.isBlockingActivated 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 ffa1f36..d6d0858 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 @@ -29,11 +29,12 @@ data class AppTrackersState( val isQuickPrivacyEnabled: Boolean = false, val showQuickPrivacyDisabledMessage: Boolean = false, ) { - fun getTrackersStatus(): List>? - = trackersWithWhiteList?.map { it.first to !it.second } + fun getTrackersStatus(): List>? { + return trackersWithWhiteList?.map { it.first to !it.second } + } fun getTrackersCount() = trackersWithWhiteList?.size ?: 0 fun getBlockedTrackersCount(): Int = if (isQuickPrivacyEnabled && isBlockingActivated) - trackersWithWhiteList?.count { !it.second }?: 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 4a81b2c..52ef2c4 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,11 +54,13 @@ class AppTrackersViewModel( init { viewModelScope.launch(Dispatchers.IO) { - _state.update { it.copy( - appDesc = trackersStateUseCase.getApplicationDescription(appUid), - isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), - ) } + _state.update { + it.copy( + appDesc = trackersStateUseCase.getApplicationDescription(appUid), + isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid), + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), + ) + } } } @@ -75,54 +77,67 @@ class AppTrackersViewModel( } fun submitAction(action: Action) = viewModelScope.launch { - when (action) { - is Action.BlockAllToggleAction -> blockAllToggleAction(action) - is Action.ToggleTrackerAction -> toggleTrackerAction(action) - is Action.ClickTracker ->actionClickTracker(action) - is Action.CloseQuickPrivacyDisabledMessage -> - getQuickPrivacyStateUseCase.resetQuickPrivacyDisabledMessage() - } + when (action) { + is Action.BlockAllToggleAction -> blockAllToggleAction(action) + is Action.ToggleTrackerAction -> toggleTrackerAction(action) + is Action.ClickTracker -> actionClickTracker(action) + is Action.CloseQuickPrivacyDisabledMessage -> + getQuickPrivacyStateUseCase.resetQuickPrivacyDisabledMessage() + } } - private suspend fun blockAllToggleAction(action: Action.BlockAllToggleAction) - = withContext(Dispatchers.IO) { - trackersStateUseCase.toggleAppWhitelist(appUid, !action.isBlocked) - _state.update { it.copy( - isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid) - ) } + private suspend fun blockAllToggleAction(action: Action.BlockAllToggleAction) { + withContext(Dispatchers.IO) { + trackersStateUseCase.toggleAppWhitelist(appUid, !action.isBlocked) + _state.update { + it.copy( + isBlockingActivated = !trackersStateUseCase.isWhitelisted(appUid) + ) + } + } } - private suspend fun toggleTrackerAction(action: Action.ToggleTrackerAction) - = withContext(Dispatchers.IO) { - if (state.value.isBlockingActivated) { - trackersStateUseCase.blockTracker(appUid, action.tracker, action.isBlocked) - _state.update { it.copy( - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid) - ) } + private suspend fun toggleTrackerAction(action: Action.ToggleTrackerAction) { + withContext(Dispatchers.IO) { + if (state.value.isBlockingActivated) { + trackersStateUseCase.blockTracker(appUid, action.tracker, action.isBlocked) + _state.update { + it.copy( + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList( + appUid + ) + ) + } + } } } - private suspend fun actionClickTracker(action: Action.ClickTracker) - = withContext(Dispatchers.IO) { - action.tracker.exodusId?.let { - try { - _singleEvents.emit(SingleEvent.OpenUrl( - Uri.parse(exodusBaseUrl + it) - )) - } catch (e: Exception) {} + private suspend fun actionClickTracker(action: Action.ClickTracker) { + withContext(Dispatchers.IO) { + action.tracker.exodusId?.let { + try { + _singleEvents.emit( + SingleEvent.OpenUrl( + Uri.parse(exodusBaseUrl + it) + ) + ) + } catch (e: Exception) { + } + } } } private fun fetchStatistics() { val (blocked, leaked) = trackersStatisticsUseCase.getCalls(appUid) - return _state.update { s -> s.copy( - trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), - leaked = leaked, - blocked = blocked, - ) } + return _state.update { s -> + s.copy( + trackersWithWhiteList = trackersStatisticsUseCase.getTrackersWithWhiteList(appUid), + leaked = leaked, + blocked = blocked, + ) + } } - sealed class SingleEvent { data class ErrorEvent(@StringRes val errorResId: Int) : SingleEvent() data class OpenUrl(val url: Uri) : SingleEvent() diff --git a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt index 63ec27f..58ac797 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/main/MainActivity.kt @@ -28,7 +28,6 @@ import foundation.e.privacycentralapp.PrivacyCentralApplication import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.features.dashboard.DashboardFragment import foundation.e.privacycentralapp.features.trackers.TrackersFragment -import kotlinx.coroutines.FlowPreview open class MainActivity : FragmentActivity(R.layout.activity_main) { override fun onPostCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt index e886cd8..ddfcc2e 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/Widget.kt @@ -141,7 +141,6 @@ class Widget : AppWidgetProvider() { } } - override fun onAppWidgetOptionsChanged( context: Context, appWidgetManager: AppWidgetManager, diff --git a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt index 27589a8..682e5cc 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/widget/WidgetUI.kt @@ -29,8 +29,8 @@ import android.widget.RemoteViews import foundation.e.privacycentralapp.R import foundation.e.privacycentralapp.Widget import foundation.e.privacycentralapp.Widget.Companion.isDarkText -import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.common.extensions.dpToPxF +import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState import foundation.e.privacycentralapp.domain.entities.TrackerMode import foundation.e.privacycentralapp.main.MainActivity import foundation.e.privacycentralapp.widget.WidgetCommandReceiver.Companion.ACTION_TOGGLE_PRIVACY @@ -44,7 +44,6 @@ data class State( val activeTrackersCount: Int = 0, ) - fun render( context: Context, state: State, @@ -93,7 +92,7 @@ fun render( setTextViewText( R.id.state_trackers, context.getString( - when(state.trackerMode) { + when (state.trackerMode) { TrackerMode.DENIED -> R.string.widget_state_trackers_on TrackerMode.VULNERABLE -> R.string.widget_state_trackers_off TrackerMode.CUSTOM -> R.string.widget_state_trackers_custom @@ -277,7 +276,7 @@ fun applyDarkText(context: Context, state: State, views: RemoteViews) { R.id.graph_legend_blocked, R.id.graph_legend_allowed, - ) + ) .forEach { setTextColor( it, -- cgit v1.2.1 From fdeecefd34c00b225bd58f6cc7135a95e21728f1 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Fri, 14 Oct 2022 10:25:52 +0200 Subject: PR suggestions, make apply Hide Ip clearer --- .../domain/usecases/IpScramblingStateUseCase.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt index 947e8e9..cb9fcd5 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt @@ -20,6 +20,10 @@ package foundation.e.privacycentralapp.domain.usecases import foundation.e.privacycentralapp.data.repositories.AppListsRepository import foundation.e.privacycentralapp.data.repositories.LocalStateRepository import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode +import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode.HIDE_IP +import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode.HIDE_IP_LOADING +import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode.REAL_IP +import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode.REAL_IP_LOADING import foundation.e.privacymodules.ipscramblermodule.IIpScramblerModule import foundation.e.privacymodules.permissions.IPermissionsPrivacyModule import foundation.e.privacymodules.permissions.data.ApplicationDescription @@ -126,14 +130,16 @@ class IpScramblingStateUseCase( } private fun applySettings(isQuickPrivacyEnabled: Boolean, isIpScramblingEnabled: Boolean) { - val mode = localStateRepository.internetPrivacyMode.value + val settingEnabled = isQuickPrivacyEnabled && isIpScramblingEnabled + val currentMode = localStateRepository.internetPrivacyMode.value + when { - isQuickPrivacyEnabled && isIpScramblingEnabled && - mode in setOf(InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING) -> + settingEnabled && currentMode in setOf(REAL_IP, REAL_IP_LOADING) -> applyStartIpScrambling() - mode in setOf(InternetPrivacyMode.HIDE_IP, InternetPrivacyMode.HIDE_IP_LOADING) -> + !settingEnabled && currentMode in setOf(HIDE_IP, HIDE_IP_LOADING) -> ipScramblerModule.stop() + else -> {} } } -- cgit v1.2.1