Skip to main content

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, jobject, 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#[cfg(all(not(feature = "no-runtime-libloading"), not(target_os = "android")))]
45pub fn cache_classloader_of(_env: *mut JNIEnv, _obj: jobject) -> errors::Result<()> {Ok(())}
46// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
47
48#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
49mod no_runtime_lib_loading;
50
51#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
52pub fn get_created_java_vms(
53    vm_buf: &mut Vec<*mut JavaVM>,
54    buf_len: jsize,
55    n_vms: *mut jsize,
56) -> jint {
57    no_runtime_lib_loading::get_created_java_vms(vm_buf, buf_len, n_vms)
58}
59
60#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
61pub fn set_java_vm(_: *mut JavaVM) {}
62
63#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
64pub fn create_java_vm(pvm: *mut *mut JavaVM, penv: *mut *mut c_void, args: *mut c_void) -> jint {
65    no_runtime_lib_loading::create_java_vm(pvm, penv, args)
66}
67
68#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
69pub fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
70    no_runtime_lib_loading::find_class(env, classname)
71}
72
73#[cfg(all(feature = "no-runtime-libloading", not(target_os = "android")))]
74pub fn cache_classloader_of(_env: *mut JNIEnv, _obj: jobject) -> errors::Result<()> {Ok(())}
75// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
76
77#[cfg(target_os = "android")]
78mod android;
79
80#[cfg(target_os = "android")]
81pub fn get_created_java_vms(
82    vm_buf: &mut Vec<*mut JavaVM>,
83    buf_len: jsize,
84    n_vms: *mut jsize,
85) -> jint {
86    android::get_created_java_vms(vm_buf, buf_len, n_vms)
87}
88
89#[cfg(target_os = "android")]
90pub fn set_java_vm(java_vm: *mut JavaVM) {
91    android::set_java_vm(java_vm);
92}
93
94#[cfg(target_os = "android")]
95pub fn create_java_vm(pvm: *mut *mut JavaVM, penv: *mut *mut c_void, args: *mut c_void) -> jint {
96    android::create_java_vm(pvm, penv, args)
97}
98
99#[cfg(target_os = "android")]
100pub fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
101    android::find_class(env, classname)
102}
103
104#[cfg(target_os = "android")]
105pub fn cache_classloader_of(env: *mut JNIEnv, obj: jobject) -> errors::Result<()> {
106    android::cache_classloader_of(env, obj)
107}