From d3b3ef81786d9c62e1b1c35e91ffddc3395b411f Mon Sep 17 00:00:00 2001 From: Fredy Wijaya Date: Sat, 7 Sep 2024 00:10:13 -0500 Subject: [PATCH] mobile: Create a JNI binding for Runtime::runtimeFeatureEnabled (#36011) This PR allows us to have a runtime guard check in the Android code. Risk Level: low Testing: n/a Docs Changes: n/a Release Notes: n/a Platform Specific Features: mobile Signed-off-by: Fredy Wijaya --- .../java/io/envoyproxy/envoymobile/engine/JniLibrary.java | 5 +++++ mobile/library/jni/jni_impl.cc | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/mobile/library/java/io/envoyproxy/envoymobile/engine/JniLibrary.java b/mobile/library/java/io/envoyproxy/envoymobile/engine/JniLibrary.java index 49b93102c0b3..bb1d25507931 100644 --- a/mobile/library/java/io/envoyproxy/envoymobile/engine/JniLibrary.java +++ b/mobile/library/java/io/envoyproxy/envoymobile/engine/JniLibrary.java @@ -319,4 +319,9 @@ public static native long createBootstrap( * href="https://c-ares.org/docs/ares_library_init_android.html">ares_library_init_android. */ public static native void initCares(ConnectivityManager connectivityManager); + + /** + * Returns true if the runtime feature is enabled. + */ + public static native boolean isRuntimeFeatureEnabled(String featureName); } diff --git a/mobile/library/jni/jni_impl.cc b/mobile/library/jni/jni_impl.cc index 049be773eff5..4fcf5897768d 100644 --- a/mobile/library/jni/jni_impl.cc +++ b/mobile/library/jni/jni_impl.cc @@ -215,6 +215,14 @@ extern "C" JNIEXPORT void JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibra #endif } +extern "C" JNIEXPORT jboolean JNICALL +Java_io_envoyproxy_envoymobile_engine_JniLibrary_runtimeFeatureEnabled(JNIEnv* env, jclass, + jstring feature_name) { + Envoy::JNI::JniHelper jni_helper(env); + return Envoy::Runtime::runtimeFeatureEnabled( + Envoy::JNI::javaStringToCppString(jni_helper, feature_name)); +} + extern "C" JNIEXPORT jint JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibrary_recordCounterInc( JNIEnv* env, jclass, // class