Merge master

pull/37069/head
tanvi-jagtap 5 months ago
commit a95b1b9543
  1. 6
      src/core/ext/transport/binder/client/binder_connector.cc
  2. 49
      src/core/ext/transport/binder/client/channel_create.cc
  3. 18
      src/core/ext/transport/binder/client/jni_utils.cc
  4. 11
      src/core/ext/transport/binder/security_policy/binder_security_policy.cc
  5. 9
      src/core/ext/transport/binder/server/binder_server.cc
  6. 49
      src/core/ext/transport/binder/transport/binder_transport.cc
  7. 2
      src/core/ext/transport/binder/transport/binder_transport.h
  8. 14
      src/core/ext/transport/binder/utils/ndk_binder.cc
  9. 14
      src/core/ext/transport/binder/wire_format/binder_android.cc
  10. 2
      src/core/ext/transport/binder/wire_format/transaction.h

@ -34,6 +34,7 @@
#include <map>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpcpp/security/binder_security_policy.h>
@ -71,8 +72,7 @@ class BinderConnector : public grpc_core::SubchannelConnector {
#else
CHECK(0);
#endif
gpr_log(GPR_INFO, "BinderConnector %p conn_id_ = %s", this,
conn_id_.c_str());
LOG(INFO) << "BinderConnector " << this << " conn_id_ = " << conn_id_;
args_ = args;
CHECK_EQ(notify_, nullptr);
@ -124,7 +124,7 @@ namespace grpc_core {
RefCountedPtr<Subchannel> BinderClientChannelFactory::CreateSubchannel(
const grpc_resolved_address& address, const ChannelArgs& args) {
gpr_log(GPR_INFO, "BinderClientChannelFactory creating subchannel %p", this);
LOG(INFO) << "BinderClientChannelFactory creating subchannel " << this;
return Subchannel::Create(
MakeOrphanable<BinderConnector>(), address,
args.Set(GRPC_ARG_DEFAULT_AUTHORITY, "binder.authority"));

@ -28,7 +28,6 @@
#include <grpc/grpc.h>
#include <grpc/grpc_posix.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
@ -161,10 +160,10 @@ namespace experimental {
std::shared_ptr<grpc::Channel> CreateBinderChannel(
void*, jobject, absl::string_view, absl::string_view,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}
@ -173,10 +172,10 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
void*, jobject, absl::string_view, absl::string_view,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>,
const ChannelArguments&) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}
@ -184,10 +183,10 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
std::shared_ptr<grpc::Channel> CreateBinderChannel(
void*, jobject, absl::string_view,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}
@ -196,29 +195,29 @@ std::shared_ptr<grpc::Channel> CreateCustomBinderChannel(
void*, jobject, absl::string_view,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>,
const ChannelArguments&) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}
bool InitializeBinderChannelJavaClass(void* jni_env_void) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}
bool InitializeBinderChannelJavaClass(
void* jni_env_void, std::function<void*(std::string)> class_finder) {
gpr_log(GPR_ERROR,
"This APK is compiled with Android API level = %d, which is not "
"supported. See port_platform.h for supported versions.",
__ANDROID_API__);
LOG(ERROR) << "This APK is compiled with Android API level = "
<< __ANDROID_API__
<< ", which is not supported. See port_platform.h for supported "
"versions.";
CHECK(0);
return {};
}

@ -15,14 +15,12 @@
#include "src/core/ext/transport/binder/client/jni_utils.h"
#include "absl/log/check.h"
#include "absl/log/log.h" // IWYU pragma: keep
#include "absl/log/log.h"
#include <grpc/support/port_platform.h>
#ifndef GRPC_NO_BINDER
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
#if defined(ANDROID) || defined(__ANDROID__)
@ -56,13 +54,13 @@ jclass FindNativeConnectionHelper(
// from JNI_OnLoad
// * The APK does not correctly depends on the helper class, or the
// class get shrinked
gpr_log(GPR_ERROR,
"Cannot find binder transport Java helper class. Did you invoke "
"grpc::experimental::InitializeBinderChannelJavaClass correctly "
"beforehand? Did the APK correctly include the connection helper "
"class (i.e depends on build target "
"src/core/ext/transport/binder/java/io/grpc/binder/"
"cpp:connection_helper) ?");
LOG(ERROR)
<< "Cannot find binder transport Java helper class. Did you invoke "
"grpc::experimental::InitializeBinderChannelJavaClass correctly "
"beforehand? Did the APK correctly include the connection helper "
"class (i.e depends on build target "
"src/core/ext/transport/binder/java/io/grpc/binder/"
"cpp:connection_helper) ?";
// TODO(mingcl): Maybe it is worth to try again so the failure can be fixed
// by invoking this function again at a different thread.
return nullptr;

@ -24,8 +24,7 @@
#include <unistd.h>
#include "absl/log/check.h"
#include <grpc/support/log.h>
#include "absl/log/log.h"
#include "src/core/ext/transport/binder/client/jni_utils.h"
#include "src/core/lib/gprpp/crash.h"
@ -91,11 +90,11 @@ bool SameSignatureSecurityPolicy::IsAuthorized(int uid) {
JNIEnv* env = GetEnv(jvm_);
bool result = grpc_binder::IsSignatureMatch(env, context_, getuid(), uid);
if (result) {
gpr_log(GPR_INFO, "uid %d and uid %d passed SameSignature check", getuid(),
uid);
LOG(INFO) << "uid " << getuid() << " and uid " << uid
<< " passed SameSignature check";
} else {
gpr_log(GPR_ERROR, "uid %d and uid %d failed SameSignature check", getuid(),
uid);
LOG(ERROR) << "uid " << getuid() << " and uid " << uid
<< " failed SameSignature check";
}
return result;
}

@ -23,6 +23,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/memory/memory.h"
#include <grpc/grpc.h>
@ -54,8 +55,8 @@ Java_io_grpc_binder_cpp_GrpcCppServerBuilder_GetEndpointBinderInternal__Ljava_la
ai_binder = static_cast<grpc_binder::ndk_util::AIBinder*>(
grpc_get_endpoint_binder(std::string(conn_id)));
if (ai_binder == nullptr) {
gpr_log(GPR_ERROR, "Cannot find endpoint binder with connection id = %s",
conn_id);
LOG(ERROR) << "Cannot find endpoint binder with connection id = "
<< conn_id;
}
if (isCopy == JNI_TRUE) {
jni_env->ReleaseStringUTFChars(conn_id_jstring, conn_id);
@ -180,7 +181,7 @@ class BinderServerListener : public Server::ListenerInterface {
return absl::InvalidArgumentError("Not a SETUP_TRANSPORT request");
}
gpr_log(GPR_INFO, "BinderServerListener calling uid = %d", uid);
LOG(INFO) << "BinderServerListener calling uid = " << uid;
if (!security_policy_->IsAuthorized(uid)) {
// TODO(mingcl): For now we just ignore this unauthorized
// SETUP_TRANSPORT transaction and ghost the client. Check if we should
@ -196,7 +197,7 @@ class BinderServerListener : public Server::ListenerInterface {
if (!status.ok()) {
return status;
}
gpr_log(GPR_INFO, "BinderTransport client protocol version = %d", version);
LOG(INFO) << "BinderTransport client protocol version = " << version;
// TODO(mingcl): Make sure we only give client a version that is not newer
// than the version they specify. For now, we always tell client that we
// only support version=1.

@ -29,8 +29,6 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/substitute.h"
#include <grpc/support/log.h>
#include "src/core/ext/transport/binder/transport/binder_stream.h"
#include "src/core/ext/transport/binder/utils/transport_stream_receiver.h"
#include "src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h"
@ -108,8 +106,8 @@ void grpc_binder_transport::InitStream(grpc_stream* gs,
grpc_stream_refcount* refcount,
const void* server_data,
grpc_core::Arena* arena) {
gpr_log(GPR_INFO, "%s = %p %p %p %p %p", __func__, this, gs, refcount,
server_data, arena);
LOG(INFO) << __func__ << " = " << this << " " << gs << " " << refcount << " "
<< server_data << " " << arena;
// Note that this function is not locked and may be invoked concurrently
new (gs) grpc_binder_stream(this, refcount, server_data, arena,
NewStreamTxCode(), is_client);
@ -132,9 +130,8 @@ static void AssignMetadata(grpc_metadata_batch* mb,
for (auto& p : md) {
mb->Append(p.first, grpc_core::Slice::FromCopiedString(p.second),
[&](absl::string_view error, const grpc_core::Slice&) {
gpr_log(
GPR_DEBUG, "Failed to parse metadata: %s",
absl::StrCat("key=", p.first, " error=", error).c_str());
VLOG(2) << "Failed to parse metadata: "
<< "key=" << p.first << " error=" << error;
});
}
}
@ -192,9 +189,8 @@ static void recv_initial_metadata_locked(void* arg,
RecvInitialMetadataArgs* args = static_cast<RecvInitialMetadataArgs*>(arg);
grpc_binder_stream* stream = args->stream;
gpr_log(GPR_INFO,
"recv_initial_metadata_locked is_client = %d is_closed = %d",
stream->is_client, stream->is_closed);
LOG(INFO) << "recv_initial_metadata_locked is_client = " << stream->is_client
<< " is_closed = " << stream->is_closed;
if (!stream->is_closed) {
grpc_error_handle error = [&] {
@ -230,8 +226,8 @@ static void recv_message_locked(void* arg, grpc_error_handle /*error*/) {
RecvMessageArgs* args = static_cast<RecvMessageArgs*>(arg);
grpc_binder_stream* stream = args->stream;
gpr_log(GPR_INFO, "recv_message_locked is_client = %d is_closed = %d",
stream->is_client, stream->is_closed);
LOG(INFO) << "recv_message_locked is_client = " << stream->is_client
<< " is_closed = " << stream->is_closed;
if (!stream->is_closed) {
grpc_error_handle error = [&] {
@ -273,9 +269,8 @@ static void recv_trailing_metadata_locked(void* arg,
RecvTrailingMetadataArgs* args = static_cast<RecvTrailingMetadataArgs*>(arg);
grpc_binder_stream* stream = args->stream;
gpr_log(GPR_INFO,
"recv_trailing_metadata_locked is_client = %d is_closed = %d",
stream->is_client, stream->is_closed);
LOG(INFO) << "recv_trailing_metadata_locked is_client = " << stream->is_client
<< " is_closed = " << stream->is_closed;
if (!stream->is_closed) {
grpc_error_handle error = [&] {
@ -378,8 +373,8 @@ static void accept_stream_locked(void* gt, grpc_error_handle /*error*/) {
transport, transport);
} else {
++transport->accept_stream_fn_called_count_;
gpr_log(GPR_INFO, "accept_stream_fn not set, current count = %d",
transport->accept_stream_fn_called_count_);
LOG(INFO) << "accept_stream_fn not set, current count = "
<< transport->accept_stream_fn_called_count_;
}
}
@ -580,8 +575,8 @@ static void perform_stream_op_locked(void* stream_op,
void grpc_binder_transport::PerformStreamOp(
grpc_stream* gs, grpc_transport_stream_op_batch* op) {
grpc_binder_stream* stream = reinterpret_cast<grpc_binder_stream*>(gs);
gpr_log(GPR_INFO, "%s = %p %p %p is_client = %d", __func__, this, gs, op,
stream->is_client);
LOG(INFO) << __func__ << " = " << this << " " << gs << " " << op
<< " is_client = " << stream->is_client;
GRPC_BINDER_STREAM_REF(stream, "perform_stream_op");
op->handler_private.extra_arg = stream;
combiner->Run(GRPC_CLOSURE_INIT(&op->handler_private.closure,
@ -621,8 +616,8 @@ static void perform_transport_op_locked(void* transport_op,
transport->accept_stream_fn = op->set_accept_stream_fn;
transport->registered_method_matcher_cb =
op->set_registered_method_matcher_fn;
gpr_log(GPR_DEBUG, "accept_stream_fn_called_count_ = %d",
transport->accept_stream_fn_called_count_);
VLOG(2) << "accept_stream_fn_called_count_ = "
<< transport->accept_stream_fn_called_count_;
while (transport->accept_stream_fn_called_count_ > 0) {
--transport->accept_stream_fn_called_count_;
transport->combiner->Run(
@ -647,7 +642,7 @@ static void perform_transport_op_locked(void* transport_op,
}
void grpc_binder_transport::PerformOp(grpc_transport_op* op) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
op->handler_private.extra_arg = this;
GRPC_BINDER_REF_TRANSPORT(this, "perform_transport_op");
combiner->Run(GRPC_CLOSURE_INIT(&op->handler_private.closure,
@ -668,7 +663,7 @@ static void destroy_stream_locked(void* sp, grpc_error_handle /*error*/) {
void grpc_binder_transport::DestroyStream(grpc_stream* gs,
grpc_closure* then_schedule_closure) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
grpc_binder_stream* stream = reinterpret_cast<grpc_binder_stream*>(gs);
stream->destroy_stream_then_closure = then_schedule_closure;
stream->t->combiner->Run(
@ -688,7 +683,7 @@ static void destroy_transport_locked(void* gt, grpc_error_handle /*error*/) {
}
void grpc_binder_transport::Orphan() {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
combiner->Run(GRPC_CLOSURE_CREATE(destroy_transport_locked, this, nullptr),
absl::OkStatus());
}
@ -707,7 +702,7 @@ grpc_binder_transport::grpc_binder_transport(
is_client ? "binder_transport_client" : "binder_transport_server",
GRPC_CHANNEL_READY),
refs(1, nullptr) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
transport_stream_receiver =
std::make_shared<grpc_binder::TransportStreamReceiverImpl>(
is_client, /*accept_stream_callback=*/[this] {
@ -736,7 +731,7 @@ grpc_core::Transport* grpc_create_binder_transport_client(
std::unique_ptr<grpc_binder::Binder> endpoint_binder,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
CHECK(endpoint_binder != nullptr);
CHECK_NE(security_policy, nullptr);
@ -751,7 +746,7 @@ grpc_core::Transport* grpc_create_binder_transport_server(
std::unique_ptr<grpc_binder::Binder> client_binder,
std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
security_policy) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
CHECK(client_binder != nullptr);
CHECK_NE(security_policy, nullptr);

@ -23,8 +23,8 @@
#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpcpp/security/binder_security_policy.h>

@ -25,8 +25,6 @@
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/sync.h"
@ -36,9 +34,8 @@ void* GetNdkBinderHandle() {
// first
static void* handle = dlopen("libbinder_ndk.so", RTLD_LAZY);
if (handle == nullptr) {
gpr_log(
GPR_ERROR,
"Cannot open libbinder_ndk.so. Does this device support API level 29?");
LOG(ERROR) << "Cannot open libbinder_ndk.so. Does this device support API "
"level 29?";
CHECK(0);
}
return handle;
@ -101,10 +98,9 @@ namespace ndk_util {
static func_type ptr = \
reinterpret_cast<func_type>(dlsym(GetNdkBinderHandle(), #name)); \
if (ptr == nullptr) { \
gpr_log(GPR_ERROR, \
"dlsym failed. Cannot find %s in libbinder_ndk.so. " \
"BinderTransport requires API level >= 33", \
#name); \
LOG(ERROR) << "dlsym failed. Cannot find " << #name \
<< " in libbinder_ndk.so. " \
<< "BinderTransport requires API level >= 33"; \
CHECK(0); \
} \
return ptr

@ -25,8 +25,6 @@
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include <grpc/support/log.h>
#include "src/core/ext/transport/binder/wire_format/binder_android.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/sync.h"
@ -65,7 +63,7 @@ ndk_util::binder_status_t f_onTransact(ndk_util::AIBinder* binder,
transaction_code_t code,
const ndk_util::AParcel* in,
ndk_util::AParcel* /*out*/) {
gpr_log(GPR_INFO, __func__);
LOG(INFO) << __func__;
LOG(INFO) << "tx code = " << code;
auto* user_data =
@ -155,9 +153,8 @@ TransactionReceiverAndroid::TransactionReceiverAndroid(
args.callback = &transact_cb_;
binder_ = ndk_util::AIBinder_new(aibinder_class, &args);
CHECK(binder_);
gpr_log(GPR_INFO, "ndk_util::AIBinder_associateClass = %d",
static_cast<int>(
ndk_util::AIBinder_associateClass(binder_, aibinder_class)));
LOG(INFO) << "ndk_util::AIBinder_associateClass = "
<< ndk_util::AIBinder_associateClass(binder_, aibinder_class);
}
TransactionReceiverAndroid::~TransactionReceiverAndroid() {
@ -181,9 +178,8 @@ void AssociateWithNoopClass(ndk_util::AIBinder* binder) {
ndk_util::AIBinder_Class_disableInterfaceTokenHeader(aibinder_class);
gpr_log(GPR_INFO, "ndk_util::AIBinder_associateClass = %d",
static_cast<int>(
ndk_util::AIBinder_associateClass(binder, aibinder_class)));
LOG(INFO) << "ndk_util::AIBinder_associateClass = "
<< ndk_util::AIBinder_associateClass(binder, aibinder_class);
}
} // namespace

@ -19,9 +19,9 @@
#include <vector>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/string_view.h"
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/crash.h"

Loading…
Cancel
Save