pub unsafe fn install_android_jni_context(
java_vm: *mut c_void,
application_context: *mut c_void,
)Expand description
Exposes a JVM to iroh so that we can read the system’s DNS configuration.
This calls ndk_context::initialize_android_context to expose a
JavaVM and Application Context to Rust code so that we can use JNI.
This is required to get the configured nameservers on Android.
If this function is not called, fetching the configured nameservers will fail
and the default DnsResolver will use fallback nameservers instead.
If you call ndk_context::initialize_android_context already somewhere
up the stack in your app, or use a crate like ndk-glue or android-activity
that do this for you, then there’s no need to call this function.
If you don’t use a glue crate, a typical way to initialize the context is
via JNI_OnLoad:
Note: install_android_jni_context is reexported from iroh, so you can substitute
iroh_dns for iroh below.
#[cfg(target_os = "android")]
#[no_mangle]
pub extern "C" fn JNI_OnLoad(
vm: jni::JavaVM,
res: *mut std::os::raw::c_void,
) -> jni::sys::jint {
use std::ffi::c_void;
let vm = vm.get_java_vm_pointer() as *mut c_void;
unsafe {
iroh_dns::install_android_jni_context(vm, res);
}
jni::JNIVersion::V6.into()
}§Safety
Both the java_vm and context_jobject pointers must remain valid until the process exits.
See also ndk_context::initialize_android_context.