aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2017-07-06 22:40:17 +0200
committerPacien TRAN-GIRARD2017-07-06 22:40:17 +0200
commit5c52c7fbc522e7d11141291d5650bb53cd1fa509 (patch)
treed125d24bb7d4e39d5f39820db8ba2f2f613434e2 /app/src
parent29c989ad157e1b03b867c7a98158c32358df082f (diff)
downloadtincapp-5c52c7fbc522e7d11141291d5650bb53cd1fa509.tar.gz
Return to start screen if VPN disconnected by other means
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt10
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt11
2 files changed, 17 insertions, 4 deletions
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 b4ba7dd..44f4f89 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt
@@ -72,11 +72,17 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
72 updateView = false 72 updateView = false
73 } 73 }
74 74
75 override fun onResume() {
76 super.onResume()
77 if (!TincVpnService.isConnected()) openStartActivity()
78 }
79
75 override fun onRefresh() { 80 override fun onRefresh() {
76 val nodes = getNodeNames() 81 val nodes = getNodeNames()
77 runOnUiThread { 82 runOnUiThread {
78 nodeListAdapter?.setElements(nodes) 83 nodeListAdapter?.setElements(nodes)
79 node_list_wrapper.isRefreshing = false 84 node_list_wrapper.isRefreshing = false
85 if (!TincVpnService.isConnected()) openStartActivity()
80 } 86 }
81 } 87 }
82 88
@@ -114,10 +120,12 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef
114 120
115 fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem) { 121 fun stopVpn(@Suppress("UNUSED_PARAMETER") i: MenuItem) {
116 TincVpnService.stopVpn() 122 TincVpnService.stopVpn()
117 startActivity(Intent(this, StartActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 123 openStartActivity()
118 finish() 124 finish()
119 } 125 }
120 126
127 fun openStartActivity() = startActivity(Intent(this, StartActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
128
121 companion object { 129 companion object {
122 private val REFRESH_RATE = 5000L 130 private val REFRESH_RATE = 5000L
123 131
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