File tree 4 files changed +42
-2
lines changed
src/core/ext/transport/binder/client
4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
78
78
// / Returns true when the initialization is successful.
79
79
bool InitializeBinderChannelJavaClass (void * jni_env_void);
80
80
81
+ // / EXPERIMENTAL Alternative version of `InitializeBinderChannelJavaClass(void*
82
+ // / jni_env_void)`. This version used a user-specified function to find the
83
+ // / required internal Java class. When a class is found, the `class_finder`
84
+ // / function should return a local reference to the class (jclass type). The
85
+ // / returned jclass will then be used to create global reference for gRPC to use
86
+ // / it later. After that, gRPC will DeleteLocalRef the returned local reference.
87
+ bool InitializeBinderChannelJavaClass (
88
+ void * jni_env_void, std::function<void *(std::string)> class_finder);
89
+
81
90
} // namespace experimental
82
91
} // namespace grpc
83
92
Original file line number Diff line number Diff line change 50
50
#include " src/core/ext/transport/binder/wire_format/binder.h"
51
51
#include " src/core/ext/transport/binder/wire_format/binder_android.h"
52
52
#include " src/core/lib/channel/channel_args.h"
53
+ #include " src/core/lib/config/core_configuration.h"
53
54
#include " src/core/lib/surface/channel.h"
54
55
#include " src/core/lib/transport/transport.h"
55
56
#include " src/cpp/client/create_channel_internal.h"
@@ -122,6 +123,12 @@ bool InitializeBinderChannelJavaClass(void* jni_env_void) {
122
123
static_cast <JNIEnv*>(jni_env_void)) != nullptr ;
123
124
}
124
125
126
+ bool InitializeBinderChannelJavaClass (
127
+ void * jni_env_void, std::function<void *(std::string)> class_finder) {
128
+ return grpc_binder::FindNativeConnectionHelper (
129
+ static_cast <JNIEnv*>(jni_env_void), class_finder) != nullptr ;
130
+ }
131
+
125
132
} // namespace experimental
126
133
} // namespace grpc
127
134
@@ -162,6 +169,16 @@ bool InitializeBinderChannelJavaClass(void* jni_env_void) {
162
169
return {};
163
170
}
164
171
172
+ bool InitializeBinderChannelJavaClass (
173
+ void * jni_env_void, std::function<void *(std::string)> class_finder) {
174
+ gpr_log (GPR_ERROR,
175
+ " This APK is compiled with Android API level = %d, which is not "
176
+ " supported. See port_platform.h for supported versions." ,
177
+ __ANDROID_API__);
178
+ GPR_ASSERT (0 );
179
+ return {};
180
+ }
181
+
165
182
} // namespace experimental
166
183
} // namespace grpc
167
184
Original file line number Diff line number Diff line change 25
25
namespace grpc_binder {
26
26
27
27
jclass FindNativeConnectionHelper (JNIEnv* env) {
28
- auto do_find = [env]() {
29
- jclass cl = env->FindClass (" io/grpc/binder/cpp/NativeConnectionHelper" );
28
+ return FindNativeConnectionHelper (
29
+ env, [env](std::string cl) { return env->FindClass (cl.c_str ()); });
30
+ }
31
+
32
+ jclass FindNativeConnectionHelper (
33
+ JNIEnv* env, std::function<void *(std::string)> class_finder) {
34
+ auto do_find = [env, class_finder]() {
35
+ jclass cl = static_cast <jclass>(
36
+ class_finder (" io/grpc/binder/cpp/NativeConnectionHelper" ));
30
37
if (cl == nullptr ) {
31
38
return cl;
32
39
}
33
40
jclass global_cl = static_cast <jclass>(env->NewGlobalRef (cl));
41
+ env->DeleteLocalRef (cl);
34
42
GPR_ASSERT (global_cl != nullptr );
35
43
return global_cl;
36
44
};
Original file line number Diff line number Diff line change 21
21
22
22
#include < jni.h>
23
23
24
+ #include < functional>
25
+ #include < string>
26
+
24
27
#include " absl/strings/string_view.h"
25
28
26
29
namespace grpc_binder {
@@ -31,6 +34,9 @@ namespace grpc_binder {
31
34
// JNI_OnLoad) so subsequent BinderTransport code can find Java class
32
35
jclass FindNativeConnectionHelper (JNIEnv* env);
33
36
37
+ jclass FindNativeConnectionHelper (
38
+ JNIEnv* env, std::function<void *(std::string)> class_finder);
39
+
34
40
// Calls Java method NativeConnectionHelper.tryEstablishConnection
35
41
void TryEstablishConnection (JNIEnv* env, jobject application,
36
42
absl::string_view pkg, absl::string_view cls,
You can’t perform that action at this time.
0 commit comments