j4rs/api_tweaks/
mod.rs

1use std::os::raw::c_void;
2
3// Copyright 2018 astonbitecode
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16use crate::errors;
17use jni_sys::{jclass, jint, jsize, JNIEnv, JavaVM};
18
19#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
20mod generic;
21
22#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
23pub fn get_created_java_vms(
24    vm_buf: &mut Vec<*mut JavaVM>,
25    buf_len: jsize,
26    n_vms: *mut jsize,
27) -> jint {
28    generic::get_created_java_vms(vm_buf, buf_len, n_vms)
29}
30
31#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
32pub fn set_java_vm(_: *mut JavaVM) {}
33
34#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
35pub fn create_java_vm(pvm: *mut *mut JavaVM, penv: *mut *mut c_void, args: *mut c_void) -> jint {
36    generic::create_java_vm(pvm, penv, args)
37}
38
39#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
40pub fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
41    generic::find_class(env, classname)
42}
43
44// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
45
46#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
47mod no_runtime_lib_loading;
48
49#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
50pub fn get_created_java_vms(
51    vm_buf: &mut Vec<*mut JavaVM>,
52    buf_len: jsize,
53    n_vms: *mut jsize,
54) -> jint {
55    no_runtime_lib_loading::get_created_java_vms(vm_buf, buf_len, n_vms)
56}
57
58#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
59pub fn set_java_vm(_: *mut JavaVM) {}
60
61#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
62pub fn create_java_vm(pvm: *mut *mut JavaVM, penv: *mut *mut c_void, args: *mut c_void) -> jint {
63    no_runtime_lib_loading::create_java_vm(pvm, penv, args)
64}
65
66#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
67pub fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
68    no_runtime_lib_loading::find_class(env, classname)
69}
70
71// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
72
73#[cfg(target_os = "android")]
74mod android;
75
76#[cfg(target_os = "android")]
77pub fn get_created_java_vms(
78    vm_buf: &mut Vec<*mut JavaVM>,
79    buf_len: jsize,
80    n_vms: *mut jsize,
81) -> jint {
82    android::get_created_java_vms(vm_buf, buf_len, n_vms)
83}
84
85#[cfg(target_os = "android")]
86pub fn set_java_vm(java_vm: *mut JavaVM) {
87    android::set_java_vm(java_vm);
88}
89
90#[cfg(target_os = "android")]
91pub fn create_java_vm(pvm: *mut *mut JavaVM, penv: *mut *mut c_void, args: *mut c_void) -> jint {
92    android::create_java_vm(pvm, penv, args)
93}
94
95#[cfg(target_os = "android")]
96pub fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
97    android::find_class(env, classname)
98}