From e86e1870fb6311f95a132f2e445e1caaee358ad6 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Mon, 5 Aug 2024 14:31:38 +0100 Subject: [PATCH 1/2] feat: fix paths used by probe --- .../kotlin/org/ooni/probe/AndroidApplication.kt | 5 +++++ .../src/commonMain/kotlin/org/ooni/engine/Engine.kt | 9 +++++---- .../kotlin/org/ooni/probe/di/Dependencies.kt | 3 ++- .../iosMain/kotlin/org/ooni/probe/SetupDependencies.kt | 10 +++++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/org/ooni/probe/AndroidApplication.kt b/composeApp/src/androidMain/kotlin/org/ooni/probe/AndroidApplication.kt index 79a58291..f1dd6f57 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/probe/AndroidApplication.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/probe/AndroidApplication.kt @@ -7,12 +7,17 @@ import org.ooni.probe.di.Dependencies import org.ooni.probe.shared.Platform import org.ooni.probe.shared.PlatformInfo +/** + * See link for `baseFileDir` https://github.com/ooni/probe-android/blob/5a11d1a36ec952aa1f355ba8db4129146139a5cc/engine/src/main/java/org/openobservatory/engine/Engine.java#L52 + * See link for `cacheDir` https://github.com/ooni/probe-android/blob/5a11d1a36ec952aa1f355ba8db4129146139a5cc/engine/src/main/java/org/openobservatory/engine/Engine.java#L70 + */ class AndroidApplication : Application() { val dependencies by lazy { Dependencies( platformInfo = platformInfo, oonimkallBridge = AndroidOonimkallBridge(), baseFileDir = filesDir.absolutePath, + cacheDir = cacheDir.absolutePath, ) } diff --git a/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt b/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt index 08fb4e2f..2f02c138 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt @@ -18,15 +18,16 @@ class Engine( private val bridge: OonimkallBridge, private val json: Json, private val baseFilePath: String, + private val cacheDir: String, ) { fun startTask(taskSettings: TaskSettings): Flow = channelFlow { val finalSettings = taskSettings.copy( - stateDir = baseFilePath, - tunnelDir = baseFilePath, - tempDir = baseFilePath, - assetsDir = baseFilePath, + stateDir = "$baseFilePath/state", + tunnelDir = "$baseFilePath/tunnel", + tempDir = cacheDir, + assetsDir = "$baseFilePath/assets", ) val response = httpDo(finalSettings) diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt index 0eb54d1c..1e258534 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt @@ -13,6 +13,7 @@ class Dependencies( val platformInfo: PlatformInfo, private val oonimkallBridge: OonimkallBridge, private val baseFileDir: String, + private val cacheDir: String, ) { // Data @@ -25,7 +26,7 @@ class Dependencies( // Engine - private val engine by lazy { Engine(oonimkallBridge, json, baseFileDir) } + private val engine by lazy { Engine(oonimkallBridge, json, baseFileDir , cacheDir) } // ViewModels diff --git a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt index 313294fe..8bfafe23 100644 --- a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt +++ b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt @@ -5,14 +5,22 @@ import org.ooni.probe.di.Dependencies import org.ooni.probe.shared.Platform import org.ooni.probe.shared.PlatformInfo import platform.Foundation.NSBundle +import platform.Foundation.NSDocumentDirectory +import platform.Foundation.NSSearchPathForDirectoriesInDomains import platform.Foundation.NSTemporaryDirectory +import platform.Foundation.NSUserDomainMask import platform.UIKit.UIDevice +/** + * See link for `baseFileDir` https://github.com/ooni/probe-ios/blob/2145bbd5eda6e696be216e3bce97e8d5fb33dcea/ooniprobe/Engine/Engine.m#L54 + * See link for `cacheDir` https://github.com/ooni/probe-ios/blob/2145bbd5eda6e696be216e3bce97e8d5fb33dcea/ooniprobe/Engine/Engine.m#L66 + */ fun setupDependencies(bridge: OonimkallBridge) = Dependencies( platformInfo = platformInfo, oonimkallBridge = bridge, - baseFileDir = NSTemporaryDirectory(), + baseFileDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).first().toString(), + cacheDir = NSTemporaryDirectory(), ) private val platformInfo get() = From 2c2a9aaddb4a8b62676e40fd032e590d62ed1763 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Mon, 5 Aug 2024 14:33:29 +0100 Subject: [PATCH 2/2] chore: fix formatting --- .../src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt index 1e258534..de3531f7 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt @@ -26,7 +26,7 @@ class Dependencies( // Engine - private val engine by lazy { Engine(oonimkallBridge, json, baseFileDir , cacheDir) } + private val engine by lazy { Engine(oonimkallBridge, json, baseFileDir, cacheDir) } // ViewModels