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.
  • Loading branch information
Rawa authored and Serock3 committed Dec 18, 2023
1 parent e8d9ac2 commit bd1b5cb
Show file tree
Hide file tree
Showing 30 changed files with 82 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -114,7 +113,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -147,7 +145,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -179,7 +176,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -212,7 +208,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -240,12 +235,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
Expand Down Expand Up @@ -280,7 +274,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
Expand Down Expand Up @@ -319,7 +312,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
Expand Down Expand Up @@ -355,7 +347,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -390,7 +381,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -420,12 +410,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
Expand Down Expand Up @@ -457,7 +446,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -489,7 +477,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand All @@ -515,12 +502,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
Expand Down Expand Up @@ -551,7 +537,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand All @@ -567,38 +552,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
),
onToggleTunnelInfo = mockedClickHandler
)
}

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

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

@Test
fun showLocationInfo() {
// Arrange
Expand All @@ -622,14 +575,15 @@ class ConnectScreenTest {
inAddress = mockInAddress,
outAddress = mockOutAddress,
showLocation = false,
isTunnelInfoExpanded = true,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
),
)
}

composeTestRule.onNodeWithTag(LOCATION_INFO_TEST_TAG).performClick()

// Assert
composeTestRule.apply {
onNodeWithText(mockHostName).assertExists()
Expand Down Expand Up @@ -660,7 +614,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UpdateAvailable(versionInfo)
Expand Down Expand Up @@ -696,7 +649,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo)
Expand Down Expand Up @@ -729,7 +681,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate)
Expand Down Expand Up @@ -767,7 +718,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo)
Expand Down Expand Up @@ -799,7 +749,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate)
Expand All @@ -816,10 +765,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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +110,6 @@ fun Connect(navigator: DestinationsNavigator) {
onSwitchLocationClick = {
navigator.navigate(SelectLocationDestination) { launchSingleTop = true }
},
onToggleTunnelInfo = connectViewModel::toggleTunnelInfoExpansion,
onUpdateVersionClick = {
val intent =
Intent(
Expand All @@ -135,7 +136,6 @@ fun ConnectScreen(
onConnectClick: () -> Unit = {},
onCancelClick: () -> Unit = {},
onSwitchLocationClick: () -> Unit = {},
onToggleTunnelInfo: () -> Unit = {},
onUpdateVersionClick: () -> Unit = {},
onManageAccountClick: () -> Unit = {},
onSettingsClick: () -> Unit = {},
Expand Down Expand Up @@ -230,12 +230,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private fun PreviewOutOfTimeScreenDisconnected() {
OutOfTimeScreen(
uiState =
OutOfTimeUiState(
tunnelState = TunnelState.Disconnected,
tunnelState = TunnelState.Disconnected(),
"Heroic Frog",
showSitePayment = true
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
) {
Expand All @@ -24,12 +23,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Loading

0 comments on commit bd1b5cb

Please sign in to comment.