17 #ifndef GRPC_NO_BINDER
33 #ifdef GPR_SUPPORT_BINDER_TRANSPORT
37 #include "absl/memory/memory.h"
38 #include "absl/time/clock.h"
39 #include "absl/time/time.h"
61 const char* kStandardActionName =
"grpc.io.action.BIND";
64 const char* kCustomIntentActionNameArgKey =
65 "grpc.binder.custom_android_intent_action_name";
69 namespace experimental {
74 std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
76 return CreateCustomBinderChannel(jni_env_void, application, package_name,
81 std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
84 std::shared_ptr<grpc::experimental::binder::SecurityPolicy> security_policy,
85 const ChannelArguments&
args) {
98 args.SetChannelArgs(&channel_args_with_custom_action);
105 &channel_args_with_custom_action, kCustomIntentActionNameArgKey);
106 if (action_name_arg !=
nullptr) {
109 if (action_name_arg_string !=
nullptr) {
110 action_name = action_name_arg_string;
117 const char* to_remove[] = {kCustomIntentActionNameArgKey};
119 &channel_args_with_custom_action, to_remove, 1);
127 grpc_binder::TryEstablishConnection(
static_cast<JNIEnv*
>(jni_env_void),
129 action_name, connection_id);
138 const_cast<char*
>((
"binder:" + connection_id).
c_str()));
141 channel_args, to_remove, 1, &server_uri_arg, 1);
149 std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>());
157 bool InitializeBinderChannelJavaClass(
void* jni_env_void) {
158 return grpc_binder::FindNativeConnectionHelper(
159 static_cast<JNIEnv*
>(jni_env_void)) !=
nullptr;
162 bool InitializeBinderChannelJavaClass(
164 return grpc_binder::FindNativeConnectionHelper(
165 static_cast<JNIEnv*
>(jni_env_void), class_finder) !=
nullptr;
171 #else // !GPR_SUPPORT_BINDER_TRANSPORT
174 namespace experimental {
178 std::shared_ptr<grpc::experimental::binder::SecurityPolicy>) {
180 "This APK is compiled with Android API level = %d, which is not "
181 "supported. See port_platform.h for supported versions.",
187 std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
189 std::shared_ptr<grpc::experimental::binder::SecurityPolicy>,
190 const ChannelArguments&) {
192 "This APK is compiled with Android API level = %d, which is not "
193 "supported. See port_platform.h for supported versions.",
199 bool InitializeBinderChannelJavaClass(
void* jni_env_void) {
201 "This APK is compiled with Android API level = %d, which is not "
202 "supported. See port_platform.h for supported versions.",
208 bool InitializeBinderChannelJavaClass(
211 "This APK is compiled with Android API level = %d, which is not "
212 "supported. See port_platform.h for supported versions.",
221 #endif // GPR_SUPPORT_BINDER_TRANSPORT
223 #endif // GPR_ANDROID
225 #endif // GRPC_NO_BINDER