diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-15 00:44:37 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-22 13:46:49 +0000 |
| commit | a9ccc386eeebab549fd20230a2ee131877422f15 (patch) | |
| tree | b2b899ff8de442adfc8e8492cc832daab2b143d5 | |
| parent | 29146e61874980059a4f19632fe9bb6816891873 (diff) | |
| download | mullvadvpn-a9ccc386eeebab549fd20230a2ee131877422f15.tar.xz mullvadvpn-a9ccc386eeebab549fd20230a2ee131877422f15.zip | |
Use Android app files directory for resources
3 files changed, 19 insertions, 41 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt index aac6175ec6..e1fb9537b8 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/FileResourceExtractor.kt @@ -4,14 +4,16 @@ import android.content.Context import java.io.File import java.io.FileOutputStream -class FileResourceExtractor(val asset: String, val destination: String) { +class FileResourceExtractor(val asset: String) { fun extract(context: Context) { - if (!File(destination).exists()) { - extractFile(context) + val destination = File(context.filesDir, asset) + + if (!destination.exists()) { + extractFile(context, destination) } } - private fun extractFile(context: Context) { + private fun extractFile(context: Context, destination: File) { val destinationStream = FileOutputStream(destination) context diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 4df3ff6791..1cd3fcc8b3 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -14,10 +14,7 @@ import net.mullvad.talpid.TalpidVpnService import net.mullvad.talpid.util.EventNotifier private const val API_ROOT_CA_FILE = "api_root_ca.pem" -private const val API_ROOT_CA_PATH = "/data/data/net.mullvad.mullvadvpn/api_root_ca.pem" - private const val RELAYS_FILE = "relays.json" -private const val RELAYS_PATH = "/data/data/net.mullvad.mullvadvpn/relays.json" class MullvadVpnService : TalpidVpnService() { private enum class PendingAction { @@ -144,11 +141,8 @@ class MullvadVpnService : TalpidVpnService() { } private fun startDaemon() = GlobalScope.launch(Dispatchers.Default) { - FileResourceExtractor(API_ROOT_CA_FILE, API_ROOT_CA_PATH) - .extract(application) - - FileResourceExtractor(RELAYS_FILE, RELAYS_PATH) - .extract(application) + FileResourceExtractor(API_ROOT_CA_FILE).extract(application) + FileResourceExtractor(RELAYS_FILE).extract(application) val newDaemon = MullvadDaemon(this@MullvadVpnService).apply { onSettingsChange.subscribe { settings -> diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs index d807c205b3..3ead52febe 100644 --- a/mullvad-jni/src/lib.rs +++ b/mullvad-jni/src/lib.rs @@ -129,7 +129,7 @@ fn initialize( this: &JObject<'_>, vpn_service: &JObject<'_>, cache_dir: PathBuf, - log_dir: PathBuf, + resource_dir: PathBuf, ) -> Result<(), Error> { let android_context = create_android_context(env, *vpn_service)?; let daemon_command_channel = DaemonCommandChannel::new(); @@ -139,7 +139,7 @@ fn initialize( env, this, cache_dir, - log_dir, + resource_dir, daemon_command_channel, android_context, )?; @@ -165,7 +165,7 @@ fn spawn_daemon( env: &JnixEnv<'_>, this: &JObject<'_>, cache_dir: PathBuf, - log_dir: PathBuf, + resource_dir: PathBuf, command_channel: DaemonCommandChannel, android_context: AndroidContext, ) -> Result<(), Error> { @@ -177,14 +177,16 @@ fn spawn_daemon( thread::spawn(move || { let jvm = android_context.jvm.clone(); - - match create_daemon( - listener, + let daemon = Daemon::start( + Some(resource_dir.clone()), + resource_dir, cache_dir, - log_dir, + listener, command_channel, android_context, - ) { + ); + + match daemon { Ok(daemon) => { let _ = tx.send(Ok(())); match daemon.run() { @@ -193,7 +195,7 @@ fn spawn_daemon( } } Err(error) => { - let _ = tx.send(Err(error)); + let _ = tx.send(Err(Error::InitializeDaemon(error))); } } @@ -203,26 +205,6 @@ fn spawn_daemon( rx.recv().unwrap() } -fn create_daemon( - listener: JniEventListener, - cache_dir: PathBuf, - log_dir: PathBuf, - command_channel: DaemonCommandChannel, - android_context: AndroidContext, -) -> Result<Daemon<JniEventListener>, Error> { - let resource_dir = mullvad_paths::get_resource_dir(); - - Daemon::start( - Some(log_dir), - resource_dir, - cache_dir, - listener, - command_channel, - android_context, - ) - .map_err(Error::InitializeDaemon) -} - fn notify_daemon_stopped(jvm: Arc<JavaVM>, daemon_object: GlobalRef) { match jvm.attach_current_thread_as_daemon() { Ok(env) => { |
