-
-
Couldn't load subscription status.
- Fork 179
Description
I have just done a lovely 4 hour debugging session to find a panic. Because java + rust + tokio sucks ass, backtraces were invalid.
Anyhow, I do not know how nobody had this problem yet, because as soon as you connect to a Peripheral, one would have noticed that it panics inside jni-utils.
To be more precise this unwrap on a None value:
https://github.com/deviceplug/jni-utils-rs/blob/1737fd69e8d980ec045df6daafef250f2dd07ebd/rust/future.rs#L42
JFuture::from_env is being called here:
btleplug/src/droidplug/jni/objects.rs
Line 150 in c227cc1
| JFuture::from_env(self.env, future_obj) |
The classcache gets populated here:
https://github.com/deviceplug/jni-utils-rs/blob/1737fd69e8d980ec045df6daafef250f2dd07ebd/rust/ops.rs#L382-L393
and this ops::init function is being called automatically if jni_utls::init(env) is called.
Note that btleplugs droidplug uses one of these classes in connect:
Lio/github/gedgygedgy/rust/future/Future
BUT droidplug never called jni_utils::init. In the droidplug::init function and the following call to self::jni only the btleplug classes get added to the classcache:
btleplug/src/droidplug/jni/mod.rs
Lines 27 to 53 in c227cc1
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/Peripheral", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/ScanFilter", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/NotConnectedException", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/PermissionDeniedException", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/UnexpectedCallbackException", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/UnexpectedCharacteristicException", | |
| )?; | |
| jni_utils::classcache::find_add_class( | |
| env, | |
| "com/nonpolynomial/btleplug/android/impl/NoSuchCharacteristicException", |
But jni_utils::init is never called and therefore the classcache is missing all these classes:
https://github.com/deviceplug/jni-utils-rs/blob/1737fd69e8d980ec045df6daafef250f2dd07ebd/rust/ops.rs#L384-L393
... which leads to total failure. To fix this, droidplug::init only has to also call jni_utils::init and everything works fine....