diff options
Diffstat (limited to 'app/src/main/java/foundation/e/advancedprivacy/domain')
4 files changed, 42 insertions, 101 deletions
diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/InternetPrivacyMode.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/InternetPrivacyMode.kt deleted file mode 100644 index 986e798..0000000 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/InternetPrivacyMode.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2021 E FOUNDATION - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package foundation.e.advancedprivacy.domain.entities - -enum class InternetPrivacyMode { - REAL_IP, - HIDE_IP, - HIDE_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/advancedprivacy/domain/entities/ShowFeaturesWarning.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/ShowFeaturesWarning.kt index 221f4e1..0d8e0e8 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/entities/ShowFeaturesWarning.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/ShowFeaturesWarning.kt @@ -21,9 +21,11 @@ import android.content.Intent import android.os.Parcelable import kotlinx.parcelize.Parcelize -@Parcelize sealed class ShowFeaturesWarning : Parcelable { + @Parcelize object TrackersControl : ShowFeaturesWarning() + @Parcelize object FakeLocation : ShowFeaturesWarning() + @Parcelize data class IpScrambling(val startVpnDisclaimer: Intent? = null) : ShowFeaturesWarning() } diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt index bc4871a..1b8f62c 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/GetQuickPrivacyStateUseCase.kt @@ -19,7 +19,7 @@ package foundation.e.advancedprivacy.domain.usecases import foundation.e.advancedprivacy.data.repositories.LocalStateRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode +import foundation.e.advancedprivacy.domain.entities.FeatureServiceState import foundation.e.advancedprivacy.domain.entities.LocationMode import foundation.e.advancedprivacy.domain.entities.QuickPrivacyState import foundation.e.advancedprivacy.domain.entities.TrackerMode @@ -41,13 +41,13 @@ class GetQuickPrivacyStateUseCase( when { !isBlockTrackers && locationMode == LocationMode.REAL_LOCATION && - internetPrivacyMode == InternetPrivacyMode.REAL_IP -> QuickPrivacyState.DISABLED + internetPrivacyMode == FeatureServiceState.OFF -> QuickPrivacyState.DISABLED isAllTrackersBlocked && locationMode != LocationMode.REAL_LOCATION && internetPrivacyMode in listOf( - InternetPrivacyMode.HIDE_IP, - InternetPrivacyMode.HIDE_IP_LOADING + FeatureServiceState.ON, + FeatureServiceState.STARTING ) -> QuickPrivacyState.FULL_ENABLED else -> QuickPrivacyState.ENABLED @@ -71,7 +71,8 @@ class GetQuickPrivacyStateUseCase( val locationMode: StateFlow<LocationMode> = localStateRepository.locationMode - val ipScramblingMode: Flow<InternetPrivacyMode> = localStateRepository.internetPrivacyMode + val ipScramblingMode: Flow<FeatureServiceState> = + localStateRepository.internetPrivacyMode fun toggleTrackers(enabled: Boolean?) { val value = enabled ?: !localStateRepository.blockTrackers.value diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt index 9c89329..79c79f7 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/IpScramblingStateUseCase.kt @@ -23,74 +23,40 @@ import foundation.e.advancedprivacy.common.isStandaloneBuild import foundation.e.advancedprivacy.data.repositories.AppListsRepository import foundation.e.advancedprivacy.data.repositories.LocalStateRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode.HIDE_IP -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode.HIDE_IP_LOADING -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode.REAL_IP -import foundation.e.advancedprivacy.domain.entities.InternetPrivacyMode.REAL_IP_LOADING +import foundation.e.advancedprivacy.domain.entities.FeatureServiceState import foundation.e.advancedprivacy.externalinterfaces.permissions.IPermissionsPrivacyModule -import foundation.e.advancedprivacy.ipscrambler.IpScramblerModule +import foundation.e.advancedprivacy.ipscrambler.OrbotServiceSupervisor +import foundation.e.advancedprivacy.trackers.domain.externalinterfaces.TrackersServiceSupervisor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.channels.awaitClose -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.callbackFlow -import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch class IpScramblingStateUseCase( - private val ipScramblerModule: IpScramblerModule, + private val orbotServiceSupervisor: OrbotServiceSupervisor, private val permissionsPrivacyModule: IPermissionsPrivacyModule, private val appDesc: ApplicationDescription, private val localStateRepository: LocalStateRepository, private val appListsRepository: AppListsRepository, + private val trackersServiceSupervisor: TrackersServiceSupervisor, private val coroutineScope: CoroutineScope ) { - val internetPrivacyMode: StateFlow<InternetPrivacyMode> = callbackFlow { - val listener = object : IpScramblerModule.Listener { - override fun onStatusChanged(newStatus: IpScramblerModule.Status) { - trySend(map(newStatus)) - } - - override fun log(message: String) {} - override fun onTrafficUpdate( - upload: Long, - download: Long, - read: Long, - write: Long - ) { - } - } - ipScramblerModule.addListener(listener) - ipScramblerModule.requestStatus() - awaitClose { ipScramblerModule.removeListener(listener) } - }.stateIn( - scope = coroutineScope, - started = SharingStarted.Eagerly, - initialValue = REAL_IP - ) + val internetPrivacyMode: StateFlow<FeatureServiceState> = orbotServiceSupervisor.state init { + orbotServiceSupervisor.requestStatus() + coroutineScope.launch(Dispatchers.Default) { localStateRepository.ipScramblingSetting.collect { applySettings(it) } } - coroutineScope.launch(Dispatchers.IO) { - internetPrivacyMode.collect { - if ( - it == REAL_IP && - localStateRepository.internetPrivacyMode.value == REAL_IP_LOADING - ) { - // Wait for orbot to relax before allowing user to reactivate it. - delay(1000) - } - localStateRepository.internetPrivacyMode.value = it - } - } + orbotServiceSupervisor.state.map { + localStateRepository.internetPrivacyMode.value = it + }.launchIn(coroutineScope) } fun toggle(hideIp: Boolean) { @@ -102,7 +68,7 @@ class IpScramblingStateUseCase( } val bypassTorApps: Set<String> get() { - var whitelist = ipScramblerModule.appList + var whitelist = orbotServiceSupervisor.appList if (getHiddenPackageNames().any { it in whitelist }) { val mutable = whitelist.toMutableSet() mutable.removeAll(getHiddenPackageNames()) @@ -120,7 +86,7 @@ class IpScramblingStateUseCase( fun toggleBypassTor(packageName: String) { val visibleList = bypassTorApps.toMutableSet() - val rawList = ipScramblerModule.appList.toMutableSet() + val rawList = orbotServiceSupervisor.appList.toMutableSet() if (visibleList.contains(packageName)) { if (packageName == appListsRepository.dummySystemApp.packageName) { @@ -139,24 +105,34 @@ class IpScramblingStateUseCase( rawList.add(packageName) } } - ipScramblerModule.appList = rawList + orbotServiceSupervisor.appList = rawList + } + + val availablesLocations: List<String> = orbotServiceSupervisor.getAvailablesLocations().sorted() + + val exitCountry: String get() = orbotServiceSupervisor.getExitCountryCode() + + suspend fun setExitCountry(locationId: String) { + if (locationId != exitCountry) { + orbotServiceSupervisor.setExitCountryCode(locationId) + } } private suspend fun applySettings(isIpScramblingEnabled: Boolean) { val currentMode = localStateRepository.internetPrivacyMode.value when { - isIpScramblingEnabled && currentMode in setOf(REAL_IP, REAL_IP_LOADING) -> + isIpScramblingEnabled && currentMode in setOf(FeatureServiceState.OFF, FeatureServiceState.STOPPING) -> applyStartIpScrambling() - !isIpScramblingEnabled && currentMode in setOf(HIDE_IP, HIDE_IP_LOADING) -> - ipScramblerModule.stop() + !isIpScramblingEnabled && currentMode in setOf(FeatureServiceState.ON, FeatureServiceState.STARTING) -> + orbotServiceSupervisor.stop() else -> {} } } private suspend fun applyStartIpScrambling() { - val authorizeVpnIntent = ipScramblerModule.prepareAndroidVpn() + val authorizeVpnIntent = orbotServiceSupervisor.prepareAndroidVpn() if (authorizeVpnIntent == null) { localStateRepository.emitStartVpnDisclaimer(null) @@ -190,17 +166,8 @@ class IpScramblingStateUseCase( } fun startIpScrambling() { - localStateRepository.internetPrivacyMode.value = HIDE_IP_LOADING - ipScramblerModule.start(enableNotification = isStandaloneBuild) - } - - private fun map(status: IpScramblerModule.Status): InternetPrivacyMode { - return when (status) { - IpScramblerModule.Status.OFF -> REAL_IP - IpScramblerModule.Status.ON -> HIDE_IP - IpScramblerModule.Status.STARTING -> HIDE_IP_LOADING - IpScramblerModule.Status.STOPPING, - IpScramblerModule.Status.START_DISABLED -> REAL_IP_LOADING - } + localStateRepository.internetPrivacyMode.value = FeatureServiceState.STARTING + orbotServiceSupervisor.setDNSFilter((trackersServiceSupervisor.dnsFilterForIpScrambling)) + orbotServiceSupervisor.start(enableNotification = isStandaloneBuild) } } |