From ff616269f8759369595e3642263532655b7f096c Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Mon, 5 Feb 2024 15:36:58 +0900 Subject: [PATCH] Fix Chromium roll failures due to classpath format changes in jni_zero This commit addresses an issue resulting from a change [1] in the jni_zero project, where the format of classpath entries changed (from using slashes 'org/webrtc/PeerConnectionFactory' to dots 'org.webrtc.PeerConnectionFactory'). These changes led to failures in the Chromium rolls in WebRTC, as the Class loader in JNI was not designed to handle class names with dots. This CL fixes this issue by changing webrtc::GetClass to convert class paths to what JNI expects. [1] https://chromium-review.googlesource.com/c/chromium/src/+/5234469 Bug: chromium:1377351 Change-Id: I2f243bb4ed04136f86510fcd5472e9bfc2d4ba85 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/337900 Reviewed-by: Jeremy Leconte Reviewed-by: Harald Alvestrand Commit-Queue: Jeremy Leconte Cr-Commit-Position: refs/heads/main@{#41666} --- sdk/android/native_api/jni/class_loader.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sdk/android/native_api/jni/class_loader.cc b/sdk/android/native_api/jni/class_loader.cc index 1789d78c85..48082bd43e 100644 --- a/sdk/android/native_api/jni/class_loader.cc +++ b/sdk/android/native_api/jni/class_loader.cc @@ -69,12 +69,20 @@ void InitClassLoader(JNIEnv* env) { g_class_loader = new ClassLoader(env); } -ScopedJavaLocalRef GetClass(JNIEnv* env, const char* name) { - // The class loader will be null in the JNI code called from the ClassLoader - // ctor when we are bootstrapping ourself. - return (g_class_loader == nullptr) - ? ScopedJavaLocalRef(env, env->FindClass(name)) - : g_class_loader->FindClass(env, name); +ScopedJavaLocalRef GetClass(JNIEnv* env, const char* c_name) { + if (g_class_loader != nullptr) { + // The class loader will be null in the JNI code called from the ClassLoader + // ctor when we are bootstrapping ourself. + return g_class_loader->FindClass(env, c_name); + } + // jni_zero generated code uses dots instead of slashes. + // Convert to use slashes since that's what JNI's FindClass expects. + // See + // https://cs.android.com/android/platform/superproject/main/+/main:art/runtime/jni/check_jni.cc;l=349;drc=0f62043c1670cd365aba1894ad8046cdfc1c905d + + std::string name(c_name); + std::replace(name.begin(), name.end(), '.', '/'); + return ScopedJavaLocalRef(env, env->FindClass(name.c_str())); } } // namespace webrtc