1 //! example rust crate to be used in AconfigDemoActivity app
2
3 use jni::objects::JClass;
4 use jni::sys::jstring;
5 use jni::JNIEnv;
6
7 /// get flag value via static interface
get_flag_via_static_interface() -> String8 pub fn get_flag_via_static_interface() -> String {
9 format!(
10 "flag value: {}",
11 if aconfig_demo_flags_rust::append_static_content() { "true" } else { "false" }
12 )
13 }
14
15 /// get flag value via injection
get_flag_via_injection_interface( provider: &aconfig_demo_flags_rust::FlagProvider, ) -> String16 pub fn get_flag_via_injection_interface(
17 provider: &aconfig_demo_flags_rust::FlagProvider,
18 ) -> String {
19 format!("flag value: {}", if provider.append_injected_content() { "true" } else { "false" })
20 }
21
22 /// printRustFlag function
23 #[no_mangle]
24 #[allow(unused)]
Java_com_example_android_aconfig_demo_AconfigDemoActivity_printRustFlag< 'local, >( mut env: JNIEnv<'local>, class: JClass<'local>, ) -> jstring25 pub extern "system" fn Java_com_example_android_aconfig_demo_AconfigDemoActivity_printRustFlag<
26 'local,
27 >(
28 mut env: JNIEnv<'local>,
29 class: JClass<'local>,
30 ) -> jstring {
31 let mut result = String::new();
32
33 result.push_str("flag name : append_static_content\n");
34 result.push_str("use pattern : static method\n");
35 result.push_str(&get_flag_via_static_interface());
36
37 result.push_str("\n\n");
38
39 result.push_str("flag name : append_injected_content\n");
40 result.push_str("use pattern : injection\n");
41 result.push_str(&get_flag_via_injection_interface(&aconfig_demo_flags_rust::PROVIDER));
42
43 let output = env.new_string(result).expect("Couldn't create java string!");
44
45 output.into_raw()
46 }
47