summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt22
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt6
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt24
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt5
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt12
-rw-r--r--app/src/main/res/values/strings.xml1
6 files changed, 53 insertions, 17 deletions
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 af8646a..672f260 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,9 +20,12 @@ 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 kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.flow.update
class LocalStateRepository(context: Context) {
companion object {
@@ -48,6 +51,13 @@ class LocalStateRepository(context: Context) {
return isFirstActivation
}
+ private val _otherVpnRunning = MutableSharedFlow<Boolean>()
+ suspend fun emitOtherVpnRunning() {
+ _otherVpnRunning.emit(true)
+ }
+
+ val otherVpnRunning: SharedFlow<Boolean> = _otherVpnRunning
+
var quickPrivacyEnabledFlow: StateFlow<Boolean> = quickPrivacyEnabledMutableFlow
val areAllTrackersBlocked: MutableStateFlow<Boolean> = MutableStateFlow(false)
@@ -79,9 +89,13 @@ class LocalStateRepository(context: Context) {
val locationMode: MutableStateFlow<LocationMode> = MutableStateFlow(LocationMode.REAL_LOCATION)
- var isIpScramblingEnabled: Boolean
- get() = sharedPref.getBoolean(KEY_IP_SCRAMBLING, true)
- set(value) = set(KEY_IP_SCRAMBLING, value)
+ private val _ipScramblingSetting = MutableStateFlow(sharedPref.getBoolean(KEY_IP_SCRAMBLING, true))
+ val ipScramblingSetting = _ipScramblingSetting.asStateFlow()
+
+ fun setIpScramblingSetting(enabled: Boolean) {
+ set(KEY_IP_SCRAMBLING, enabled)
+ _ipScramblingSetting.update { enabled }
+ }
val internetPrivacyMode: MutableStateFlow<InternetPrivacyMode> = MutableStateFlow(InternetPrivacyMode.REAL_IP)
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 a9c608e..e1f773f 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
@@ -17,7 +17,6 @@
package foundation.e.privacycentralapp.domain.usecases
-import android.util.Log
import foundation.e.privacycentralapp.data.repositories.LocalStateRepository
import foundation.e.privacycentralapp.domain.entities.InternetPrivacyMode
import foundation.e.privacycentralapp.domain.entities.LocationMode
@@ -25,8 +24,8 @@ import foundation.e.privacycentralapp.domain.entities.QuickPrivacyState
import foundation.e.privacycentralapp.domain.entities.TrackerMode
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
@@ -106,4 +105,7 @@ class GetQuickPrivacyStateUseCase(
fun resetQuickPrivacyDisabledMessage() {
localStateRepository.setShowQuickPrivacyDisabledMessage(false)
}
+
+ val otherVpnRunning: SharedFlow<Boolean> = 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 c7c434c..3320721 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
@@ -25,7 +25,6 @@ import foundation.e.privacymodules.permissions.IPermissionsPrivacyModule
import foundation.e.privacymodules.permissions.data.ApplicationDescription
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
-import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
@@ -38,11 +37,10 @@ class IpScramblingStateUseCase(
private val appDesc: ApplicationDescription,
private val localStateRepository: LocalStateRepository,
private val appListsRepository: AppListsRepository,
- coroutineScope: CoroutineScope
+ private val coroutineScope: CoroutineScope
) {
- val _configuredMode = MutableStateFlow(localStateRepository.isIpScramblingEnabled)
- val configuredMode: StateFlow<Boolean> = _configuredMode
+ val configuredMode: StateFlow<Boolean> = localStateRepository.ipScramblingSetting
val internetPrivacyMode: StateFlow<InternetPrivacyMode> = callbackFlow {
val listener = object : IIpScramblerModule.Listener {
@@ -71,7 +69,7 @@ class IpScramblingStateUseCase(
init {
coroutineScope.launch {
localStateRepository.quickPrivacyEnabledFlow.collect {
- applySettings(it, localStateRepository.isIpScramblingEnabled)
+ applySettings(it, localStateRepository.ipScramblingSetting.value)
}
}
@@ -81,8 +79,7 @@ class IpScramblingStateUseCase(
}
fun toggle(hideIp: Boolean) {
- localStateRepository.isIpScramblingEnabled = hideIp
- _configuredMode.value = hideIp
+ localStateRepository.setIpScramblingSetting(enabled = hideIp)
if (!localStateRepository.isQuickPrivacyEnabled) {
localStateRepository.setShowQuickPrivacyDisabledMessage(true)
@@ -132,11 +129,20 @@ class IpScramblingStateUseCase(
when {
isQuickPrivacyEnabled && isIpScramblingEnabled -> when (localStateRepository.internetPrivacyMode.value) {
InternetPrivacyMode.REAL_IP, InternetPrivacyMode.REAL_IP_LOADING -> {
- val intent = ipScramblerModule.prepareAndroidVpn()
+ 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)
}
- ipScramblerModule.start(enableNotification = false)
}
else -> {}
}
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 0ddceb1..cd7e414 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
@@ -74,6 +74,11 @@ class DashboardViewModel(
},
getPrivacyStateUseCase.showQuickPrivacyDisabledMessage.map {
_state.update { s -> s.copy(showQuickPrivacyDisabledMessage = it) }
+ },
+ getPrivacyStateUseCase.otherVpnRunning.map {
+ _singleEvents.emit(SingleEvent.ToastMessageSingleEvent(
+ R.string.ipscrambling_error_always_on_vpn_already_running
+ ))
}
).collect {}
}
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 6d083bd..ab5e24d 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
@@ -105,6 +105,14 @@ class InternetPrivacyViewModel(
)
}
}
+
+ launch {
+ getQuickPrivacyStateUseCase.otherVpnRunning.collect {
+ _singleEvents.emit(SingleEvent.ErrorEvent(R.string.ipscrambling_error_always_on_vpn_already_running))
+ _state.update { it.copy(forceRedraw = !it.forceRedraw)}
+
+ }
+ }
}
fun submitAction(action: Action) = viewModelScope.launch {
@@ -126,12 +134,12 @@ class InternetPrivacyViewModel(
ipScramblingStateUseCase.toggle(hideIp = true)
}
- suspend private fun actionToggleAppIpScrambled(action: Action.ToggleAppIpScrambled) = withContext(Dispatchers.IO) {
+ private suspend fun actionToggleAppIpScrambled(action: Action.ToggleAppIpScrambled) = withContext(Dispatchers.IO) {
ipScramblingStateUseCase.toggleBypassTor(action.packageName)
_state.update { it.copy(bypassTorApps = ipScramblingStateUseCase.bypassTorApps) }
}
- suspend private fun actionSelectLocation(action: Action.SelectLocationAction) = withContext(Dispatchers.IO) {
+ private suspend fun actionSelectLocation(action: Action.SelectLocationAction) = withContext(Dispatchers.IO) {
val locationId = _state.value.availableLocationIds[action.position]
if (locationId != ipScramblerModule.exitCountry) {
ipScramblerModule.exitCountry = locationId
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 79b2a98..79272ae 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -54,6 +54,7 @@
<string name="ipscrambling_select_app">Apply this setting to all selected applications * :</string>
<string name="ipscrambling_app_list_infos">Only apps with internet permission are listed.</string>
<string name="ipscrambling_error_quickprivacy_disabled">Enabled Quick Privacy to use functionalities</string>
+ <string name="ipscrambling_error_always_on_vpn_already_running">Please disable any 3rd-party VPN in order for Advanced Privacy to hide your real IP address.</string>
<string name="ipscrambling_warning_starting_long">Our scrambling IP service is taking time to launch. It can take a few minutes. Leaving the screen won\'t interrupt the process.</string>
<!-- Location -->
<string name="location_title">Manage my location</string>