fix clippy and globalref and android

This commit is contained in:
John Smith
2022-03-13 12:45:36 -04:00
parent f7f4d86cf1
commit 2cdfa59bb6
13 changed files with 97 additions and 107 deletions

View File

@@ -19,6 +19,13 @@ pub struct AndroidGlobals {
pub ctx: GlobalRef,
}
impl Drop for AndroidGlobals {
fn drop(&mut self) {
// Ensure we're attached before dropping GlobalRef
self.vm.attach_current_thread_as_daemon().unwrap();
}
}
lazy_static! {
pub static ref ANDROID_GLOBALS: Arc<Mutex<Option<AndroidGlobals>>> = Arc::new(Mutex::new(None));
}
@@ -76,7 +83,7 @@ pub fn veilid_core_setup_android<'a>(
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
let globals_locked = ANDROID_GLOBALS.lock();
let globals = globals_locked.as_ref().unwrap();
let env = globals.vm.attach_current_thread().unwrap();
let env = globals.vm.attach_current_thread_as_daemon().unwrap();
let vm = env.get_java_vm().unwrap();
let ctx = globals.ctx.clone();
(vm, ctx)