1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Shared JNI attach helper for [`crate::android::screencast`] — the only Android domain that
//! needs JNI at all (`camera.rs`/`mic.rs` are pure NDK, zero JNI). See
//! [ADR-0003](adr/android/0003-mediaprojection-jni-screen-capture.md) § open questions #2.
use JavaVM;
use Error as JniError;
/// Attach the current (worker) thread to `vm_ptr` and run `f` with the resulting [`jni::Env`].
///
/// If the calling thread was not already attached, it is detached again once `f` returns —
/// [`JavaVM::attach_current_thread`]'s own contract. Cheap to call repeatedly from the same
/// thread once it *is* already attached (a thread-local check, no JNI call).
///
/// # Safety
///
/// `vm_ptr` must be a valid, live `JavaVM*` for the whole call. The host-app contract this
/// crate documents (ADR-0003) is that the `JavaVM*` handed into
/// [`crate::android::screencast::AndroidScreenCaptureConfig::java_vm`] outlives the capture
/// session — this function trusts that contract, it cannot verify it.
pub unsafe
/// Every JNI call in `screencast.rs` funnels its `?`-propagated [`JniError`]s through this
/// `From` impl — a Java exception or a JNI-layer failure both surface as an honest
/// [`crate::CaptureError::Backend`] (no NDK-style status code exists here to distinguish finer
/// causes without inspecting the thrown exception's type, which this slice does not do).