summaryrefslogtreecommitdiff
path: root/ipscrambling/src/main
diff options
context:
space:
mode:
authorGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-11-06 08:14:27 +0000
committerGuillaume Jacquart <guillaume.jacquart@hoodbrains.com>2023-11-06 08:14:27 +0000
commit95d9421d4d982562f83db019e5c3f59c5acfcdf4 (patch)
tree56c69c0911e512aaaecd22cb02f2c1305f42d8e2 /ipscrambling/src/main
parent50e213ce1db332b95af5018e553c0ee2cd810e39 (diff)
parent9d55978063947d5865bb3fa4e0c2ebef78f78812 (diff)
Merge branch 'epic18-standalone_trackers_tor' into 'main'
epic18: Manage VPN services for Tor or Tracker control See merge request e/os/advanced-privacy!149
Diffstat (limited to 'ipscrambling/src/main')
-rw-r--r--ipscrambling/src/main/java/foundation/e/advancedprivacy/ipscrambler/KoinModule.kt2
-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) {