Skip to content

Commit bc7e4ca

Browse files
committed
Fix building for Android
1 parent 0596904 commit bc7e4ca

File tree

6 files changed

+45
-38
lines changed

6 files changed

+45
-38
lines changed

mullvad-api/src/api.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! [`ApiConnectionMode`], which in turn is used by `mullvad-api` for
55
//! establishing connections when performing API requests.
66
7+
#[cfg(feature = "api-override")]
8+
use crate::ApiEndpoint;
79
use crate::{
810
proxy::{AllowedClientsProvider, ApiConnectionMode, ConnectionModeProvider, ProxyConfig},
911
AddressCache,
@@ -12,17 +14,13 @@ use futures::{
1214
channel::{mpsc, oneshot},
1315
StreamExt,
1416
};
15-
#[cfg(feature = "api-override")]
16-
use mullvad_api::ApiEndpoint;
1717
use mullvad_encrypted_dns_proxy::state::EncryptedDnsProxyState;
1818
use mullvad_relay_selector::RelaySelector;
1919
use mullvad_types::access_method::{
2020
AccessMethod, AccessMethodSetting, BuiltInAccessMethod, Id, Settings,
2121
};
2222
use std::{net::SocketAddr, path::PathBuf};
23-
use talpid_types::net::{
24-
proxy::CustomProxy, AllowedEndpoint, Endpoint, TransportProtocol,
25-
};
23+
use talpid_types::net::{proxy::CustomProxy, AllowedEndpoint, Endpoint, TransportProtocol};
2624

2725
pub enum Message {
2826
Get(ResponseTx<ResolvedConnectionMode>),
@@ -306,6 +304,8 @@ impl AccessModeSelector {
306304
let api_connection_mode = initial_connection_mode.connection_mode.clone();
307305

308306
let selector = AccessModeSelector {
307+
#[cfg(feature = "api-override")]
308+
api_endpoint,
309309
cmd_rx,
310310
cache_dir,
311311
relay_selector,
@@ -317,8 +317,6 @@ impl AccessModeSelector {
317317
current: initial_connection_mode,
318318
index,
319319
provider,
320-
#[cfg(feature = "api-override")]
321-
api_endpoint,
322320
};
323321

324322
tokio::spawn(selector.into_future());

mullvad-api/src/bin/relay_list.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
//! Used by the installer artifact packer to bundle the latest available
33
//! relay list at the time of creating the installer.
44
5+
#[cfg(not(target_os = "android"))]
56
use mullvad_api::{
67
proxy::ApiConnectionMode, rest::Error as RestError, ApiEndpoint, RelayListProxy,
78
};
9+
#[cfg(not(target_os = "android"))]
810
use std::process;
11+
#[cfg(not(target_os = "android"))]
912
use talpid_types::ErrorExt;
1013

1114
#[tokio::main]
15+
#[cfg(target_os = "android")]
16+
async fn main() {}
17+
#[tokio::main]
18+
#[cfg(not(target_os = "android"))]
1219
async fn main() {
1320
let runtime = mullvad_api::Runtime::new(
1421
tokio::runtime::Handle::current(),

mullvad-daemon/src/access_method.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{settings, Daemon};
2-
use mullvad_api::{api, rest};
3-
use mullvad_api::{proxy::ApiConnectionMode, ApiProxy};
2+
use mullvad_api::{api, proxy::ApiConnectionMode, rest, ApiProxy};
43
use mullvad_types::{
54
access_method::{self, AccessMethod, AccessMethodSetting},
65
settings::Settings,
@@ -154,7 +153,7 @@ impl Daemon {
154153
#[cfg(not(target_os = "android"))]
155154
pub(crate) async fn test_access_method(
156155
proxy: talpid_types::net::AllowedEndpoint,
157-
access_method_selector: mullvad_api::api::AccessModeSelectorHandle,
156+
access_method_selector: api::AccessModeSelectorHandle,
158157
daemon_event_sender: crate::DaemonEventSender<(
159158
mullvad_api::api::AccessMethodEvent,
160159
futures::channel::oneshot::Sender<()>,

mullvad-daemon/src/api.rs

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
11
#[cfg(target_os = "android")]
22
use crate::DaemonCommand;
3-
use futures::channel::mpsc;
4-
use futures::StreamExt;
5-
use mullvad_api::availability::ApiAvailability;
6-
use mullvad_api::proxy::AllowedClientsProvider;
7-
use mullvad_api::proxy::ApiConnectionMode;
8-
use mullvad_api::proxy::ProxyConfig;
9-
use talpid_types::net::AllowedClients;
10-
use talpid_types::net::Connectivity;
11-
123
#[cfg(target_os = "android")]
13-
pub(crate) fn create_bypass_tx(
14-
event_sender: &DaemonEventSender,
15-
) -> Option<mpsc::Sender<mullvad_api::SocketBypassRequest>> {
16-
let (bypass_tx, mut bypass_rx) = mpsc::channel(1);
17-
let daemon_tx = event_sender.to_specialized_sender();
18-
tokio::spawn(async move {
19-
while let Some((raw_fd, done_tx)) = bypass_rx.next().await {
20-
if daemon_tx
21-
.send(DaemonCommand::BypassSocket(raw_fd, done_tx))
22-
.is_err()
23-
{
24-
log::error!("Can't send socket bypass request to daemon");
25-
break;
26-
}
27-
}
28-
});
29-
Some(bypass_tx)
30-
}
4+
use crate::DaemonEventSender;
5+
use futures::{channel::mpsc, StreamExt};
6+
use mullvad_api::{
7+
availability::ApiAvailability,
8+
proxy::{AllowedClientsProvider, ApiConnectionMode, ProxyConfig},
9+
};
10+
#[cfg(target_os = "android")]
11+
use talpid_core::mpsc::Sender;
12+
use talpid_types::net::{AllowedClients, Connectivity};
3113

3214
#[derive(Clone, Copy)]
3315
pub struct AllowedClientsSelector {}
@@ -60,6 +42,26 @@ impl AllowedClientsProvider for AllowedClientsSelector {
6042
}
6143
}
6244

45+
#[cfg(target_os = "android")]
46+
pub(crate) fn create_bypass_tx(
47+
event_sender: &DaemonEventSender,
48+
) -> Option<mpsc::Sender<mullvad_api::SocketBypassRequest>> {
49+
let (bypass_tx, mut bypass_rx) = mpsc::channel(1);
50+
let daemon_tx = event_sender.to_specialized_sender();
51+
tokio::spawn(async move {
52+
while let Some((raw_fd, done_tx)) = bypass_rx.next().await {
53+
if daemon_tx
54+
.send(DaemonCommand::BypassSocket(raw_fd, done_tx))
55+
.is_err()
56+
{
57+
log::error!("Can't send socket bypass request to daemon");
58+
break;
59+
}
60+
}
61+
});
62+
Some(bypass_tx)
63+
}
64+
6365
/// Forwards the received values from `offline_state_rx` to the [`ApiAvailability`].
6466
pub(crate) fn forward_offline_state(
6567
api_availability: ApiAvailability,

mullvad-jni/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ workspace = true
1212

1313
[features]
1414
# Allow the API server to use to be configured
15-
api-override = ["mullvad-api/api-override"]
15+
api-override = ["mullvad-api/api-override", "mullvad-daemon/api-override"]
1616

1717
[lib]
1818
crate-type = ["cdylib"]

test/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)