keyring fixes

This commit is contained in:
John Smith 2022-01-07 11:06:46 -05:00
parent 8d4ef01086
commit 0a7ebcb3be
4 changed files with 62 additions and 30 deletions

19
Cargo.lock generated
View File

@ -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",

2
external/keyring-rs vendored

@ -1 +1 @@
Subproject commit 8b34ace77dfca20c482fc856a4b027bdd297f445
Subproject commit dadfe40c70d7679a56e36e22240920c78acd0f06

View File

@ -5,6 +5,8 @@ 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();
with_null_local_frame(env, 64, || {
// context.getFilesDir().getAbsolutePath()
let file = env
.call_method(ag.ctx.as_obj(), "getFilesDir", "()Ljava/io/File;", &[])
@ -18,13 +20,17 @@ pub fn get_files_dir() -> String {
.unwrap();
let jstrval = env.get_string(JString::from(path)).unwrap();
String::from(jstrval.to_string_lossy())
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();
with_null_local_frame(env, 64, || {
// context.getCacheDir().getAbsolutePath()
let file = env
.call_method(ag.ctx.as_obj(), "getCacheDir", "()Ljava/io/File;", &[])
@ -39,4 +45,6 @@ pub fn get_cache_dir() -> String {
let jstrval = env.get_string(JString::from(path)).unwrap();
String::from(jstrval.to_string_lossy())
})
.unwrap()
}

View File

@ -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<T>
where
F: FnOnce() -> JniResult<T>,
{
env.push_local_frame(s)?;
let out = f();
env.pop_local_frame(JObject::null())?;
out
}