summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-12-03 15:06:08 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-12-04 12:17:24 +0000
commit3086b675415bddcd22b60004d6abd1ab762c4980 (patch)
tree1be77da88ced8e63fa53bad9ba4de708928abb3f /talpid-core/src
parent69ae2007c052a9b71943d57162516c98244f5e24 (diff)
downloadmullvadvpn-3086b675415bddcd22b60004d6abd1ab762c4980.tar.xz
mullvadvpn-3086b675415bddcd22b60004d6abd1ab762c4980.zip
Store sender address in Java class
Return the ownership to the Rust code when the object is garbage collected so that it is correctly freed.
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/offline/android.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/talpid-core/src/offline/android.rs b/talpid-core/src/offline/android.rs
index e62147a03c..5f21e143e8 100644
--- a/talpid-core/src/offline/android.rs
+++ b/talpid-core/src/offline/android.rs
@@ -1,5 +1,6 @@
use crate::tunnel_state_machine::TunnelCommand;
use futures::sync::mpsc::UnboundedSender;
+use jnix::jni::{objects::JObject, sys::jlong, JNIEnv};
use std::sync::Weak;
#[derive(err_derive::Error, Debug)]
@@ -14,6 +15,21 @@ impl MonitorHandle {
}
}
+/// Entry point for Android Java code to return ownership of the sender reference.
+#[no_mangle]
+#[allow(non_snake_case)]
+pub extern "system" fn Java_net_mullvad_talpid_ConnectivityListener_destroySender(
+ _: JNIEnv<'_>,
+ _: JObject<'_>,
+ sender_address: jlong,
+) {
+ let _ = unsafe { get_sender_from_address(sender_address) };
+}
+
+unsafe fn get_sender_from_address(address: jlong) -> Box<Weak<UnboundedSender<TunnelCommand>>> {
+ Box::from_raw(address as *mut Weak<UnboundedSender<TunnelCommand>>)
+}
+
pub fn spawn_monitor(
_sender: Weak<UnboundedSender<TunnelCommand>>,
) -> Result<MonitorHandle, Error> {