summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com>2022-10-04 08:34:34 +0200
committerGuillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com>2022-10-26 14:01:43 +0200
commitf8d19823ea9be0c8700a69a215fac7d3af4d6d87 (patch)
tree1a6cf3ef0903dfd52bd40db55cebfa19e046fbd9 /app/src/main/java
parent7c41d557a3523abc202b0d0a09835f79a85c1947 (diff)
5561: display name of other VPNrunning always on.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/common/extensions/AnyExtension.kt6
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt9
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt3
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt44
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt6
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardViewModel.kt8
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt3
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyViewModel.kt10
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt3
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersViewModel.kt3
10 files changed, 52 insertions, 43 deletions
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<Boolean>()
- suspend fun emitOtherVpnRunning() {
- _otherVpnRunning.emit(true)
+ private val _otherVpnRunning = MutableSharedFlow<ApplicationDescription>()
+ suspend fun emitOtherVpnRunning(appDesc: ApplicationDescription) {
+ _otherVpnRunning.emit(appDesc)
}
- val otherVpnRunning: SharedFlow<Boolean> = _otherVpnRunning
+ val otherVpnRunning: SharedFlow<ApplicationDescription> = _otherVpnRunning
var quickPrivacyEnabledFlow: StateFlow<Boolean> = 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<Boolean> = localStateRepository.otherVpnRunning
+ val otherVpnRunning: SharedFlow<ApplicationDescription> = 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<Any> = 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<Any> = 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()
}