diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-03 21:17:11 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-05 12:32:42 +0000 |
| commit | 6bc6d0e0b35485ea1d69a8167d20b212db661a60 (patch) | |
| tree | 9773866a7afb3f72c657e5491409127a8a5af69a /android | |
| parent | 8ff831b8d60ab6a95db965890b0abbefe283fb67 (diff) | |
| download | mullvadvpn-6bc6d0e0b35485ea1d69a8167d20b212db661a60.tar.xz mullvadvpn-6bc6d0e0b35485ea1d69a8167d20b212db661a60.zip | |
Quit when notification is dismissed
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt index 7f95cf5b39..de384379cf 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt @@ -10,6 +10,7 @@ import android.support.v4.app.NotificationCompat import kotlin.properties.Delegates.observable import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.model.TunnelState +import net.mullvad.mullvadvpn.service.MullvadVpnService import net.mullvad.mullvadvpn.ui.MainActivity import net.mullvad.talpid.tunnel.ActionAfterDisconnect @@ -90,13 +91,15 @@ class TunnelStateNotification(val context: Context) { val pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT) + val deleteIntent = buildDeleteIntent() + val actions = if (showAction) { listOf(buildAction()) } else { emptyList() } - return channel.buildNotification(pendingIntent, notificationText, actions) + return channel.buildNotification(pendingIntent, notificationText, actions, deleteIntent) } private fun buildAction(): NotificationCompat.Action { @@ -114,4 +117,15 @@ class TunnelStateNotification(val context: Context) { return NotificationCompat.Action(action.icon, label, pendingIntent) } + + private fun buildDeleteIntent(): PendingIntent { + val intent = Intent(MullvadVpnService.KEY_QUIT_ACTION).setPackage("net.mullvad.mullvadvpn") + val flags = PendingIntent.FLAG_UPDATE_CURRENT + + if (Build.VERSION.SDK_INT >= 26) { + return PendingIntent.getForegroundService(context, 1, intent, flags) + } else { + return PendingIntent.getService(context, 1, intent, flags) + } + } } |
