summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-05-17 11:57:43 +0200
committerAlbin <albin@mullvad.net>2022-05-18 10:40:01 +0200
commit59893d8882f8af79efc0d3f49efddbdf4ef8c15f (patch)
tree8be0d6135c5d027c33de6327c4e3ebf781236c8a /android
parentf183ac42cce6a876de9ff0ddf437c09713843623 (diff)
downloadmullvadvpn-59893d8882f8af79efc0d3f49efddbdf4ef8c15f.tar.xz
mullvadvpn-59893d8882f8af79efc0d3f49efddbdf4ef8c15f.zip
Remove Android wireguard key view
The wireguard key view is removed in favor of the new way of managing devices. Translations and some error handling remain.
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt35
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt21
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt101
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt11
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt5
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt350
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt58
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/KeyStatusListener.kt33
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt2
-rw-r--r--android/app/src/main/res/layout/advanced_header.xml5
15 files changed, 1 insertions, 640 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt
index bbf84bf143..7871dc2d73 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt
@@ -9,7 +9,6 @@ import net.mullvad.mullvadvpn.model.AccountHistory
import net.mullvad.mullvadvpn.model.AppVersionInfo as AppVersionInfoData
import net.mullvad.mullvadvpn.model.DeviceState
import net.mullvad.mullvadvpn.model.GeoIpLocation
-import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.model.LoginResult
import net.mullvad.mullvadvpn.model.RelayList
import net.mullvad.mullvadvpn.model.Settings
@@ -71,9 +70,6 @@ sealed class Event : Message.EventMessage() {
@Parcelize
object VpnPermissionRequest : Event()
- @Parcelize
- data class WireGuardKeyStatus(val keyStatus: KeygenEvent?) : Event()
-
companion object {
private const val MESSAGE_KEY = "event"
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
index 212f79fba4..5937954fc2 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
@@ -97,12 +97,6 @@ sealed class Request : Message.RequestMessage() {
@Parcelize
data class VpnPermissionResponse(val isGranted: Boolean) : Request()
- @Parcelize
- object WireGuardGenerateKey : Request()
-
- @Parcelize
- object WireGuardVerifyKey : Request()
-
companion object {
private const val MESSAGE_KEY = "request"
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt
deleted file mode 100644
index 875371657e..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/KeygenEvent.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.mullvad.mullvadvpn.model
-
-import android.os.Parcelable
-import kotlinx.parcelize.Parcelize
-
-sealed class KeygenEvent : Parcelable {
- @Parcelize
- class NewKey(
- val publicKey: PublicKey,
- val verified: Boolean?,
- val replacementFailure: KeygenFailure?
- ) : KeygenEvent() {
- constructor(publicKey: PublicKey) : this(publicKey, null, null)
- }
-
- @Parcelize
- object TooManyKeys : KeygenEvent()
-
- @Parcelize
- object GenerationFailure : KeygenEvent()
-
- fun failure(): KeygenFailure? {
- return when (this) {
- is KeygenEvent.TooManyKeys -> KeygenFailure.TooManyKeys
- is KeygenEvent.GenerationFailure -> KeygenFailure.GenerationFailure
- else -> null
- }
- }
-}
-
-@Parcelize
-enum class KeygenFailure : Parcelable {
- TooManyKeys,
- GenerationFailure,
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
index a7ad35ef6d..551e61961f 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
@@ -9,9 +9,7 @@ import net.mullvad.mullvadvpn.model.DeviceState
import net.mullvad.mullvadvpn.model.DnsOptions
import net.mullvad.mullvadvpn.model.GeoIpLocation
import net.mullvad.mullvadvpn.model.GetAccountDataResult
-import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.model.LoginResult
-import net.mullvad.mullvadvpn.model.PublicKey
import net.mullvad.mullvadvpn.model.RelayList
import net.mullvad.mullvadvpn.model.RelaySettingsUpdate
import net.mullvad.mullvadvpn.model.RemoveDeviceEvent
@@ -29,7 +27,6 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
var onTunnelStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected)
var onAppVersionInfoChange: ((AppVersionInfo) -> Unit)? = null
- var onKeygenEvent: ((KeygenEvent) -> Unit)? = null
var onRelayListChange: ((RelayList) -> Unit)? = null
var onDaemonStopped: (() -> Unit)? = null
@@ -57,11 +54,6 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
disconnect(daemonInterfaceAddress)
}
- fun generateWireguardKey(): KeygenEvent? {
- // TODO: remove
- return null
- }
-
fun getAccountData(accountToken: String): GetAccountDataResult {
return getAccountData(daemonInterfaceAddress, accountToken)
}
@@ -98,11 +90,6 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
return getVersionInfo(daemonInterfaceAddress)
}
- fun getWireguardKey(): PublicKey? {
- // TODO: no longer needed
- return getWireguardKey(daemonInterfaceAddress)
- }
-
fun reconnect() {
reconnect(daemonInterfaceAddress)
}
@@ -164,16 +151,11 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
updateRelaySettings(daemonInterfaceAddress, update)
}
- fun verifyWireguardKey(): Boolean? {
- return verifyWireguardKey(daemonInterfaceAddress)
- }
-
fun onDestroy() {
onSettingsChange.unsubscribeAll()
onTunnelStateChange.unsubscribeAll()
onAppVersionInfoChange = null
- onKeygenEvent = null
onRelayListChange = null
onDaemonStopped = null
@@ -204,7 +186,6 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
private external fun getSettings(daemonInterfaceAddress: Long): Settings?
private external fun getState(daemonInterfaceAddress: Long): TunnelState?
private external fun getVersionInfo(daemonInterfaceAddress: Long): AppVersionInfo?
- private external fun getWireguardKey(daemonInterfaceAddress: Long): PublicKey?
private external fun reconnect(daemonInterfaceAddress: Long)
private external fun clearAccountHistory(daemonInterfaceAddress: Long)
private external fun loginAccount(
@@ -241,8 +222,6 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
update: RelaySettingsUpdate
)
- private external fun verifyWireguardKey(daemonInterfaceAddress: Long): Boolean?
-
private fun notifyAppVersionInfoEvent(appVersionInfo: AppVersionInfo) {
onAppVersionInfoChange?.invoke(appVersionInfo)
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt
deleted file mode 100644
index 679f74e9af..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt
+++ /dev/null
@@ -1,101 +0,0 @@
-package net.mullvad.mullvadvpn.service.endpoint
-
-import kotlin.properties.Delegates.observable
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.channels.Channel
-import kotlinx.coroutines.channels.ClosedReceiveChannelException
-import kotlinx.coroutines.channels.actor
-import kotlinx.coroutines.channels.sendBlocking
-import net.mullvad.mullvadvpn.ipc.Event
-import net.mullvad.mullvadvpn.ipc.Request
-import net.mullvad.mullvadvpn.model.KeygenEvent
-
-class KeyStatusListener(endpoint: ServiceEndpoint) {
- companion object {
- private enum class Command {
- GenerateKey,
- VerifyKey,
- }
- }
-
- private val daemon = endpoint.intermittentDaemon
-
- private val commandChannel = spawnActor()
-
- var keyStatus by observable<KeygenEvent?>(null) { _, _, status ->
- endpoint.sendEvent(Event.WireGuardKeyStatus(status))
- }
- private set
-
- init {
- daemon.registerListener(this) { newDaemon ->
- newDaemon?.apply {
- keyStatus = getWireguardKey()?.let { wireguardKey ->
- KeygenEvent.NewKey(wireguardKey, null, null)
- }
-
- onKeygenEvent = { event -> keyStatus = event }
- }
- }
-
- endpoint.dispatcher.apply {
- registerHandler(Request.WireGuardGenerateKey::class) { _ ->
- commandChannel.sendBlocking(Command.GenerateKey)
- }
-
- registerHandler(Request.WireGuardVerifyKey::class) { _ ->
- commandChannel.sendBlocking(Command.VerifyKey)
- }
- }
- }
-
- fun onDestroy() {
- commandChannel.close()
- daemon.unregisterListener(this)
- }
-
- private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) {
- try {
- for (command in channel) {
- when (command) {
- Command.GenerateKey -> {
- // TODO: Skip until device integration is ready.
- // generateKey()
- }
- Command.VerifyKey -> {
- // TODO: Skip until device integration is ready.
- // verifyKey()
- }
- }
- }
- } catch (exception: ClosedReceiveChannelException) {
- }
- }
-
- private suspend fun generateKey() {
- val oldStatus = keyStatus
- val newStatus = daemon.await().generateWireguardKey()
- val newFailure = newStatus?.failure()
- if (oldStatus is KeygenEvent.NewKey && newFailure != null) {
- keyStatus = KeygenEvent.NewKey(
- oldStatus.publicKey,
- oldStatus.verified,
- newFailure
- )
- } else {
- keyStatus = newStatus ?: KeygenEvent.GenerationFailure
- }
- }
-
- private suspend fun verifyKey() {
- // Only update verification status if the key is actually there
- (keyStatus as? KeygenEvent.NewKey)?.let { currentStatus ->
- keyStatus = KeygenEvent.NewKey(
- currentStatus.publicKey,
- daemon.await().verifyWireguardKey(),
- currentStatus.replacementFailure
- )
- }
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
index 2592ffa3ec..bf8cab7e5b 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/ServiceEndpoint.kt
@@ -52,7 +52,6 @@ class ServiceEndpoint(
val appVersionInfoCache = AppVersionInfoCache(this)
val authTokenCache = AuthTokenCache(this)
val customDns = CustomDns(this)
- val keyStatusListener = KeyStatusListener(this)
val locationInfoCache = LocationInfoCache(this)
val relayListListener = RelayListListener(this)
val splitTunneling = SplitTunneling(SplitTunnelingPersistence(context), this)
@@ -82,7 +81,6 @@ class ServiceEndpoint(
connectionProxy.onDestroy()
customDns.onDestroy()
deviceRepositoryBackend.onDestroy()
- keyStatusListener.onDestroy()
locationInfoCache.onDestroy()
relayListListener.onDestroy()
settingsListener.onDestroy()
@@ -137,7 +135,6 @@ class ServiceEndpoint(
Event.AccountHistoryEvent(accountCache.onAccountHistoryChange.latestEvent),
Event.SettingsUpdate(settingsListener.settings),
Event.NewLocation(locationInfoCache.location),
- Event.WireGuardKeyStatus(keyStatusListener.keyStatus),
Event.SplitTunnelingUpdate(splitTunneling.onChange.latestEvent),
Event.CurrentVersion(appVersionInfoCache.currentVersion),
Event.AppVersionInfo(appVersionInfoCache.appVersionInfo),
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
index 33fbd295ea..bfb24c4f33 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AdvancedFragment.kt
@@ -101,10 +101,6 @@ class AdvancedFragment : ServiceDependentFragment(OnNoService.GoBack) {
onSubmit = { mtu -> settingsListener.wireguardMtu = mtu }
}
- view.findViewById<NavigateCell>(R.id.wireguard_keys).apply {
- targetFragment = WireguardKeyFragment::class
- }
-
view.findViewById<NavigateCell>(R.id.split_tunneling).apply {
targetFragment = SplitTunnelingFragment::class
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
index 629c5942c3..efc32a303f 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
@@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.map
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.mullvadvpn.ui.notification.AccountExpiryNotification
-import net.mullvad.mullvadvpn.ui.notification.KeyStatusNotification
import net.mullvad.mullvadvpn.ui.notification.TunnelStateNotification
import net.mullvad.mullvadvpn.ui.notification.VersionInfoNotification
import net.mullvad.mullvadvpn.ui.widget.HeaderBar
@@ -54,7 +53,6 @@ class ConnectFragment :
notificationBanner = view.findViewById<NotificationBanner>(R.id.notification_banner).apply {
notifications.apply {
register(TunnelStateNotification(parentActivity, connectionProxy))
- register(KeyStatusNotification(parentActivity, authTokenCache, keyStatusListener))
register(VersionInfoNotification(parentActivity, appVersionInfoCache))
register(AccountExpiryNotification(parentActivity, authTokenCache, accountCache))
}
@@ -121,7 +119,6 @@ class ConnectFragment :
locationInfoCache.onNewLocation = null
relayListListener.onRelayListChange = null
- keyStatusListener.onKeyStatusChange.unsubscribe(this)
connectionProxy.onUiStateChange.unsubscribe(this)
notificationBanner.onPause()
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
index 73d5e9d3f5..68df75417a 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SelectLocationFragment.kt
@@ -15,7 +15,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.flow.collect
import net.mullvad.mullvadvpn.R
-import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.RelayList
import net.mullvad.mullvadvpn.relaylist.RelayListAdapter
@@ -43,7 +42,7 @@ class SelectLocationFragment :
onSelect = { relayItem ->
jobTracker.newBackgroundJob("selectRelay") {
relayListListener.selectedRelayLocation = relayItem?.location
- maybeConnect()
+ connectionProxy.connect()
jobTracker.newUiJob("close") {
close()
@@ -152,14 +151,6 @@ class SelectLocationFragment :
relayListAdapter.onRelayListChange(relayList, selectedItem)
}
- private fun maybeConnect() {
- val keyStatus = keyStatusListener.keyStatus
-
- if (keyStatus == null || keyStatus is KeygenEvent.NewKey) {
- connectionProxy.connect()
- }
- }
-
private fun initializeLoadingSpinner(parentView: View) {
val spinner = parentView.findViewById<View>(R.id.loading_spinner)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
index c2c1c2fc26..f40f497857 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ServiceDependentFragment.kt
@@ -11,7 +11,6 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.AuthTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy
import net.mullvad.mullvadvpn.ui.serviceconnection.CustomDns
import net.mullvad.mullvadvpn.ui.serviceconnection.DeviceRepository
-import net.mullvad.mullvadvpn.ui.serviceconnection.KeyStatusListener
import net.mullvad.mullvadvpn.ui.serviceconnection.LocationInfoCache
import net.mullvad.mullvadvpn.ui.serviceconnection.RelayListListener
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnection
@@ -52,9 +51,6 @@ abstract class ServiceDependentFragment(private val onNoService: OnNoService) :
lateinit var deviceRepository: DeviceRepository
private set
- lateinit var keyStatusListener: KeyStatusListener
- private set
-
lateinit var locationInfoCache: LocationInfoCache
private set
@@ -76,7 +72,6 @@ abstract class ServiceDependentFragment(private val onNoService: OnNoService) :
connectionProxy = serviceConnection.connectionProxy
deviceRepository = serviceConnection.deviceRepository
customDns = serviceConnection.customDns
- keyStatusListener = serviceConnection.keyStatusListener
locationInfoCache = serviceConnection.locationInfoCache
relayListListener = serviceConnection.relayListListener
settingsListener = serviceConnection.settingsListener
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
deleted file mode 100644
index 506cf340da..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
+++ /dev/null
@@ -1,350 +0,0 @@
-package net.mullvad.mullvadvpn.ui
-
-import android.content.Context
-import android.os.Bundle
-import android.util.Base64
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.widget.TextView
-import kotlinx.coroutines.CompletableDeferred
-import kotlinx.coroutines.delay
-import net.mullvad.mullvadvpn.R
-import net.mullvad.mullvadvpn.model.KeygenEvent
-import net.mullvad.mullvadvpn.model.KeygenFailure
-import net.mullvad.mullvadvpn.model.TunnelState
-import net.mullvad.mullvadvpn.ui.widget.Button
-import net.mullvad.mullvadvpn.ui.widget.CopyableInformationView
-import net.mullvad.mullvadvpn.ui.widget.InformationView
-import net.mullvad.mullvadvpn.ui.widget.InformationView.WhenMissing
-import net.mullvad.mullvadvpn.ui.widget.UrlButton
-import net.mullvad.mullvadvpn.util.TimeAgoFormatter
-import net.mullvad.talpid.tunnel.ErrorStateCause
-import org.joda.time.DateTime
-import org.joda.time.DateTimeZone
-import org.joda.time.format.DateTimeFormat
-
-val RFC3339_FORMAT = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss.SSSSSSSSSS z")
-
-class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
- override val isSecureScreen = true
-
- sealed class ActionState {
- class Idle(val verified: Boolean) : ActionState()
- class Generating(val replacing: Boolean) : ActionState()
- class Verifying() : ActionState()
- }
-
- private lateinit var timeAgoFormatter: TimeAgoFormatter
- private lateinit var titleController: CollapsibleTitleController
-
- private var greenColor: Int = 0
- private var redColor: Int = 0
-
- private var actionCompletion: CompletableDeferred<Unit>? = null
- private var tunnelState: TunnelState = TunnelState.Disconnected
-
- private var actionState: ActionState = ActionState.Idle(false)
- set(value) {
- if (field != value) {
- field = value
- updateKeySpinners()
- updateStatusMessage()
- updateGenerateKeyButtonState()
- updateGenerateKeyButtonText()
- updateVerifyKeyButtonState()
- updateVerifyingKeySpinner()
- }
- }
-
- private var keyStatus: KeygenEvent? = null
- set(value) {
- if (field != value) {
- field = value
- updateKeyInformation()
- updateStatusMessage()
- updateGenerateKeyButtonText()
- updateVerifyKeyButtonState()
-
- actionCompletion?.complete(Unit)
- }
- }
-
- private var isOffline = true
- set(value) {
- if (field != value) {
- field = value
- updateStatusMessage()
- updateGenerateKeyButtonState()
- updateVerifyKeyButtonState()
- manageKeysButton.setEnabled(!value)
- }
- }
-
- private var reconnectionExpected = false
- set(value) {
- field = value
-
- jobTracker.cancelJob("resetReconnectionExpected")
-
- if (value == true) {
- resetReconnectionExpected()
- }
- }
-
- private lateinit var publicKey: CopyableInformationView
- private lateinit var keyAge: InformationView
- private lateinit var statusMessage: TextView
- private lateinit var verifyingKeySpinner: View
- private lateinit var manageKeysButton: UrlButton
- private lateinit var generateKeyButton: Button
- private lateinit var verifyKeyButton: Button
-
- override fun onAttach(context: Context) {
- super.onAttach(context)
-
- redColor = context.getColor(R.color.red)
- greenColor = context.getColor(R.color.green)
- timeAgoFormatter = TimeAgoFormatter(context.resources)
- }
-
- override fun onSafelyCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View {
- val view = inflater.inflate(R.layout.wireguard_key, container, false)
-
- view.findViewById<View>(R.id.back).setOnClickListener {
- parentActivity.onBackPressed()
- }
-
- statusMessage = view.findViewById<TextView>(R.id.wireguard_key_status)
- publicKey = view.findViewById(R.id.public_key)
- keyAge = view.findViewById(R.id.key_age)
-
- generateKeyButton = view.findViewById<Button>(R.id.generate_key).apply {
- setOnClickAction("action", jobTracker) {
- onGenerateKeyPress()
- }
- }
-
- verifyKeyButton = view.findViewById<Button>(R.id.verify_key).apply {
- setOnClickAction("action", jobTracker) {
- onValidateKeyPress()
- }
- }
-
- verifyingKeySpinner = view.findViewById(R.id.verifying_key_spinner)
-
- manageKeysButton = view.findViewById<UrlButton>(R.id.manage_keys).apply {
- prepare(authTokenCache, jobTracker)
- }
-
- titleController = CollapsibleTitleController(view)
-
- return view
- }
-
- override fun onSafelyStart() {
- connectionProxy.onUiStateChange.subscribe(this) { uiState ->
- jobTracker.newUiJob("tunnelStateUpdate") {
- tunnelState = uiState
-
- if (actionState is ActionState.Generating) {
- reconnectionExpected = !(tunnelState is TunnelState.Disconnected)
- } else if (tunnelState is TunnelState.Connected) {
- reconnectionExpected = false
- }
-
- isOffline = uiState is TunnelState.Error &&
- uiState.errorState.cause is ErrorStateCause.IsOffline
- }
- }
-
- keyStatusListener.onKeyStatusChange.subscribe(this) { newKeyStatus ->
- jobTracker.newUiJob("keyStatusUpdate") {
- keyStatus = newKeyStatus
- }
- }
-
- manageKeysButton.updateAuthTokenCache(authTokenCache)
-
- actionState = ActionState.Idle(false)
- }
-
- override fun onSafelyStop() {
- connectionProxy.onUiStateChange.unsubscribe(this)
- keyStatusListener.onKeyStatusChange.unsubscribe(this)
-
- if (!(actionState is ActionState.Idle)) {
- actionState = ActionState.Idle(false)
- }
- }
-
- override fun onSafelyDestroyView() {
- titleController.onDestroy()
- }
-
- private fun updateKeySpinners() {
- when (actionState) {
- is ActionState.Generating -> {
- publicKey.whenMissing = WhenMissing.ShowSpinner
- keyAge.whenMissing = WhenMissing.ShowSpinner
- }
- is ActionState.Verifying, is ActionState.Idle -> {
- publicKey.whenMissing = WhenMissing.Nothing
- keyAge.whenMissing = WhenMissing.Nothing
- }
- }
- }
-
- private fun updateKeyInformation() {
- when (val keyState = keyStatus) {
- is KeygenEvent.NewKey -> {
- val key = keyState.publicKey
- val publicKeyString = Base64.encodeToString(key.key, Base64.NO_WRAP)
- val publicKeyAge =
- DateTime.parse(key.dateCreated, RFC3339_FORMAT).withZone(DateTimeZone.UTC)
-
- publicKey.error = null
- publicKey.information = publicKeyString
- keyAge.information = timeAgoFormatter.format(publicKeyAge)
- }
- is KeygenEvent.TooManyKeys, is KeygenEvent.GenerationFailure -> {
- publicKey.error = resources.getString(failureMessage(keyState.failure()!!))
- publicKey.information = null
- keyAge.information = null
- }
- null -> {
- publicKey.error = null
- publicKey.information = null
- keyAge.information = null
- }
- }
- }
-
- private fun updateStatusMessage() {
- when (val state = actionState) {
- is ActionState.Generating -> statusMessage.visibility = View.INVISIBLE
- is ActionState.Verifying -> statusMessage.visibility = View.INVISIBLE
- is ActionState.Idle -> {
- if (!isOffline) {
- updateKeyStatus(state.verified, keyStatus)
- } else {
- updateOfflineStatus()
- }
- }
- }
- }
-
- private fun updateOfflineStatus() {
- if (reconnectionExpected) {
- setStatusMessage(R.string.wireguard_key_reconnecting, greenColor)
- }
- }
-
- private fun updateKeyStatus(verificationWasDone: Boolean, keyStatus: KeygenEvent?) {
- if (keyStatus is KeygenEvent.NewKey) {
- val replacementFailure = keyStatus.replacementFailure
-
- if (replacementFailure != null) {
- setStatusMessage(failureMessage(replacementFailure), redColor)
- } else {
- updateKeyIsValid(verificationWasDone, keyStatus.verified)
- }
- } else {
- statusMessage.visibility = View.INVISIBLE
- }
- }
-
- private fun updateKeyIsValid(verificationWasDone: Boolean, verified: Boolean?) {
- when (verified) {
- true -> setStatusMessage(R.string.wireguard_key_valid, greenColor)
- false -> setStatusMessage(R.string.wireguard_key_invalid, redColor)
- null -> {
- if (verificationWasDone) {
- setStatusMessage(R.string.wireguard_key_verification_failure, redColor)
- } else {
- statusMessage.visibility = View.INVISIBLE
- }
- }
- }
- }
-
- private fun updateGenerateKeyButtonState() {
- generateKeyButton.setEnabled(actionState is ActionState.Idle && !isOffline)
- }
-
- private fun updateGenerateKeyButtonText() {
- val state = actionState
- val replacingKey = state is ActionState.Generating && state.replacing
- val hasKey = keyStatus is KeygenEvent.NewKey
-
- if (hasKey || replacingKey) {
- generateKeyButton.setText(R.string.wireguard_replace_key)
- } else {
- generateKeyButton.setText(R.string.wireguard_generate_key)
- }
- }
-
- private fun updateVerifyKeyButtonState() {
- val isIdle = actionState is ActionState.Idle
- val hasKey = keyStatus is KeygenEvent.NewKey
-
- verifyKeyButton.setEnabled(isIdle && hasKey && !isOffline)
- }
-
- private fun updateVerifyingKeySpinner() {
- verifyingKeySpinner.visibility = when (actionState) {
- is ActionState.Verifying -> View.VISIBLE
- else -> View.INVISIBLE
- }
- }
-
- private fun setStatusMessage(message: Int, color: Int) {
- statusMessage.setText(message)
- statusMessage.setTextColor(color)
- statusMessage.visibility = View.VISIBLE
- }
-
- private fun failureMessage(failure: KeygenFailure): Int {
- when (failure) {
- KeygenFailure.TooManyKeys -> return R.string.too_many_keys
- KeygenFailure.GenerationFailure -> return R.string.failed_to_generate_key
- }
- }
-
- private suspend fun onGenerateKeyPress() {
- actionState = ActionState.Generating(keyStatus is KeygenEvent.NewKey)
- reconnectionExpected = !(tunnelState is TunnelState.Disconnected)
-
- keyStatus = null
-
- actionCompletion = CompletableDeferred()
- keyStatusListener.generateKey()
- actionCompletion?.await()
-
- actionState = ActionState.Idle(false)
- }
-
- private suspend fun onValidateKeyPress() {
- actionState = ActionState.Verifying()
-
- actionCompletion = CompletableDeferred()
- keyStatusListener.verifyKey()
- actionCompletion?.await()
-
- actionState = ActionState.Idle(true)
- }
-
- private fun resetReconnectionExpected() {
- jobTracker.newUiJob("resetReconnectionExpected") {
- delay(20_000)
-
- if (reconnectionExpected) {
- reconnectionExpected = false
- }
- }
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt
deleted file mode 100644
index 93bd4f4cb3..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/KeyStatusNotification.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-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.ui.serviceconnection.AuthTokenCache
-import net.mullvad.mullvadvpn.ui.serviceconnection.KeyStatusListener
-
-class KeyStatusNotification(
- context: Context,
- authTokenCache: AuthTokenCache,
- private val keyStatusListener: KeyStatusListener
-) : NotificationWithUrlWithToken(context, authTokenCache, 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
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/KeyStatusListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/KeyStatusListener.kt
deleted file mode 100644
index 96e7c852aa..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/KeyStatusListener.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package net.mullvad.mullvadvpn.ui.serviceconnection
-
-import android.os.Messenger
-import net.mullvad.mullvadvpn.ipc.Event
-import net.mullvad.mullvadvpn.ipc.EventDispatcher
-import net.mullvad.mullvadvpn.ipc.Request
-import net.mullvad.mullvadvpn.model.KeygenEvent
-import net.mullvad.talpid.util.EventNotifier
-
-class KeyStatusListener(private val connection: Messenger, eventDispatcher: EventDispatcher) {
- val onKeyStatusChange = EventNotifier<KeygenEvent?>(null)
-
- var keyStatus by onKeyStatusChange.notifiable()
- private set
-
- init {
- eventDispatcher.registerHandler(Event.WireGuardKeyStatus::class) { event ->
- keyStatus = event.keyStatus
- }
- }
-
- fun generateKey() {
- connection.send(Request.WireGuardGenerateKey.message)
- }
-
- fun verifyKey() {
- connection.send(Request.WireGuardVerifyKey.message)
- }
-
- fun onDestroy() {
- onKeyStatusChange.unsubscribeAll()
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt
index 7c44013bca..3e3496fa14 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt
@@ -38,7 +38,6 @@ class ServiceConnection(
val connectionProxy = ConnectionProxy(connection, dispatcher)
val deviceRepository =
DeviceRepository(ServiceConnectionDeviceDataSource(connection, dispatcher), MainScope())
- val keyStatusListener = KeyStatusListener(connection, dispatcher)
val locationInfoCache = LocationInfoCache(dispatcher)
val settingsListener = SettingsListener(connection, dispatcher)
val splitTunneling = get<SplitTunneling>(parameters = { parametersOf(connection, dispatcher) })
@@ -63,7 +62,6 @@ class ServiceConnection(
authTokenCache.onDestroy()
connectionProxy.onDestroy()
- keyStatusListener.onDestroy()
locationInfoCache.onDestroy()
settingsListener.onDestroy()
voucherRedeemer.onDestroy()
diff --git a/android/app/src/main/res/layout/advanced_header.xml b/android/app/src/main/res/layout/advanced_header.xml
index eb04259b3d..0ef50737f7 100644
--- a/android/app/src/main/res/layout/advanced_header.xml
+++ b/android/app/src/main/res/layout/advanced_header.xml
@@ -19,11 +19,6 @@
android:focusable="true"
android:focusableInTouchMode="true"
mullvad:text="@string/wireguard_mtu" />
- <net.mullvad.mullvadvpn.ui.widget.NavigateCell android:id="@+id/wireguard_keys"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/vertical_space"
- mullvad:text="@string/wireguard_key" />
<net.mullvad.mullvadvpn.ui.widget.NavigateCell android:id="@+id/split_tunneling"
android:layout_width="match_parent"
android:layout_height="wrap_content"