From ffcf16711bc77ab7e2c3bb577a4fc211ed698fa8 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 1 Sep 2023 17:44:42 -0400 Subject: [PATCH] android fixes --- Cargo.lock | 42 +++++++++---------- dev-setup/setup_macos.sh | 2 +- external/keyring-manager | 2 +- .../intf/native/android/get_directories.rs | 19 +++++---- veilid-core/src/intf/native/android/mod.rs | 11 ----- veilid-tools/Cargo.toml | 2 +- veilid-tools/src/tests/android/mod.rs | 14 +++++-- 7 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd09df0f..e2b3188b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,24 +86,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" -[[package]] -name = "android-logd-logger" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d7b9303373a56714732e3371513edd14d12987d04ff4f48527444e804bc3ae" -dependencies = [ - "bytes 1.4.0", - "env_logger 0.10.0", - "lazy_static", - "libc", - "log", - "parking_lot 0.12.1", - "redox_syscall 0.3.5", - "thiserror", - "time 0.3.28", - "winapi", -] - [[package]] name = "android-tzdata" version = "0.1.1" @@ -116,13 +98,31 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e" +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + [[package]] name = "android_logger" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8619b80c242aa7bd638b5c7ddd952addeecb71f69c75e33f1d47b2804f8f883a" dependencies = [ - "android_log-sys", + "android_log-sys 0.2.0", + "env_logger 0.10.0", + "log", + "once_cell", +] + +[[package]] +name = "android_logger" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c494134f746c14dc653a35a4ea5aca24ac368529da5370ecf41fe0341c35772f" +dependencies = [ + "android_log-sys 0.3.1", "env_logger 0.10.0", "log", "once_cell", @@ -3047,7 +3047,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0434fabdd2c15e0aab768ca31d5b7b333717f03cf02037d5a0a3ff3c278ed67f" dependencies = [ - "android_logger", + "android_logger 0.11.3", "libc", "log", "ndk", @@ -5821,7 +5821,7 @@ dependencies = [ name = "veilid-tools" version = "0.1.10" dependencies = [ - "android-logd-logger", + "android_logger 0.13.3", "async-lock", "async-std", "async_executors", diff --git a/dev-setup/setup_macos.sh b/dev-setup/setup_macos.sh index f2c07d4e..eb2cb191 100755 --- a/dev-setup/setup_macos.sh +++ b/dev-setup/setup_macos.sh @@ -123,7 +123,7 @@ if [ "$BREW_USER" == "" ]; then BREW_USER=`whoami` fi fi -sudo -H -u $BREW_USER brew install capnp cmake wabt llvm protobuf openjdk@11 jq +sudo -H -u $BREW_USER brew install capnp cmake wabt llvm protobuf openjdk@17 jq # Ensure android sdk packages are installed $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager build-tools\;33.0.1 ndk\;25.1.8937393 cmake\;3.22.1 platform-tools platforms\;android-33 diff --git a/external/keyring-manager b/external/keyring-manager index ee21446f..e00be7d4 160000 --- a/external/keyring-manager +++ b/external/keyring-manager @@ -1 +1 @@ -Subproject commit ee21446f822fa397057e88083ebbcd3c1bae7adf +Subproject commit e00be7d4130f3e3f69548121de26b24aeb935df2 diff --git a/veilid-core/src/intf/native/android/get_directories.rs b/veilid-core/src/intf/native/android/get_directories.rs index f9a8ea30..99746f01 100644 --- a/veilid-core/src/intf/native/android/get_directories.rs +++ b/veilid-core/src/intf/native/android/get_directories.rs @@ -1,13 +1,14 @@ use super::*; +use jni::errors::Result as JniResult; use jni::objects::JString; #[allow(dead_code)] pub fn get_files_dir() -> String { let aglock = ANDROID_GLOBALS.lock(); let ag = aglock.as_ref().unwrap(); - let env = ag.vm.attach_current_thread().unwrap(); + let mut env = ag.vm.attach_current_thread().unwrap(); - with_null_local_frame(*env, 64, || { + env.with_local_frame(64, |env| { // context.getFilesDir().getAbsolutePath() let file = env .call_method(ag.ctx.as_obj(), "getFilesDir", "()Ljava/io/File;", &[]) @@ -20,8 +21,9 @@ pub fn get_files_dir() -> String { .l() .unwrap(); - let jstrval = env.get_string(JString::from(path)).unwrap(); - Ok(String::from(jstrval.to_string_lossy())) + let jstr = JString::from(path); + let jstrval = env.get_string(&jstr).unwrap(); + JniResult::Ok(String::from(jstrval.to_string_lossy())) }) .unwrap() } @@ -30,9 +32,9 @@ pub fn get_files_dir() -> String { pub fn get_cache_dir() -> String { let aglock = ANDROID_GLOBALS.lock(); let ag = aglock.as_ref().unwrap(); - let env = ag.vm.attach_current_thread().unwrap(); + let mut env = ag.vm.attach_current_thread().unwrap(); - with_null_local_frame(*env, 64, || { + env.with_local_frame(64, |env| { // context.getCacheDir().getAbsolutePath() let file = env .call_method(ag.ctx.as_obj(), "getCacheDir", "()Ljava/io/File;", &[]) @@ -45,8 +47,9 @@ pub fn get_cache_dir() -> String { .l() .unwrap(); - let jstrval = env.get_string(JString::from(path)).unwrap(); - Ok(String::from(jstrval.to_string_lossy())) + let jstr = JString::from(path); + let jstrval = env.get_string(&jstr).unwrap(); + JniResult::Ok(String::from(jstrval.to_string_lossy())) }) .unwrap() } diff --git a/veilid-core/src/intf/native/android/mod.rs b/veilid-core/src/intf/native/android/mod.rs index 00a34def..bc2ff4c0 100644 --- a/veilid-core/src/intf/native/android/mod.rs +++ b/veilid-core/src/intf/native/android/mod.rs @@ -2,7 +2,6 @@ mod get_directories; pub use get_directories::*; use crate::*; -use jni::errors::Result as JniResult; use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM}; use lazy_static::*; @@ -41,13 +40,3 @@ pub fn get_android_globals() -> (JavaVM, GlobalRef) { let ctx = globals.ctx.clone(); (vm, ctx) } - -pub fn with_null_local_frame<'b, T, F>(env: JNIEnv<'b>, s: i32, f: F) -> JniResult -where - F: FnOnce() -> JniResult, -{ - env.push_local_frame(s)?; - let out = f(); - env.pop_local_frame(JObject::null())?; - out -} diff --git a/veilid-tools/Cargo.toml b/veilid-tools/Cargo.toml index 62c580e8..c55c9539 100644 --- a/veilid-tools/Cargo.toml +++ b/veilid-tools/Cargo.toml @@ -85,7 +85,7 @@ ndk = { version = "0.7.0" } ndk-glue = { version = "0.7.0", features = ["logger"] } lazy_static = "1.4.0" paranoid-android = { version = "0.2.1", optional = true } -android-logd-logger = "0.4.2" +android_logger = "0.13.3" # Dependencies for Windows # [target.'cfg(target_os = "windows")'.dependencies] diff --git a/veilid-tools/src/tests/android/mod.rs b/veilid-tools/src/tests/android/mod.rs index 1cba5195..09e0ece5 100644 --- a/veilid-tools/src/tests/android/mod.rs +++ b/veilid-tools/src/tests/android/mod.rs @@ -44,14 +44,20 @@ pub fn veilid_tools_setup_android_tests() { .try_init() .expect("failed to init android tracing"); } else { - let mut builder = android_logd_logger::builder(); - builder.tag("veilid-tools"); - builder.prepend_module(true); + use log::LevelFilter; + use android_logger::{Config,FilterBuilder}; + + let mut builder = FilterBuilder::new(); builder.filter_level(LevelFilter::Trace); for ig in DEFAULT_LOG_IGNORE_LIST { builder.filter_module(ig, LevelFilter::Off); } - builder.init(); + android_logger::init_once( + Config::default() + .with_max_level(LevelFilter::Trace) // limit log level + .with_tag("veilid-tools") // logs will show under mytag tag + .with_filter(builder.build()) + ); } }