summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-09-26 11:58:18 +0200
committerAlbin <albin@mullvad.net>2022-09-26 11:58:18 +0200
commitf864c39cf7da27d772377f493b730a8a1f9a2298 (patch)
treeb3b45ac440f757f5e0a650320f95879f5efeef5c /android/app/src
parent3f0713e89ad5792c2b026acc5621e0dc0386103d (diff)
parent8e9bb97d28b1e2d5fdd166d4ea8f0d281fb9c4b7 (diff)
downloadmullvadvpn-f864c39cf7da27d772377f493b730a8a1f9a2298.tar.xz
mullvadvpn-f864c39cf7da27d772377f493b730a8a1f9a2298.zip
Merge branch 'bump-android-sdk-version'
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/service/notifications/AccountExpiryNotification.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt21
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt28
-rw-r--r--android/app/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt8
5 files changed, 49 insertions, 26 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/service/notifications/AccountExpiryNotification.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
index 3181f2ee95..ae4fcc75ff 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
@@ -15,6 +15,7 @@ import net.mullvad.mullvadvpn.service.MullvadDaemon
import net.mullvad.mullvadvpn.service.endpoint.AccountCache
import net.mullvad.mullvadvpn.util.Intermittent
import net.mullvad.mullvadvpn.util.JobTracker
+import net.mullvad.mullvadvpn.util.SdkUtils
import org.joda.time.DateTime
import org.joda.time.Duration
@@ -94,10 +95,9 @@ class AccountExpiryNotification(
val url = jobTracker.runOnBackground {
Uri.parse("$buyMoreTimeUrl?token=${daemon.await().getWwwAuthToken()}")
}
-
val intent = Intent(Intent.ACTION_VIEW, url)
- val flags = PendingIntent.FLAG_UPDATE_CURRENT
- val pendingIntent = PendingIntent.getActivity(context, 1, intent, flags)
+ val pendingIntent =
+ PendingIntent.getActivity(context, 1, intent, SdkUtils.getSupportedPendingIntentFlags())
return channel.buildNotification(pendingIntent, format(expiry, remainingTime))
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
index 94002ba735..aee8115c1e 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt
@@ -10,6 +10,7 @@ import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.mullvadvpn.ui.MainActivity
+import net.mullvad.mullvadvpn.util.SdkUtils
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class TunnelStateNotification(val context: Context) {
@@ -85,10 +86,12 @@ class TunnelStateNotification(val context: Context) {
val intent = Intent(context, MainActivity::class.java)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
.setAction(Intent.ACTION_MAIN)
-
- val pendingIntent =
- PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
-
+ val pendingIntent = PendingIntent.getActivity(
+ context,
+ 1,
+ intent,
+ SdkUtils.getSupportedPendingIntentFlags()
+ )
val actions = if (showAction) {
listOf(buildAction())
} else {
@@ -101,11 +104,13 @@ class TunnelStateNotification(val context: Context) {
private fun buildAction(): NotificationCompat.Action {
val action = TunnelStateNotificationAction.from(tunnelState)
val label = context.getString(action.text)
-
val intent = Intent(action.key).setPackage("net.mullvad.mullvadvpn")
- val flags = PendingIntent.FLAG_UPDATE_CURRENT
-
- val pendingIntent = PendingIntent.getForegroundService(context, 1, intent, flags)
+ val pendingIntent = PendingIntent.getForegroundService(
+ context,
+ 1,
+ intent,
+ SdkUtils.getSupportedPendingIntentFlags()
+ )
return NotificationCompat.Action(action.icon, label, pendingIntent)
}
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..7f1ba6bd74
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SdkUtils.kt
@@ -0,0 +1,28 @@
+package net.mullvad.mullvadvpn.util
+
+import android.app.PendingIntent
+import android.net.VpnService
+import android.os.Build
+import android.service.quicksettings.Tile
+
+object SdkUtils {
+ fun getSupportedPendingIntentFlags(): Int {
+ return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S) {
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
+ } else {
+ PendingIntent.FLAG_UPDATE_CURRENT
+ }
+ }
+
+ 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()