1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
pub(crate) mod crypto;
pub(crate) mod lru;
pub(crate) mod lz4;
mod refcnt;
mod time;
pub(crate) mod utils;
pub(crate) mod version;
pub(crate) mod vio;
pub use self::refcnt::RefCnt;
pub use self::time::Time;
pub use self::version::Version;
use std::sync::{Arc, Once, RwLock};
#[cfg(target_os = "android")]
use std::ptr::NonNull;
#[cfg(target_os = "android")]
use std::sync::Mutex;
#[cfg(target_os = "android")]
use jni::{JNIEnv, JavaVM};
#[cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))]
use env_logger;
#[inline]
pub fn zbox_version() -> String {
format!("ZboxFS v{}", Version::lib_version())
}
static INIT: Once = Once::new();
#[cfg(target_os = "android")]
lazy_static! {
pub static ref JVM: Mutex<JavaVM> = unsafe {
let p = NonNull::dangling();
Mutex::new(JavaVM::from_raw(p.as_ptr()).unwrap())
};
}
cfg_if! {
if #[cfg(target_os = "android")] {
pub fn init_env(env: JNIEnv) {
INIT.call_once(|| {
crypto::Crypto::init().expect("Initialise crypto failed");
let jvm = env.get_java_vm().unwrap();
let mut jvm_ptr = JVM.lock().unwrap();
*jvm_ptr = jvm;
info!(
"{} - Zero-details, privacy-focused in-app file system",
zbox_version()
);
});
}
} else {
pub fn init_env() {
INIT.call_once(|| {
#[cfg(not(target_arch = "wasm32"))]
{
env_logger::try_init().ok();
}
crypto::Crypto::init().expect("Initialise crypto failed");
info!(
"{} - Zero-details, privacy-focused in-app file system",
zbox_version()
);
});
}
}
}
pub trait IntoRef: Sized {
fn into_ref(self) -> Arc<RwLock<Self>> {
Arc::new(RwLock::new(self))
}
}