diff --git a/Cargo.lock b/Cargo.lock index 193a62c4..7e544974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1153,6 +1153,15 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "directories" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-sys" version = "0.3.6" @@ -1821,16 +1830,20 @@ dependencies = [ "clap", "core-foundation 0.9.2", "core-foundation-sys 0.8.3", + "directories 4.0.1", "jni", "keychain-services", "lazy_static", "log", "ndk", "ndk-glue", + "owning_ref", "rpassword", "secret-service", "security-framework", "security-framework-sys", + "serde 1.0.133", + "serde_cbor", "serial_test 0.5.1", "simplelog", "tempfile", @@ -3743,7 +3756,7 @@ dependencies = [ "cursive", "cursive-flexi-logger-view", "cursive_buffered_backend", - "directories", + "directories 3.0.2", "flexi_logger", "futures", "log", @@ -3780,7 +3793,7 @@ dependencies = [ "curve25519-dalek-ng", "data-encoding", "digest", - "directories", + "directories 3.0.2", "ed25519-dalek", "futures-util", "generic-array", @@ -3848,7 +3861,7 @@ dependencies = [ "config 0.11.0", "ctrlc", "daemonize", - "directories", + "directories 3.0.2", "failure", "futures", "lazy_static", diff --git a/external/keyring-rs b/external/keyring-rs index 8b34ace7..dadfe40c 160000 --- a/external/keyring-rs +++ b/external/keyring-rs @@ -1 +1 @@ -Subproject commit 8b34ace77dfca20c482fc856a4b027bdd297f445 +Subproject commit dadfe40c70d7679a56e36e22240920c78acd0f06 diff --git a/veilid-core/src/intf/native/utils/android/get_directories.rs b/veilid-core/src/intf/native/utils/android/get_directories.rs index c9047065..ebc28032 100644 --- a/veilid-core/src/intf/native/utils/android/get_directories.rs +++ b/veilid-core/src/intf/native/utils/android/get_directories.rs @@ -5,38 +5,46 @@ 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(); - // context.getFilesDir().getAbsolutePath() - let file = env - .call_method(ag.ctx.as_obj(), "getFilesDir", "()Ljava/io/File;", &[]) - .unwrap() - .l() - .unwrap(); - let path = env - .call_method(file, "getAbsolutePath", "()Ljava/lang/String;", &[]) - .unwrap() - .l() - .unwrap(); - let jstrval = env.get_string(JString::from(path)).unwrap(); - String::from(jstrval.to_string_lossy()) + with_null_local_frame(env, 64, || { + // context.getFilesDir().getAbsolutePath() + let file = env + .call_method(ag.ctx.as_obj(), "getFilesDir", "()Ljava/io/File;", &[]) + .unwrap() + .l() + .unwrap(); + let path = env + .call_method(file, "getAbsolutePath", "()Ljava/lang/String;", &[]) + .unwrap() + .l() + .unwrap(); + + let jstrval = env.get_string(JString::from(path)).unwrap(); + Ok(String::from(jstrval.to_string_lossy())) + }) + .unwrap() } 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(); - // context.getCacheDir().getAbsolutePath() - let file = env - .call_method(ag.ctx.as_obj(), "getCacheDir", "()Ljava/io/File;", &[]) - .unwrap() - .l() - .unwrap(); - let path = env - .call_method(file, "getAbsolutePath", "()Ljava/lang/String;", &[]) - .unwrap() - .l() - .unwrap(); - let jstrval = env.get_string(JString::from(path)).unwrap(); - String::from(jstrval.to_string_lossy()) + with_null_local_frame(env, 64, || { + // context.getCacheDir().getAbsolutePath() + let file = env + .call_method(ag.ctx.as_obj(), "getCacheDir", "()Ljava/io/File;", &[]) + .unwrap() + .l() + .unwrap(); + let path = env + .call_method(file, "getAbsolutePath", "()Ljava/lang/String;", &[]) + .unwrap() + .l() + .unwrap(); + + let jstrval = env.get_string(JString::from(path)).unwrap(); + String::from(jstrval.to_string_lossy()) + }) + .unwrap() } diff --git a/veilid-core/src/intf/native/utils/android/mod.rs b/veilid-core/src/intf/native/utils/android/mod.rs index ffcf282f..b8552130 100644 --- a/veilid-core/src/intf/native/utils/android/mod.rs +++ b/veilid-core/src/intf/native/utils/android/mod.rs @@ -8,6 +8,7 @@ pub use get_directories::*; use crate::xx::*; use android_logger::{Config, FilterBuilder}; use backtrace::Backtrace; +use jni::errors::Result as JniResult; use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM}; use lazy_static::*; use log::*; @@ -66,3 +67,13 @@ pub fn veilid_core_setup_android<'a>( ctx: env.new_global_ref(ctx).unwrap(), }); } + +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 +}