MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / find_class

Function find_class

rust/src/api_tweaks/android.rs:84–116  ·  view source on GitHub ↗

Search the class in the cache first. If not found, then call the FindClass of JNI and insert the result to the cache.

(env: *mut JNIEnv, classname: &str)

Source from the content-addressed store, hash-verified

82
83// Search the class in the cache first. If not found, then call the FindClass of JNI and insert the result to the cache.
84pub(crate) fn find_class(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
85 unsafe {
86 let mut add_to_cache = false;
87
88 let found_in_cache_opt = CLASSES
89 .lock()?
90 .get(classname)
91 .map(|j4rs_class| j4rs_class.class.clone());
92
93 let found: errors::Result<jclass> = match found_in_cache_opt {
94 Some(class) => Ok(class),
95 None => {
96 add_to_cache = true;
97 find_class_default(env, classname)
98 .or_else(|_| find_class_using_cached_classloader(env, classname))
99 }
100 };
101
102 if add_to_cache {
103 let mut g = CLASSES.lock()?;
104 let global = create_global_ref_from_local_ref(found?, env)?;
105 g.insert(
106 classname.to_string(),
107 J4rsAndroidJclass {
108 class: global.clone(),
109 },
110 );
111 Ok(global as jclass)
112 } else {
113 Ok(found?)
114 }
115 }
116}
117
118unsafe fn find_class_default(env: *mut JNIEnv, classname: &str) -> errors::Result<jclass> {
119 let fc = (**env).v1_6.FindClass;

Callers

nothing calls this directly

Calls 5

find_class_defaultFunction · 0.85
mapMethod · 0.80
to_stringMethod · 0.80

Tested by

no test coverage detected