summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-26 19:40:38 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-27 13:31:33 +0000
commitbc36ecfb3f0f6410696c7d0b9b0b99a2c66b7ab0 (patch)
treed469f714712e5403b1a173842408fb68bced34c5 /android/src
parent3b626332f478712129a9fad2a5c470be6179dfe1 (diff)
downloadmullvadvpn-bc36ecfb3f0f6410696c7d0b9b0b99a2c66b7ab0.tar.xz
mullvadvpn-bc36ecfb3f0f6410696c7d0b9b0b99a2c66b7ab0.zip
Hide notification action button on lock screen
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt28
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt2
2 files changed, 27 insertions, 3 deletions
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 a6e020724c..28d32c1c89 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/ForegroundNotificationManager.kt
@@ -1,5 +1,6 @@
package net.mullvad.mullvadvpn.service
+import android.app.KeyguardManager
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
@@ -24,13 +25,24 @@ val KEY_DISCONNECT_ACTION = "net.mullvad.mullvadvpn.disconnect_action"
class ForegroundNotificationManager(
val service: MullvadVpnService,
- val serviceNotifier: EventNotifier<ServiceInstance?>
+ val serviceNotifier: EventNotifier<ServiceInstance?>,
+ val keyguardManager: KeyguardManager
) {
private val notificationManager =
service.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val badgeColor = service.resources.getColor(R.color.colorPrimary)
+ 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 connectionProxy: ConnectionProxy? = null
set(value) {
if (field != value) {
@@ -73,6 +85,14 @@ class ForegroundNotificationManager(
updateNotification()
}
+ private var deviceIsUnlocked = true
+ set(value) {
+ if (field != value) {
+ field = value
+ updateNotification()
+ }
+ }
+
private var loggedIn = false
set(value) {
field = value
@@ -194,6 +214,10 @@ class ForegroundNotificationManager(
service.apply {
registerReceiver(connectReceiver, IntentFilter(KEY_CONNECT_ACTION))
registerReceiver(disconnectReceiver, IntentFilter(KEY_DISCONNECT_ACTION))
+ registerReceiver(deviceLockListener, IntentFilter().apply {
+ addAction(Intent.ACTION_USER_PRESENT)
+ addAction(Intent.ACTION_SCREEN_OFF)
+ })
}
updateNotification()
@@ -262,7 +286,7 @@ class ForegroundNotificationManager(
.setContentTitle(service.getString(notificationText))
.setContentIntent(pendingIntent)
- if (loggedIn) {
+ if (loggedIn && deviceIsUnlocked) {
builder.addAction(buildTunnelAction())
}
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 404d7913af..9224246eb0 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt
@@ -71,7 +71,7 @@ class MullvadVpnService : TalpidVpnService() {
super.onCreate()
keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
- notificationManager = ForegroundNotificationManager(this, serviceNotifier)
+ notificationManager = ForegroundNotificationManager(this, serviceNotifier, keyguardManager)
tunnelStateUpdater = TunnelStateUpdater(this, serviceNotifier)
setUp()