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.kt26
1 files changed, 13 insertions, 13 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 7176e25..45058e2 100644
--- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
@@ -85,16 +85,16 @@ class TincVpnService : VpnService() {
85 85
86 private fun startVpn(netName: String, passphrase: String? = null): Unit = synchronized(this) { 86 private fun startVpn(netName: String, passphrase: String? = null): Unit = synchronized(this) {
87 if (netName.isBlank()) 87 if (netName.isBlank())
88 return reportError(resources.getString(R.string.message_no_network_name_provided), docTopic = "intent-api") 88 return reportError(resources.getString(R.string.notification_error_message_no_network_name_provided), docTopic = "intent-api")
89 89
90 if (TincKeyring.needsPassphrase(netName) && passphrase == null) 90 if (TincKeyring.needsPassphrase(netName) && passphrase == null)
91 return reportError(resources.getString(R.string.message_passphrase_required)) 91 return reportError(resources.getString(R.string.notification_error_message_passphrase_not_provided))
92 92
93 if (!AppPaths.storageAvailable()) 93 if (!AppPaths.storageAvailable())
94 return reportError(resources.getString(R.string.start_network_list_empty_storage_not_available)) 94 return reportError(resources.getString(R.string.start_network_list_empty_storage_not_available))
95 95
96 if (!AppPaths.confDir(netName).exists()) 96 if (!AppPaths.confDir(netName).exists())
97 return reportError(resources.getString(R.string.message_no_configuration_for_network_format, netName), docTopic = "configuration") 97 return reportError(resources.getString(R.string.notification_error_message_no_configuration_for_network_format, netName), docTopic = "configuration")
98 98
99 log.info("Starting tinc daemon for network \"$netName\".") 99 log.info("Starting tinc daemon for network \"$netName\".")
100 if (isConnected()) stopVpn() 100 if (isConnected()) stopVpn()
@@ -108,19 +108,19 @@ class TincVpnService : VpnService() {
108 } catch (e: FileNotFoundException) { 108 } catch (e: FileNotFoundException) {
109 Pair(null, null) 109 Pair(null, null)
110 } catch (e: PEMException) { 110 } catch (e: PEMException) {
111 return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message)) 111 return reportError(resources.getString(R.string.notification_error_message_could_not_decrypt_private_keys_format, e.message))
112 } catch (e: Exception) { 112 } catch (e: Exception) {
113 return reportError(resources.getString(R.string.message_could_not_read_private_key_format, e.defaultMessage()), e) 113 return reportError(resources.getString(R.string.notification_error_message_could_not_read_private_key_format, e.defaultMessage()), e)
114 } 114 }
115 115
116 val interfaceCfg = try { 116 val interfaceCfg = try {
117 VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName))) 117 VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName)))
118 } catch (e: FileNotFoundException) { 118 } catch (e: FileNotFoundException) {
119 return reportError(resources.getString(R.string.message_network_config_not_found_format, e.defaultMessage()), e, "configuration") 119 return reportError(resources.getString(R.string.notification_error_message_network_config_not_found_format, e.defaultMessage()), e, "configuration")
120 } catch (e: ConversionException) { 120 } catch (e: ConversionException) {
121 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface") 121 return reportError(resources.getString(R.string.notification_error_message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
122 } catch (e: Exception) { 122 } catch (e: Exception) {
123 return reportError(resources.getString(R.string.message_could_not_read_network_configuration_format, e.defaultMessage()), e) 123 return reportError(resources.getString(R.string.notification_error_message_could_not_read_network_configuration_format, e.defaultMessage()), e)
124 } 124 }
125 125
126 val deviceFd = try { 126 val deviceFd = try {
@@ -129,11 +129,11 @@ class TincVpnService : VpnService() {
129 .also { applyIgnoringException(it::addDisallowedApplication, BuildConfig.APPLICATION_ID) } 129 .also { applyIgnoringException(it::addDisallowedApplication, BuildConfig.APPLICATION_ID) }
130 .establish()!! 130 .establish()!!
131 } catch (e: IllegalArgumentException) { 131 } catch (e: IllegalArgumentException) {
132 return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface") 132 return reportError(resources.getString(R.string.notification_error_message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
133 } catch (e: NullPointerException) { 133 } catch (e: NullPointerException) {
134 return reportError(resources.getString(R.string.message_could_not_bind_iface), e) 134 return reportError(resources.getString(R.string.notification_error_message_could_not_bind_iface), e)
135 } catch (e: Exception) { 135 } catch (e: Exception) {
136 return reportError(resources.getString(R.string.message_could_not_configure_iface, e.defaultMessage()), e) 136 return reportError(resources.getString(R.string.notification_error_message_could_not_configure_iface, e.defaultMessage()), e)
137 } 137 }
138 138
139 val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd) 139 val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd)
@@ -145,7 +145,7 @@ class TincVpnService : VpnService() {
145 privateKeys.second?.close() 145 privateKeys.second?.close()
146 146
147 if (exception != null) { 147 if (exception != null) {
148 reportError(resources.getString(R.string.message_daemon_exited, exception.cause!!.defaultMessage()), exception) 148 reportError(resources.getString(R.string.notification_error_message_daemon_exited, exception.cause!!.defaultMessage()), exception)
149 } else { 149 } else {
150 log.info("tinc daemon started.") 150 log.info("tinc daemon started.")
151 broadcastEvent(Actions.EVENT_CONNECTED) 151 broadcastEvent(Actions.EVENT_CONNECTED)
@@ -171,7 +171,7 @@ class TincVpnService : VpnService() {
171 log.error(msg) 171 log.error(msg)
172 172
173 broadcastEvent(Actions.EVENT_ABORTED) 173 broadcastEvent(Actions.EVENT_ABORTED)
174 App.alert(R.string.title_unable_to_start_tinc, msg, 174 App.alert(R.string.notification_error_title_unable_to_start_tinc, msg,
175 if (docTopic != null) resources.getString(R.string.app_doc_url_format, docTopic) else null) 175 if (docTopic != null) resources.getString(R.string.app_doc_url_format, docTopic) else null)
176 } 176 }
177 177