19 #ifndef GRPC_NO_BINDER
23 #if defined(ANDROID) || defined(__ANDROID__)
27 jclass FindNativeConnectionHelper(JNIEnv*
env) {
28 return FindNativeConnectionHelper(
32 jclass FindNativeConnectionHelper(
34 auto do_find = [
env, class_finder]() {
35 jclass cl =
static_cast<jclass
>(
36 class_finder(
"io/grpc/binder/cpp/NativeConnectionHelper"));
40 jclass global_cl =
static_cast<jclass
>(
env->NewGlobalRef(cl));
41 env->DeleteLocalRef(cl);
45 static jclass connection_helper_class = do_find();
46 if (connection_helper_class !=
nullptr) {
47 return connection_helper_class;
55 "Cannot find binder transport Java helper class. Did you invoke "
56 "grpc::experimental::InitializeBinderChannelJavaClass correctly "
57 "beforehand? Did the APK correctly include the connection helper "
58 "class (i.e depends on build target "
59 "src/core/ext/transport/binder/java/io/grpc/binder/"
60 "cpp:connection_helper) ?");
66 void TryEstablishConnection(JNIEnv*
env, jobject application,
72 "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/"
73 "lang/String;Ljava/lang/String;)V";
75 jclass cl = FindNativeConnectionHelper(
env);
80 jmethodID mid =
env->GetStaticMethodID(cl,
method.c_str(),
type.c_str());
85 env->CallStaticVoidMethod(cl, mid, application,
92 bool IsSignatureMatch(JNIEnv*
env, jobject
context,
int uid1,
int uid2) {
96 jclass cl = FindNativeConnectionHelper(
env);
101 jmethodID mid =
env->GetStaticMethodID(cl,
method.c_str(),
type.c_str());
102 if (mid ==
nullptr) {
106 jboolean
result =
env->CallStaticBooleanMethod(cl, mid,
context, uid1, uid2);
107 return result == JNI_TRUE;