diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-09-19 06:59:31 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-09-19 06:59:31 +0000 |
commit | c421acd91db4decbf9a9f136ecfa2719ffada665 (patch) | |
tree | 951cd5ebc57b3972dbece4651de28761e5e1120d /app/src/main/java/foundation/e/advancedprivacy/domain | |
parent | a38472602d259b6c265660bf3b0ba472f20c6a7f (diff) | |
download | advanced-privacy-c421acd91db4decbf9a9f136ecfa2719ffada665.tar.gz |
epic18: make IPScrambling work standalone
Diffstat (limited to 'app/src/main/java/foundation/e/advancedprivacy/domain')
3 files changed, 80 insertions, 24 deletions
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 new file mode 100644 index 0000000..221f4e1 --- /dev/null +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/entities/ShowFeaturesWarning.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 MURENA SAS + * Copyright (C) 2022 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 + +import android.content.Intent +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +sealed class ShowFeaturesWarning : Parcelable { + object TrackersControl : ShowFeaturesWarning() + object FakeLocation : ShowFeaturesWarning() + data class IpScrambling(val startVpnDisclaimer: Intent? = null) : ShowFeaturesWarning() +} 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 a7ed660..27e7fe4 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 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2021 E FOUNDATION, 2023 MURENA SAS + * Copyright (C) 2023 MURENA SAS + * 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 @@ -17,6 +18,7 @@ package foundation.e.advancedprivacy.domain.usecases +import android.content.Intent import foundation.e.advancedprivacy.data.repositories.AppListsRepository import foundation.e.advancedprivacy.data.repositories.LocalStateRepository import foundation.e.advancedprivacy.domain.entities.ApplicationDescription @@ -139,7 +141,7 @@ class IpScramblingStateUseCase( ipScramblerModule.appList = rawList } - private fun applySettings(isIpScramblingEnabled: Boolean) { + private suspend fun applySettings(isIpScramblingEnabled: Boolean) { val currentMode = localStateRepository.internetPrivacyMode.value when { isIpScramblingEnabled && currentMode in setOf(REAL_IP, REAL_IP_LOADING) -> @@ -152,23 +154,45 @@ class IpScramblingStateUseCase( } } - private fun applyStartIpScrambling() { - localStateRepository.internetPrivacyMode.value = HIDE_IP_LOADING - ipScramblerModule.prepareAndroidVpn()?.let { - permissionsPrivacyModule.setVpnPackageAuthorization(appDesc.packageName) - permissionsPrivacyModule.getAlwaysOnVpnPackage() - }?.let { - coroutineScope.launch { + private suspend fun applyStartIpScrambling() { + val authorizeVpnIntent = ipScramblerModule.prepareAndroidVpn() + if (authorizeVpnIntent == null) { + localStateRepository.emitStartVpnDisclaimer(null) + + startIpScrambling() + return + } + + acquireVpnAuthorization(authorizeVpnIntent) + } + + private suspend fun acquireVpnAuthorization(authorizeVpnIntent: Intent) { + val authorized = permissionsPrivacyModule.setVpnPackageAuthorization(appDesc.packageName) + val alwaysOnVpnPackage = permissionsPrivacyModule.getAlwaysOnVpnPackage() + + when { + authorized && alwaysOnVpnPackage == null -> { + localStateRepository.emitStartVpnDisclaimer(null) + startIpScrambling() + } + authorized && alwaysOnVpnPackage != null -> { localStateRepository.emitOtherVpnRunning( - permissionsPrivacyModule.getApplicationDescription(packageName = it, withIcon = false) + permissionsPrivacyModule.getApplicationDescription( + packageName = alwaysOnVpnPackage, + withIcon = false + ) ) + localStateRepository.setIpScramblingSetting(enabled = false) } - localStateRepository.setIpScramblingSetting(enabled = false) - } ?: run { - ipScramblerModule.start(enableNotification = false) + else -> localStateRepository.emitStartVpnDisclaimer(authorizeVpnIntent) } } + fun startIpScrambling() { + localStateRepository.internetPrivacyMode.value = HIDE_IP_LOADING + ipScramblerModule.start(enableNotification = false) // change the false ? + } + private fun map(status: IpScramblerModule.Status): InternetPrivacyMode { return when (status) { IpScramblerModule.Status.OFF -> REAL_IP diff --git a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/ShowFeaturesWarningUseCase.kt b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/ShowFeaturesWarningUseCase.kt index 11bce86..c99d5f1 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/ShowFeaturesWarningUseCase.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/domain/usecases/ShowFeaturesWarningUseCase.kt @@ -18,7 +18,10 @@ package foundation.e.advancedprivacy.domain.usecases import foundation.e.advancedprivacy.data.repositories.LocalStateRepository -import foundation.e.advancedprivacy.domain.entities.MainFeatures +import foundation.e.advancedprivacy.domain.entities.ShowFeaturesWarning +import foundation.e.advancedprivacy.domain.entities.ShowFeaturesWarning.FakeLocation +import foundation.e.advancedprivacy.domain.entities.ShowFeaturesWarning.IpScrambling +import foundation.e.advancedprivacy.domain.entities.ShowFeaturesWarning.TrackersControl import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.dropWhile @@ -30,25 +33,25 @@ class ShowFeaturesWarningUseCase( private val localStateRepository: LocalStateRepository ) { - fun showWarning(): Flow<MainFeatures> { + fun showWarning(): Flow<ShowFeaturesWarning> { return merge( localStateRepository.blockTrackers.drop(1).dropWhile { !it } .filter { it && !localStateRepository.hideWarningTrackers } - .map { MainFeatures.TRACKERS_CONTROL }, + .map { TrackersControl }, localStateRepository.fakeLocationEnabled.drop(1).dropWhile { !it } .filter { it && !localStateRepository.hideWarningLocation } - .map { MainFeatures.FAKE_LOCATION }, - localStateRepository.ipScramblingSetting.drop(1).dropWhile { !it } - .filter { it && !localStateRepository.hideWarningIpScrambling } - .map { MainFeatures.IP_SCRAMBLING } + .map { FakeLocation }, + localStateRepository.startVpnDisclaimer.filter { + it.startVpnDisclaimer != null || !localStateRepository.hideWarningIpScrambling + } ) } - fun doNotShowAgain(feature: MainFeatures) { + fun doNotShowAgain(feature: ShowFeaturesWarning) { when (feature) { - MainFeatures.TRACKERS_CONTROL -> localStateRepository.hideWarningTrackers = true - MainFeatures.FAKE_LOCATION -> localStateRepository.hideWarningLocation = true - MainFeatures.IP_SCRAMBLING -> localStateRepository.hideWarningIpScrambling = true + TrackersControl -> localStateRepository.hideWarningTrackers = true + FakeLocation -> localStateRepository.hideWarningLocation = true + is IpScrambling -> localStateRepository.hideWarningIpScrambling = true } } } |