diff options
| author | Albin <albin@mullvad.net> | 2022-01-24 13:49:12 +0100 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-01-24 13:49:12 +0100 |
| commit | 127fdb5bc7e9ca10ca4ce690ff1e986a2732a8c2 (patch) | |
| tree | 073b44ed2d40c480963e5164a9e513b86e6dd905 | |
| parent | 5615c124acec08bf62fbad316d7814245edabf5b (diff) | |
| parent | 673a2ee514732c5a0ca9e268b09ce752675ede07 (diff) | |
| download | mullvadvpn-127fdb5bc7e9ca10ca4ce690ff1e986a2732a8c2.tar.xz mullvadvpn-127fdb5bc7e9ca10ca4ce690ff1e986a2732a8c2.zip | |
Merge branch 'fix-tunnel-state-notification-behavior'
6 files changed, 34 insertions, 51 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 661d111b53..b46b3caa44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Line wrap the file at 100 chars. Th * The System Settings way of killing apps ("Force Stop"). - Change Quick Settings tile label to reflect the action of clicking the tile. Also add a subtitle on supported Android versions (Q and above) to reflect the state. +- Hide the tunnel state notification from the lock screen. #### Windows - Update wireguard-nt to 0.10.1. @@ -93,6 +94,8 @@ Line wrap the file at 100 chars. Th - Fix Quick Settings tile showing wrong state in certain scenarios. - Fix banner sometimes incorrectly showing (e.g. "BLOCKING INTERNET"). - Fix issue with the user getting kicked out of certain views in settings when the app is brought to the foreground. +- Fix "Secure my connection" action not always visible in tunnel state notification. +- Fix tunnel state notification sometimes re-appearing after being dismissed. ### Security - Restrict which applications are allowed to communicate with the API while in a blocking state. 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 92c4fcd078..115784c8f3 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 @@ -1,11 +1,6 @@ package net.mullvad.mullvadvpn.service -import android.app.KeyguardManager import android.app.Service -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter import kotlin.properties.Delegates.observable import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -19,8 +14,7 @@ import net.mullvad.talpid.util.autoSubscribable class ForegroundNotificationManager( val service: MullvadVpnService, - val connectionProxy: ConnectionProxy, - val keyguardManager: KeyguardManager + val connectionProxy: ConnectionProxy ) { private sealed class UpdaterMessage { class UpdateNotification : UpdaterMessage() @@ -32,20 +26,6 @@ class ForegroundNotificationManager( private val tunnelStateNotification = TunnelStateNotification(service) - private val deviceLockListener = object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - val action = intent.action - - if (action == Intent.ACTION_USER_PRESENT || action == Intent.ACTION_SCREEN_OFF) { - deviceIsUnlocked = !keyguardManager.isDeviceLocked - } - } - } - - private var deviceIsUnlocked by observable(!keyguardManager.isDeviceLocked) { _, _, _ -> - updater.sendBlocking(UpdaterMessage.UpdateAction()) - } - private var loggedIn by observable(false) { _, _, _ -> updater.sendBlocking(UpdaterMessage.UpdateAction()) } @@ -72,25 +52,11 @@ class ForegroundNotificationManager( updater.sendBlocking(UpdaterMessage.NewTunnelState(newState)) } - service.apply { - registerReceiver( - deviceLockListener, - IntentFilter().apply { - addAction(Intent.ACTION_USER_PRESENT) - addAction(Intent.ACTION_SCREEN_OFF) - } - ) - } - updater.sendBlocking(UpdaterMessage.UpdateNotification()) } fun onDestroy() { - accountNumberEvents = null - connectionProxy.onStateChange.unsubscribe(this) - service.unregisterReceiver(deviceLockListener) - updater.close() } @@ -130,7 +96,11 @@ class ForegroundNotificationManager( } } + fun cancelNotification() { + tunnelStateNotification.visible = false + } + private fun updateNotificationAction() { - tunnelStateNotification.showAction = loggedIn && deviceIsUnlocked + tunnelStateNotification.showAction = loggedIn } } 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 d09472fa3d..6875655e46 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 @@ -83,7 +83,7 @@ class MullvadVpnService : TalpidVpnService() { } notificationManager = - ForegroundNotificationManager(this, connectionProxy, keyguardManager).apply { + ForegroundNotificationManager(this, connectionProxy).apply { accountNumberEvents = endpoint.settingsListener.accountNumberNotifier } @@ -174,6 +174,7 @@ class MullvadVpnService : TalpidVpnService() { connectionProxy.onStateChange.latestEvent.let { tunnelState -> Log.d(TAG, "Task removed (tunnelState=$tunnelState)") if (tunnelState == TunnelState.Disconnected) { + notificationManager.cancelNotification() stop() } } 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 049dd68d0a..7b835bccdc 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 @@ -6,6 +6,7 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.net.Uri +import androidx.core.app.NotificationCompat import kotlin.properties.Delegates.observable import kotlinx.coroutines.delay import net.mullvad.mullvadvpn.R @@ -36,9 +37,11 @@ class AccountExpiryNotification( private val channel = NotificationChannel( context, "mullvad_account_time", + NotificationCompat.VISIBILITY_PRIVATE, R.string.account_time_notification_channel_name, R.string.account_time_notification_channel_description, - NotificationManager.IMPORTANCE_HIGH + NotificationManager.IMPORTANCE_HIGH, + true ) var loginStatus by observable<LoginStatus?>(null) { _, oldValue, newValue -> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt index e251e5b4de..cceb5b4344 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt @@ -1,35 +1,38 @@ package net.mullvad.mullvadvpn.service.notifications import android.app.Notification -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.PendingIntent import android.content.Context +import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import net.mullvad.mullvadvpn.R class NotificationChannel( val context: Context, val id: String, - val name: Int, - val description: Int, - val importance: Int + val visibility: Int, + name: Int, + description: Int, + importance: Int, + isVibrationEnabled: Boolean ) { private val badgeColor by lazy { context.getColor(R.color.colorPrimary) } - val notificationManager = - context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val notificationManager = NotificationManagerCompat.from(context) init { val channelName = context.getString(name) val channelDescription = context.getString(description) - val channel = NotificationChannel(id, channelName, importance).apply { - description = channelDescription - setShowBadge(true) - } + val channel = NotificationChannelCompat.Builder(id, importance) + .setName(channelName) + .setDescription(channelDescription) + .setShowBadge(true) + .setVibrationEnabled(isVibrationEnabled) + .build() notificationManager.createNotificationChannel(channel) } @@ -59,7 +62,7 @@ class NotificationChannel( return buildNotification(pendingIntent, context.getString(title), actions, deleteIntent) } - fun buildNotification( + private fun buildNotification( pendingIntent: PendingIntent, title: String, actions: List<NotificationCompat.Action>, @@ -70,6 +73,7 @@ class NotificationChannel( .setColor(badgeColor) .setContentTitle(title) .setContentIntent(pendingIntent) + .setVisibility(visibility) for (action in actions) { builder.addAction(action) 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 10f929ab97..a69b769d36 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 @@ -20,9 +20,11 @@ class TunnelStateNotification(val context: Context) { private val channel = NotificationChannel( context, "vpn_tunnel_status", + NotificationCompat.VISIBILITY_SECRET, R.string.foreground_notification_channel_name, R.string.foreground_notification_channel_description, - NotificationManager.IMPORTANCE_MIN + NotificationManager.IMPORTANCE_MIN, + false ) private val notificationText: Int |
