diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-05 10:00:21 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-10-05 10:00:21 -0300 |
| commit | 15f0704daff4ae1b33e6cf12770fcf65b4654714 (patch) | |
| tree | d66bd503fe2e7823fbd7c0332ad5c896d6dcfe2e | |
| parent | dccb131165ba5a03507e68fe8cf654f1a3468f1d (diff) | |
| parent | e67f949c8c57bcc1584f9b0777aa01338bef6f63 (diff) | |
| download | mullvadvpn-15f0704daff4ae1b33e6cf12770fcf65b4654714.tar.xz mullvadvpn-15f0704daff4ae1b33e6cf12770fcf65b4654714.zip | |
Merge branch 'quit-when-notification-is-dismissed'
6 files changed, 49 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e36272bdf..466d15d150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ Line wrap the file at 100 chars. Th - Fix crash if connection to service is lost while opening the Split Tunneling settings screen. - Fix rare crash that could occur when the tunnel state changes when showing or hiding the quick settings tile. +- Fix app starting by itself sometimes. #### Linux - Fix split tunneling rules preventing `systemd-resolved` from performing DNS lookups for excluded diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 0093dbcb21..6295231f64 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -36,6 +36,9 @@ <intent-filter> <action android:name="net.mullvad.mullvadvpn.disconnect_action" /> </intent-filter> + <intent-filter> + <action android:name="net.mullvad.mullvadvpn.quit_action" /> + </intent-filter> </service> <service android:name="net.mullvad.mullvadvpn.service.MullvadTileService" android:label="@string/app_name" diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt index 9d76a0be52..0329e156bf 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt @@ -46,14 +46,15 @@ class ForegroundNotificationManager( private var loggedIn by observable(false) { _, _, _ -> updateNotificationAction() } - private var onForeground = false - private val tunnelState get() = tunnelStateEvents?.latestEvent ?: TunnelState.Disconnected() private val shouldBeOnForeground get() = lockedToForeground || !(tunnelState is TunnelState.Disconnected) + var onForeground = false + private set + var lockedToForeground by observable(false) { _, _, _ -> updateNotification() } init { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 5034d561a1..439216e897 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -28,6 +28,7 @@ class MullvadVpnService : TalpidVpnService() { val KEY_CONNECT_ACTION = "net.mullvad.mullvadvpn.connect_action" val KEY_DISCONNECT_ACTION = "net.mullvad.mullvadvpn.disconnect_action" + val KEY_QUIT_ACTION = "net.mullvad.mullvadvpn.quit_action" init { System.loadLibrary("mullvad_jni") @@ -99,6 +100,7 @@ class MullvadVpnService : TalpidVpnService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Log.d(TAG, "Starting service") val startResult = super.onStartCommand(intent, flags, startId) + var quitCommand = false if (!keyguardManager.isDeviceLocked) { val action = intent?.action @@ -107,10 +109,13 @@ class MullvadVpnService : TalpidVpnService() { pendingAction = PendingAction.Connect } else if (action == KEY_DISCONNECT_ACTION) { pendingAction = PendingAction.Disconnect + } else if (action == KEY_QUIT_ACTION && !notificationManager.onForeground) { + quitCommand = true + stop() } } - if (shouldStop) { + if (shouldStop && !quitCommand) { shouldStop = false if (isStopping) { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt index 7a638721ac..0f4646335c 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt @@ -37,26 +37,36 @@ class NotificationChannel( } } - fun buildNotification(intent: PendingIntent, title: String): Notification { - return buildNotification(intent, title, emptyList()) + fun buildNotification( + intent: PendingIntent, + title: String, + deleteIntent: PendingIntent? = null + ): Notification { + return buildNotification(intent, title, emptyList(), deleteIntent) } - fun buildNotification(intent: PendingIntent, title: Int): Notification { - return buildNotification(intent, title, emptyList()) + fun buildNotification( + intent: PendingIntent, + title: Int, + deleteIntent: PendingIntent? = null + ): Notification { + return buildNotification(intent, title, emptyList(), deleteIntent) } fun buildNotification( pendingIntent: PendingIntent, title: Int, - actions: List<NotificationCompat.Action> + actions: List<NotificationCompat.Action>, + deleteIntent: PendingIntent? = null ): Notification { - return buildNotification(pendingIntent, context.getString(title), actions) + return buildNotification(pendingIntent, context.getString(title), actions, deleteIntent) } fun buildNotification( pendingIntent: PendingIntent, title: String, - actions: List<NotificationCompat.Action> + actions: List<NotificationCompat.Action>, + deleteIntent: PendingIntent? = null ): Notification { val builder = NotificationCompat.Builder(context, id) .setSmallIcon(R.drawable.small_logo_black) @@ -68,6 +78,10 @@ class NotificationChannel( builder.addAction(action) } + deleteIntent?.let { intent -> + builder.setDeleteIntent(intent) + } + return builder.build() } } 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) + } + } } |
