diff options
Diffstat (limited to 'android/service')
| -rw-r--r-- | android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt index b360613eaa..dad6ea5b56 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt @@ -1,6 +1,9 @@ package net.mullvad.mullvadvpn.service import android.app.Service +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED +import android.net.VpnService +import android.os.Build import kotlin.properties.Delegates.observable import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -90,11 +93,22 @@ class ForegroundNotificationManager( } fun showOnForeground() { - service.startForeground( - TunnelStateNotification.NOTIFICATION_ID, - tunnelStateNotification.build() - ) - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + if (VpnService.prepare(service) == null) { + service.startForeground( + TunnelStateNotification.NOTIFICATION_ID, + tunnelStateNotification.build(), + FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED + ) + } else { + return + } + } else { + service.startForeground( + TunnelStateNotification.NOTIFICATION_ID, + tunnelStateNotification.build(), + ) + } onForeground = true } |
