aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt11
1 files changed, 8 insertions, 3 deletions
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 90b7b87..45f901b 100644
--- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
@@ -28,8 +28,10 @@ class TincVpnService : VpnService() {
28 } 28 }
29 29
30 override fun onDestroy() { 30 override fun onDestroy() {
31 connected = false
32
31 try { 33 try {
32 Tinc.stop(netName!!) 34 if (netName != null) Tinc.stop(netName!!)
33 fd?.close() 35 fd?.close()
34 } catch (e: IOException) { 36 } catch (e: IOException) {
35 e.printStackTrace() 37 e.printStackTrace()
@@ -42,7 +44,7 @@ class TincVpnService : VpnService() {
42 } 44 }
43 45
44 private fun startVpn(netName: String) { 46 private fun startVpn(netName: String) {
45 if (netName == TincVpnService.netName) onDestroy() 47 if (isConnected()) onDestroy()
46 TincVpnService.netName = netName 48 TincVpnService.netName = netName
47 TincVpnService.interfaceCfg = VpnInterfaceConfiguration(AppPaths.netConfFile(netName)) 49 TincVpnService.interfaceCfg = VpnInterfaceConfiguration(AppPaths.netConfFile(netName))
48 50
@@ -55,6 +57,8 @@ class TincVpnService : VpnService() {
55 } catch (e: IOException) { 57 } catch (e: IOException) {
56 e.printStackTrace() 58 e.printStackTrace()
57 } 59 }
60
61 connected = true
58 } 62 }
59 63
60 companion object { 64 companion object {
@@ -64,6 +68,7 @@ class TincVpnService : VpnService() {
64 68
65 private enum class Action { START, STOP } 69 private enum class Action { START, STOP }
66 70
71 private var connected: Boolean = false
67 private var netName: String? = null 72 private var netName: String? = null
68 private var interfaceCfg: VpnInterfaceConfiguration? = null 73 private var interfaceCfg: VpnInterfaceConfiguration? = null
69 private var fd: ParcelFileDescriptor? = null 74 private var fd: ParcelFileDescriptor? = null
@@ -81,7 +86,7 @@ class TincVpnService : VpnService() {
81 86
82 fun getCurrentNetName() = netName 87 fun getCurrentNetName() = netName
83 fun getCurrentInterfaceCfg() = interfaceCfg 88 fun getCurrentInterfaceCfg() = interfaceCfg
84 fun isConnected() = netName != null 89 fun isConnected() = connected
85 90
86 } 91 }
87 92