Skip to content

Commit

Permalink
Support new tunnel state API in the Android frontend.
Browse files Browse the repository at this point in the history
Remove `get_current_location` from jni.
Rawa authored and Serock3 committed Dec 19, 2023
1 parent f9111bf commit 2417049
Showing 30 changed files with 82 additions and 477 deletions.
Original file line number Diff line number Diff line change
@@ -79,7 +79,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked,
@@ -115,7 +114,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked,
@@ -149,7 +147,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -182,7 +179,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -216,7 +212,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -245,12 +240,11 @@ class ConnectScreenTest {
ConnectUiState(
location = null,
relayLocation = mockRelayLocation,
tunnelUiState = TunnelState.Disconnected,
tunnelRealState = TunnelState.Disconnected,
tunnelUiState = TunnelState.Disconnected(),
tunnelRealState = TunnelState.Disconnected(),
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -286,7 +280,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
@@ -326,7 +319,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
@@ -363,7 +355,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked,
@@ -399,7 +390,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked,
@@ -430,12 +420,11 @@ class ConnectScreenTest {
ConnectUiState(
location = null,
relayLocation = mockRelayLocation,
tunnelUiState = TunnelState.Disconnected,
tunnelRealState = TunnelState.Disconnected,
tunnelUiState = TunnelState.Disconnected(),
tunnelRealState = TunnelState.Disconnected(),
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -468,7 +457,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -501,7 +489,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -528,12 +515,11 @@ class ConnectScreenTest {
ConnectUiState(
location = null,
relayLocation = null,
tunnelUiState = TunnelState.Disconnected,
tunnelRealState = TunnelState.Disconnected,
tunnelUiState = TunnelState.Disconnected(),
tunnelRealState = TunnelState.Disconnected(),
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -565,7 +551,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -582,39 +567,6 @@ class ConnectScreenTest {
verify { mockedClickHandler.invoke() }
}

@Test
fun testToggleTunnelInfo() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
val dummyLocation = GeoIpLocation(null, null, "dummy country", null, "dummy hostname")
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
location = dummyLocation,
relayLocation = null,
tunnelUiState = TunnelState.Connecting(null, null),
tunnelRealState = TunnelState.Connecting(null, null),
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
isPlayBuild = false
),
onToggleTunnelInfo = mockedClickHandler
)
}

// Act
composeTestRule.onNodeWithTag(LOCATION_INFO_TEST_TAG).performClick()

// Assert
verify { mockedClickHandler.invoke() }
}

@Test
fun showLocationInfo() {
// Arrange
@@ -638,7 +590,6 @@ class ConnectScreenTest {
inAddress = mockInAddress,
outAddress = mockOutAddress,
showLocation = false,
isTunnelInfoExpanded = true,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null,
@@ -647,6 +598,8 @@ class ConnectScreenTest {
)
}

composeTestRule.onNodeWithTag(LOCATION_INFO_TEST_TAG).performClick()

// Assert
composeTestRule.apply {
onNodeWithText(mockHostName).assertExists()
@@ -677,7 +630,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UpdateAvailable(versionInfo),
@@ -714,7 +666,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo),
@@ -748,7 +699,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate),
@@ -787,7 +737,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo),
@@ -820,7 +769,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate),
@@ -838,10 +786,8 @@ class ConnectScreenTest {

@Test
fun testOpenAccountView() {

val onAccountClickMockk: () -> Unit = mockk(relaxed = true)

// Arrange
val onAccountClickMockk: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
ConnectScreen(uiState = ConnectUiState.INITIAL, onAccountClick = onAccountClickMockk)
}
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import net.mullvad.talpid.tunnel.ErrorStateCause
private fun PreviewConnectionStatusText() {
AppTheme {
SpacedColumn {
ConnectionStatusText(TunnelState.Disconnected)
ConnectionStatusText(TunnelState.Disconnected())
ConnectionStatusText(TunnelState.Connecting(null, null))
ConnectionStatusText(
state = TunnelState.Error(ErrorState(ErrorStateCause.Ipv6Unavailable, true))
Original file line number Diff line number Diff line change
@@ -19,7 +19,9 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -108,7 +110,6 @@ fun Connect(navigator: DestinationsNavigator) {
onSwitchLocationClick = {
navigator.navigate(SelectLocationDestination) { launchSingleTop = true }
},
onToggleTunnelInfo = connectViewModel::toggleTunnelInfoExpansion,
onUpdateVersionClick = {
val intent =
Intent(
@@ -137,7 +138,6 @@ fun ConnectScreen(
onConnectClick: () -> Unit = {},
onCancelClick: () -> Unit = {},
onSwitchLocationClick: () -> Unit = {},
onToggleTunnelInfo: () -> Unit = {},
onUpdateVersionClick: () -> Unit = {},
onManageAccountClick: () -> Unit = {},
onSettingsClick: () -> Unit = {},
@@ -233,12 +233,13 @@ fun ConnectScreen(
color = MaterialTheme.colorScheme.onPrimary,
modifier = Modifier.padding(horizontal = Dimens.sideMargin)
)
var expanded by rememberSaveable { mutableStateOf(false) }
LocationInfo(
onToggleTunnelInfo = onToggleTunnelInfo,
onToggleTunnelInfo = { expanded = !expanded },
isVisible =
uiState.tunnelRealState != TunnelState.Disconnected &&
uiState.tunnelRealState !is TunnelState.Disconnected &&
uiState.location?.hostname != null,
isExpanded = uiState.isTunnelInfoExpanded,
isExpanded = expanded,
location = uiState.location,
inAddress = uiState.inAddress,
outAddress = uiState.outAddress,
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ private fun PreviewOutOfTimeScreenDisconnected() {
OutOfTimeScreen(
uiState =
OutOfTimeUiState(
tunnelState = TunnelState.Disconnected,
tunnelState = TunnelState.Disconnected(),
"Heroic Frog",
showSitePayment = true
),
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ data class ConnectUiState(
val outAddress: String,
val showLocation: Boolean,
val inAppNotification: InAppNotification?,
val isTunnelInfoExpanded: Boolean,
val deviceName: String?,
val daysLeftUntilExpiry: Int?,
val isPlayBuild: Boolean
@@ -25,12 +24,11 @@ data class ConnectUiState(
ConnectUiState(
location = null,
relayLocation = null,
tunnelUiState = TunnelState.Disconnected,
tunnelRealState = TunnelState.Disconnected,
tunnelUiState = TunnelState.Disconnected(),
tunnelRealState = TunnelState.Disconnected(),
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
inAppNotification = null,
deviceName = null,
daysLeftUntilExpiry = null,
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package net.mullvad.mullvadvpn.compose.state
import net.mullvad.mullvadvpn.model.TunnelState

data class OutOfTimeUiState(
val tunnelState: TunnelState = TunnelState.Disconnected,
val tunnelState: TunnelState = TunnelState.Disconnected(),
val deviceName: String = "",
val showSitePayment: Boolean = false,
val billingPaymentState: PaymentState? = null,
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package net.mullvad.mullvadvpn.compose.state
import net.mullvad.mullvadvpn.model.TunnelState

data class WelcomeUiState(
val tunnelState: TunnelState = TunnelState.Disconnected,
val tunnelState: TunnelState = TunnelState.Disconnected(),
val accountNumber: String? = null,
val deviceName: String? = null,
val showSitePayment: Boolean = false,
Original file line number Diff line number Diff line change
@@ -19,8 +19,8 @@ const val ANTICIPATED_STATE_TIMEOUT_MS = 1500L
class ConnectionProxy(private val connection: Messenger, eventDispatcher: EventDispatcher) {
private var resetAnticipatedStateJob: Job? = null

val onStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected)
val onUiStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected)
val onStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected())
val onUiStateChange = EventNotifier<TunnelState>(TunnelState.Disconnected())

var state by onStateChange.notifiable()
private set

This file was deleted.

Loading

0 comments on commit 2417049

Please sign in to comment.