Add product flavor to in app logs

This commit is contained in:
Kalle Lindström 2025-04-02 18:40:42 +02:00 committed by Jonatan Rhodin
parent f2da810790
commit 0a59263d2c
No known key found for this signature in database
GPG Key ID: 5BAD29994724ED5E
9 changed files with 31 additions and 7 deletions

5
Cargo.lock generated
View File

@ -2198,9 +2198,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]] [[package]]
name = "jnix" name = "jnix"
version = "0.5.2" version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "542b2072131a62ec940ee161ff0a01e7a1c2a129796b30143efc952cb6e0f28f" checksum = "63c460f1b7afbfcb0810208d3b0efc6ac1d7574f5e379fa2c19fb957bb57678a"
dependencies = [ dependencies = [
"jni", "jni",
"jnix-macros", "jnix-macros",
@ -2783,6 +2783,7 @@ dependencies = [
"mullvad-types", "mullvad-types",
"nix 0.23.2", "nix 0.23.2",
"rand 0.8.5", "rand 0.8.5",
"talpid-platform-metadata",
"talpid-tunnel", "talpid-tunnel",
"talpid-types", "talpid-types",
"thiserror 2.0.9", "thiserror 2.0.9",

View File

@ -7,12 +7,14 @@ object MullvadDaemon {
System.loadLibrary("mullvad_jni") System.loadLibrary("mullvad_jni")
} }
@Suppress("LongParameterList")
external fun initialize( external fun initialize(
vpnService: MullvadVpnService, vpnService: MullvadVpnService,
rpcSocketPath: String, rpcSocketPath: String,
filesDirectory: String, filesDirectory: String,
cacheDirectory: String, cacheDirectory: String,
apiEndpointOverride: ApiEndpointOverride?, apiEndpointOverride: ApiEndpointOverride?,
extraMetadata: Map<String, String>,
) )
external fun shutdown() external fun shutdown()

View File

@ -170,6 +170,7 @@ class MullvadVpnService : TalpidVpnService() {
filesDirectory = filesDir.absolutePath, filesDirectory = filesDir.absolutePath,
cacheDirectory = cacheDir.absolutePath, cacheDirectory = cacheDir.absolutePath,
apiEndpointOverride = apiEndpointOverride, apiEndpointOverride = apiEndpointOverride,
extraMetadata = mapOf("flavor" to BuildConfig.FLAVOR),
) )
Logger.i("MullvadVpnService: Daemon initialized") Logger.i("MullvadVpnService: Daemon initialized")
} }

View File

@ -35,3 +35,4 @@ mullvad-problem-report = { path = "../mullvad-problem-report" }
mullvad-types = { path = "../mullvad-types" } mullvad-types = { path = "../mullvad-types" }
talpid-tunnel = { path = "../talpid-tunnel" } talpid-tunnel = { path = "../talpid-tunnel" }
talpid-types = { path = "../talpid-types" } talpid-types = { path = "../talpid-types" }
talpid-platform-metadata = { path = "../talpid-platform-metadata" }

View File

@ -3,6 +3,7 @@ pub const CLASSES: &[&str] = &[
"java/net/InetAddress", "java/net/InetAddress",
"java/net/InetSocketAddress", "java/net/InetSocketAddress",
"java/util/ArrayList", "java/util/ArrayList",
"java/util/HashMap",
"net/mullvad/mullvadvpn/service/MullvadDaemon", "net/mullvad/mullvadvpn/service/MullvadDaemon",
"net/mullvad/mullvadvpn/service/MullvadVpnService", "net/mullvad/mullvadvpn/service/MullvadVpnService",
"net/mullvad/talpid/model/InetNetwork", "net/mullvad/talpid/model/InetNetwork",

View File

@ -16,6 +16,7 @@ use mullvad_daemon::{
cleanup_old_rpc_socket, exception_logging, logging, runtime::new_multi_thread, version, Daemon, cleanup_old_rpc_socket, exception_logging, logging, runtime::new_multi_thread, version, Daemon,
DaemonCommandChannel, DaemonCommandSender, DaemonConfig, DaemonCommandChannel, DaemonCommandSender, DaemonConfig,
}; };
use std::collections::HashMap;
use std::{ use std::{
ffi::CString, ffi::CString,
io, io,
@ -84,6 +85,7 @@ pub extern "system" fn Java_net_mullvad_mullvadvpn_service_MullvadDaemon_initial
files_directory: JObject<'_>, files_directory: JObject<'_>,
cache_directory: JObject<'_>, cache_directory: JObject<'_>,
api_endpoint: JObject<'_>, api_endpoint: JObject<'_>,
extra_metadata: JObject<'_>,
) { ) {
let mut ctx = DAEMON_CONTEXT.lock().unwrap(); let mut ctx = DAEMON_CONTEXT.lock().unwrap();
assert!(ctx.is_none(), "multiple calls to MullvadDaemon.initialize"); assert!(ctx.is_none(), "multiple calls to MullvadDaemon.initialize");
@ -99,6 +101,8 @@ pub extern "system" fn Java_net_mullvad_mullvadvpn_service_MullvadDaemon_initial
LOAD_CLASSES.call_once(|| env.preload_classes(classes::CLASSES.iter().cloned())); LOAD_CLASSES.call_once(|| env.preload_classes(classes::CLASSES.iter().cloned()));
log::info!("Done loading classes"); log::info!("Done loading classes");
talpid_platform_metadata::set_extra_metadata(HashMap::from_java(&env, extra_metadata));
let rpc_socket = pathbuf_from_java(&env, rpc_socket_path); let rpc_socket = pathbuf_from_java(&env, rpc_socket_path);
let cache_dir = pathbuf_from_java(&env, cache_directory); let cache_dir = pathbuf_from_java(&env, cache_directory);

View File

@ -104,4 +104,4 @@ tonic-build = { workspace = true, default-features = false, features = ["transpo
[dev-dependencies] [dev-dependencies]
tokio = { workspace = true, features = [ "io-util", "test-util", "time" ] } tokio = { workspace = true, features = ["io-util", "test-util", "time"] }

View File

@ -1,4 +1,5 @@
use std::collections::HashMap; use std::collections::{BTreeMap, HashMap};
use std::sync::{LazyLock, RwLock};
mod command; mod command;
use command::command_stdout_lossy; use command::command_stdout_lossy;
@ -27,15 +28,26 @@ fn os_version() -> String {
get_prop("ro.build.version.release").unwrap_or_else(|| "N/A".to_owned()) get_prop("ro.build.version.release").unwrap_or_else(|| "N/A".to_owned())
} }
pub fn extra_metadata() -> HashMap<String, String> { pub fn extra_metadata() -> impl Iterator<Item = (String, String)> {
let mut metadata = HashMap::new(); let mut metadata = BTreeMap::new();
metadata.insert( metadata.insert(
"abi".to_owned(), "abi".to_owned(),
get_prop("ro.product.cpu.abilist").unwrap_or_else(|| "N/A".to_owned()), get_prop("ro.product.cpu.abilist").unwrap_or_else(|| "N/A".to_owned()),
); );
metadata let extra = EXTRA_METADATA.read().unwrap();
for (k, v) in extra.iter() {
metadata.insert(k.clone(), v.clone());
}
metadata.into_iter()
} }
fn get_prop(property: &str) -> Option<String> { fn get_prop(property: &str) -> Option<String> {
command_stdout_lossy("getprop", &[property]).ok() command_stdout_lossy("getprop", &[property]).ok()
} }
pub fn set_extra_metadata(extra: HashMap<String, String>) {
*EXTRA_METADATA.write().unwrap() = extra;
}
static EXTRA_METADATA: LazyLock<RwLock<HashMap<String, String>>> =
LazyLock::new(|| RwLock::new(HashMap::new()));

View File

@ -15,6 +15,8 @@ mod imp;
#[path = "android.rs"] #[path = "android.rs"]
mod imp; mod imp;
#[cfg(target_os = "android")]
pub use self::imp::set_extra_metadata;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub use self::imp::MacosVersion; pub use self::imp::MacosVersion;
#[cfg(windows)] #[cfg(windows)]