aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt6
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt9
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tinc.kt24
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tincd.kt8
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt26
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt14
6 files changed, 34 insertions, 53 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
index 69408d8..3590f99 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt
@@ -20,9 +20,9 @@ class ConfigureActivity : BaseActivity() {
20 } 20 }
21 21
22 private fun writeContent() { 22 private fun writeContent() {
23 text_configuration_directories.text = AppPaths.Storage.values().map { AppPaths.confDir(it) }.joinToString("\n") 23 text_configuration_directory.text = AppPaths.confDir().absolutePath
24 text_log_directories.text = AppPaths.Storage.values().map { AppPaths.cacheDir(it) }.joinToString("\n") 24 text_log_directory.text = AppPaths.cacheDir().absolutePath
25 text_tinc_binaries.text = listOf(AppPaths.tinc(), AppPaths.tincd()).joinToString("\n") 25 text_tinc_binary.text = AppPaths.tinc().absolutePath
26 } 26 }
27 27
28 fun generateConf(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet") 28 fun generateConf(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet")
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
index 709989b..1c4b5a1 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -13,9 +13,7 @@ import android.view.ViewGroup
13import android.widget.EditText 13import android.widget.EditText
14import android.widget.FrameLayout 14import android.widget.FrameLayout
15import kotlinx.android.synthetic.main.base.* 15import kotlinx.android.synthetic.main.base.*
16
17import org.pacien.tincapp.R 16import org.pacien.tincapp.R
18import org.pacien.tincapp.context.AppPaths
19import org.pacien.tincapp.service.TincVpnService 17import org.pacien.tincapp.service.TincVpnService
20 18
21/** 19/**
@@ -65,10 +63,7 @@ class StartActivity : BaseActivity() {
65 63
66 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = startActivity(Intent(this, ConfigureActivity::class.java)) 64 fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = startActivity(Intent(this, ConfigureActivity::class.java))
67 65
68 private fun startVpn(netName: String) { 66 private fun startVpn(netName: String) =
69 startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_CONF, 67 startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_NAME, netName))
70 if (netName.startsWith("external/")) AppPaths.NetConf(AppPaths.Storage.EXTERNAL, netName.substringAfter("/"))
71 else AppPaths.NetConf(AppPaths.Storage.INTERNAL, netName)))
72 }
73 68
74} 69}
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 5116d63..22cbe71 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
@@ -8,16 +8,16 @@ import java.io.IOException
8 */ 8 */
9object Tinc { 9object Tinc {
10 10
11 private fun newCommand(netConf: AppPaths.NetConf): Command = 11 private fun newCommand(netName: String): Command =
12 Command(AppPaths.tinc().absolutePath) 12 Command(AppPaths.tinc().absolutePath)
13 .withOption("config", AppPaths.confDir(netConf).absolutePath) 13 .withOption("config", AppPaths.confDir(netName).absolutePath)
14 .withOption("pidfile", AppPaths.pidFile(netConf).absolutePath) 14 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath)
15 15
16 // independently runnable commands 16 // independently runnable commands
17 17
18 @Throws(IOException::class) 18 @Throws(IOException::class)
19 fun fsck(netConf: AppPaths.NetConf, fix: Boolean): List<String> { 19 fun fsck(netName: String, fix: Boolean): List<String> {
20 var cmd = newCommand(netConf).withArguments("fsck") 20 var cmd = newCommand(netName).withArguments("fsck")
21 if (fix) cmd = cmd.withOption("force") 21 if (fix) cmd = cmd.withOption("force")
22 return Executor.call(cmd) 22 return Executor.call(cmd)
23 } 23 }
@@ -25,18 +25,18 @@ object Tinc {
25 // commands requiring a running tinc daemon 25 // commands requiring a running tinc daemon
26 26
27 @Throws(IOException::class) 27 @Throws(IOException::class)
28 fun stop(netConf: AppPaths.NetConf) { 28 fun stop(netName: String) {
29 Executor.call(newCommand(netConf).withArguments("stop")) 29 Executor.call(newCommand(netName).withArguments("stop"))
30 } 30 }
31 31
32 @Throws(IOException::class) 32 @Throws(IOException::class)
33 fun dumpNodes(netConf: AppPaths.NetConf, reachable: Boolean): List<String> = 33 fun dumpNodes(netName: String, reachable: Boolean): List<String> =
34 Executor.call( 34 Executor.call(
35 if (reachable) newCommand(netConf).withArguments("dump", "reachable", "nodes") 35 if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes")
36 else newCommand(netConf).withArguments("dump", "nodes")) 36 else newCommand(netName).withArguments("dump", "nodes"))
37 37
38 @Throws(IOException::class) 38 @Throws(IOException::class)
39 fun info(netConf: AppPaths.NetConf, node: String): String = 39 fun info(netName: String, node: String): String =
40 Executor.call(newCommand(netConf).withArguments("info", node)).joinToString("\n") 40 Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n")
41 41
42} 42}
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
index c54b328..19ebfbd 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
@@ -9,12 +9,12 @@ import java.io.IOException
9object Tincd { 9object Tincd {
10 10
11 @Throws(IOException::class) 11 @Throws(IOException::class)
12 fun start(netConf: AppPaths.NetConf, fd: Int) { 12 fun start(netName: String, fd: Int) {
13 Executor.forkExec(Command(AppPaths.tincd().absolutePath) 13 Executor.forkExec(Command(AppPaths.tincd().absolutePath)
14 .withOption("no-detach") 14 .withOption("no-detach")
15 .withOption("config", AppPaths.confDir(netConf).absolutePath) 15 .withOption("config", AppPaths.confDir(netName).absolutePath)
16 .withOption("pidfile", AppPaths.pidFile(netConf).absolutePath) 16 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath)
17 .withOption("logfile", AppPaths.logFile(netConf).absolutePath) 17 .withOption("logfile", AppPaths.logFile(netName).absolutePath)
18 .withOption("option", "DeviceType=fd") 18 .withOption("option", "DeviceType=fd")
19 .withOption("option", "Device=" + fd)) 19 .withOption("option", "Device=" + fd))
20 } 20 }
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
index 58c6de2..078a81d 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppPaths.kt
@@ -1,7 +1,6 @@
1package org.pacien.tincapp.context 1package org.pacien.tincapp.context
2 2
3import java.io.File 3import java.io.File
4import java.io.Serializable
5 4
6/** 5/**
7 * @author pacien 6 * @author pacien
@@ -10,9 +9,6 @@ import java.io.Serializable
10 */ 9 */
11object AppPaths { 10object AppPaths {
12 11
13 enum class Storage { INTERNAL, EXTERNAL }
14 data class NetConf(val storage: Storage, val netName: String) : Serializable
15
16 private val TINCD_BIN = "libtincd.so" 12 private val TINCD_BIN = "libtincd.so"
17 private val TINC_BIN = "libtinc.so" 13 private val TINC_BIN = "libtinc.so"
18 14
@@ -21,24 +17,14 @@ object AppPaths {
21 17
22 private val NET_CONF_FILE = "network.conf" 18 private val NET_CONF_FILE = "network.conf"
23 19
24 fun filesDir(storage: Storage): File = when (storage) { 20 fun cacheDir() = App.getContext().externalCacheDir!!
25 Storage.INTERNAL -> App.getContext().filesDir 21 fun confDir() = App.getContext().getExternalFilesDir(null)!!
26 Storage.EXTERNAL -> App.getContext().getExternalFilesDir(null)
27 }
28
29 fun cacheDir(storage: Storage): File = when (storage) {
30 Storage.INTERNAL -> App.getContext().cacheDir
31 Storage.EXTERNAL -> App.getContext().externalCacheDir
32 }
33
34 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir) 22 fun binDir() = File(App.getContext().applicationInfo.nativeLibraryDir)
35 23
36 fun confDir(storage: Storage) = filesDir(storage) 24 fun confDir(netName: String) = File(confDir(), netName)
37 fun confDir(netConf: NetConf) = File(confDir(netConf.storage), netConf.netName) 25 fun netConfFile(netName: String) = File(confDir(netName), NET_CONF_FILE)
38 26 fun logFile(netName: String) = File(cacheDir(), String.format(LOGFILE_FORMAT, netName))
39 fun netConfFile(netConf: NetConf) = File(confDir(netConf), NET_CONF_FILE) 27 fun pidFile(netName: String) = File(App.getContext().cacheDir, String.format(PIDFILE_FORMAT, netName))
40 fun logFile(netConf: NetConf) = File(cacheDir(netConf.storage), String.format(LOGFILE_FORMAT, netConf.netName))
41 fun pidFile(netConf: NetConf) = File(cacheDir(Storage.INTERNAL), String.format(PIDFILE_FORMAT, netConf.netName))
42 28
43 fun tincd() = File(binDir(), TINCD_BIN) 29 fun tincd() = File(binDir(), TINCD_BIN)
44 fun tinc() = File(binDir(), TINC_BIN) 30 fun tinc() = File(binDir(), TINC_BIN)
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 366e208..31541b3 100644
--- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
@@ -15,17 +15,17 @@ import java.io.IOException
15 */ 15 */
16class TincVpnService : VpnService() { 16class TincVpnService : VpnService() {
17 17
18 private var netConf: AppPaths.NetConf? = null 18 private var netName: String? = null
19