diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-09-30 00:54:07 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-09-30 12:29:57 +0000 |
| commit | 2a1dd114964a294b31819eede7557897f28ebf8e (patch) | |
| tree | 2e8869e8a1908d4ad9cee5c4a893439e9a76e7f6 | |
| parent | ffa48bffcf42d18e0457e11544126d90a7a273fe (diff) | |
| download | mullvadvpn-2a1dd114964a294b31819eede7557897f28ebf8e.tar.xz mullvadvpn-2a1dd114964a294b31819eede7557897f28ebf8e.zip | |
Don't show notification button when logged out
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt | 15 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt index dfb153bbc2..b4783c4161 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ForegroundNotificationManager.kt @@ -128,6 +128,11 @@ class ForegroundNotificationManager(val service: Service, val connectionProxy: C var onConnect: (() -> Unit)? = null var onDisconnect: (() -> Unit)? = null + var loggedIn = false + set(value) { + field = value + updateNotification() + } init { if (Build.VERSION.SDK_INT >= 26) { @@ -183,13 +188,17 @@ class ForegroundNotificationManager(val service: Service, val connectionProxy: C val pendingIntent = PendingIntent.getActivity(service, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT) - return NotificationCompat.Builder(service, CHANNEL_ID) + val builder = NotificationCompat.Builder(service, CHANNEL_ID) .setSmallIcon(R.drawable.notification) .setColor(service.getColor(R.color.colorPrimary)) .setContentTitle(service.getString(notificationText)) .setContentIntent(pendingIntent) - .addAction(buildTunnelAction()) - .build() + + if (loggedIn) { + builder.addAction(buildTunnelAction()) + } + + return builder.build() } private fun buildTunnelAction(): NotificationCompat.Action { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt index 08fde91f95..8ccad4f02e 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt @@ -105,7 +105,11 @@ class MullvadVpnService : VpnService() { private fun startDaemon() = GlobalScope.async(Dispatchers.Default) { created.await() ApiRootCaFile().extract(application) - MullvadDaemon(this@MullvadVpnService) + MullvadDaemon(this@MullvadVpnService).apply { + onSettingsChange.subscribe { settings -> + notificationManager.loggedIn = settings?.accountToken != null + } + } } private fun startNotificationManager(): ForegroundNotificationManager { |
