summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-11-21 11:17:23 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-11-21 13:19:57 +0000
commitf66f39b9b29421b5fd02605f07b585ef3440c3b4 (patch)
tree50e56943dac9bd5b78da848875a9beff4ac57ae0 /android/src
parent40d3b7634aff71b89fc89a8f6082a01a5c61630f (diff)
downloadmullvadvpn-f66f39b9b29421b5fd02605f07b585ef3440c3b4.tar.xz
mullvadvpn-f66f39b9b29421b5fd02605f07b585ef3440c3b4.zip
Create `TalpidVpnService` super class
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt31
-rw-r--r--android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt32
2 files changed, 34 insertions, 29 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
index 174387eabb..67fe711a6c 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
@@ -1,7 +1,6 @@
package net.mullvad.mullvadvpn
import android.content.Intent
-import android.net.VpnService
import android.os.Binder
import android.os.IBinder
import kotlinx.coroutines.CompletableDeferred
@@ -11,9 +10,9 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy
-import net.mullvad.talpid.tun_provider.TunConfig
+import net.mullvad.talpid.TalpidVpnService
-class MullvadVpnService : VpnService() {
+class MullvadVpnService : TalpidVpnService() {
private val binder = LocalBinder()
private val created = CompletableDeferred<Unit>()
@@ -50,32 +49,6 @@ class MullvadVpnService : VpnService() {
created.cancel()
}
- fun createTun(config: TunConfig): Int {
- val builder = Builder().apply {
- for (address in config.addresses) {
- addAddress(address, 32)
- }
-
- for (dnsServer in config.dnsServers) {
- addDnsServer(dnsServer)
- }
-
- for (route in config.routes) {
- addRoute(route.address, route.prefixLength.toInt())
- }
-
- setMtu(config.mtu)
- }
-
- val vpnInterface = builder.establish()
-
- return vpnInterface.detachFd()
- }
-
- fun bypass(socket: Int): Boolean {
- return protect(socket)
- }
-
inner class LocalBinder : Binder() {
val daemon
get() = this@MullvadVpnService.daemon
diff --git a/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
new file mode 100644
index 0000000000..96de4082cc
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
@@ -0,0 +1,32 @@
+package net.mullvad.talpid
+
+import android.net.VpnService
+import net.mullvad.talpid.tun_provider.TunConfig
+
+open class TalpidVpnService : VpnService() {
+ fun createTun(config: TunConfig): Int {
+ val builder = Builder().apply {
+ for (address in config.addresses) {
+ addAddress(address, 32)
+ }
+
+ for (dnsServer in config.dnsServers) {
+ addDnsServer(dnsServer)
+ }
+
+ for (route in config.routes) {
+ addRoute(route.address, route.prefixLength.toInt())
+ }
+
+ setMtu(config.mtu)
+ }
+
+ val vpnInterface = builder.establish()
+
+ return vpnInterface.detachFd()
+ }
+
+ fun bypass(socket: Int): Boolean {
+ return protect(socket)
+ }
+}