summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-01-21 15:35:36 +0100
committerAlbin <albin@mullvad.net>2022-01-24 13:44:45 +0100
commit12d08a1e79c05488e60e486ae2b4cd0466b7551b (patch)
treeae842c6aa27ca0ca800b6dc096be4cb9c635fcbc /android/app/src
parent640d74e88804be666fb2f04ff67a8ba8d3c5e37e (diff)
downloadmullvadvpn-12d08a1e79c05488e60e486ae2b4cd0466b7551b.tar.xz
mullvadvpn-12d08a1e79c05488e60e486ae2b4cd0466b7551b.zip
Hide tunnel state notification from lock screen
The tunnel state notification is hidden from the lock screen by using the Android notification visibility mechanism.
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt36
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt2
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/NotificationChannel.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/TunnelStateNotification.kt1
5 files changed, 8 insertions, 37 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 2592b17529..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,23 +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() {
connectionProxy.onStateChange.unsubscribe(this)
- service.unregisterReceiver(deviceLockListener)
-
updater.close()
}
@@ -133,6 +101,6 @@ class ForegroundNotificationManager(
}
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 9e52bebdd5..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
}
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..c2e227b725 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,6 +37,7 @@ 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
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 54c8fe05a1..e8b5ab7e8e 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,8 +1,6 @@
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
@@ -13,6 +11,7 @@ import net.mullvad.mullvadvpn.R
class NotificationChannel(
val context: Context,
val id: String,
+ val visibility: Int,
name: Int,
description: Int,
importance: Int
@@ -72,6 +71,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..e6b3a5da55 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,6 +20,7 @@ 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