diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-11-06 08:14:27 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2023-11-06 08:14:27 +0000 |
commit | 9d55978063947d5865bb3fa4e0c2ebef78f78812 (patch) | |
tree | 49a07707f82375dc9d5d1048a07bbdf866bffe67 /ipscrambling/src | |
parent | 0312ce64f85b5530a00bdc72eb310ba9dc1de05b (diff) |
epic18: Manage VPN services for Tor or Tracker control
Diffstat (limited to 'ipscrambling/src')
-rw-r--r-- | ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt | 2 | ||||
-rw-r--r-- | ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt (renamed from ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotServiceSupervisor.kt) | 32 |
2 files changed, 19 insertions, 15 deletions
diff --git a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt index 79aeb05..d9ef0be 100644 --- a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt +++ b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt @@ -21,5 +21,5 @@ import org.koin.core.module.dsl.singleOf import org.koin.dsl.module val ipScramblerModule = module { - singleOf(::OrbotServiceSupervisor) + singleOf(::OrbotSupervisor) } diff --git a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotServiceSupervisor.kt b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt index 8813948..6e0e205 100644 --- a/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotServiceSupervisor.kt +++ b/ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/OrbotSupervisor.kt @@ -29,7 +29,8 @@ import android.os.Handler import android.os.Looper import android.os.Message import androidx.localbroadcastmanager.content.LocalBroadcastManager -import foundation.e.advancedprivacy.domain.entities.FeatureServiceState +import foundation.e.advancedprivacy.domain.entities.FeatureState +import foundation.e.advancedprivacy.externalinterfaces.servicesupervisors.FeatureSupervisor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -48,12 +49,12 @@ import java.security.InvalidParameterException import java.util.function.Function @SuppressLint("CommitPrefEdits") -class OrbotServiceSupervisor( +class OrbotSupervisor( private val context: Context, private val coroutineScope: CoroutineScope, -) { - private val _state = MutableStateFlow(FeatureServiceState.OFF) - val state: StateFlow<FeatureServiceState> = _state +) : FeatureSupervisor { + private val _state = MutableStateFlow(FeatureState.OFF) + override val state: StateFlow<FeatureState> = _state enum class Status { OFF, ON, STARTING, STOPPING, START_DISABLED @@ -150,17 +151,17 @@ class OrbotServiceSupervisor( private fun updateStatus(status: Status, force: Boolean = false) { if (force || status != currentStatus) { val newState = when (status) { - Status.OFF -> FeatureServiceState.OFF - Status.ON -> FeatureServiceState.ON - Status.STARTING -> FeatureServiceState.STARTING + Status.OFF -> FeatureState.OFF + Status.ON -> FeatureState.ON + Status.STARTING -> FeatureState.STARTING Status.STOPPING, - Status.START_DISABLED -> FeatureServiceState.STOPPING + Status.START_DISABLED -> FeatureState.STOPPING } coroutineScope.launch(Dispatchers.IO) { _state.update { currentState -> - if (newState == FeatureServiceState.OFF && - currentState == FeatureServiceState.STOPPING + if (newState == FeatureState.OFF && + currentState == FeatureState.STOPPING ) { // Wait for orbot to relax before allowing user to reactivate it. delay(1000) @@ -244,17 +245,19 @@ class OrbotServiceSupervisor( OrbotService.shouldBlock = shouldBlock } - fun start(enableNotification: Boolean) { + override fun start(): Boolean { + val enableNotification = OrbotService.shouldBlock != null Prefs.enableNotification(enableNotification) Prefs.putUseVpn(true) Prefs.putStartOnBoot(true) sendIntentToService(OrbotConstants.ACTION_START) sendIntentToService(OrbotConstants.ACTION_START_VPN) + return true } - fun stop() { - if (!isServiceRunning()) return + override fun stop(): Boolean { + if (!isServiceRunning()) return false updateStatus(Status.STOPPING) @@ -267,6 +270,7 @@ class OrbotServiceSupervisor( extra = Bundle().apply { putBoolean(ACTION_STOP_FOREGROUND_TASK, true) } ) stoppingWatchdog(5) + return true } private fun stoppingWatchdog(countDown: Int) { |