diff options
author | Pacien TRAN-GIRARD | 2017-07-06 21:57:47 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2017-07-06 22:02:12 +0200 |
commit | 29c989ad157e1b03b867c7a98158c32358df082f (patch) | |
tree | 737115688672ffeff31db3daeed1bfa82a804aa8 /app/src/main/java | |
parent | 819b3a44920e303a670928ee56e32b5ae02efca1 (diff) | |
download | tincapp-29c989ad157e1b03b867c7a98158c32358df082f.tar.gz |
Small cleanup
Diffstat (limited to 'app/src/main/java')
3 files changed, 16 insertions, 30 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Command.kt b/app/src/main/java/org/pacien/tincapp/commands/Command.kt index 9b22d5f..6eab66b 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Command.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Command.kt | |||
@@ -8,16 +8,11 @@ import java.util.* | |||
8 | internal class Command(private val cmd: String) { | 8 | internal class Command(private val cmd: String) { |
9 | 9 | ||
10 | private data class Option(val key: String, val value: String?) { | 10 | private data class Option(val key: String, val value: String?) { |
11 | override fun toString(): String = if (value != null) "--$key=$value" else "--$key" | 11 | fun toCommandLineOption(): String = if (value != null) "--$key=$value" else "--$key" |
12 | } | 12 | } |
13 | 13 | ||
14 | private val opts: MutableList<Option> | 14 | private val opts: MutableList<Option> = LinkedList() |
15 | private val args: MutableList<String> | 15 | private val args: MutableList<String> = LinkedList() |
16 | |||
17 | init { | ||
18 | this.opts = LinkedList<Option>() | ||
19 | this.args = LinkedList<String>() | ||
20 | } | ||
21 | 16 | ||
22 | fun withOption(key: String, value: String? = null): Command { | 17 | fun withOption(key: String, value: String? = null): Command { |
23 | this.opts.add(Option(key, value)) | 18 | this.opts.add(Option(key, value)) |
@@ -29,7 +24,7 @@ internal class Command(private val cmd: String) { | |||
29 | return this | 24 | return this |
30 | } | 25 | } |
31 | 26 | ||
32 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toString() } + args | 27 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toCommandLineOption() } + args |
33 | 28 | ||
34 | fun asArray(): Array<String> = this.asList().toTypedArray() | 29 | fun asArray(): Array<String> = this.asList().toTypedArray() |
35 | 30 | ||
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index e8ebb21..9b57233 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -13,17 +13,6 @@ object Tinc { | |||
13 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
15 | 15 | ||
16 | // independently runnable commands | ||
17 | |||
18 | @Throws(IOException::class) | ||
19 | fun fsck(netName: String, fix: Boolean): List<String> { | ||
20 | var cmd = newCommand(netName).withArguments("fsck") | ||
21 | if (fix) cmd = cmd.withOption("force") | ||
22 | return Executor.call(cmd) | ||
23 | } | ||
24 | |||
25 | // commands requiring a running tinc daemon | ||
26 | |||
27 | @Throws(IOException::class) | 16 | @Throws(IOException::class) |
28 | fun stop(netName: String) { | 17 | fun stop(netName: String) { |
29 | Executor.call(newCommand(netName).withArguments("stop")) | 18 | Executor.call(newCommand(netName).withArguments("stop")) |
diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt index 7813601..90b7b87 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | |||
@@ -27,16 +27,18 @@ class TincVpnService : VpnService() { | |||
27 | return Service.START_STICKY | 27 | return Service.START_STICKY |
28 | } | 28 | } |
29 | 29 | ||
30 | override fun onDestroy() = try { | 30 | override fun onDestroy() { |
31 | Tinc.stop(netName!!) | 31 | try { |
32 | fd!!.close() | 32 | Tinc.stop(netName!!) |
33 | } catch (e: IOException) { | 33 | fd?.close() |
34 | e.printStackTrace() | 34 | } catch (e: IOException) { |
35 | } finally { | 35 | e.printStackTrace() |
36 | netName = null | 36 | } finally { |
37 | interfaceCfg = null | 37 | netName = null |
38 | fd = null | 38 | interfaceCfg = null |
39 | super.onDestroy() | 39 | fd = null |
40 | super.onDestroy() | ||
41 | } | ||
40 | } | 42 | } |
41 | 43 | ||
42 | private fun startVpn(netName: String) { | 44 | private fun startVpn(netName: String) { |