aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/foundation/e/privacycentralapp/domain
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/domain')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/entities/InternetPrivacyMode.kt6
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/FakeLocationStateUseCase.kt41
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/GetQuickPrivacyStateUseCase.kt71
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/IpScramblingStateUseCase.kt35
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/domain/usecases/TrackersStateUseCase.kt9
5 files changed, 63 insertions, 99 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/InternetPrivacyMode.kt b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/InternetPrivacyMode.kt
index 534bb2f..f849d57 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/domain/entities/InternetPrivacyMode.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/domain/entities/InternetPrivacyMode.kt
@@ -21,5 +21,9 @@ enum class InternetPrivacyMode {
REAL_IP,
HIDE_IP,
HIDE_IP_LOADING,
- REAL_IP_LOADING
+ REAL_IP_LOADING;
+
+ val isChecked get() = this == HIDE_IP || this == HIDE_IP_LOADING
+
+ val isLoading get() = this == HIDE_IP_LOADING || this == REAL_IP_LOADING
}
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 e9da855..2910f26 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
@@ -57,7 +57,7 @@ class FakeLocationStateUseCase(
init {
coroutineScope.launch {
- localStateRepository.quickPrivacyEnabledFlow.collect {
+ localStateRepository.fakeLocationEnabled.collect {
applySettings(it, localStateRepository.fakeLocation)
}
}
@@ -71,10 +71,10 @@ class FakeLocationStateUseCase(
permissionsModule.toggleDangerousPermission(appDesc, android.Manifest.permission.ACCESS_FINE_LOCATION, true)
}
- private fun applySettings(isQuickPrivacyEnabled: Boolean, fakeLocation: Pair<Float, Float>?, isSpecificLocation: Boolean = false) {
- _configuredLocationMode.value = computeLocationMode(fakeLocation, isSpecificLocation)
+ private fun applySettings(isEnabled: Boolean, fakeLocation: Pair<Float, Float>, isSpecificLocation: Boolean = false) {
+ _configuredLocationMode.value = computeLocationMode(isEnabled, fakeLocation, isSpecificLocation)
- if (isQuickPrivacyEnabled && fakeLocation != null && hasAcquireMockLocationPermission()) {
+ if (isEnabled && hasAcquireMockLocationPermission()) {
fakeLocationModule.startFakeLocation()
fakeLocationModule.setFakeLocation(fakeLocation.first.toDouble(), fakeLocation.second.toDouble())
localStateRepository.locationMode.value = configuredLocationMode.value.first
@@ -90,18 +90,10 @@ class FakeLocationStateUseCase(
}
fun setSpecificLocation(latitude: Float, longitude: Float) {
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- }
-
setFakeLocation(latitude to longitude, true)
}
fun setRandomLocation() {
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- }
-
val randomIndex = Random.nextInt(citiesRepository.citiesLocationsList.size)
val location = citiesRepository.citiesLocationsList[randomIndex]
@@ -110,26 +102,29 @@ class FakeLocationStateUseCase(
private fun setFakeLocation(location: Pair<Float, Float>, isSpecificLocation: Boolean = false) {
localStateRepository.fakeLocation = location
- applySettings(localStateRepository.isQuickPrivacyEnabled, location, isSpecificLocation)
+ localStateRepository.setFakeLocationEnabled(true)
+ applySettings(true, location, isSpecificLocation)
}
fun stopFakeLocation() {
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- }
-
- localStateRepository.fakeLocation = null
- applySettings(localStateRepository.isQuickPrivacyEnabled, null)
+ localStateRepository.setFakeLocationEnabled(false)
+ applySettings(false, localStateRepository.fakeLocation)
}
- private fun computeLocationMode(fakeLocation: Pair<Float, Float>?, isSpecificLocation: Boolean = false): Triple<LocationMode, Float?, Float?> {
+ private fun computeLocationMode(
+ isFakeLocationEnabled: Boolean,
+ fakeLocation: Pair<Float, Float>,
+ isSpecificLocation: Boolean = false,
+ ): Triple<LocationMode, Float?, Float?> {
return Triple(
when {
- fakeLocation == null -> LocationMode.REAL_LOCATION
- fakeLocation in citiesRepository.citiesLocationsList && !isSpecificLocation -> LocationMode.RANDOM_LOCATION
+ !isFakeLocationEnabled -> LocationMode.REAL_LOCATION
+ (fakeLocation in citiesRepository.citiesLocationsList && !isSpecificLocation) ->
+ LocationMode.RANDOM_LOCATION
else -> LocationMode.SPECIFIC_LOCATION
},
- fakeLocation?.first, fakeLocation?.second
+ fakeLocation.first,
+ fakeLocation.second
)
}
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 46e054e..85410d0 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
@@ -23,88 +23,69 @@ 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
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
-import kotlinx.coroutines.launch
+import kotlinx.coroutines.flow.map
class GetQuickPrivacyStateUseCase(
- private val localStateRepository: LocalStateRepository,
- coroutineScope: CoroutineScope
+ private val localStateRepository: LocalStateRepository
) {
-
- init {
- coroutineScope.launch {
- localStateRepository.quickPrivacyEnabledFlow.collect {
- if (it) resetQuickPrivacyDisabledMessage()
- }
- }
- }
-
- val quickPrivacyEnabledFlow: Flow<Boolean> = localStateRepository.quickPrivacyEnabledFlow
-
- val isQuickPrivacyEnabled: Boolean get() = localStateRepository.isQuickPrivacyEnabled
-
val quickPrivacyState: Flow<QuickPrivacyState> = combine(
- localStateRepository.quickPrivacyEnabledFlow,
+ localStateRepository.blockTrackers,
localStateRepository.areAllTrackersBlocked,
localStateRepository.locationMode,
localStateRepository.internetPrivacyMode
- ) { isQuickPrivacyEnabled, isAllTrackersBlocked, locationMode, internetPrivacyMode ->
+ ) { isBlockTrackers, isAllTrackersBlocked, locationMode, internetPrivacyMode ->
when {
- !isQuickPrivacyEnabled -> QuickPrivacyState.DISABLED
+ !isBlockTrackers &&
+ locationMode == LocationMode.REAL_LOCATION &&
+ internetPrivacyMode == InternetPrivacyMode.REAL_IP -> QuickPrivacyState.DISABLED
+
isAllTrackersBlocked &&
locationMode != LocationMode.REAL_LOCATION &&
internetPrivacyMode in listOf(
InternetPrivacyMode.HIDE_IP,
InternetPrivacyMode.HIDE_IP_LOADING
) -> QuickPrivacyState.FULL_ENABLED
+
else -> QuickPrivacyState.ENABLED
}
}
val trackerMode: Flow<TrackerMode> = combine(
- localStateRepository.quickPrivacyEnabledFlow,
+ localStateRepository.blockTrackers,
localStateRepository.areAllTrackersBlocked
- ) { isQuickPrivacyEnabled, isAllTrackersBlocked ->
+ ) { isBlockTrackers, isAllTrackersBlocked ->
when {
- isQuickPrivacyEnabled && isAllTrackersBlocked -> TrackerMode.DENIED
- isQuickPrivacyEnabled && !isAllTrackersBlocked -> TrackerMode.CUSTOM
+ isBlockTrackers && isAllTrackersBlocked -> TrackerMode.DENIED
+ isBlockTrackers && !isAllTrackersBlocked -> TrackerMode.CUSTOM
else -> TrackerMode.VULNERABLE
}
}
- val isLocationHidden: Flow<Boolean> = combine(
- localStateRepository.quickPrivacyEnabledFlow,
- localStateRepository.locationMode
- ) { isQuickPrivacyEnabled, locationMode ->
- isQuickPrivacyEnabled && locationMode != LocationMode.REAL_LOCATION
+ val isLocationHidden: Flow<Boolean> = localStateRepository.locationMode.map { locationMode ->
+ locationMode != LocationMode.REAL_LOCATION
}
val locationMode: StateFlow<LocationMode> = localStateRepository.locationMode
- val isIpHidden: Flow<Boolean?> = combine(
- localStateRepository.quickPrivacyEnabledFlow,
- localStateRepository.internetPrivacyMode
- ) { isQuickPrivacyEnabled, internetPrivacyMode ->
- when {
- !isQuickPrivacyEnabled || internetPrivacyMode == InternetPrivacyMode.REAL_IP -> false
- internetPrivacyMode == InternetPrivacyMode.HIDE_IP -> true
- else -> null
- }
- }
+ val ipScramblingMode: Flow<InternetPrivacyMode> = localStateRepository.internetPrivacyMode
- fun toggleReturnIsFirstActivation(): Boolean {
- val newState = !localStateRepository.isQuickPrivacyEnabled
- return localStateRepository.setQuickPrivacyReturnIsFirstActivation(newState)
+ fun toggleTrackers() {
+ localStateRepository.setBlockTrackers(!localStateRepository.blockTrackers.value)
}
- val showQuickPrivacyDisabledMessage: StateFlow<Boolean> = localStateRepository.showQuickPrivacyDisabledMessage
+ fun toggleLocation() {
+ localStateRepository.setFakeLocationEnabled(!localStateRepository.fakeLocationEnabled.value)
+ }
- fun resetQuickPrivacyDisabledMessage() {
- localStateRepository.setShowQuickPrivacyDisabledMessage(false)
+ fun toggleIpScramblingIsFirstActivation(): Boolean {
+ val enabled = !localStateRepository.ipScramblingSetting.value
+ val firstActivation = localStateRepository.isIpScramblingFirstActivation(enabled)
+ localStateRepository.setIpScramblingSetting(enabled)
+ return firstActivation
}
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 cb9fcd5..9216233 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
@@ -28,6 +28,7 @@ import foundation.e.privacymodules.ipscramblermodule.IIpScramblerModule
import foundation.e.privacymodules.permissions.IPermissionsPrivacyModule
import foundation.e.privacymodules.permissions.data.ApplicationDescription
import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
@@ -43,9 +44,6 @@ class IpScramblingStateUseCase(
private val appListsRepository: AppListsRepository,
private val coroutineScope: CoroutineScope
) {
-
- val configuredMode: StateFlow<Boolean> = localStateRepository.ipScramblingSetting
-
val internetPrivacyMode: StateFlow<InternetPrivacyMode> = callbackFlow {
val listener = object : IIpScramblerModule.Listener {
override fun onStatusChanged(newStatus: IIpScramblerModule.Status) {
@@ -67,13 +65,13 @@ class IpScramblingStateUseCase(
}.stateIn(
scope = coroutineScope,
started = SharingStarted.Eagerly,
- initialValue = InternetPrivacyMode.REAL_IP
+ initialValue = REAL_IP
)
init {
- coroutineScope.launch {
- localStateRepository.quickPrivacyEnabledFlow.collect {
- applySettings(it, localStateRepository.ipScramblingSetting.value)
+ coroutineScope.launch(Dispatchers.Default) {
+ localStateRepository.ipScramblingSetting.collect {
+ applySettings(it)
}
}
@@ -84,12 +82,7 @@ class IpScramblingStateUseCase(
fun toggle(hideIp: Boolean) {
localStateRepository.setIpScramblingSetting(enabled = hideIp)
-
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- } else {
- applySettings(true, hideIp)
- }
+ applySettings(hideIp)
}
private fun getHiddenPackageNames(): List<String> {
@@ -129,15 +122,13 @@ class IpScramblingStateUseCase(
ipScramblerModule.appList = rawList
}
- private fun applySettings(isQuickPrivacyEnabled: Boolean, isIpScramblingEnabled: Boolean) {
- val settingEnabled = isQuickPrivacyEnabled && isIpScramblingEnabled
+ private fun applySettings(isIpScramblingEnabled: Boolean) {
val currentMode = localStateRepository.internetPrivacyMode.value
-
when {
- settingEnabled && currentMode in setOf(REAL_IP, REAL_IP_LOADING) ->
+ isIpScramblingEnabled && currentMode in setOf(REAL_IP, REAL_IP_LOADING) ->
applyStartIpScrambling()
- !settingEnabled && currentMode in setOf(HIDE_IP, HIDE_IP_LOADING) ->
+ !isIpScramblingEnabled && currentMode in setOf(HIDE_IP, HIDE_IP_LOADING) ->
ipScramblerModule.stop()
else -> {}
@@ -162,11 +153,11 @@ class IpScramblingStateUseCase(
private fun map(status: IIpScramblerModule.Status): InternetPrivacyMode {
return when (status) {
- IIpScramblerModule.Status.OFF -> InternetPrivacyMode.REAL_IP
- IIpScramblerModule.Status.ON -> InternetPrivacyMode.HIDE_IP
- IIpScramblerModule.Status.STARTING -> InternetPrivacyMode.HIDE_IP_LOADING
+ IIpScramblerModule.Status.OFF -> REAL_IP
+ IIpScramblerModule.Status.ON -> HIDE_IP
+ IIpScramblerModule.Status.STARTING -> HIDE_IP_LOADING
IIpScramblerModule.Status.STOPPING,
- IIpScramblerModule.Status.START_DISABLED -> InternetPrivacyMode.REAL_IP_LOADING
+ IIpScramblerModule.Status.START_DISABLED -> REAL_IP_LOADING
}
}
}
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 17e5096..8b37152 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
@@ -38,7 +38,7 @@ class TrackersStateUseCase(
init {
trackersPrivacyModule.start(trackersRepository.trackers, enableNotification = false)
coroutineScope.launch {
- localStateRepository.quickPrivacyEnabledFlow.collect { enabled ->
+ localStateRepository.blockTrackers.collect { enabled ->
if (enabled) {
blockTrackersPrivacyModule.enableBlocking()
} else {
@@ -76,10 +76,6 @@ class TrackersStateUseCase(
}
fun toggleAppWhitelist(appUid: Int, isWhitelisted: Boolean) {
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- }
-
if (appUid == appListsRepository.dummySystemApp.uid) {
appListsRepository.getHiddenSystemApps().forEach {
blockTrackersPrivacyModule.setWhiteListed(it.uid, isWhitelisted)
@@ -90,9 +86,6 @@ class TrackersStateUseCase(
}
fun blockTracker(appUid: Int, tracker: Tracker, isBlocked: Boolean) {
- if (!localStateRepository.isQuickPrivacyEnabled) {
- localStateRepository.setShowQuickPrivacyDisabledMessage(true)
- }
if (appUid == appListsRepository.dummySystemApp.uid) {
appListsRepository.getHiddenSystemApps().forEach {
blockTrackersPrivacyModule.setWhiteListed(tracker, it.uid, !isBlocked)