Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DAITA support to the android app #6684

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ jobs:
with:
submodules: true

- name: Checkout wireguard-go-rs recursively
run: |
git config --global --add safe.directory '*'
git submodule update --init --recursive --depth=1 wireguard-go-rs

- name: Calculate native lib cache hash
id: native-lib-cache-hash
shell: bash
Expand All @@ -201,6 +206,8 @@ jobs:
RUSTFLAGS: --deny warnings
BUILD_TYPE: debug
run: |
# Temporary fix to address maybenot.h build issues.
cargo install --force cbindgen --version "0.26.0"
ARCHITECTURES="${{ matrix.abi }}"
UNSTRIPPED_LIB_PATH="$CARGO_TARGET_DIR/${{ matrix.target }}/$BUILD_TYPE/libmullvad_jni.so"
STRIPPED_LIB_PATH="./android/app/build/extraJni/${{ matrix.abi }}/libmullvad_jni.so"
Expand Down Expand Up @@ -319,6 +326,9 @@ jobs:
name: relay-list
path: android/app/build/extraAssets

- name: Copy maybenot machines to asset directory
run: cp dist-assets/maybenot_machines android/app/build/extraAssets/maybenot_machines

- name: Build app
uses: burrunan/gradle-cache-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Checkout wireguard-go submodule
run: |
git config --global --add safe.directory '*'
git submodule update --init --depth=1 wireguard-go-rs
git submodule update --init --recursive --depth=1 wireguard-go-rs

- name: Clippy check
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-unused-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Checkout wireguard-go submodule
run: |
git config --global --add safe.directory '*'
git submodule update --init --depth=1 wireguard-go-rs
git submodule update --init --recursive --depth=1 wireguard-go-rs

- name: Install nightly Rust toolchain
run: |
Expand Down
10 changes: 10 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins {
val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
val extraAssetsDirectory = "${project.buildDir}/extraAssets"
val relayListPath = "$extraAssetsDirectory/relays.json"
val maybenotMachinesDirectory = "$extraAssetsDirectory/maybenot_machines"
val defaultChangelogAssetsDirectory = "$repoRootPath/android/src/main/play/release-notes/"
val extraJniDirectory = "${project.buildDir}/extraJni"

Expand Down Expand Up @@ -239,6 +240,7 @@ android {
// Ensure all relevant assemble tasks depend on our ensure tasks.
tasks.get("assemble$capitalizedVariantName").apply {
dependsOn(tasks.get("ensureRelayListExist"))
dependsOn(tasks.get("ensureMaybenotMachinesExist"))
dependsOn(tasks.get("ensureJniDirectoryExist"))
dependsOn(tasks.get("ensureValidVersionCode"))
}
Expand Down Expand Up @@ -283,6 +285,14 @@ tasks.register("ensureRelayListExist") {
}
}

tasks.register("ensureMaybenotMachinesExist") {
doLast {
if (!file(maybenotMachinesDirectory).exists()) {
throw GradleException("Missing maybenot machines: $maybenotMachinesDirectory")
}
}
}

tasks.register("ensureJniDirectoryExist") {
doLast {
if (!file(extraJniDirectory).exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private val DUMMY_RELAY_1 =
active = true,
provider =
Provider(providerId = ProviderId("PROVIDER RENTED"), ownership = Ownership.Rented),
daita = false,
)
private val DUMMY_RELAY_2 =
RelayItem.Location.Relay(
Expand All @@ -33,6 +34,7 @@ private val DUMMY_RELAY_2 =
active = true,
provider =
Provider(providerId = ProviderId("PROVIDER OWNED"), ownership = Ownership.MullvadOwned),
daita = false,
)
private val DUMMY_RELAY_CITY_1 =
RelayItem.Location.City(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fun FilterRow(
is FilterChip.Ownership ->
OwnershipFilterChip(it.ownership, onRemoveOwnershipFilter)
is FilterChip.Provider -> ProviderFilterChip(it.count, onRemoveProviderFilter)
is FilterChip.Daita -> DaitaFilterChip()
}
}
}
Expand All @@ -67,6 +68,7 @@ fun ProviderFilterChip(providers: Int, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers, providers),
onRemoveClick = onRemoveClick,
enabled = true,
)
}

Expand All @@ -75,6 +77,16 @@ fun OwnershipFilterChip(ownership: Ownership, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(ownership.stringResources()),
onRemoveClick = onRemoveClick,
enabled = true,
)
}

@Composable
fun DaitaFilterChip() {
MullvadFilterChip(
text = stringResource(id = R.string.setting_chip, stringResource(id = R.string.daita)),
onRemoveClick = {},
enabled = false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ import net.mullvad.mullvadvpn.lib.theme.shape.chipShape

@Preview
@Composable
private fun PreviewMullvadFilterChip() {
private fun PreviewEnabledMullvadFilterChip() {
AppTheme {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers),
onRemoveClick = {},
enabled = true,
)
}
}

@Preview
@Composable
private fun PreviewDisabledMullvadFilterChip() {
AppTheme {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers),
onRemoveClick = {},
enabled = false,
)
}
}
Expand All @@ -36,30 +49,38 @@ fun MullvadFilterChip(
iconColor: Color = MaterialTheme.colorScheme.onPrimary,
text: String,
onRemoveClick: () -> Unit,
enabled: Boolean,
) {
InputChip(
enabled = enabled,
shape = MaterialTheme.shapes.chipShape,
colors =
FilterChipDefaults.filterChipColors(
containerColor = containerColor,
disabledContainerColor = containerColor,
labelColor = labelColor,
disabledLabelColor = labelColor,
iconColor = iconColor,
),
border =
FilterChipDefaults.filterChipBorder(
borderColor = borderColor,
disabledBorderColor = borderColor,
enabled = true,
selected = false,
),
selected = false,
onClick = onRemoveClick,
label = { Text(text = text, style = MaterialTheme.typography.labelMedium) },
trailingIcon = {
Icon(
painter = painterResource(id = R.drawable.icon_close),
contentDescription = null,
modifier = Modifier.size(Dimens.smallIconSize),
)
},
trailingIcon =
if (enabled) {
{
Icon(
painter = painterResource(id = R.drawable.icon_close),
contentDescription = null,
modifier = Modifier.size(Dimens.smallIconSize),
)
}
} else null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private fun PreviewLocationInfo() {
isVisible = true,
isExpanded = true,
location = null,
isUsingDaita = false,
inAddress = null,
outAddress = "",
)
Expand All @@ -48,6 +49,7 @@ fun LocationInfo(
isVisible: Boolean,
isExpanded: Boolean,
location: GeoIpLocation?,
isUsingDaita: Boolean,
inAddress: Triple<String, Int, TransportProtocol>?,
outAddress: String,
) {
Expand All @@ -61,15 +63,12 @@ fun LocationInfo(
.then(modifier)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = location?.hostname ?: "",
color =
if (isExpanded) {
colorExpanded
} else {
colorCollapsed
},
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold),
RelayHostname(
hostname = location?.hostname,
isUsingDaita = isUsingDaita,
isExpanded = isExpanded,
colorExpanded = colorExpanded,
colorCollapsed = colorCollapsed,
)
Chevron(
isExpanded = isExpanded,
Expand Down Expand Up @@ -119,3 +118,36 @@ fun LocationInfo(
)
}
}

@Composable
private fun RelayHostname(
hostname: String?,
isUsingDaita: Boolean,
isExpanded: Boolean,
colorExpanded: Color,
colorCollapsed: Color,
) {
val hostnameTitle =
when {
hostname != null && isUsingDaita -> {
stringResource(
id = R.string.connected_using_daita,
hostname,
stringResource(id = R.string.daita),
)
}
hostname != null -> hostname
else -> ""
}

Text(
text = hostnameTitle,
color =
if (isExpanded) {
colorExpanded
} else {
colorCollapsed
},
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.component.drawVerticalScrollbar
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.lib.theme.color.AlphaScrollbar

@Preview
@Composable
private fun PreviewDaitaConfirmationDialog() {
AppTheme { DaitaConfirmation(EmptyResultBackNavigator()) }
}

@Destination<RootGraph>(style = DestinationStyle.Dialog::class)
@Composable
fun DaitaConfirmation(navigator: ResultBackNavigator<Boolean>) {
AlertDialog(
onDismissRequest = dropUnlessResumed { navigator.navigateBack(false) },
icon = {
Icon(
modifier = Modifier.fillMaxWidth().height(Dimens.dialogIconHeight),
painter = painterResource(id = R.drawable.icon_alert),
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface,
)
},
text = {
val scrollState = rememberScrollState()
Column(
Modifier.drawVerticalScrollbar(
scrollState,
MaterialTheme.colorScheme.onPrimary.copy(alpha = AlphaScrollbar),
)
.verticalScroll(scrollState),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = stringResource(id = R.string.daita_relay_subset_warning),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(Dimens.verticalSpace))

Text(
text =
stringResource(
id = R.string.daita_warning,
stringResource(id = R.string.daita),
),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
)
}
},
confirmButton = {
Column(verticalArrangement = Arrangement.spacedBy(Dimens.buttonSpacing)) {
PrimaryButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.enable_anyway),
onClick = { navigator.navigateBack(true) },
)

PrimaryButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.back),
onClick = dropUnlessResumed { navigator.navigateBack(false) },
)
}
},
containerColor = MaterialTheme.colorScheme.surface,
titleContentColor = MaterialTheme.colorScheme.onSurface,
)
}
Loading
Loading