diff options
Diffstat (limited to 'app/src/main/java/org')
5 files changed, 15 insertions, 14 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 a67887c..e571cf5 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt | |||
@@ -113,7 +113,7 @@ class ConfigureActivity : BaseActivity() { | |||
113 | R.string.message_encrypting_decrypting_private_keys, | 113 | R.string.message_encrypting_decrypting_private_keys, |
114 | TincApp.setPassphrase(netName, currentPassphrase, newPassphrase)) | 114 | TincApp.setPassphrase(netName, currentPassphrase, newPassphrase)) |
115 | 115 | ||
116 | private fun execAction(@StringRes label: Int, action: CompletableFuture<Void>) { | 116 | private fun execAction(@StringRes label: Int, action: CompletableFuture<Unit>) { |
117 | showProgressDialog(label).let { progressDialog -> | 117 | showProgressDialog(label).let { progressDialog -> |
118 | action | 118 | action |
119 | .whenComplete { _, _ -> progressDialog.dismiss() } | 119 | .whenComplete { _, _ -> progressDialog.dismiss() } |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt index 0726ee9..1872081 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt | |||
@@ -17,6 +17,7 @@ import kotlinx.android.synthetic.main.dialog_node_details.view.* | |||
17 | import kotlinx.android.synthetic.main.fragment_list_view.* | 17 | import kotlinx.android.synthetic.main.fragment_list_view.* |
18 | import kotlinx.android.synthetic.main.fragment_network_status_header.* | 18 | import kotlinx.android.synthetic.main.fragment_network_status_header.* |
19 | import org.pacien.tincapp.R | 19 | import org.pacien.tincapp.R |
20 | import org.pacien.tincapp.commands.Executor | ||
20 | import org.pacien.tincapp.commands.Tinc | 21 | import org.pacien.tincapp.commands.Tinc |
21 | import org.pacien.tincapp.data.VpnInterfaceConfiguration | 22 | import org.pacien.tincapp.data.VpnInterfaceConfiguration |
22 | import org.pacien.tincapp.extensions.Android.setElements | 23 | import org.pacien.tincapp.extensions.Android.setElements |
@@ -163,7 +164,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef | |||
163 | TincVpnService.isConnected() -> | 164 | TincVpnService.isConnected() -> |
164 | Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).thenApply<List<String>> { it.map { it.substringBefore(' ') } } | 165 | Tinc.dumpNodes(TincVpnService.getCurrentNetName()!!).thenApply<List<String>> { it.map { it.substringBefore(' ') } } |
165 | else -> | 166 | else -> |
166 | CompletableFuture.supplyAsync<List<String>> { emptyList() } | 167 | Executor.supplyAsyncTask<List<String>> { emptyList() } |
167 | } | 168 | } |
168 | } | 169 | } |
169 | } | 170 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt index fedd0d2..39c413e 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt | |||
@@ -33,12 +33,12 @@ internal object Executor { | |||
33 | 33 | ||
34 | private fun read(stream: InputStream) = BufferedReader(InputStreamReader(stream)).readLines() | 34 | private fun read(stream: InputStream) = BufferedReader(InputStreamReader(stream)).readLines() |
35 | 35 | ||
36 | fun forkExec(cmd: Command): CompletableFuture<Void> { | 36 | fun forkExec(cmd: Command): CompletableFuture<Unit> { |
37 | val pid = forkExec(cmd.asArray()).also { | 37 | val pid = forkExec(cmd.asArray()).also { |
38 | if (it == FAILED) throw CommandExecutionException("Could not fork child process.") | 38 | if (it == FAILED) throw CommandExecutionException("Could not fork child process.") |
39 | } | 39 | } |
40 | 40 | ||
41 | return CompletableFuture.runAsync { | 41 | return runAsyncTask { |
42 | when (wait(pid)) { | 42 | when (wait(pid)) { |
43 | SUCCESS -> Unit | 43 | SUCCESS -> Unit |
44 | FAILED -> throw CommandExecutionException("Process terminated abnormally.") | 44 | FAILED -> throw CommandExecutionException("Process terminated abnormally.") |
@@ -60,6 +60,6 @@ internal object Executor { | |||
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | fun runAsyncTask(r: () -> Unit) = CompletableFuture.runAsync(Runnable(r), AsyncTask.THREAD_POOL_EXECUTOR)!! | 63 | fun runAsyncTask(r: () -> Unit) = CompletableFuture.supplyAsync(Supplier(r), AsyncTask.THREAD_POOL_EXECUTOR)!! |
64 | fun <U> supplyAsyncTask(s: () -> U) = CompletableFuture.supplyAsync(Supplier(s), AsyncTask.THREAD_POOL_EXECUTOR)!! | 64 | fun <U> supplyAsyncTask(s: () -> U) = CompletableFuture.supplyAsync(Supplier(s), AsyncTask.THREAD_POOL_EXECUTOR)!! |
65 | } | 65 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt index e5172c8..3c2e27a 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/TincApp.kt | |||
@@ -1,6 +1,5 @@ | |||
1 | package org.pacien.tincapp.commands | 1 | package org.pacien.tincapp.commands |
2 | 2 | ||
3 | import java8.util.concurrent.CompletableFuture | ||
4 | import org.pacien.tincapp.R | 3 | import org.pacien.tincapp.R |
5 | import org.pacien.tincapp.commands.Executor.runAsyncTask | 4 | import org.pacien.tincapp.commands.Executor.runAsyncTask |
6 | import org.pacien.tincapp.context.App | 5 | import org.pacien.tincapp.context.App |
@@ -30,17 +29,17 @@ object TincApp { | |||
30 | throw FileNotFoundException(App.getResources().getString(R.string.message_network_config_not_found_format, e.message!!)) | 29 | throw FileNotFoundException(App.getResources().getString(R.string.message_network_config_not_found_format, e.message!!)) |
31 | } | 30 | } |
32 | 31 | ||
33 | fun removeScripts(netName: String): CompletableFuture<Void> = runAsyncTask { | 32 | fun removeScripts(netName: String) = runAsyncTask { |
34 | listScripts(netName).forEach { it.delete() } | 33 | listScripts(netName).forEach { it.delete() } |
35 | } | 34 | } |
36 | 35 | ||
37 | fun generateIfaceCfg(netName: String): CompletableFuture<Void> = runAsyncTask { | 36 | fun generateIfaceCfg(netName: String) = runAsyncTask { |
38 | VpnInterfaceConfiguration | 37 | VpnInterfaceConfiguration |
39 | .fromInvitation(AppPaths.invitationFile(netName)) | 38 | .fromInvitation(AppPaths.invitationFile(netName)) |
40 | .write(AppPaths.netConfFile(netName)) | 39 | .write(AppPaths.netConfFile(netName)) |
41 | } | 40 | } |
42 | 41 | ||
43 | fun setPassphrase(netName: String, currentPassphrase: String? = null, newPassphrase: String?): CompletableFuture<Void> = runAsyncTask { | 42 | fun setPassphrase(netName: String, currentPassphrase: String? = null, newPassphrase: String?) = runAsyncTask { |
44 | listPrivateKeys(netName) | 43 | listPrivateKeys(netName) |
45 | .filter { it.exists() } | 44 | .filter { it.exists() } |
46 | .map { Pair(PemUtils.read(it), it) } | 45 | .map { Pair(PemUtils.read(it), it) } |
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 223763d..b59be80 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | |||
@@ -11,6 +11,7 @@ import org.apache.commons.configuration2.ex.ConversionException | |||
11 | import org.bouncycastle.openssl.PEMException | 11 | import org.bouncycastle.openssl.PEMException |
12 | import org.pacien.tincapp.BuildConfig | 12 | import org.pacien.tincapp.BuildConfig |
13 | import org.pacien.tincapp.R | 13 | import org.pacien.tincapp.R |
14 | import org.pacien.tincapp.commands.Executor | ||
14 | import org.pacien.tincapp.commands.Tinc | 15 | import org.pacien.tincapp.commands.Tinc |
15 | import org.pacien.tincapp.commands.Tincd | 16 | import org.pacien.tincapp.commands.Tincd |
16 | import org.pacien.tincapp.context.App | 17 | import org.pacien.tincapp.context.App |
@@ -136,9 +137,9 @@ class TincVpnService : VpnService() { | |||
136 | } | 137 | } |
137 | 138 | ||
138 | private fun waitForDaemonStartup() = | 139 | private fun waitForDaemonStartup() = |
139 | CompletableFuture | 140 | Executor |
140 | .runAsync { Thread.sleep(SETUP_DELAY) } | 141 | .runAsyncTask { Thread.sleep(SETUP_DELAY) } |
141 | .thenCompose { if (daemon!!.isDone) daemon!! else CompletableFuture.runAsync { } } | 142 | .thenCompose { if (daemon!!.isDone) daemon!! else Executor.runAsyncTask { Unit } } |
142 | 143 | ||
143 | companion object { | 144 | companion object { |
144 | private const val SETUP_DELAY = 500L // ms | 145 | private const val SETUP_DELAY = 500L // ms |
@@ -146,10 +147,10 @@ class TincVpnService : VpnService() { | |||
146 | private var netName: String? = null | 147 | private var netName: String? = null |
147 | private var interfaceCfg: VpnInterfaceConfiguration? = null | 148 | private var interfaceCfg: VpnInterfaceConfiguration? = null |
148 | private var fd: ParcelFileDescriptor? = null | 149 | private var fd: ParcelFileDescriptor? = null |
149 | private var daemon: CompletableFuture<Void>? = null | 150 | private var daemon: CompletableFuture<Unit>? = null |
150 | 151 | ||
151 | private fun setState(netName: String?, interfaceCfg: VpnInterfaceConfiguration?, | 152 | private fun setState(netName: String?, interfaceCfg: VpnInterfaceConfiguration?, |
152 | fd: ParcelFileDescriptor?, daemon: CompletableFuture<Void>?) { | 153 | fd: ParcelFileDescriptor?, daemon: CompletableFuture<Unit>?) { |
153 | 154 | ||
154 | TincVpnService.netName = netName | 155 | TincVpnService.netName = netName |
155 | TincVpnService.interfaceCfg = interfaceCfg | 156 | TincVpnService.interfaceCfg = interfaceCfg |