diff --git a/.changes/ndk-0.9.md b/.changes/ndk-0.9.md new file mode 100644 index 000000000..c876b8310 --- /dev/null +++ b/.changes/ndk-0.9.md @@ -0,0 +1,6 @@ +--- +"wry": minor +--- + +**Breaking change**: Upgrade `ndk` crate to `0.9` and delete unused `ndk-sys` and `ndk-context` dependencies. Types from the `ndk` crate are used in public API surface. +**Breaking change**: The public `android_setup()` function now takes `&ThreadLooper` instead of `&ForeignLooper`, signifying that the setup function must be called on the thread where the looper is attached (and the `JNIEnv` argument is already thread-local as well). diff --git a/Cargo.toml b/Cargo.toml index 514f5fad3..1a74c1ce5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,9 +104,7 @@ kuchiki = { package = "kuchikiki", version = "0.8" } sha2 = "0.10" base64 = "0.22" jni = "0.21" -ndk = "0.7" -ndk-sys = "0.4" -ndk-context = "0.1" +ndk = "0.9" tao-macros = "0.1" libc = "0.2" diff --git a/src/android/binding.rs b/src/android/binding.rs index 8855f00b4..63a91400b 100644 --- a/src/android/binding.rs +++ b/src/android/binding.rs @@ -27,7 +27,7 @@ macro_rules! android_binding { ($domain:ident, $package:ident) => { ::wry::android_binding!($domain, $package, ::wry) }; - // use import `android_setup` just to force the import path to use `wry::{}` + // use imported `android_setup` just to force the import path to use `wry::{}` // as the macro breaks without braces ($domain:ident, $package:ident, $wry:path) => {{ use $wry::{android_setup as _, prelude::*}; diff --git a/src/android/main_pipe.rs b/src/android/main_pipe.rs index 042bcb2db..ae7ebc460 100644 --- a/src/android/main_pipe.rs +++ b/src/android/main_pipe.rs @@ -15,10 +15,10 @@ use std::{os::unix::prelude::*, sync::atomic::Ordering}; use super::{find_class, EvalCallback, EVAL_CALLBACKS, EVAL_ID_GENERATOR, PACKAGE}; static CHANNEL: Lazy<(Sender, Receiver)> = Lazy::new(|| bounded(8)); -pub static MAIN_PIPE: Lazy<[RawFd; 2]> = Lazy::new(|| { +pub static MAIN_PIPE: Lazy<[OwnedFd; 2]> = Lazy::new(|| { let mut pipe: [RawFd; 2] = Default::default(); unsafe { libc::pipe(pipe.as_mut_ptr()) }; - pipe + unsafe { pipe.map(|fd| OwnedFd::from_raw_fd(fd)) } }); pub struct MainPipe<'a> { @@ -32,7 +32,13 @@ impl<'a> MainPipe<'a> { pub(crate) fn send(message: WebViewMessage) { let size = std::mem::size_of::(); if let Ok(()) = CHANNEL.0.send(message) { - unsafe { libc::write(MAIN_PIPE[1], &true as *const _ as *const _, size) }; + unsafe { + libc::write( + MAIN_PIPE[1].as_raw_fd(), + &true as *const _ as *const _, + size, + ) + }; } } diff --git a/src/android/mod.rs b/src/android/mod.rs index 37d186ce0..f8d69e2ad 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -17,13 +17,14 @@ use jni::{ JNIEnv, }; use kuchiki::NodeRef; -use ndk::looper::{FdEvent, ForeignLooper}; +use ndk::looper::{FdEvent, ThreadLooper}; use once_cell::sync::OnceCell; use raw_window_handle::HasWindowHandle; use sha2::{Digest, Sha256}; use std::{ borrow::Cow, collections::HashMap, + os::fd::{AsFd as _, AsRawFd as _}, sync::{atomic::AtomicI32, mpsc::channel, Mutex}, }; @@ -75,10 +76,13 @@ pub static EVAL_CALLBACKS: once_cell::sync::OnceCell(); let mut wake = false; - if libc::read(MAIN_PIPE[0], &mut wake as *mut _ as *mut _, size) == size as libc::ssize_t { + if libc::read(fd.as_raw_fd(), &mut wake as *mut _ as *mut _, size) == size as libc::ssize_t { main_pipe.recv().is_ok() } else { false