summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-09-22 16:54:33 +0200
committerAlbin <albin@mullvad.net>2022-09-26 11:43:52 +0200
commitc8fae17c22c66062f076e070d761e6866437652d (patch)
treeebdd7c7a2c3c83fbcdee66a5a97030aa90a68218 /android/app/src
parent0ec5a790fbc87e3b4de9e25156ed35af0d79efad (diff)
downloadmullvadvpn-c8fae17c22c66062f076e070d761e6866437652d.tar.xz
mullvadvpn-c8fae17c22c66062f076e070d761e6866437652d.zip
Refactor sdk dependent calls
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt12
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt19
-rw-r--r--android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt8
3 files changed, 24 insertions, 15 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
index ecbc117f63..e26ae28697 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt
@@ -2,7 +2,6 @@ package net.mullvad.mullvadvpn.service
import android.content.Intent
import android.graphics.drawable.Icon
-import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.util.Log
@@ -21,6 +20,7 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.ipc.ServiceConnection
import net.mullvad.mullvadvpn.model.ServiceResult
import net.mullvad.mullvadvpn.model.TunnelState
+import net.mullvad.mullvadvpn.util.SdkUtils.setSubtitleIfSupported
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class MullvadTileService : TileService() {
@@ -130,17 +130,11 @@ class MullvadTileService : TileService() {
if (newState == Tile.STATE_ACTIVE) {
state = Tile.STATE_ACTIVE
icon = securedIcon
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- subtitle = resources.getText(R.string.secured)
- }
+ setSubtitleIfSupported(resources.getText(R.string.secured))
} else {
state = Tile.STATE_INACTIVE
icon = unsecuredIcon
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- subtitle = resources.getText(R.string.unsecured)
- }
+ setSubtitleIfSupported(resources.getText(R.string.unsecured))
}
updateTile()
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt
new file mode 100644
index 0000000000..b147c449ea
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt
@@ -0,0 +1,19 @@
+package net.mullvad.mullvadvpn.util
+
+import android.net.VpnService
+import android.os.Build
+import android.service.quicksettings.Tile
+
+object SdkUtils {
+ fun VpnService.Builder.setMeteredIfSupported(isMetered: Boolean) {
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
+ this.setMetered(isMetered)
+ }
+ }
+
+ fun Tile.setSubtitleIfSupported(subtitleText: CharSequence) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ this.subtitle = subtitleText
+ }
+ }
+}
diff --git a/android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
index 7a9160c684..4203d0b0a1 100644
--- a/android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
+++ b/android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
@@ -1,12 +1,12 @@
package net.mullvad.talpid
import android.net.VpnService
-import android.os.Build
import android.os.ParcelFileDescriptor
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress
import kotlin.properties.Delegates.observable
+import net.mullvad.mullvadvpn.util.SdkUtils.setMeteredIfSupported
import net.mullvad.talpid.tun_provider.TunConfig
open class TalpidVpnService : VpnService() {
@@ -115,13 +115,9 @@ open class TalpidVpnService : VpnService() {
addDisallowedApplication(app)
}
}
-
- if (Build.VERSION.SDK_INT >= 29) {
- setMetered(false)
- }
-
setMtu(config.mtu)
setBlocking(false)
+ setMeteredIfSupported(false)
}
val vpnInterface = builder.establish()