summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-06-23 10:57:45 +0200
committerAlbin <albin@mullvad.net>2022-06-27 17:21:36 +0200
commit3d49685ca6d6fc51f77dfbf1462db2ef1267af2b (patch)
tree8ed8ad884e74af480c772f052fca359652882a08 /android
parent467cfab4dbf4d1cfe79f00718fe7129f9e1b3f8b (diff)
downloadmullvadvpn-3d49685ca6d6fc51f77dfbf1462db2ef1267af2b.tar.xz
mullvadvpn-3d49685ca6d6fc51f77dfbf1462db2ef1267af2b.zip
Promote service to fg when actions provided
As of Android 8 (API level 26), the system has a strict timer where the service must run `startForeground` within seconds after being started as foreground (`startForegroundService`). To mitigate cases where the service has been too slow to reach the target state, for instance when the tile service starts the vpn service as foreground with the connect action, this change aims to always promote the service to foreground when connect/disconnect actions are provided. This solution relies on the service demoting itself to from foreground in cases where it shouldn't run as foreground.
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt6
2 files changed, 7 insertions, 1 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
index e98646d34f..b961de947d 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
@@ -87,7 +87,7 @@ class ForegroundNotificationManager(
}
}
- private fun showOnForeground() {
+ fun showOnForeground() {
service.startForeground(
TunnelStateNotification.NOTIFICATION_ID,
tunnelStateNotification.build()
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
index 9ff1e9f6a5..0a6c29b44e 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -114,6 +114,12 @@ class MullvadVpnService : TalpidVpnService() {
val startResult = super.onStartCommand(intent, flags, startId)
var quitCommand = false
+ // Always promote to foreground if connect/disconnect actions are provided to mitigate cases
+ // where the service would potentially otherwise be too slow running `startForeground`.
+ if (intent?.action == KEY_CONNECT_ACTION || intent?.action == KEY_DISCONNECT_ACTION) {
+ notificationManager.showOnForeground()
+ }
+
notificationManager.updateNotification()
if (!keyguardManager.isDeviceLocked) {