aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml1
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt2
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt2
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tinc.kt33
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Tincd.kt13
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/App.kt22
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppInfo.kt15
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppPaths.kt20
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt6
9 files changed, 66 insertions, 48 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2822d37..8321208 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
6 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 6 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
7 7
8 <application 8 <application
9 android:name="org.pacien.tincapp.context.App"
9 android:allowBackup="false" 10 android:allowBackup="false"
10 android:icon="@mipmap/ic_launcher" 11 android:icon="@mipmap/ic_launcher"
11 android:label="@string/app_label" 12 android:label="@string/app_label"
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt
index 6070a0a..2146cec 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt
@@ -39,7 +39,7 @@ abstract class BaseActivity : AppCompatActivity() {
39 .setMessage(resources.getString(R.string.app_short_desc) + "\n\n" + 39 .setMessage(resources.getString(R.string.app_short_desc) + "\n\n" +
40 resources.getString(R.string.app_copyright) + " " + 40 resources.getString(R.string.app_copyright) + " " +
41 resources.getString(R.string.app_license) + "\n\n" + 41 resources.getString(R.string.app_license) + "\n\n" +
42 AppInfo.all(resources)) 42 AppInfo.all())
43 .setNeutralButton(R.string.action_open_project_website) { _, _ -> openWebsite(R.string.app_website_url) } 43 .setNeutralButton(R.string.action_open_project_website) { _, _ -> openWebsite(R.string.app_website_url) }
44 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } 44 .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ }
45 .show() 45 .show()
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 71d5403..3807ddc 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt
@@ -57,7 +57,7 @@ class StartActivity : BaseActivity() {
57 } 57 }
58 58
59 fun confDirDialog(@Suppress("UNUSED_PARAMETER") v: View) { 59 fun confDirDialog(@Suppress("UNUSED_PARAMETER") v: View) {
60 val confDir = AppPaths.confDir(this).path 60 val confDir = AppPaths.confDir().path
61 61
62 AlertDialog.Builder(this) 62 AlertDialog.Builder(this)
63 .setTitle(R.string.title_tinc_config_dir) 63 .setTitle(R.string.title_tinc_config_dir)
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 eb5689a..91a2678 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt
@@ -1,6 +1,5 @@
1package org.pacien.tincapp.commands 1package org.pacien.tincapp.commands
2 2
3import android.content.Context
4import org.pacien.tincapp.context.AppPaths 3import org.pacien.tincapp.context.AppPaths
5import java.io.IOException 4import java.io.IOException
6 5
@@ -9,22 +8,22 @@ import java.io.IOException
9 */ 8 */
10object Tinc { 9object Tinc {
11 10
12 private fun newCommand(ctx: Context, netName: String): Command = 11 private fun newCommand(netName: String): Command =
13 Command(AppPaths.tinc(ctx).absolutePath) 12 Command(AppPaths.tinc().absolutePath)
14 .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) 13 .withOption("config", AppPaths.confDir(netName).absolutePath)
15 .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) 14 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath)
16 15
17 // independently runnable commands 16 // independently runnable commands
18 17
19 @Throws(IOException::class) 18 @Throws(IOException::class)
20 fun network(ctx: Context): List<String> = 19 fun network(): List<String> =
21 Executor.call(Command(AppPaths.tinc(ctx).absolutePath) 20 Executor.call(Command(AppPaths.tinc().absolutePath)
22 .withOption("config", AppPaths.confDir(ctx).absolutePath) 21 .withOption("config", AppPaths.confDir().absolutePath)
23 .withArguments("network")) 22 .withArguments("network"))
24 23
25 @Throws(IOException::class) 24 @Throws(IOException::class)
26 fun fsck(ctx: Context, netName: String, fix: Boolean): List<String> { 25 fun fsck(netName: String, fix: Boolean): List<String> {
27 var cmd = newCommand(ctx, netName).withArguments("fsck") 26 var cmd = newCommand(netName).withArguments("fsck")
28 if (fix) cmd = cmd.withOption("force") 27 if (fix) cmd = cmd.withOption("force")
29 return Executor.call(cmd) 28 return Executor.call(cmd)
30 } 29 }
@@ -32,18 +31,18 @@ object Tinc {
32 // commands requiring a running tinc daemon 31 // commands requiring a running tinc daemon
33 32
34 @Throws(IOException::class) 33 @Throws(IOException::class)
35 fun stop(ctx: Context, netName: String) { 34 fun stop(netName: String) {
36 Executor.call(newCommand(ctx, netName).withArguments("stop")) 35 Executor.call(newCommand(netName).withArguments("stop"))
37 } 36 }
38 37
39 @Throws(IOException::class) 38 @Throws(IOException::class)
40 fun dumpNodes(ctx: Context, netName: String, reachable: Boolean): List<String> = 39 fun dumpNodes(netName: String, reachable: Boolean): List<String> =
41 Executor.call( 40 Executor.call(
42 if (reachable) newCommand(ctx, netName).withArguments("dump", "reachable", "nodes") 41 if (reachable) newCommand(netName).withArguments("dump", "reachable", "nodes")
43 else newCommand(ctx, netName).withArguments("dump", "nodes")) 42 else newCommand(netName).withArguments("dump", "nodes"))
44 43
45 @Throws(IOException::class) 44 @Throws(IOException::class)
46 fun info(ctx: Context, netName: String, node: String): String = 45 fun info(netName: String, node: String): String =
47 Executor.call(newCommand(ctx, netName).withArguments("info", node)).joinToString("\n") 46 Executor.call(newCommand(netName).withArguments("info", node)).joinToString("\n")
48 47
49} 48}
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 9f2491e..19ebfbd 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Tincd.kt
@@ -1,9 +1,6 @@
1package org.pacien.tincapp.commands 1package org.pacien.tincapp.commands
2 2
3import android.content.Context
4
5import org.pacien.tincapp.context.AppPaths 3import org.pacien.tincapp.context.AppPaths
6
7import java.io.IOException 4import java.io.IOException
8 5
9/** 6/**
@@ -12,12 +9,12 @@ import java.io.IOException
12object Tincd { 9object Tincd {
13 10
14 @Throws(IOException::class) 11 @Throws(IOException::class)
15 fun start(ctx: Context, netName: String, fd: Int) { 12 fun start(netName: String, fd: Int) {
16 Executor.forkExec(Command(AppPaths.tincd(ctx).absolutePath) 13 Executor.forkExec(Command(AppPaths.tincd().absolutePath)
17 .withOption("no-detach") 14 .withOption("no-detach")
18 .withOption("config", AppPaths.confDir(ctx, netName).absolutePath) 15 .withOption("config", AppPaths.confDir(netName).absolutePath)
19 .withOption("pidfile", AppPaths.pidFile(ctx, netName).absolutePath) 16 .withOption("pidfile", AppPaths.pidFile(netName).absolutePath)
20 .withOption("logfile", AppPaths.logFile(ctx, netName).absolutePath) 17 .withOption("logfile", AppPaths.logFile(netName).absolutePath)
21 .withOption("option", "DeviceType=fd") 18 .withOption("option", "DeviceType=fd")
22 .withOption("option", "Device=" + fd)) 19 .withOption("option", "Device=" + fd))
23 } 20 }
diff --git a/app/src/main/java/org/pacien/tincapp/context/App.kt b/app/src/main/java/org/pacien/tincapp/context/App.kt
new file mode 100644
index 0000000..4b7e44e
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/context/App.kt
@@ -0,0 +1,22 @@
1package org.pacien.tincapp.context
2
3import android.app.Application
4import android.content.Context
5
6/**
7 * @author pacien
8 */
9class App : Application() {
10
11 override fun onCreate() {
12 super.onCreate()
13 appContext = applicationContext
14 }
15
16 companion object {
17 private var appContext: Context? = null
18 fun getContext() = appContext!!
19 fun getResources() = getContext().resources!!
20 }
21
22}
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
index 2eb2aa1..39ef0f1 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppInfo.kt
@@ -1,6 +1,5 @@
1package org.pacien.tincapp.context 1package org.pacien.tincapp.context
2 2
3import android.content.res.Resources
4import android.os.Build 3import android.os.Build
5import org.pacien.tincapp.BuildConfig 4import org.pacien.tincapp.BuildConfig
6import org.pacien.tincapp.R 5import org.pacien.tincapp.R
@@ -10,23 +9,23 @@ import org.pacien.tincapp.R
10 */ 9 */
11object AppInfo { 10object AppInfo {
12 11
13 fun appVersion(r: Resources): String = r.getString( 12 fun appVersion(): String = App.getResources().getString(
14 R.string.info_version_format, 13 R.string.info_version_format,
15 BuildConfig.VERSION_NAME, 14 BuildConfig.VERSION_NAME,
16 BuildConfig.BUILD_TYPE) 15 BuildConfig.BUILD_TYPE)
17 16
18 fun androidVersion(r: Resources): String = r.getString( 17