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 15, 2023
1 parent f746336 commit 4418907
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.CONNECT_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.NOTIFICATION_BANNER_ACTION
import net.mullvad.mullvadvpn.compose.test.RECONNECT_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SCROLLABLE_COLUMN_TEST_TAG
Expand Down Expand Up @@ -79,7 +78,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -114,7 +112,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -147,7 +144,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -179,7 +175,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -212,7 +207,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -240,12 +234,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 +273,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
Expand Down Expand Up @@ -319,7 +311,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification =
Expand Down Expand Up @@ -355,7 +346,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -390,7 +380,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.TunnelStateBlocked
Expand Down Expand Up @@ -420,12 +409,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 +445,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -489,7 +476,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand All @@ -515,12 +501,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 +536,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand All @@ -567,38 +551,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,7 +574,6 @@ class ConnectScreenTest {
inAddress = mockInAddress,
outAddress = mockOutAddress,
showLocation = false,
isTunnelInfoExpanded = true,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = null
Expand Down Expand Up @@ -660,7 +611,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UpdateAvailable(versionInfo)
Expand Down Expand Up @@ -696,7 +646,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo)
Expand Down Expand Up @@ -729,7 +678,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate)
Expand Down Expand Up @@ -767,7 +715,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.UnsupportedVersion(versionInfo)
Expand Down Expand Up @@ -799,7 +746,6 @@ class ConnectScreenTest {
inAddress = null,
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
deviceName = "",
daysLeftUntilExpiry = null,
inAppNotification = InAppNotification.AccountExpiry(expiryDate)
Expand All @@ -816,10 +762,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 @@ -47,7 +49,6 @@ import net.mullvad.mullvadvpn.compose.destinations.SettingsDestination
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.CONNECT_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.RECONNECT_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SCROLLABLE_COLUMN_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_BUTTON_TEST_TAG
Expand Down Expand Up @@ -108,7 +109,6 @@ fun Connect(navigator: DestinationsNavigator) {
onSwitchLocationClick = {
navigator.navigate(SelectLocationDestination) { launchSingleTop = true }
},
onToggleTunnelInfo = connectViewModel::toggleTunnelInfoExpansion,
onUpdateVersionClick = {
val intent =
Intent(
Expand All @@ -135,7 +135,6 @@ fun ConnectScreen(
onConnectClick: () -> Unit = {},
onCancelClick: () -> Unit = {},
onSwitchLocationClick: () -> Unit = {},
onToggleTunnelInfo: () -> Unit = {},
onUpdateVersionClick: () -> Unit = {},
onManageAccountClick: () -> Unit = {},
onSettingsClick: () -> Unit = {},
Expand Down Expand Up @@ -230,19 +229,17 @@ 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,
modifier =
Modifier.fillMaxWidth()
.padding(horizontal = Dimens.sideMargin)
.testTag(LOCATION_INFO_TEST_TAG)
modifier = Modifier.fillMaxWidth().padding(horizontal = Dimens.sideMargin)
)
Spacer(modifier = Modifier.height(Dimens.buttonSpacing))
SwitchLocationButton(
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 @@ -24,7 +24,6 @@ const val SCROLLABLE_COLUMN_TEST_TAG = "scrollable_column_test_tag"
const val SELECT_LOCATION_BUTTON_TEST_TAG = "select_location_button_test_tag"
const val CONNECT_BUTTON_TEST_TAG = "connect_button_test_tag"
const val RECONNECT_BUTTON_TEST_TAG = "reconnect_button_test_tag"
const val LOCATION_INFO_TEST_TAG = "location_info_test_tag"

// ConnectScreen - Notification banner
const val NOTIFICATION_BANNER = "notification_banner"
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
Loading

0 comments on commit 4418907

Please sign in to comment.