summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-26 17:09:05 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-01 20:22:02 +0000
commit580524edb7d7d6d6dd27bba20ec3e71adb6ed534 (patch)
tree9b43036155a75033f3f385a453c9879b137875d9 /android
parent3e221112d304fc50a0ddf7e61b34ff15a81ac068 (diff)
downloadmullvadvpn-580524edb7d7d6d6dd27bba20ec3e71adb6ed534.tar.xz
mullvadvpn-580524edb7d7d6d6dd27bba20ec3e71adb6ed534.zip
Create WireGuard key error in-app notification
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt58
1 files changed, 58 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt
new file mode 100644
index 0000000000..880cea9f8c
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt
@@ -0,0 +1,58 @@
+package net.mullvad.mullvadvpn.ui.notification
+
+import android.content.Context
+import net.mullvad.mullvadvpn.R
+import net.mullvad.mullvadvpn.model.KeygenEvent
+import net.mullvad.mullvadvpn.service.KeyStatusListener
+import net.mullvad.mullvadvpn.service.MullvadDaemon
+
+class KeyStatusNotification(
+ context: Context,
+ daemon: MullvadDaemon,
+ private val keyStatusListener: KeyStatusListener
+) : NotificationWithUrlWithToken(context, daemon, R.string.wg_key_url) {
+ private val failedToGenerateKey = context.getString(R.string.failed_to_generate_key)
+ private val tooManyKeys = context.getString(R.string.too_many_keys)
+
+ init {
+ status = StatusLevel.Error
+ title = context.getString(R.string.wireguard_error)
+ }
+
+ override fun onResume() {
+ keyStatusListener.onKeyStatusChange.subscribe(this) { keyStatus ->
+ jobTracker.newUiJob("updateKeyStatus") {
+ updateKeyStatus(keyStatus)
+ }
+ }
+ }
+
+ override fun onPause() {
+ keyStatusListener.onKeyStatusChange.unsubscribe(this)
+ }
+
+ private fun updateKeyStatus(keyStatus: KeygenEvent?) {
+ when (keyStatus) {
+ null -> shouldShow = false
+ is KeygenEvent.NewKey -> shouldShow = false
+ is KeygenEvent.TooManyKeys -> showTooManyKeys()
+ is KeygenEvent.GenerationFailure -> showGenerationFailure()
+ }
+
+ update()
+ }
+
+ private fun showTooManyKeys() {
+ onClick = openUrl
+ message = tooManyKeys
+ showIcon = true
+ shouldShow = true
+ }
+
+ private fun showGenerationFailure() {
+ onClick = null
+ message = failedToGenerateKey
+ showIcon = false
+ shouldShow = true
+ }
+}