summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-09-07 11:49:26 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-09-07 12:06:51 +0000
commit7ae0fc71b44512b94bde4f32f3da9d59a2c9a59b (patch)
treeb3ddaba00712198709464f80ed3b07cce4d21137 /android
parent76be396b390fba33ed3c410c88c963be4849deae (diff)
downloadmullvadvpn-7ae0fc71b44512b94bde4f32f3da9d59a2c9a59b.tar.xz
mullvadvpn-7ae0fc71b44512b94bde4f32f3da9d59a2c9a59b.zip
Use notification channel for service notification
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt20
-rw-r--r--android/src/main/res/values/strings.xml4
2 files changed, 23 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt
index 5718e66036..22f685daa1 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt
@@ -1,17 +1,20 @@
package net.mullvad.mullvadvpn
import android.app.Notification
+import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
+import android.os.Build
import android.support.v4.app.NotificationCompat
import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy
import net.mullvad.mullvadvpn.model.ActionAfterDisconnect
import net.mullvad.mullvadvpn.model.TunnelState
+val CHANNEL_ID = "vpn_tunnel_status"
val FOREGROUND_NOTIFICATION_ID: Int = 1
class ForegroundNotificationManager(val service: Service, val connectionProxy: ConnectionProxy) {
@@ -65,6 +68,10 @@ class ForegroundNotificationManager(val service: Service, val connectionProxy: C
tunnelState = uiState
}
+ if (Build.VERSION.SDK_INT >= 26) {
+ initChannel()
+ }
+
service.startForeground(FOREGROUND_NOTIFICATION_ID, buildNotification())
}
@@ -76,6 +83,17 @@ class ForegroundNotificationManager(val service: Service, val connectionProxy: C
service.stopForeground(FOREGROUND_NOTIFICATION_ID)
}
+ private fun initChannel() {
+ val channelName = service.getString(R.string.foreground_notification_channel_name)
+ val importance = NotificationManager.IMPORTANCE_MIN
+ val channel = NotificationChannel(CHANNEL_ID, channelName, importance).apply {
+ description = service.getString(R.string.foreground_notification_channel_description)
+ setShowBadge(true)
+ }
+
+ notificationManager.createNotificationChannel(channel)
+ }
+
private fun updateNotification() {
if (!reconnecting || !showingReconnecting) {
notificationManager.notify(FOREGROUND_NOTIFICATION_ID, buildNotification())
@@ -90,7 +108,7 @@ class ForegroundNotificationManager(val service: Service, val connectionProxy: C
val pendingIntent =
PendingIntent.getActivity(service, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
- return NotificationCompat.Builder(service)
+ return NotificationCompat.Builder(service, CHANNEL_ID)
.setSmallIcon(R.drawable.notification)
.setColor(service.getColor(R.color.colorPrimary))
.setContentTitle(service.getString(notificationText))
diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml
index f03cef4181..229cb6c933 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -7,6 +7,10 @@
<string name="secured">Secured</string>
<string name="unsecured">Unsecured</string>
<string name="blocking_all_connections">Blocking all connections</string>
+ <string name="foreground_notification_channel_name">VPN tunnel status</string>
+ <string name="foreground_notification_channel_description">
+ Shows current VPN tunnel status
+ </string>
<string name="connecting_to_daemon">Connecting to Mullvad system service...</string>