Skip to content
Snippets Groups Projects
Commit 0518acac authored by Matthew Finkel's avatar Matthew Finkel
Browse files

fixup! Bug 40028: Implement Tor Service controller

Minor improvements
parent d01d44a7
Branches
No related tags found
1 merge request!26Bug 40041 09
......@@ -210,9 +210,7 @@ class TorController(
)
// Request service status
val torServiceStatus = Intent(context, TorService::class.java)
torServiceStatus.action = TorServiceConstants.ACTION_STATUS
context.startService(torServiceStatus)
sendServiceAction(TorServiceConstants.ACTION_STATUS)
// Wait for response and unregister receiver
var torIsStarted = false
......@@ -223,7 +221,7 @@ class TorController(
return torIsStarted
}
fun initiateTorBootstrap(lifecycleScope: LifecycleCoroutineScope, withDebugLogging: Boolean = false) {
fun initiateTorBootstrap(lifecycleScope: LifecycleCoroutineScope? = null, withDebugLogging: Boolean = false) {
if (BuildConfig.DISABLE_TOR) {
return
}
......@@ -231,12 +229,14 @@ class TorController(
context.getSharedPreferences("org.torproject.android_preferences", Context.MODE_PRIVATE)
.edit().putBoolean("pref_enable_logging", withDebugLogging).apply()
if (lifecycleScope == null) {
sendServiceAction(TorServiceConstants.ACTION_START)
} else {
lifecycleScope.launch {
val torNeedsStart = !checkTorIsStarted()
if (torNeedsStart) {
val torServiceStatus = Intent(context, TorService::class.java)
torServiceStatus.action = TorServiceConstants.ACTION_START
context.startService(torServiceStatus)
sendServiceAction(TorServiceConstants.ACTION_START)
}
}
}
}
......@@ -256,6 +256,11 @@ class TorController(
onTorStopped()
}
private fun sendServiceAction(action: String) {
val torServiceStatus = Intent(context, TorService::class.java)
torServiceStatus.action = action
context.startService(torServiceStatus)
}
companion object {
const val torServiceResponseTimeout = 5000L
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment