From b41b323fbe25a5382f4354450363fe804fafbee2 Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Tue, 8 Oct 2024 15:53:59 -0700 Subject: [PATCH] Automated rollback of commit 4abd199841751c7d956287d88660d10228272c2b. PiperOrigin-RevId: 683793486 --- BUILD | 133 +++ CMakeLists.txt | 910 +++++++++++++++++- Makefile | 1 + Package.swift | 1 + WORKSPACE | 10 + build_autogenerated.yaml | 765 +++++++++++++++ config.m4 | 2 + config.w32 | 2 + gRPC-C++.podspec | 61 ++ gRPC-Core.podspec | 1 + grpc.gemspec | 1 + include/grpc/support/port_platform.h | 1 + .../grpcpp/security/binder_security_policy.h | 82 ++ package.xml | 1 + src/core/BUILD | 32 +- src/core/ext/transport/binder/README.md | 10 + .../binder/client/channel_create_impl.h | 42 + .../binder/client/connection_id_generator.cc | 69 ++ src/core/ext/transport/binder/java/WORKSPACE | 0 .../binder/java/io/grpc/binder/cpp/BUILD | 30 + .../grpc/binder/cpp/GrpcBinderConnection.java | 104 ++ .../grpc/binder/cpp/GrpcCppServerBuilder.java | 40 + .../binder/cpp/NativeConnectionHelper.java | 71 ++ .../binder/security_policy/security_policy.h | 40 + .../binder/transport/binder_stream.h | 117 +++ .../binder/utils/binder_auto_utils.h | 76 ++ .../ext/transport/binder/utils/ndk_binder.h | 107 ++ .../binder/wire_format/binder_constants.cc | 29 + .../binder/wire_format/transaction.cc | 33 + .../plugin_registry/grpc_plugin_registry.cc | 6 + src/core/resolver/binder/README.md | 9 + src/python/grpcio/grpc_core_dependencies.py | 1 + test/core/resolver/BUILD | 16 + test/core/transport/binder/BUILD | 133 +++ test/core/transport/binder/end2end/BUILD | 119 +++ .../transport/binder/end2end/fuzzers/BUILD | 101 ++ .../empty | 0 .../fuzzers/binder_transport_fuzzer.proto | 81 ++ .../empty | 0 .../binder/end2end/fuzzers/client.proto | 17 + .../binder/end2end/fuzzers/fuzzer_utils.cc | 157 +++ .../binder/end2end/fuzzers/server.proto | 17 + test/core/transport/binder/mock_objects.cc | 55 ++ test/core/transport/binder/mock_objects.h | 121 +++ tools/doxygen/Doxyfile.c++ | 3 + tools/doxygen/Doxyfile.c++.internal | 42 + tools/doxygen/Doxyfile.core.internal | 3 + ...pc_binder_transport_apk_build_in_docker.sh | 40 + tools/run_tests/generated/tests.json | 192 ++++ 49 files changed, 3861 insertions(+), 23 deletions(-) create mode 100644 include/grpcpp/security/binder_security_policy.h create mode 100644 src/core/ext/transport/binder/README.md create mode 100644 src/core/ext/transport/binder/client/channel_create_impl.h create mode 100644 src/core/ext/transport/binder/client/connection_id_generator.cc create mode 100644 src/core/ext/transport/binder/java/WORKSPACE create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/BUILD create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java create mode 100644 src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java create mode 100644 src/core/ext/transport/binder/security_policy/security_policy.h create mode 100644 src/core/ext/transport/binder/transport/binder_stream.h create mode 100644 src/core/ext/transport/binder/utils/binder_auto_utils.h create mode 100644 src/core/ext/transport/binder/utils/ndk_binder.h create mode 100644 src/core/ext/transport/binder/wire_format/binder_constants.cc create mode 100644 src/core/ext/transport/binder/wire_format/transaction.cc create mode 100644 src/core/resolver/binder/README.md create mode 100644 test/core/transport/binder/BUILD create mode 100644 test/core/transport/binder/end2end/BUILD create mode 100644 test/core/transport/binder/end2end/fuzzers/BUILD create mode 100644 test/core/transport/binder/end2end/fuzzers/binder_transport_client_fuzzer_corpus/empty create mode 100644 test/core/transport/binder/end2end/fuzzers/binder_transport_fuzzer.proto create mode 100644 test/core/transport/binder/end2end/fuzzers/binder_transport_server_fuzzer_corpus/empty create mode 100644 test/core/transport/binder/end2end/fuzzers/client.proto create mode 100644 test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc create mode 100644 test/core/transport/binder/end2end/fuzzers/server.proto create mode 100644 test/core/transport/binder/mock_objects.cc create mode 100644 test/core/transport/binder/mock_objects.h create mode 100755 tools/internal_ci/linux/grpc_binder_transport_apk_build_in_docker.sh diff --git a/BUILD b/BUILD index b737fb5ecdb..4d57a053c1f 100644 --- a/BUILD +++ b/BUILD @@ -74,6 +74,17 @@ config_setting( flag_values = {":disable_grpc_rls": "true"}, ) +# When gRPC is build as shared library, binder transport code might still +# get included even when user's code does not depend on it. In that case +# --define=grpc_no_binder=true can be used to disable binder transport +# related code to reduce binary size. +# For users using build system other than bazel, they can define +# GRPC_NO_BINDER to achieve the same effect. +config_setting( + name = "grpc_no_binder_define", + values = {"define": "grpc_no_binder=true"}, +) + config_setting( name = "android", values = {"crosstool_top": "//external:android/crosstool"}, @@ -124,6 +135,15 @@ selects.config_setting_group( ], ) +selects.config_setting_group( + name = "grpc_no_binder", + match_any = [ + ":grpc_no_binder_define", + # We do not need binder on ios. + ":ios", + ], +) + selects.config_setting_group( name = "grpc_no_rls", match_any = [ @@ -835,6 +855,7 @@ grpc_cc_library( "//src/core:grpc_lb_policy_weighted_target", "//src/core:grpc_channel_idle_filter", "//src/core:grpc_message_size_filter", + "//src/core:grpc_resolver_binder", "grpc_resolver_dns_ares", "grpc_resolver_fake", "//src/core:grpc_resolver_dns_native", @@ -920,6 +941,12 @@ grpc_cc_library( "grpc++_xds_server", ], }, + { + "grpc_no_binder": [], + "//conditions:default": [ + "grpc++_binder", + ], + }, ], tags = ["nofixdeps"], visibility = ["@grpc:public"], @@ -1050,6 +1077,112 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "grpc++_binder", + srcs = [ + "//src/core:ext/transport/binder/client/binder_connector.cc", + "//src/core:ext/transport/binder/client/channel_create.cc", + "//src/core:ext/transport/binder/client/channel_create_impl.cc", + "//src/core:ext/transport/binder/client/connection_id_generator.cc", + "//src/core:ext/transport/binder/client/endpoint_binder_pool.cc", + "//src/core:ext/transport/binder/client/jni_utils.cc", + "//src/core:ext/transport/binder/client/security_policy_setting.cc", + "//src/core:ext/transport/binder/security_policy/binder_security_policy.cc", + "//src/core:ext/transport/binder/server/binder_server.cc", + "//src/core:ext/transport/binder/server/binder_server_credentials.cc", + "//src/core:ext/transport/binder/transport/binder_transport.cc", + "//src/core:ext/transport/binder/utils/ndk_binder.cc", + "//src/core:ext/transport/binder/utils/transport_stream_receiver_impl.cc", + "//src/core:ext/transport/binder/wire_format/binder_android.cc", + "//src/core:ext/transport/binder/wire_format/binder_constants.cc", + "//src/core:ext/transport/binder/wire_format/transaction.cc", + "//src/core:ext/transport/binder/wire_format/wire_reader_impl.cc", + "//src/core:ext/transport/binder/wire_format/wire_writer.cc", + ], + hdrs = [ + "//src/core:ext/transport/binder/client/binder_connector.h", + "//src/core:ext/transport/binder/client/channel_create_impl.h", + "//src/core:ext/transport/binder/client/connection_id_generator.h", + "//src/core:ext/transport/binder/client/endpoint_binder_pool.h", + "//src/core:ext/transport/binder/client/jni_utils.h", + "//src/core:ext/transport/binder/client/security_policy_setting.h", + "//src/core:ext/transport/binder/server/binder_server.h", + "//src/core:ext/transport/binder/transport/binder_stream.h", + "//src/core:ext/transport/binder/transport/binder_transport.h", + "//src/core:ext/transport/binder/utils/binder_auto_utils.h", + "//src/core:ext/transport/binder/utils/ndk_binder.h", + "//src/core:ext/transport/binder/utils/transport_stream_receiver.h", + "//src/core:ext/transport/binder/utils/transport_stream_receiver_impl.h", + "//src/core:ext/transport/binder/wire_format/binder.h", + "//src/core:ext/transport/binder/wire_format/binder_android.h", + "//src/core:ext/transport/binder/wire_format/binder_constants.h", + "//src/core:ext/transport/binder/wire_format/transaction.h", + "//src/core:ext/transport/binder/wire_format/wire_reader.h", + "//src/core:ext/transport/binder/wire_format/wire_reader_impl.h", + "//src/core:ext/transport/binder/wire_format/wire_writer.h", + ], + defines = select({ + "grpc_no_binder": ["GRPC_NO_BINDER"], + "//conditions:default": [], + }), + external_deps = [ + "absl/base:core_headers", + "absl/cleanup", + "absl/container:flat_hash_map", + "absl/functional:any_invocable", + "absl/hash", + "absl/log:check", + "absl/log:log", + "absl/memory", + "absl/meta:type_traits", + "absl/status", + "absl/status:statusor", + "absl/strings", + "absl/synchronization", + "absl/time", + "absl/types:variant", + ], + language = "c++", + public_hdrs = [ + "include/grpcpp/security/binder_security_policy.h", + "include/grpcpp/create_channel_binder.h", + "include/grpcpp/security/binder_credentials.h", + ], + tags = ["nofixdeps"], + deps = [ + "channel", + "channel_create", + "config", + "debug_location", + "exec_ctx", + "gpr", + "gpr_platform", + "grpc", + "grpc++_base", + "grpc_base", + "grpc_client_channel", + "grpc_public_hdrs", + "orphanable", + "ref_counted_ptr", + "server", + "//src/core:arena", + "//src/core:channel_args", + "//src/core:channel_args_preconditioning", + "//src/core:channel_stack_type", + "//src/core:default_event_engine", + "//src/core:error_utils", + "//src/core:iomgr_fwd", + "//src/core:iomgr_port", + "//src/core:metadata_batch", + "//src/core:notification", + "//src/core:slice", + "//src/core:slice_refcount", + "//src/core:status_helper", + "//src/core:subchannel_connector", + "//src/core:transport_fwd", + ], +) + grpc_cc_library( name = "grpc++_xds_client", srcs = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 113eb420a38..41e69b70ab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -962,6 +962,9 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx bin_decoder_test) add_dependencies(buildtests_cxx bin_encoder_test) add_dependencies(buildtests_cxx binary_metadata_test) + add_dependencies(buildtests_cxx binder_resolver_test) + add_dependencies(buildtests_cxx binder_server_test) + add_dependencies(buildtests_cxx binder_transport_test) add_dependencies(buildtests_cxx bitset_test) add_dependencies(buildtests_cxx blackboard_test) add_dependencies(buildtests_cxx buffer_list_test) @@ -1077,8 +1080,12 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx dump_args_test) add_dependencies(buildtests_cxx duplicate_header_bad_client_test) add_dependencies(buildtests_cxx empty_batch_test) + if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) + add_dependencies(buildtests_cxx end2end_binder_transport_test) + endif() add_dependencies(buildtests_cxx end2end_test) add_dependencies(buildtests_cxx endpoint_addresses_test) + add_dependencies(buildtests_cxx endpoint_binder_pool_test) add_dependencies(buildtests_cxx endpoint_config_test) add_dependencies(buildtests_cxx endpoint_pair_test) add_dependencies(buildtests_cxx env_test) @@ -1098,6 +1105,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx experiments_tag_test) add_dependencies(buildtests_cxx experiments_test) add_dependencies(buildtests_cxx factory_test) + add_dependencies(buildtests_cxx fake_binder_test) add_dependencies(buildtests_cxx fake_resolver_test) add_dependencies(buildtests_cxx fake_transport_security_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) @@ -1529,6 +1537,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx trailing_metadata_test) add_dependencies(buildtests_cxx transport_security_common_api_test) add_dependencies(buildtests_cxx transport_security_test) + add_dependencies(buildtests_cxx transport_stream_receiver_test) add_dependencies(buildtests_cxx try_join_test) add_dependencies(buildtests_cxx try_seq_metadata_test) add_dependencies(buildtests_cxx try_seq_test) @@ -1553,6 +1562,8 @@ if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX OR _gRPC_PLATFORM_WINDOWS) add_dependencies(buildtests_cxx windows_endpoint_test) endif() + add_dependencies(buildtests_cxx wire_reader_test) + add_dependencies(buildtests_cxx wire_writer_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx work_serializer_test) endif() @@ -2536,6 +2547,7 @@ add_library(grpc src/core/load_balancing/xds/xds_wrr_locality.cc src/core/plugin_registry/grpc_plugin_registry.cc src/core/plugin_registry/grpc_plugin_registry_extra.cc + src/core/resolver/binder/binder_resolver.cc src/core/resolver/dns/c_ares/dns_resolver_ares.cc src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -3302,6 +3314,7 @@ add_library(grpc_unsecure src/core/load_balancing/weighted_target/weighted_target.cc src/core/plugin_registry/grpc_plugin_registry.cc src/core/plugin_registry/grpc_plugin_registry_noextra.cc + src/core/resolver/binder/binder_resolver.cc src/core/resolver/dns/c_ares/dns_resolver_ares.cc src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -4175,6 +4188,24 @@ endif() endif() add_library(grpc++ + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc src/cpp/client/call_credentials.cc src/cpp/client/channel_cc.cc src/cpp/client/channel_credentials.cc @@ -4356,6 +4387,7 @@ foreach(_hdr include/grpcpp/client_context.h include/grpcpp/completion_queue.h include/grpcpp/create_channel.h + include/grpcpp/create_channel_binder.h include/grpcpp/create_channel_posix.h include/grpcpp/ext/call_metric_recorder.h include/grpcpp/ext/health_check_service_server_builder_option.h @@ -4447,6 +4479,8 @@ foreach(_hdr include/grpcpp/security/auth_context.h include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/authorization_policy_provider.h + include/grpcpp/security/binder_credentials.h + include/grpcpp/security/binder_security_policy.h include/grpcpp/security/credentials.h include/grpcpp/security/server_credentials.h include/grpcpp/security/tls_certificate_provider.h @@ -8136,6 +8170,220 @@ target_link_libraries(binary_metadata_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(binder_resolver_test + test/core/resolver/binder_resolver_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(binder_resolver_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(binder_resolver_test PUBLIC cxx_std_14) +target_include_directories(binder_resolver_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(binder_resolver_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + +add_executable(binder_server_test + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h + test/core/transport/binder/end2end/binder_server_test.cc + test/core/transport/binder/end2end/fake_binder.cc + test/cpp/end2end/test_service_impl.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(binder_server_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + "GRPCXX_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(binder_server_test PUBLIC cxx_std_14) +target_include_directories(binder_server_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(binder_server_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc++_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + +add_executable(binder_transport_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/binder_transport_test.cc + test/core/transport/binder/mock_objects.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(binder_transport_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(binder_transport_test PUBLIC cxx_std_14) +target_include_directories(binder_transport_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(binder_transport_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) @@ -13052,6 +13300,70 @@ target_link_libraries(empty_batch_test ) +endif() +if(gRPC_BUILD_TESTS) +if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) + + add_executable(end2end_binder_transport_test + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/orca_load_report.grpc.pb.h + test/core/transport/binder/end2end/end2end_binder_transport_test.cc + test/core/transport/binder/end2end/fake_binder.cc + test/core/transport/binder/end2end/testing_channel_create.cc + test/cpp/end2end/test_service_impl.cc + ) + if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(end2end_binder_transport_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + "GRPCXX_DLL_IMPORTS" + ) + endif() + endif() + target_compile_features(end2end_binder_transport_test PUBLIC cxx_std_14) + target_include_directories(end2end_binder_transport_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} + ) + + target_link_libraries(end2end_binder_transport_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc++_test_util + ) + + +endif() endif() if(gRPC_BUILD_TESTS) @@ -13162,28 +13474,139 @@ target_link_libraries(endpoint_addresses_test endif() if(gRPC_BUILD_TESTS) -add_executable(endpoint_config_test - src/core/lib/channel/channel_args.cc - src/core/lib/event_engine/channel_args_endpoint_config.cc - src/core/lib/surface/channel_stack_type.cc - src/core/util/ref_counted_string.cc - src/core/util/time.cc - test/core/event_engine/endpoint_config_test.cc -) -if(WIN32 AND MSVC) - if(BUILD_SHARED_LIBS) - target_compile_definitions(endpoint_config_test - PRIVATE - "GPR_DLL_IMPORTS" - ) - endif() -endif() -target_compile_features(endpoint_config_test PUBLIC cxx_std_14) -target_include_directories(endpoint_config_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} +add_executable(endpoint_binder_pool_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/endpoint_binder_pool_test.cc + test/core/transport/binder/mock_objects.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(endpoint_binder_pool_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(endpoint_binder_pool_test PUBLIC cxx_std_14) +target_include_directories(endpoint_binder_pool_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(endpoint_binder_pool_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + +add_executable(endpoint_config_test + src/core/lib/channel/channel_args.cc + src/core/lib/event_engine/channel_args_endpoint_config.cc + src/core/lib/surface/channel_stack_type.cc + src/core/util/ref_counted_string.cc + src/core/util/time.cc + test/core/event_engine/endpoint_config_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(endpoint_config_test + PRIVATE + "GPR_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(endpoint_config_test PUBLIC cxx_std_14) +target_include_directories(endpoint_config_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} ${_gRPC_RE2_INCLUDE_DIR} ${_gRPC_SSL_INCLUDE_DIR} ${_gRPC_UPB_GENERATED_DIR} @@ -13904,6 +14327,117 @@ target_link_libraries(factory_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(fake_binder_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/end2end/fake_binder.cc + test/core/transport/binder/end2end/fake_binder_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(fake_binder_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(fake_binder_test PUBLIC cxx_std_14) +target_include_directories(fake_binder_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(fake_binder_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) @@ -32048,6 +32582,116 @@ target_link_libraries(transport_security_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(transport_stream_receiver_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/transport_stream_receiver_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(transport_stream_receiver_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(transport_stream_receiver_test PUBLIC cxx_std_14) +target_include_directories(transport_stream_receiver_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(transport_stream_receiver_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) @@ -32825,6 +33469,228 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX OR _gRPC_PLATFORM_WINDOWS) endif() +endif() +if(gRPC_BUILD_TESTS) + +add_executable(wire_reader_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/mock_objects.cc + test/core/transport/binder/wire_reader_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(wire_reader_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(wire_reader_test PUBLIC cxx_std_14) +target_include_directories(wire_reader_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(wire_reader_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + +endif() +if(gRPC_BUILD_TESTS) + +add_executable(wire_writer_test + src/core/ext/transport/binder/client/binder_connector.cc + src/core/ext/transport/binder/client/channel_create.cc + src/core/ext/transport/binder/client/channel_create_impl.cc + src/core/ext/transport/binder/client/connection_id_generator.cc + src/core/ext/transport/binder/client/endpoint_binder_pool.cc + src/core/ext/transport/binder/client/jni_utils.cc + src/core/ext/transport/binder/client/security_policy_setting.cc + src/core/ext/transport/binder/security_policy/binder_security_policy.cc + src/core/ext/transport/binder/server/binder_server.cc + src/core/ext/transport/binder/server/binder_server_credentials.cc + src/core/ext/transport/binder/transport/binder_transport.cc + src/core/ext/transport/binder/utils/ndk_binder.cc + src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + src/core/ext/transport/binder/wire_format/binder_android.cc + src/core/ext/transport/binder/wire_format/binder_constants.cc + src/core/ext/transport/binder/wire_format/transaction.cc + src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + src/core/ext/transport/binder/wire_format/wire_writer.cc + src/cpp/client/call_credentials.cc + src/cpp/client/channel_cc.cc + src/cpp/client/channel_credentials.cc + src/cpp/client/client_callback.cc + src/cpp/client/client_context.cc + src/cpp/client/client_interceptor.cc + src/cpp/client/client_stats_interceptor.cc + src/cpp/client/create_channel.cc + src/cpp/client/create_channel_internal.cc + src/cpp/client/create_channel_posix.cc + src/cpp/client/global_callback_hook.cc + src/cpp/client/insecure_credentials.cc + src/cpp/client/secure_credentials.cc + src/cpp/common/alarm.cc + src/cpp/common/auth_property_iterator.cc + src/cpp/common/channel_arguments.cc + src/cpp/common/completion_queue_cc.cc + src/cpp/common/resource_quota_cc.cc + src/cpp/common/rpc_method.cc + src/cpp/common/secure_auth_context.cc + src/cpp/common/secure_create_auth_context.cc + src/cpp/common/tls_certificate_provider.cc + src/cpp/common/tls_certificate_verifier.cc + src/cpp/common/tls_credentials_options.cc + src/cpp/common/validate_service_config.cc + src/cpp/common/version_cc.cc + src/cpp/server/async_generic_service.cc + src/cpp/server/backend_metric_recorder.cc + src/cpp/server/channel_argument_option.cc + src/cpp/server/create_default_thread_pool.cc + src/cpp/server/external_connection_acceptor_impl.cc + src/cpp/server/health/default_health_check_service.cc + src/cpp/server/health/health_check_service.cc + src/cpp/server/health/health_check_service_server_builder_option.cc + src/cpp/server/insecure_server_credentials.cc + src/cpp/server/secure_server_credentials.cc + src/cpp/server/server_builder.cc + src/cpp/server/server_callback.cc + src/cpp/server/server_cc.cc + src/cpp/server/server_context.cc + src/cpp/server/server_credentials.cc + src/cpp/server/server_posix.cc + src/cpp/thread_manager/thread_manager.cc + src/cpp/util/byte_buffer_cc.cc + src/cpp/util/status.cc + src/cpp/util/string_ref.cc + src/cpp/util/time_cc.cc + test/core/transport/binder/mock_objects.cc + test/core/transport/binder/wire_writer_test.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(wire_writer_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(wire_writer_test PUBLIC cxx_std_14) +target_include_directories(wire_writer_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(wire_writer_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + absl::absl_check + absl::absl_log + ${_gRPC_PROTOBUF_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) diff --git a/Makefile b/Makefile index 063659c0cfb..b33a29370b9 100644 --- a/Makefile +++ b/Makefile @@ -1355,6 +1355,7 @@ LIBGRPC_SRC = \ src/core/load_balancing/xds/xds_wrr_locality.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/plugin_registry/grpc_plugin_registry_extra.cc \ + src/core/resolver/binder/binder_resolver.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ diff --git a/Package.swift b/Package.swift index bfda2eef090..f1e60c511ca 100644 --- a/Package.swift +++ b/Package.swift @@ -1702,6 +1702,7 @@ let package = Package( "src/core/load_balancing/xds/xds_wrr_locality.cc", "src/core/plugin_registry/grpc_plugin_registry.cc", "src/core/plugin_registry/grpc_plugin_registry_extra.cc", + "src/core/resolver/binder/binder_resolver.cc", "src/core/resolver/dns/c_ares/dns_resolver_ares.cc", "src/core/resolver/dns/c_ares/dns_resolver_ares.h", "src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h", diff --git a/WORKSPACE b/WORKSPACE index f3188fcaeaf..675233b2eb1 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -56,6 +56,16 @@ android_ndk_repository(name = "androidndk") # here, because the toolchain rule fails when $ANDROID_NDK_HOME is not set. # Use `--extra_toolchains=@androidndk//:all` to manually register it when building for Android. +# Prevents bazel's '...' expansion from including the following folder. +# This is required because the BUILD file in the following folder +# will trigger bazel failure when Android SDK is not configured. +# The targets in the following folder need to be included in APK and will +# be invoked by binder transport implementation through JNI. +local_repository( + name = "binder_transport_android_helper", + path = "src/core/ext/transport/binder/java", +) + # Prevents bazel's '...' expansion from including the following folder. # This is required to avoid triggering "Unable to find package for @rules_fuzzing//fuzzing:cc_defs.bzl" # error. diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 0df78d48a7a..3ae9dd5577c 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -1958,6 +1958,7 @@ libs: - src/core/load_balancing/xds/xds_wrr_locality.cc - src/core/plugin_registry/grpc_plugin_registry.cc - src/core/plugin_registry/grpc_plugin_registry_extra.cc + - src/core/resolver/binder/binder_resolver.cc - src/core/resolver/dns/c_ares/dns_resolver_ares.cc - src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc - src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -3076,6 +3077,7 @@ libs: - src/core/load_balancing/weighted_target/weighted_target.cc - src/core/plugin_registry/grpc_plugin_registry.cc - src/core/plugin_registry/grpc_plugin_registry_noextra.cc + - src/core/resolver/binder/binder_resolver.cc - src/core/resolver/dns/c_ares/dns_resolver_ares.cc - src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc - src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -3761,6 +3763,7 @@ libs: - include/grpcpp/client_context.h - include/grpcpp/completion_queue.h - include/grpcpp/create_channel.h + - include/grpcpp/create_channel_binder.h - include/grpcpp/create_channel_posix.h - include/grpcpp/ext/call_metric_recorder.h - include/grpcpp/ext/health_check_service_server_builder_option.h @@ -3852,6 +3855,8 @@ libs: - include/grpcpp/security/auth_context.h - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/authorization_policy_provider.h + - include/grpcpp/security/binder_credentials.h + - include/grpcpp/security/binder_security_policy.h - include/grpcpp/security/credentials.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/tls_certificate_provider.h @@ -3890,6 +3895,26 @@ libs: - include/grpcpp/version_info.h - include/grpcpp/xds_server_builder.h headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h - src/core/xds/grpc/xds_enabled_server.h - src/cpp/client/client_stats_interceptor.h - src/cpp/client/create_channel_internal.h @@ -3903,6 +3928,24 @@ libs: - src/cpp/server/thread_pool_interface.h - src/cpp/thread_manager/thread_manager.h src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc - src/cpp/client/call_credentials.cc - src/cpp/client/channel_cc.cc - src/cpp/client/channel_credentials.cc @@ -6091,6 +6134,146 @@ targets: - grpc_authorization_provider - grpc_unsecure - grpc_test_util +- name: binder_resolver_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/resolver/binder_resolver_test.cc + deps: + - gtest + - grpc_test_util +- name: binder_server_test + gtest: true + build: test + language: c++ + headers: + - test/core/transport/binder/end2end/fake_binder.h + - test/cpp/end2end/test_service_impl.h + src: + - src/proto/grpc/testing/echo.proto + - src/proto/grpc/testing/echo_messages.proto + - src/proto/grpc/testing/simple_messages.proto + - src/proto/grpc/testing/xds/v3/orca_load_report.proto + - test/core/transport/binder/end2end/binder_server_test.cc + - test/core/transport/binder/end2end/fake_binder.cc + - test/cpp/end2end/test_service_impl.cc + deps: + - gtest + - grpc++_test_util +- name: binder_transport_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + - test/core/transport/binder/mock_objects.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/binder_transport_test.cc + - test/core/transport/binder/mock_objects.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false - name: bitset_test gtest: true build: test @@ -9462,6 +9645,30 @@ targets: - grpc_authorization_provider - grpc_unsecure - grpc_test_util +- name: end2end_binder_transport_test + gtest: true + build: test + run: false + language: c++ + headers: + - test/core/transport/binder/end2end/fake_binder.h + - test/core/transport/binder/end2end/testing_channel_create.h + - test/cpp/end2end/test_service_impl.h + src: + - src/proto/grpc/testing/echo.proto + - src/proto/grpc/testing/echo_messages.proto + - src/proto/grpc/testing/simple_messages.proto + - src/proto/grpc/testing/xds/v3/orca_load_report.proto + - test/core/transport/binder/end2end/end2end_binder_transport_test.cc + - test/core/transport/binder/end2end/fake_binder.cc + - test/core/transport/binder/end2end/testing_channel_create.cc + - test/cpp/end2end/test_service_impl.cc + deps: + - gtest + - grpc++_test_util + platforms: + - linux + - posix - name: end2end_test gtest: true build: test @@ -9493,6 +9700,118 @@ targets: - gtest - grpc_test_util uses_polling: false +- name: endpoint_binder_pool_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + - test/core/transport/binder/mock_objects.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/endpoint_binder_pool_test.cc + - test/core/transport/binder/mock_objects.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false - name: endpoint_config_test gtest: true build: test @@ -9857,6 +10176,118 @@ targets: deps: - gtest - grpc_test_util_unsecure +- name: fake_binder_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + - test/core/transport/binder/end2end/fake_binder.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/end2end/fake_binder.cc + - test/core/transport/binder/end2end/fake_binder_test.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false - name: fake_resolver_test gtest: true build: test @@ -20218,6 +20649,116 @@ targets: deps: - gtest - grpc_test_util +- name: transport_stream_receiver_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/transport_stream_receiver_test.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false - name: try_join_test gtest: true build: test @@ -20527,6 +21068,230 @@ targets: - posix - windows uses_polling: false +- name: wire_reader_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + - test/core/transport/binder/mock_objects.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/mock_objects.cc + - test/core/transport/binder/wire_reader_test.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false +- name: wire_writer_test + gtest: true + build: test + language: c++ + headers: + - src/core/ext/transport/binder/client/binder_connector.h + - src/core/ext/transport/binder/client/channel_create_impl.h + - src/core/ext/transport/binder/client/connection_id_generator.h + - src/core/ext/transport/binder/client/endpoint_binder_pool.h + - src/core/ext/transport/binder/client/jni_utils.h + - src/core/ext/transport/binder/client/security_policy_setting.h + - src/core/ext/transport/binder/server/binder_server.h + - src/core/ext/transport/binder/transport/binder_stream.h + - src/core/ext/transport/binder/transport/binder_transport.h + - src/core/ext/transport/binder/utils/binder_auto_utils.h + - src/core/ext/transport/binder/utils/ndk_binder.h + - src/core/ext/transport/binder/utils/transport_stream_receiver.h + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h + - src/core/ext/transport/binder/wire_format/binder.h + - src/core/ext/transport/binder/wire_format/binder_android.h + - src/core/ext/transport/binder/wire_format/binder_constants.h + - src/core/ext/transport/binder/wire_format/transaction.h + - src/core/ext/transport/binder/wire_format/wire_reader.h + - src/core/ext/transport/binder/wire_format/wire_reader_impl.h + - src/core/ext/transport/binder/wire_format/wire_writer.h + - src/cpp/client/client_stats_interceptor.h + - src/cpp/client/create_channel_internal.h + - src/cpp/client/secure_credentials.h + - src/cpp/common/secure_auth_context.h + - src/cpp/server/backend_metric_recorder.h + - src/cpp/server/dynamic_thread_pool.h + - src/cpp/server/external_connection_acceptor_impl.h + - src/cpp/server/health/default_health_check_service.h + - src/cpp/server/secure_server_credentials.h + - src/cpp/server/thread_pool_interface.h + - src/cpp/thread_manager/thread_manager.h + - test/core/transport/binder/mock_objects.h + src: + - src/core/ext/transport/binder/client/binder_connector.cc + - src/core/ext/transport/binder/client/channel_create.cc + - src/core/ext/transport/binder/client/channel_create_impl.cc + - src/core/ext/transport/binder/client/connection_id_generator.cc + - src/core/ext/transport/binder/client/endpoint_binder_pool.cc + - src/core/ext/transport/binder/client/jni_utils.cc + - src/core/ext/transport/binder/client/security_policy_setting.cc + - src/core/ext/transport/binder/security_policy/binder_security_policy.cc + - src/core/ext/transport/binder/server/binder_server.cc + - src/core/ext/transport/binder/server/binder_server_credentials.cc + - src/core/ext/transport/binder/transport/binder_transport.cc + - src/core/ext/transport/binder/utils/ndk_binder.cc + - src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc + - src/core/ext/transport/binder/wire_format/binder_android.cc + - src/core/ext/transport/binder/wire_format/binder_constants.cc + - src/core/ext/transport/binder/wire_format/transaction.cc + - src/core/ext/transport/binder/wire_format/wire_reader_impl.cc + - src/core/ext/transport/binder/wire_format/wire_writer.cc + - src/cpp/client/call_credentials.cc + - src/cpp/client/channel_cc.cc + - src/cpp/client/channel_credentials.cc + - src/cpp/client/client_callback.cc + - src/cpp/client/client_context.cc + - src/cpp/client/client_interceptor.cc + - src/cpp/client/client_stats_interceptor.cc + - src/cpp/client/create_channel.cc + - src/cpp/client/create_channel_internal.cc + - src/cpp/client/create_channel_posix.cc + - src/cpp/client/global_callback_hook.cc + - src/cpp/client/insecure_credentials.cc + - src/cpp/client/secure_credentials.cc + - src/cpp/common/alarm.cc + - src/cpp/common/auth_property_iterator.cc + - src/cpp/common/channel_arguments.cc + - src/cpp/common/completion_queue_cc.cc + - src/cpp/common/resource_quota_cc.cc + - src/cpp/common/rpc_method.cc + - src/cpp/common/secure_auth_context.cc + - src/cpp/common/secure_create_auth_context.cc + - src/cpp/common/tls_certificate_provider.cc + - src/cpp/common/tls_certificate_verifier.cc + - src/cpp/common/tls_credentials_options.cc + - src/cpp/common/validate_service_config.cc + - src/cpp/common/version_cc.cc + - src/cpp/server/async_generic_service.cc + - src/cpp/server/backend_metric_recorder.cc + - src/cpp/server/channel_argument_option.cc + - src/cpp/server/create_default_thread_pool.cc + - src/cpp/server/external_connection_acceptor_impl.cc + - src/cpp/server/health/default_health_check_service.cc + - src/cpp/server/health/health_check_service.cc + - src/cpp/server/health/health_check_service_server_builder_option.cc + - src/cpp/server/insecure_server_credentials.cc + - src/cpp/server/secure_server_credentials.cc + - src/cpp/server/server_builder.cc + - src/cpp/server/server_callback.cc + - src/cpp/server/server_cc.cc + - src/cpp/server/server_context.cc + - src/cpp/server/server_credentials.cc + - src/cpp/server/server_posix.cc + - src/cpp/thread_manager/thread_manager.cc + - src/cpp/util/byte_buffer_cc.cc + - src/cpp/util/status.cc + - src/cpp/util/string_ref.cc + - src/cpp/util/time_cc.cc + - test/core/transport/binder/mock_objects.cc + - test/core/transport/binder/wire_writer_test.cc + deps: + - gtest + - absl/log:absl_check + - absl/log:absl_log + - protobuf + - grpc_test_util + uses_polling: false - name: work_serializer_test gtest: true build: test diff --git a/config.m4 b/config.m4 index 8a5692bac9a..cd9212d3572 100644 --- a/config.m4 +++ b/config.m4 @@ -730,6 +730,7 @@ if test "$PHP_GRPC" != "no"; then src/core/load_balancing/xds/xds_wrr_locality.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/plugin_registry/grpc_plugin_registry_extra.cc \ + src/core/resolver/binder/binder_resolver.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ @@ -1600,6 +1601,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/load_balancing/xds) PHP_ADD_BUILD_DIR($ext_builddir/src/core/plugin_registry) PHP_ADD_BUILD_DIR($ext_builddir/src/core/resolver) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/resolver/binder) PHP_ADD_BUILD_DIR($ext_builddir/src/core/resolver/dns) PHP_ADD_BUILD_DIR($ext_builddir/src/core/resolver/dns/c_ares) PHP_ADD_BUILD_DIR($ext_builddir/src/core/resolver/dns/event_engine) diff --git a/config.w32 b/config.w32 index 088607cb0a0..b590018a1bd 100644 --- a/config.w32 +++ b/config.w32 @@ -695,6 +695,7 @@ if (PHP_GRPC != "no") { "src\\core\\load_balancing\\xds\\xds_wrr_locality.cc " + "src\\core\\plugin_registry\\grpc_plugin_registry.cc " + "src\\core\\plugin_registry\\grpc_plugin_registry_extra.cc " + + "src\\core\\resolver\\binder\\binder_resolver.cc " + "src\\core\\resolver\\dns\\c_ares\\dns_resolver_ares.cc " + "src\\core\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_posix.cc " + "src\\core\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_windows.cc " + @@ -1740,6 +1741,7 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\load_balancing\\xds"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\plugin_registry"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\resolver"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\resolver\\binder"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\resolver\\dns"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\resolver\\dns\\c_ares"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\resolver\\dns\\event_engine"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 5f416533062..aeb929b9ad6 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -97,6 +97,7 @@ Pod::Spec.new do |s| 'include/grpcpp/client_context.h', 'include/grpcpp/completion_queue.h', 'include/grpcpp/create_channel.h', + 'include/grpcpp/create_channel_binder.h', 'include/grpcpp/create_channel_posix.h', 'include/grpcpp/ext/call_metric_recorder.h', 'include/grpcpp/ext/health_check_service_server_builder_option.h', @@ -184,6 +185,8 @@ Pod::Spec.new do |s| 'include/grpcpp/security/auth_context.h', 'include/grpcpp/security/auth_metadata_processor.h', 'include/grpcpp/security/authorization_policy_provider.h', + 'include/grpcpp/security/binder_credentials.h', + 'include/grpcpp/security/binder_security_policy.h', 'include/grpcpp/security/credentials.h', 'include/grpcpp/security/server_credentials.h', 'include/grpcpp/security/tls_certificate_provider.h', @@ -310,6 +313,44 @@ Pod::Spec.new do |s| 'src/core/ext/filters/rbac/rbac_service_config_parser.h', 'src/core/ext/filters/stateful_session/stateful_session_filter.h', 'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h', + 'src/core/ext/transport/binder/client/binder_connector.cc', + 'src/core/ext/transport/binder/client/binder_connector.h', + 'src/core/ext/transport/binder/client/channel_create.cc', + 'src/core/ext/transport/binder/client/channel_create_impl.cc', + 'src/core/ext/transport/binder/client/channel_create_impl.h', + 'src/core/ext/transport/binder/client/connection_id_generator.cc', + 'src/core/ext/transport/binder/client/connection_id_generator.h', + 'src/core/ext/transport/binder/client/endpoint_binder_pool.cc', + 'src/core/ext/transport/binder/client/endpoint_binder_pool.h', + 'src/core/ext/transport/binder/client/jni_utils.cc', + 'src/core/ext/transport/binder/client/jni_utils.h', + 'src/core/ext/transport/binder/client/security_policy_setting.cc', + 'src/core/ext/transport/binder/client/security_policy_setting.h', + 'src/core/ext/transport/binder/security_policy/binder_security_policy.cc', + 'src/core/ext/transport/binder/server/binder_server.cc', + 'src/core/ext/transport/binder/server/binder_server.h', + 'src/core/ext/transport/binder/server/binder_server_credentials.cc', + 'src/core/ext/transport/binder/transport/binder_stream.h', + 'src/core/ext/transport/binder/transport/binder_transport.cc', + 'src/core/ext/transport/binder/transport/binder_transport.h', + 'src/core/ext/transport/binder/utils/binder_auto_utils.h', + 'src/core/ext/transport/binder/utils/ndk_binder.cc', + 'src/core/ext/transport/binder/utils/ndk_binder.h', + 'src/core/ext/transport/binder/utils/transport_stream_receiver.h', + 'src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc', + 'src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h', + 'src/core/ext/transport/binder/wire_format/binder.h', + 'src/core/ext/transport/binder/wire_format/binder_android.cc', + 'src/core/ext/transport/binder/wire_format/binder_android.h', + 'src/core/ext/transport/binder/wire_format/binder_constants.cc', + 'src/core/ext/transport/binder/wire_format/binder_constants.h', + 'src/core/ext/transport/binder/wire_format/transaction.cc', + 'src/core/ext/transport/binder/wire_format/transaction.h', + 'src/core/ext/transport/binder/wire_format/wire_reader.h', + 'src/core/ext/transport/binder/wire_format/wire_reader_impl.cc', + 'src/core/ext/transport/binder/wire_format/wire_reader_impl.h', + 'src/core/ext/transport/binder/wire_format/wire_writer.cc', + 'src/core/ext/transport/binder/wire_format/wire_writer.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', @@ -1595,6 +1636,26 @@ Pod::Spec.new do |s| 'src/core/ext/filters/rbac/rbac_service_config_parser.h', 'src/core/ext/filters/stateful_session/stateful_session_filter.h', 'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h', + 'src/core/ext/transport/binder/client/binder_connector.h', + 'src/core/ext/transport/binder/client/channel_create_impl.h', + 'src/core/ext/transport/binder/client/connection_id_generator.h', + 'src/core/ext/transport/binder/client/endpoint_binder_pool.h', + 'src/core/ext/transport/binder/client/jni_utils.h', + 'src/core/ext/transport/binder/client/security_policy_setting.h', + 'src/core/ext/transport/binder/server/binder_server.h', + 'src/core/ext/transport/binder/transport/binder_stream.h', + 'src/core/ext/transport/binder/transport/binder_transport.h', + 'src/core/ext/transport/binder/utils/binder_auto_utils.h', + 'src/core/ext/transport/binder/utils/ndk_binder.h', + 'src/core/ext/transport/binder/utils/transport_stream_receiver.h', + 'src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h', + 'src/core/ext/transport/binder/wire_format/binder.h', + 'src/core/ext/transport/binder/wire_format/binder_android.h', + 'src/core/ext/transport/binder/wire_format/binder_constants.h', + 'src/core/ext/transport/binder/wire_format/transaction.h', + 'src/core/ext/transport/binder/wire_format/wire_reader.h', + 'src/core/ext/transport/binder/wire_format/wire_reader_impl.h', + 'src/core/ext/transport/binder/wire_format/wire_writer.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', 'src/core/ext/transport/chttp2/client/chttp2_connector.h', 'src/core/ext/transport/chttp2/server/chttp2_server.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index a30b17d89f7..26ed8c8dfab 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1818,6 +1818,7 @@ Pod::Spec.new do |s| 'src/core/load_balancing/xds/xds_wrr_locality.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', 'src/core/plugin_registry/grpc_plugin_registry_extra.cc', + 'src/core/resolver/binder/binder_resolver.cc', 'src/core/resolver/dns/c_ares/dns_resolver_ares.cc', 'src/core/resolver/dns/c_ares/dns_resolver_ares.h', 'src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h', diff --git a/grpc.gemspec b/grpc.gemspec index 01ed6ca79d7..349abdf9586 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1704,6 +1704,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/load_balancing/xds/xds_wrr_locality.cc ) s.files += %w( src/core/plugin_registry/grpc_plugin_registry.cc ) s.files += %w( src/core/plugin_registry/grpc_plugin_registry_extra.cc ) + s.files += %w( src/core/resolver/binder/binder_resolver.cc ) s.files += %w( src/core/resolver/dns/c_ares/dns_resolver_ares.cc ) s.files += %w( src/core/resolver/dns/c_ares/dns_resolver_ares.h ) s.files += %w( src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h ) diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 8f0d1fa933c..5fb7426af2b 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -172,6 +172,7 @@ #if __ANDROID_API__ < 21 #error "Requires Android API v21 and above" #endif +#define GPR_SUPPORT_BINDER_TRANSPORT 1 // TODO(apolcyn): re-evaluate support for c-ares // on android after upgrading our c-ares dependency. // See https://github.com/grpc/grpc/issues/18038. diff --git a/include/grpcpp/security/binder_security_policy.h b/include/grpcpp/security/binder_security_policy.h new file mode 100644 index 00000000000..e1c951fc660 --- /dev/null +++ b/include/grpcpp/security/binder_security_policy.h @@ -0,0 +1,82 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H +#define GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H + +#include + +#ifdef GPR_ANDROID + +#include + +#endif + +namespace grpc { +namespace experimental { +namespace binder { + +// EXPERIMENTAL Determinines if a connection is allowed to be +// established on Android. See https://source.android.com/security/app-sandbox +// for more info about UID. +class SecurityPolicy { + public: + virtual ~SecurityPolicy() = default; + // Returns true if the UID is authorized to connect. + // Must return the same value for the same inputs so callers can safely cache + // the result. + virtual bool IsAuthorized(int uid) = 0; +}; + +// EXPERIMENTAL Allows all connection. Anything on the Android device will be +// able to connect, use with caution! +class UntrustedSecurityPolicy : public SecurityPolicy { + public: + UntrustedSecurityPolicy(); + ~UntrustedSecurityPolicy() override; + bool IsAuthorized(int uid) override; +}; + +// EXPERIMENTAL Only allows the connections from processes with the same UID. In +// most cases this means "from the same APK". +class InternalOnlySecurityPolicy : public SecurityPolicy { + public: + InternalOnlySecurityPolicy(); + ~InternalOnlySecurityPolicy() override; + bool IsAuthorized(int uid) override; +}; + +#ifdef GPR_ANDROID + +// EXPERIMENTAL Only allows the connections from the APK that have the same +// signature. +class SameSignatureSecurityPolicy : public SecurityPolicy { + public: + // `context` is required for getting PackageManager Java class + SameSignatureSecurityPolicy(JavaVM* jvm, jobject context); + ~SameSignatureSecurityPolicy() override; + bool IsAuthorized(int uid) override; + + private: + JavaVM* jvm_; + jobject context_; +}; + +#endif + +} // namespace binder +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_SECURITY_BINDER_SECURITY_POLICY_H diff --git a/package.xml b/package.xml index bf2736bb0bc..3add46c2e40 100644 --- a/package.xml +++ b/package.xml @@ -1686,6 +1686,7 @@ + diff --git a/src/core/BUILD b/src/core/BUILD index 5df2ee07cd9..5f6adbeb898 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -33,7 +33,10 @@ package( # the top-level BUILD file that have not yet been moved here. Should go away # once the transition is complete. exports_files( - glob(["**"]), + glob( + ["**"], + exclude = ["ext/transport/binder/java/**"], + ), visibility = ["//:__subpackages__"], ) @@ -7155,6 +7158,33 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "grpc_resolver_binder", + srcs = [ + "resolver/binder/binder_resolver.cc", + ], + external_deps = [ + "absl/log:log", + "absl/status", + "absl/status:statusor", + "absl/strings", + ], + language = "c++", + deps = [ + "channel_args", + "error", + "iomgr_port", + "resolved_address", + "status_helper", + "//:config", + "//:endpoint_addresses", + "//:gpr", + "//:grpc_resolver", + "//:orphanable", + "//:uri", + ], +) + grpc_cc_library( name = "grpc_resolver_xds_attributes", hdrs = [ diff --git a/src/core/ext/transport/binder/README.md b/src/core/ext/transport/binder/README.md new file mode 100644 index 00000000000..74200cd371d --- /dev/null +++ b/src/core/ext/transport/binder/README.md @@ -0,0 +1,10 @@ +# Binder transport for cross process IPC on Android + +EXPERIMENTAL. API stability not guaranteed. + +This transport implements +[BinderChannel for native cross-process communication on Android](https://github.com/grpc/proposal/blob/master/L73-java-binderchannel.md) and enables C++/Java cross-process communication on Android with gRPC. + +Tests: https://github.com/grpc/grpc/tree/master/test/core/transport/binder/ + +Example apps: https://github.com/grpc/grpc/tree/master/examples/android/binder/java/io/grpc/binder/cpp diff --git a/src/core/ext/transport/binder/client/channel_create_impl.h b/src/core/ext/transport/binder/client/channel_create_impl.h new file mode 100644 index 00000000000..0cc87a5a62e --- /dev/null +++ b/src/core/ext/transport/binder/client/channel_create_impl.h @@ -0,0 +1,42 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_CLIENT_CHANNEL_CREATE_IMPL_H +#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_CLIENT_CHANNEL_CREATE_IMPL_H + +#include +#include + +#include "src/core/ext/transport/binder/wire_format/binder.h" +#include "src/core/lib/channel/channel_args.h" + +namespace grpc { +namespace internal { + +// Creates a GRPC_CLIENT_DIRECT_CHANNEL channel from endpoint binder +// At this moment this is only used for testing. +grpc_channel* CreateDirectBinderChannelImplForTesting( + std::unique_ptr endpoint_binder, + const grpc_channel_args* args, + std::shared_ptr + security_policy); + +// Creates a GRPC_CLIENT_CHANNEL channel +grpc_channel* CreateClientBinderChannelImpl(std::string target, + const grpc_channel_args* args); + +} // namespace internal +} // namespace grpc + +#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_CLIENT_CHANNEL_CREATE_IMPL_H diff --git a/src/core/ext/transport/binder/client/connection_id_generator.cc b/src/core/ext/transport/binder/client/connection_id_generator.cc new file mode 100644 index 00000000000..60cba34e31b --- /dev/null +++ b/src/core/ext/transport/binder/client/connection_id_generator.cc @@ -0,0 +1,69 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/core/ext/transport/binder/client/connection_id_generator.h" + +#include + +#ifndef GRPC_NO_BINDER + +#include "absl/log/check.h" +#include "absl/strings/str_cat.h" + +namespace { +// Make sure `s` does not contain characters other than numbers, alphabets, +// period and underscore +std::string Normalize(absl::string_view str_view) { + std::string s = std::string(str_view); + for (size_t i = 0; i < s.length(); i++) { + if (!isalnum(s[i]) && s[i] != '.') { + s[i] = '_'; + } + } + return s; +} + +// Remove prefix of the string if the string is longer than len +std::string StripToLength(const std::string& s, size_t len) { + if (s.length() > len) { + return s.substr(s.length() - len, len); + } + return s; +} +} // namespace + +namespace grpc_binder { + +std::string ConnectionIdGenerator::Generate(absl::string_view uri) { + // reserve some room for serial number + const size_t kReserveForNumbers = 15; + std::string s = + StripToLength(Normalize(uri), kPathLengthLimit - kReserveForNumbers); + std::string ret; + { + grpc_core::MutexLock l(&m_); + // Insert a hyphen before serial number + ret = absl::StrCat(s, "-", ++count_); + } + CHECK_LT(ret.length(), kPathLengthLimit); + return ret; +} + +ConnectionIdGenerator* GetConnectionIdGenerator() { + static ConnectionIdGenerator* cig = new ConnectionIdGenerator(); + return cig; +} + +} // namespace grpc_binder +#endif diff --git a/src/core/ext/transport/binder/java/WORKSPACE b/src/core/ext/transport/binder/java/WORKSPACE new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/BUILD b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/BUILD new file mode 100644 index 00000000000..5e63c32bc51 --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/BUILD @@ -0,0 +1,30 @@ +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# copybara: Import internal android_library rule here + +licenses(["notice"]) + +android_library( + name = "connection_helper", + srcs = [ + "GrpcBinderConnection.java", + "GrpcCppServerBuilder.java", + "NativeConnectionHelper.java", + ], + visibility = ["//visibility:public"], + deps = [ + # copybara: Add proguard dependency here + ], +) diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java new file mode 100644 index 00000000000..b55fe7405e7 --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcBinderConnection.java @@ -0,0 +1,104 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import static android.content.Intent.URI_ANDROID_APP_SCHEME; +import static android.content.Intent.URI_INTENT_SCHEME; + +import android.annotation.TargetApi; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.IBinder; +import android.util.Log; +import java.net.URISyntaxException; + +/* Handles the binder connection state with OnDeviceServer server */ +public class GrpcBinderConnection implements ServiceConnection { + private static final String logTag = "GrpcBinderConnection"; + + private Context mContext; + private IBinder mService; + + // A string that identifies this service connection + private final String mConnId; + + public GrpcBinderConnection(Context context, String connId) { + mContext = context; + mConnId = connId; + } + + @Override + public void onNullBinding(ComponentName className) { + // TODO(mingcl): Notify C++ that the connection is never going to happen + Log.e(logTag, "Service returned null IBinder. mConnId = " + mConnId); + } + + @Override + public void onServiceConnected(ComponentName className, IBinder service) { + Log.e(logTag, "Service has connected. mConnId = " + mConnId); + if (service == null) { + // This should not happen since onNullBinding should be invoked instead + throw new IllegalArgumentException("service was null"); + } + synchronized (this) { + mService = service; + } + notifyConnected(mConnId, mService); + } + + @Override + public void onServiceDisconnected(ComponentName className) { + Log.e(logTag, "Service has disconnected. mConnId = " + mConnId); + } + + public void tryConnect(String pkg, String cls, String action_name) { + Intent intent = new Intent(action_name); + ComponentName compName = new ComponentName(pkg, cls); + intent.setComponent(compName); + tryConnect(intent); + } + + @TargetApi(22) + public void tryConnect(String uri) { + // Try connect with an URI that can be parsed as intent. + try { + tryConnect(Intent.parseUri(uri, URI_ANDROID_APP_SCHEME | URI_INTENT_SCHEME)); + } catch (URISyntaxException e) { + Log.e(logTag, "Unable to parse the Uri: " + uri); + } + } + + private void tryConnect(Intent intent) { + synchronized (this) { + // Will return true if the system is in the process of bringing up a service that your client + // has permission to bind to; false if the system couldn't find the service or if your client + // doesn't have permission to bind to it + boolean result = mContext.bindService(intent, this, Context.BIND_AUTO_CREATE); + if (result) { + Log.e(logTag, "bindService returns ok"); + } else { + Log.e( + logTag, + "bindService failed. Maybe the system couldn't find the service or the" + + " client doesn't have permission to bind to it."); + } + } + } + + // Calls a function defined in endpoint_binder_pool.cc + private static native void notifyConnected(String connId, IBinder service); +} diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java new file mode 100644 index 00000000000..680a38e5fee --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/GrpcCppServerBuilder.java @@ -0,0 +1,40 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import android.os.IBinder; +import android.util.Log; + +/* EXPERIMENTAL. Provides a interface to get endpoint binder from C++ */ +public class GrpcCppServerBuilder { + private static final String logTag = "GrpcCppServerBuilder"; + + public static IBinder GetEndpointBinder(String uri) { + String scheme = "binder:"; + if (uri.startsWith(scheme)) { + String path = uri.substring(scheme.length()); + // TODO(mingcl): Consider if we would like to make sure the path only contain valid + // characters here + IBinder ibinder = GetEndpointBinderInternal(path); + Log.e(logTag, "Returning binder=" + ibinder + " for URI=" + uri); + return ibinder; + } else { + Log.e(logTag, "URI " + uri + " does not start with 'binder:'"); + return null; + } + } + + private static native IBinder GetEndpointBinderInternal(String conn_id); +} diff --git a/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java new file mode 100644 index 00000000000..6a05c88ff37 --- /dev/null +++ b/src/core/ext/transport/binder/java/io/grpc/binder/cpp/NativeConnectionHelper.java @@ -0,0 +1,71 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package io.grpc.binder.cpp; + +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Parcel; +import android.util.Log; +// copybara: Import proguard UsedByNative annotation here +import java.util.HashMap; +import java.util.Map; + +/** + * This class will be invoked by gRPC binder transport internal implementation (from + * src/core/ext/transport/binder/client/jni_utils.cc) to perform operations that are only possible + * in Java + */ +// copybara: Add @UsedByNative("jni_utils.cc") +final class NativeConnectionHelper { + // Maps connection id to GrpcBinderConnection instances + static Map connectionIdToGrpcBinderConnectionMap = new HashMap<>(); + + // copybara: Add @UsedByNative("jni_utils.cc") + static void tryEstablishConnection( + Context context, String pkg, String cls, String actionName, String connId) { + // TODO(mingcl): Assert that connId is unique + connectionIdToGrpcBinderConnectionMap.put(connId, new GrpcBinderConnection(context, connId)); + connectionIdToGrpcBinderConnectionMap.get(connId).tryConnect(pkg, cls, actionName); + } + + // copybara: Add @UsedByNative("jni_utils.cc") + static void tryEstablishConnectionWithUri(Context context, String uri, String connId) { + // TODO(mingcl): Assert that connId is unique + connectionIdToGrpcBinderConnectionMap.put(connId, new GrpcBinderConnection(context, connId)); + connectionIdToGrpcBinderConnectionMap.get(connId).tryConnect(uri); + } + + // Returns true if the packages signature of the 2 UIDs match. + // `context` is used to get PackageManager. + // Suppress unnecessary internal warnings related to checkSignatures compatibility issue. + // BinderTransport code is only used on newer Android platform versions so this is fine. + @SuppressWarnings("CheckSignatures") + // copybara: Add @UsedByNative("jni_utils.cc") + static boolean isSignatureMatch(Context context, int uid1, int uid2) { + int result = context.getPackageManager().checkSignatures(uid1, uid2); + if (result == PackageManager.SIGNATURE_MATCH) { + return true; + } + Log.e( + "NativeConnectionHelper", + "Signatures does not match. checkSignature return value = " + result); + return false; + } + + // copybara: Add @UsedByNative("jni_utils.cc") + static Parcel getEmptyParcel() { + return Parcel.obtain(); + } +} diff --git a/src/core/ext/transport/binder/security_policy/security_policy.h b/src/core/ext/transport/binder/security_policy/security_policy.h new file mode 100644 index 00000000000..4ef3da352f2 --- /dev/null +++ b/src/core/ext/transport/binder/security_policy/security_policy.h @@ -0,0 +1,40 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_SECURITY_POLICY_SECURITY_POLICY_H +#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_SECURITY_POLICY_SECURITY_POLICY_H + +#include + +namespace grpc { +namespace experimental { +namespace binder { + +// This interface is for determining if a connection is allowed to be +// established on Android. See https://source.android.com/security/app-sandbox +// for more info about UID. +class SecurityPolicy { + public: + virtual ~SecurityPolicy() = default; + // Returns true if the UID is authorized to connect. + // Must return the same value for the same inputs so callers can safely cache + // the result. + virtual bool IsAuthorized(int uid) = 0; +}; + +} // namespace binder +} // namespace experimental +} // namespace grpc + +#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_SECURITY_POLICY_SECURITY_POLICY_H diff --git a/src/core/ext/transport/binder/transport/binder_stream.h b/src/core/ext/transport/binder/transport/binder_stream.h new file mode 100644 index 00000000000..afd0c414514 --- /dev/null +++ b/src/core/ext/transport/binder/transport/binder_stream.h @@ -0,0 +1,117 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_TRANSPORT_BINDER_STREAM_H +#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_TRANSPORT_BINDER_STREAM_H + +#include + +#include "src/core/ext/transport/binder/transport/binder_transport.h" + +struct RecvInitialMetadataArgs { + grpc_binder_stream* stream; + grpc_binder_transport* transport; + int tx_code; + absl::StatusOr initial_metadata; +}; + +struct RecvMessageArgs { + grpc_binder_stream* stream; + grpc_binder_transport* transport; + int tx_code; + absl::StatusOr message; +}; + +struct RecvTrailingMetadataArgs { + grpc_binder_stream* stream; + grpc_binder_transport* transport; + int tx_code; + absl::StatusOr trailing_metadata; + int status; +}; + +struct RegisterStreamArgs { + grpc_binder_stream* stream; + grpc_binder_transport* transport; +}; + +// TODO(mingcl): Figure out if we want to use class instead of struct here +struct grpc_binder_stream { + // server_data will be null for client, and for server it will be whatever + // passed in to the accept_stream_fn callback by client. + grpc_binder_stream(grpc_binder_transport* t, grpc_stream_refcount* refcount, + const void* /*server_data*/, grpc_core::Arena* arena, + int tx_code, bool is_client) + : t(t), + refcount(refcount), + arena(arena), + tx_code(tx_code), + is_client(is_client), + is_closed(false) { + recv_initial_metadata_args.stream = this; + recv_initial_metadata_args.transport = t; + recv_message_args.stream = this; + recv_message_args.transport = t; + recv_trailing_metadata_args.stream = this; + recv_trailing_metadata_args.transport = t; + } + + ~grpc_binder_stream() { + if (destroy_stream_then_closure != nullptr) { + grpc_core::ExecCtx::Run(DEBUG_LOCATION, destroy_stream_then_closure, + absl::OkStatus()); + } + } + + int GetTxCode() const { return tx_code; } + + grpc_binder_transport* t; + grpc_stream_refcount* refcount; + grpc_core::Arena* arena; + int tx_code; + const bool is_client; + bool is_closed; + + grpc_closure* destroy_stream_then_closure = nullptr; + grpc_closure destroy_stream; + + // The reason why this stream is cancelled and closed. + grpc_error_handle cancel_self_error; + + grpc_closure recv_initial_metadata_closure; + RecvInitialMetadataArgs recv_initial_metadata_args; + grpc_closure recv_message_closure; + RecvMessageArgs recv_message_args; + grpc_closure recv_trailing_metadata_closure; + RecvTrailingMetadataArgs recv_trailing_metadata_args; + + grpc_closure register_stream_closure; + RegisterStreamArgs register_stream_args; + + // We store these fields passed from op batch, in order to access them through + // grpc_binder_stream + grpc_metadata_batch* recv_initial_metadata; + grpc_closure* recv_initial_metadata_ready = nullptr; + bool* trailing_metadata_available = nullptr; + absl::optional* recv_message; + grpc_closure* recv_message_ready = nullptr; + bool* call_failed_before_recv_message = nullptr; + grpc_metadata_batch* recv_trailing_metadata; + grpc_closure* recv_trailing_metadata_finished = nullptr; + + bool trailing_metadata_sent = false; + bool need_to_call_trailing_metadata_callback = false; +}; + +#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_TRANSPORT_BINDER_STREAM_H diff --git a/src/core/ext/transport/binder/utils/binder_auto_utils.h b/src/core/ext/transport/binder/utils/binder_auto_utils.h new file mode 100644 index 00000000000..c72f7760761 --- /dev/null +++ b/src/core/ext/transport/binder/utils/binder_auto_utils.h @@ -0,0 +1,76 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H +#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H + +#include + +#ifdef GPR_SUPPORT_BINDER_TRANSPORT + +#include "src/core/ext/transport/binder/utils/ndk_binder.h" + +namespace grpc_binder { +namespace ndk_util { + +/// +/// Represents one strong pointer to an AIBinder object. +/// Copied from binder/ndk/include_cpp/android/binder_auto_utils.h +/// +class SpAIBinder { + public: + SpAIBinder() : mBinder(nullptr) {} + explicit SpAIBinder(AIBinder* binder) : mBinder(binder) {} + SpAIBinder(std::nullptr_t) + : SpAIBinder() {} // NOLINT(google-explicit-constructor) + SpAIBinder(const SpAIBinder& other) { *this = other; } + + ~SpAIBinder() { set(nullptr); } + SpAIBinder& operator=(const SpAIBinder& other) { + if (this == &other) { + return *this; + } + AIBinder_incStrong(other.mBinder); + set(other.mBinder); + return *this; + } + + void set(AIBinder* binder) { + AIBinder* old = *const_cast(&mBinder); + if (old != nullptr) AIBinder_decStrong(old); + if (old != *const_cast(&mBinder)) { + __assert(__FILE__, __LINE__, "Race detected."); + } + mBinder = binder; + } + + AIBinder* get() const { return mBinder; } + AIBinder** getR() { return &mBinder; } + + bool operator!=(const SpAIBinder& rhs) const { return get() != rhs.get(); } + bool operator<(const SpAIBinder& rhs) const { return get() < rhs.get(); } + bool operator<=(const SpAIBinder& rhs) const { return get() <= rhs.get(); } + bool operator==(const SpAIBinder& rhs) const { return get() == rhs.get(); } + bool operator>(const SpAIBinder& rhs) const { return get() > rhs.get(); } + bool operator>=(const SpAIBinder& rhs) const { return get() >= rhs.get(); } + + private: + AIBinder* mBinder = nullptr; +}; +} // namespace ndk_util +} // namespace grpc_binder + +#endif + +#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_BINDER_AUTO_UTILS_H diff --git a/src/core/ext/transport/binder/utils/ndk_binder.h b/src/core/ext/transport/binder/utils/ndk_binder.h new file mode 100644 index 00000000000..1ca82c81625 --- /dev/null +++ b/src/core/ext/transport/binder/utils/ndk_binder.h @@ -0,0 +1,107 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_NDK_BINDER_H +#define GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_NDK_BINDER_H + +#include + +#ifdef GPR_SUPPORT_BINDER_TRANSPORT + +#include +#include + +#include + +// This file defines NdkBinder functions, variables, and types in +// grpc_binder::ndk_util namespace. This allows us to dynamically load +// libbinder_ndk at runtime, and make it possible to compile the code without +// the library present at compile time. + +// TODO(mingcl): Consider if we want to check API level and include NDK headers +// normally if the level is high enough + +namespace grpc_binder { +namespace ndk_util { + +struct AIBinder; +struct AParcel; +struct AIBinder_Class; + +// Only enum values used by the project is defined here +enum { + FLAG_ONEWAY = 0x01, +}; +enum { + STATUS_OK = 0, + STATUS_UNKNOWN_ERROR = (-2147483647 - 1), +}; + +typedef int32_t binder_status_t; +typedef uint32_t binder_flags_t; +typedef uint32_t transaction_code_t; + +typedef bool (*AParcel_byteArrayAllocator)(void* arrayData, int32_t length, + int8_t** outBuffer); +typedef bool (*AParcel_stringAllocator)(void* stringData, int32_t length, + char** buffer); +typedef void* (*AIBinder_Class_onCreate)(void* args); +typedef void (*AIBinder_Class_onDestroy)(void* userData); +typedef binder_status_t (*AIBinder_Class_onTransact)(AIBinder* binder, + transaction_code_t code, + const AParcel* in, + AParcel* out); + +void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz); +void* AIBinder_getUserData(AIBinder* binder); +uid_t AIBinder_getCallingUid(); +AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder); +AIBinder_Class* AIBinder_Class_define(const char* interfaceDescriptor, + AIBinder_Class_onCreate onCreate, + AIBinder_Class_onDestroy onDestroy, + AIBinder_Class_onTransact onTransact); +AIBinder* AIBinder_new(const AIBinder_Class* clazz, void* args); +bool AIBinder_associateClass(AIBinder* binder, const AIBinder_Class* clazz); +void AIBinder_incStrong(AIBinder* binder); +void AIBinder_decStrong(AIBinder* binder); +binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, + AParcel** in, AParcel** out, + binder_flags_t flags); +binder_status_t AParcel_readByteArray(const AParcel* parcel, void* arrayData, + AParcel_byteArrayAllocator allocator); +void AParcel_delete(AParcel* parcel); +int32_t AParcel_getDataSize(const AParcel* parcel); +binder_status_t AParcel_writeInt32(AParcel* parcel, int32_t value); +binder_status_t AParcel_writeInt64(AParcel* parcel, int64_t value); +binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder); +binder_status_t AParcel_writeString(AParcel* parcel, const char* string, + int32_t length); +binder_status_t AParcel_readInt32(const AParcel* parcel, int32_t* value); +binder_status_t AParcel_readInt64(const AParcel* parcel, int64_t* value); +binder_status_t AParcel_readString(const AParcel* parcel, void* stringData, + AParcel_stringAllocator allocator); +binder_status_t AParcel_readStrongBinder(const AParcel* parcel, + AIBinder** binder); +binder_status_t AParcel_writeByteArray(AParcel* parcel, const int8_t* arrayData, + int32_t length); +binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in); +jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder); + +} // namespace ndk_util + +} // namespace grpc_binder + +#endif // GPR_SUPPORT_BINDER_TRANSPORT + +#endif // GRPC_SRC_CORE_EXT_TRANSPORT_BINDER_UTILS_NDK_BINDER_H diff --git a/src/core/ext/transport/binder/wire_format/binder_constants.cc b/src/core/ext/transport/binder/wire_format/binder_constants.cc new file mode 100644 index 00000000000..e9b2439fc64 --- /dev/null +++ b/src/core/ext/transport/binder/wire_format/binder_constants.cc @@ -0,0 +1,29 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#ifndef GRPC_NO_BINDER + +#include "src/core/ext/transport/binder/wire_format/binder_constants.h" + +ABSL_CONST_INIT const int FIRST_CALL_TRANSACTION = 0x00000001; +ABSL_CONST_INIT const int LAST_CALL_TRANSACTION = 0x00FFFFFF; + +namespace grpc_binder { + +ABSL_CONST_INIT const int kFirstCallId = FIRST_CALL_TRANSACTION + 1000; + +} // namespace grpc_binder +#endif diff --git a/src/core/ext/transport/binder/wire_format/transaction.cc b/src/core/ext/transport/binder/wire_format/transaction.cc new file mode 100644 index 00000000000..9c3bb0225b6 --- /dev/null +++ b/src/core/ext/transport/binder/wire_format/transaction.cc @@ -0,0 +1,33 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#ifndef GRPC_NO_BINDER + +#include "src/core/ext/transport/binder/wire_format/transaction.h" + +namespace grpc_binder { + +ABSL_CONST_INIT const int kFlagPrefix = 0x1; +ABSL_CONST_INIT const int kFlagMessageData = 0x2; +ABSL_CONST_INIT const int kFlagSuffix = 0x4; +ABSL_CONST_INIT const int kFlagOutOfBandClose = 0x8; +ABSL_CONST_INIT const int kFlagExpectSingleMessage = 0x10; +ABSL_CONST_INIT const int kFlagStatusDescription = 0x20; +ABSL_CONST_INIT const int kFlagMessageDataIsParcelable = 0x40; +ABSL_CONST_INIT const int kFlagMessageDataIsPartial = 0x80; + +} // namespace grpc_binder +#endif diff --git a/src/core/plugin_registry/grpc_plugin_registry.cc b/src/core/plugin_registry/grpc_plugin_registry.cc index 4022d1f5735..0db484ac828 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.cc +++ b/src/core/plugin_registry/grpc_plugin_registry.cc @@ -72,6 +72,9 @@ extern void RegisterLoadBalancedCallDestination( #ifndef GRPC_NO_RLS extern void RegisterRlsLbPolicy(CoreConfiguration::Builder* builder); #endif // !GRPC_NO_RLS +#ifdef GPR_SUPPORT_BINDER_TRANSPORT +extern void RegisterBinderResolver(CoreConfiguration::Builder* builder); +#endif namespace { @@ -119,6 +122,9 @@ void BuildCoreConfiguration(CoreConfiguration::Builder* builder) { RegisterFakeResolver(builder); RegisterHttpProxyMapper(builder); RegisterLoadBalancedCallDestination(builder); +#ifdef GPR_SUPPORT_BINDER_TRANSPORT + RegisterBinderResolver(builder); +#endif #ifndef GRPC_NO_RLS RegisterRlsLbPolicy(builder); #endif // !GRPC_NO_RLS diff --git a/src/core/resolver/binder/README.md b/src/core/resolver/binder/README.md new file mode 100644 index 00000000000..b60296765d5 --- /dev/null +++ b/src/core/resolver/binder/README.md @@ -0,0 +1,9 @@ +Support for resolving the scheme used by binder transport implementation. + +The URI's authority is required to be empty. + +The path is used as the identifiers of endpoint binder objects and the length +limit of the identifier is the same as unix socket length limit. + +The length limit of the path should at least be 100 characters long. This is +guaranteed by `static_assert` in the implementation. diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index d8ca54d31be..e1bbd06531f 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -704,6 +704,7 @@ CORE_SOURCE_FILES = [ 'src/core/load_balancing/xds/xds_wrr_locality.cc', 'src/core/plugin_registry/grpc_plugin_registry.cc', 'src/core/plugin_registry/grpc_plugin_registry_extra.cc', + 'src/core/resolver/binder/binder_resolver.cc', 'src/core/resolver/dns/c_ares/dns_resolver_ares.cc', 'src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', diff --git a/test/core/resolver/BUILD b/test/core/resolver/BUILD index bf3e38a6f12..effbbac9dad 100644 --- a/test/core/resolver/BUILD +++ b/test/core/resolver/BUILD @@ -36,6 +36,22 @@ grpc_cc_test( ], ) +grpc_cc_test( + name = "binder_resolver_test", + srcs = ["binder_resolver_test.cc"], + external_deps = [ + "absl/log:log", + "gtest", + ], + language = "C++", + deps = [ + "//:gpr", + "//:grpc", + "//src/core:grpc_resolver_binder", + "//test/core/test_util:grpc_test_util", + ], +) + grpc_cc_test( name = "dns_resolver_test", srcs = ["dns_resolver_test.cc"], diff --git a/test/core/transport/binder/BUILD b/test/core/transport/binder/BUILD new file mode 100644 index 00000000000..1f7d3ebb9a0 --- /dev/null +++ b/test/core/transport/binder/BUILD @@ -0,0 +1,133 @@ +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) + +grpc_package( + name = "test/core/transport/binder", + visibility = "tests", +) + +grpc_cc_library( + name = "mock_objects", + testonly = 1, + srcs = ["mock_objects.cc"], + hdrs = ["mock_objects.h"], + external_deps = [ + "absl/memory", + "gtest", + ], + language = "C++", + deps = [ + "//:grpc++_binder", + ], +) + +grpc_cc_test( + name = "wire_writer_test", + srcs = ["wire_writer_test.cc"], + external_deps = [ + "absl/memory", + "gtest", + ], + language = "C++", + tags = ["no_test_ios"], + uses_event_engine = False, + uses_polling = False, + deps = [ + ":mock_objects", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_cc_test( + name = "wire_reader_test", + srcs = ["wire_reader_test.cc"], + external_deps = [ + "absl/memory", + "gtest", + ], + language = "C++", + tags = ["no_test_ios"], + uses_event_engine = False, + uses_polling = False, + deps = [ + ":mock_objects", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_cc_test( + name = "transport_stream_receiver_test", + srcs = ["transport_stream_receiver_test.cc"], + external_deps = [ + "absl/memory", + "gtest", + ], + language = "C++", + tags = ["no_test_ios"], + uses_event_engine = False, + uses_polling = False, + deps = [ + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_cc_test( + name = "binder_transport_test", + srcs = ["binder_transport_test.cc"], + external_deps = [ + "absl/memory", + "absl/strings", + "gtest", + ], + language = "C++", + tags = [ + # To avoid `symbolizer buffer too small` warning of UBSAN + "noubsan", + "no_test_ios", + ], + uses_event_engine = False, + uses_polling = False, + deps = [ + ":mock_objects", + "//:grpc", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_cc_test( + name = "endpoint_binder_pool_test", + srcs = ["endpoint_binder_pool_test.cc"], + external_deps = [ + "absl/memory", + "gtest", + ], + language = "C++", + tags = ["no_test_ios"], + uses_event_engine = False, + uses_polling = False, + deps = [ + ":mock_objects", + "//:grpc", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + ], +) diff --git a/test/core/transport/binder/end2end/BUILD b/test/core/transport/binder/end2end/BUILD new file mode 100644 index 00000000000..4e9ee2fe2d2 --- /dev/null +++ b/test/core/transport/binder/end2end/BUILD @@ -0,0 +1,119 @@ +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") + +licenses(["notice"]) + +grpc_package( + name = "test/core/transport/binder/end2end", + visibility = "tests", +) + +grpc_cc_library( + name = "fake_binder", + testonly = 1, + srcs = ["fake_binder.cc"], + hdrs = ["fake_binder.h"], + external_deps = [ + "absl/log:log", + "absl/memory", + "absl/random", + "absl/strings", + "absl/strings:str_format", + "absl/time", + "absl/types:variant", + ], + deps = [ + "//:gpr", + "//:grpc++_binder", + ], +) + +grpc_cc_test( + name = "fake_binder_test", + srcs = ["fake_binder_test.cc"], + external_deps = [ + "absl/strings", + "absl/time", + "gtest", + ], + language = "C++", + tags = ["no_test_ios"], + uses_event_engine = False, + uses_polling = False, + deps = [ + ":fake_binder", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_cc_library( + name = "end2end_binder_channel", + testonly = 1, + srcs = ["testing_channel_create.cc"], + hdrs = ["testing_channel_create.h"], + external_deps = ["absl/log:check"], + deps = [ + ":fake_binder", + "//:grpc++_base", + "//:grpc++_binder", + "//:grpc_base", + "//src/core:channel_args", + ], +) + +grpc_cc_test( + name = "end2end_binder_transport_test", + srcs = ["end2end_binder_transport_test.cc"], + external_deps = [ + "absl/memory", + "absl/time", + "gtest", + ], + flaky = True, + language = "C++", + tags = [ + # Flaky on windows + "no_windows", + "no_mac", + "no_test_ios", + + # Known race between stream creation and cancellation + "notsan", + ], + deps = [ + ":end2end_binder_channel", + ":fake_binder", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + "//test/cpp/end2end:test_service_impl", + ], +) + +grpc_cc_test( + name = "binder_server_test", + srcs = ["binder_server_test.cc"], + external_deps = [ + "gtest", + ], + tags = ["no_test_ios"], + deps = [ + "//:grpc++", + "//:grpc++_binder", + "//test/core/test_util:grpc_test_util", + "//test/core/transport/binder/end2end:fake_binder", + "//test/cpp/end2end:test_service_impl", + ], +) diff --git a/test/core/transport/binder/end2end/fuzzers/BUILD b/test/core/transport/binder/end2end/fuzzers/BUILD new file mode 100644 index 00000000000..a0184afd3cb --- /dev/null +++ b/test/core/transport/binder/end2end/fuzzers/BUILD @@ -0,0 +1,101 @@ +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_package", "grpc_proto_library") +load("//test/core/test_util:grpc_fuzzer.bzl", "grpc_proto_fuzzer") + +grpc_package( + name = "test/core/transport/binder/end2end/fuzzers", + features = [ + "layering_check", + ], +) + +licenses(["notice"]) + +# Protobuf messages for generating inputs. We manually define proto +# library rule here so the same proto file can be shared between multiple +# grpc_proto_fuzzer targets +grpc_proto_library( + name = "binder_transport_fuzzer_proto", + srcs = ["binder_transport_fuzzer.proto"], +) + +grpc_cc_library( + name = "fuzzer_utils", + srcs = ["fuzzer_utils.cc"], + external_deps = [ + "absl/log:check", + "absl/log:log", + ], + language = "c++", + public_hdrs = ["fuzzer_utils.h"], + deps = [ + "binder_transport_fuzzer_proto", + "//:gpr", + "//:grpc++", + "//:grpc++_base", + "//:grpc_base", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_proto_fuzzer( + name = "binder_transport_client_fuzzer", + srcs = [ + "client_fuzzer.cc", + ], + corpus = "binder_transport_client_fuzzer_corpus", + external_deps = ["absl/log:check"], + owner = "binder", + proto = "client.proto", + tags = [ + "no_mac", + "no_windows", + ], + deps = [ + "binder_transport_fuzzer_proto", + ":fuzzer_utils", + "//:gpr", + "//:grpc++", + "//:grpc++_base", + "//:grpc_base", + "//test/core/test_util:grpc_test_util", + ], +) + +grpc_proto_fuzzer( + name = "binder_transport_server_fuzzer", + srcs = [ + "server_fuzzer.cc", + ], + corpus = "binder_transport_server_fuzzer_corpus", + external_deps = ["absl/log:check"], + owner = "binder", + proto = "server.proto", + tags = [ + "no_mac", + "no_windows", + ], + deps = [ + "binder_transport_fuzzer_proto", + ":fuzzer_utils", + "//:gpr", + "//:grpc++", + "//:grpc++_base", + "//:grpc_base", + "//src/core:slice", + "//test/core/test_util:grpc_test_util", + ], +) diff --git a/test/core/transport/binder/end2end/fuzzers/binder_transport_client_fuzzer_corpus/empty b/test/core/transport/binder/end2end/fuzzers/binder_transport_client_fuzzer_corpus/empty new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/core/transport/binder/end2end/fuzzers/binder_transport_fuzzer.proto b/test/core/transport/binder/end2end/fuzzers/binder_transport_fuzzer.proto new file mode 100644 index 00000000000..8fb2aa3edd1 --- /dev/null +++ b/test/core/transport/binder/end2end/fuzzers/binder_transport_fuzzer.proto @@ -0,0 +1,81 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package binder_transport_fuzzer; + +message Binder {} + +message Value { + oneof data_type { + int32 i32 = 1; + int64 i64 = 2; + bytes byte_array = 3; + // Strings in Parcel could also contain non UTF-8 data so we use bytes + // to represent string here + bytes str = 4; + Binder binder = 5; + } +} + +message Parcel { + repeated Value values = 1; + + // Simulates the return value of AParcel_getDataSize + // (The value generated by protobuf libprotobuf-mutator might not always make sense + // but the transport implementation should handle that) + int32 data_size = 2; +} + +enum TransactionCode { + INVALID = 0; + SETUP_TRANSPORT = 1; + SHUTDOWN_TRANSPORT = 2; + ACKNOWLEDGE_BYTES = 3; + PING = 4; + PING_RESPONSE = 5; +} + +message Transaction { + TransactionCode code = 1; + int32 uid = 2; + Parcel parcel = 3; +} + +// Special parcel that used for setting up transport. +// TODO(mingcl): Consider also fuzzing the setup transport code path +message SetupTransportParcel { + int32 version = 1; + + // Simulates the return value of AParcel_getDataSize + // (The value generated by protobuf libprotobuf-mutator might not always make sense + // but the transport implementation should handle that) + int32 data_size = 2; +} + +message SetupTransportTransaction { + int32 uid = 1; + SetupTransportParcel parcel = 2; +} + +message IncomingParcels { + SetupTransportTransaction setup_transport_transaction = 1; + repeated Transaction transactions = 2; +} + +message Input { + IncomingParcels incoming_parcels = 1; +} + diff --git a/test/core/transport/binder/end2end/fuzzers/binder_transport_server_fuzzer_corpus/empty b/test/core/transport/binder/end2end/fuzzers/binder_transport_server_fuzzer_corpus/empty new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/core/transport/binder/end2end/fuzzers/client.proto b/test/core/transport/binder/end2end/fuzzers/client.proto new file mode 100644 index 00000000000..4fe133a7d24 --- /dev/null +++ b/test/core/transport/binder/end2end/fuzzers/client.proto @@ -0,0 +1,17 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package binder_transport_fuzzer; diff --git a/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc b/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc new file mode 100644 index 00000000000..11609ac92f8 --- /dev/null +++ b/test/core/transport/binder/end2end/fuzzers/fuzzer_utils.cc @@ -0,0 +1,157 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "test/core/transport/binder/end2end/fuzzers/fuzzer_utils.h" + +#include "absl/log/check.h" +#include "absl/log/log.h" + +namespace grpc_binder { +namespace fuzzing { + +namespace { + +std::thread* g_fuzzing_thread = nullptr; + +template +void CreateFuzzingThread(Args&&... args) { + CHECK_EQ(g_fuzzing_thread, nullptr); + g_fuzzing_thread = new std::thread(std::forward(args)...); +} + +} // namespace + +void JoinFuzzingThread() { + if (g_fuzzing_thread) { + g_fuzzing_thread->join(); + delete g_fuzzing_thread; + g_fuzzing_thread = nullptr; + } +} + +int32_t ReadableParcelForFuzzing::GetDataSize() const { + return parcel_data_size_; +} + +absl::Status ReadableParcelForFuzzing::ReadInt32(int32_t* data) { + if (consumed_data_size_ >= kParcelDataSizeLimit) { + return absl::InternalError("Parcel size limit exceeds"); + } + if (values_.empty() || !values_.front().has_i32()) { + return absl::InternalError("error"); + } + *data = values_.front().i32(); + values_.pop(); + consumed_data_size_ += sizeof(int32_t); + return absl::OkStatus(); +} + +absl::Status ReadableParcelForFuzzing::ReadInt64(int64_t* data) { + if (consumed_data_size_ >= kParcelDataSizeLimit) { + return absl::InternalError("Parcel size limit exceeds"); + } + if (values_.empty() || !values_.front().has_i64()) { + return absl::InternalError("error"); + } + *data = values_.front().i64(); + values_.pop(); + consumed_data_size_ += sizeof(int64_t); + return absl::OkStatus(); +} + +absl::Status ReadableParcelForFuzzing::ReadBinder( + std::unique_ptr* binder) { + if (consumed_data_size_ >= kParcelDataSizeLimit) { + return absl::InternalError("Parcel size limit exceeds"); + } + if (values_.empty() || !values_.front().has_binder()) { + return absl::InternalError("error"); + } + *binder = std::make_unique(); + values_.pop(); + consumed_data_size_ += sizeof(void*); + return absl::OkStatus(); +} + +absl::Status ReadableParcelForFuzzing::ReadByteArray(std::string* data) { + if (consumed_data_size_ >= kParcelDataSizeLimit) { + return absl::InternalError("Parcel size limit exceeds"); + } + if (values_.empty() || !values_.front().has_byte_array()) { + return absl::InternalError("error"); + } + *data = values_.front().byte_array(); + values_.pop(); + consumed_data_size_ += data->size(); + return absl::OkStatus(); +} + +absl::Status ReadableParcelForFuzzing::ReadString(std::string* data) { + if (consumed_data_size_ >= kParcelDataSizeLimit) { + return absl::InternalError("Parcel size limit exceeds"); + } + if (values_.empty() || !values_.front().has_str()) { + return absl::InternalError("error"); + } + *data = values_.front().str(); + values_.pop(); + consumed_data_size_ += data->size(); + return absl::OkStatus(); +} + +void FuzzingLoop( + binder_transport_fuzzer::IncomingParcels incoming_parcels, + grpc_core::RefCountedPtr wire_reader_ref, + grpc_binder::TransactionReceiver::OnTransactCb callback) { + { + // Send SETUP_TRANSPORT request. + std::unique_ptr parcel = + std::make_unique( + incoming_parcels.setup_transport_transaction().parcel()); + callback(static_cast( + grpc_binder::BinderTransportTxCode::SETUP_TRANSPORT), + parcel.get(), + /*uid=*/incoming_parcels.setup_transport_transaction().uid()) + .IgnoreError(); + } + for (const auto& tx_iter : incoming_parcels.transactions()) { + transaction_code_t tx_code = tx_iter.code(); + std::unique_ptr parcel = + std::make_unique(tx_iter.parcel()); + callback(tx_code, parcel.get(), + /*uid=*/tx_iter.uid()) + .IgnoreError(); + } + wire_reader_ref = nullptr; +} + +TransactionReceiverForFuzzing::TransactionReceiverForFuzzing( + binder_transport_fuzzer::IncomingParcels incoming_parcels, + grpc_core::RefCountedPtr wire_reader_ref, + TransactionReceiver::OnTransactCb cb) { + LOG(INFO) << "Construct TransactionReceiverForFuzzing"; + CreateFuzzingThread(FuzzingLoop, std::move(incoming_parcels), + std::move(wire_reader_ref), std::move(cb)); +} + +std::unique_ptr BinderForFuzzing::ConstructTxReceiver( + grpc_core::RefCountedPtr wire_reader_ref, + TransactionReceiver::OnTransactCb cb) const { + auto tx_receiver = std::make_unique( + incoming_parcels_, wire_reader_ref, cb); + return tx_receiver; +} + +} // namespace fuzzing +} // namespace grpc_binder diff --git a/test/core/transport/binder/end2end/fuzzers/server.proto b/test/core/transport/binder/end2end/fuzzers/server.proto new file mode 100644 index 00000000000..4fe133a7d24 --- /dev/null +++ b/test/core/transport/binder/end2end/fuzzers/server.proto @@ -0,0 +1,17 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package binder_transport_fuzzer; diff --git a/test/core/transport/binder/mock_objects.cc b/test/core/transport/binder/mock_objects.cc new file mode 100644 index 00000000000..7e173ef15ad --- /dev/null +++ b/test/core/transport/binder/mock_objects.cc @@ -0,0 +1,55 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "test/core/transport/binder/mock_objects.h" + +#include + +#include "absl/memory/memory.h" + +namespace grpc_binder { + +using ::testing::Return; + +MockReadableParcel::MockReadableParcel() { + ON_CALL(*this, ReadBinder).WillByDefault([](std::unique_ptr* binder) { + *binder = std::make_unique(); + return absl::OkStatus(); + }); + ON_CALL(*this, ReadInt32).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, ReadByteArray).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, ReadString).WillByDefault(Return(absl::OkStatus())); +} + +MockWritableParcel::MockWritableParcel() { + ON_CALL(*this, WriteInt32).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, WriteBinder).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, WriteString).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, WriteByteArray).WillByDefault(Return(absl::OkStatus())); +} + +MockBinder::MockBinder() { + ON_CALL(*this, PrepareTransaction).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, Transact).WillByDefault(Return(absl::OkStatus())); + ON_CALL(*this, GetWritableParcel).WillByDefault(Return(&mock_input_)); + ON_CALL(*this, ConstructTxReceiver) + .WillByDefault( + [this](grpc_core::RefCountedPtr /*wire_reader_ref*/, + TransactionReceiver::OnTransactCb cb) { + return std::make_unique( + cb, BinderTransportTxCode::SETUP_TRANSPORT, &mock_output_); + }); +} + +} // namespace grpc_binder diff --git a/test/core/transport/binder/mock_objects.h b/test/core/transport/binder/mock_objects.h new file mode 100644 index 00000000000..6424a2acd22 --- /dev/null +++ b/test/core/transport/binder/mock_objects.h @@ -0,0 +1,121 @@ +// Copyright 2021 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_TEST_CORE_TRANSPORT_BINDER_MOCK_OBJECTS_H +#define GRPC_TEST_CORE_TRANSPORT_BINDER_MOCK_OBJECTS_H + +#include + +#include "src/core/ext/transport/binder/utils/transport_stream_receiver.h" +#include "src/core/ext/transport/binder/wire_format/binder.h" +#include "src/core/ext/transport/binder/wire_format/binder_constants.h" +#include "src/core/ext/transport/binder/wire_format/wire_reader.h" +#include "src/core/ext/transport/binder/wire_format/wire_writer.h" + +namespace grpc_binder { + +class MockWritableParcel : public WritableParcel { + public: + MOCK_METHOD(int32_t, GetDataSize, (), (const, override)); + MOCK_METHOD(absl::Status, WriteInt32, (int32_t), (override)); + MOCK_METHOD(absl::Status, WriteInt64, (int64_t), (override)); + MOCK_METHOD(absl::Status, WriteBinder, (HasRawBinder*), (override)); + MOCK_METHOD(absl::Status, WriteString, (absl::string_view), (override)); + MOCK_METHOD(absl::Status, WriteByteArray, (const int8_t*, int32_t), + (override)); + + MockWritableParcel(); +}; + +class MockReadableParcel : public ReadableParcel { + public: + MOCK_METHOD(int32_t, GetDataSize, (), (const, override)); + MOCK_METHOD(absl::Status, ReadInt32, (int32_t*), (override)); + MOCK_METHOD(absl::Status, ReadInt64, (int64_t*), (override)); + MOCK_METHOD(absl::Status, ReadBinder, (std::unique_ptr*), (override)); + MOCK_METHOD(absl::Status, ReadByteArray, (std::string*), (override)); + MOCK_METHOD(absl::Status, ReadString, (std::string*), (override)); + + MockReadableParcel(); +}; + +class MockBinder : public Binder { + public: + MOCK_METHOD(void, Initialize, (), (override)); + MOCK_METHOD(absl::Status, PrepareTransaction, (), (override)); + MOCK_METHOD(absl::Status, Transact, (BinderTransportTxCode), (override)); + MOCK_METHOD(WritableParcel*, GetWritableParcel, (), (const, override)); + MOCK_METHOD(std::unique_ptr, ConstructTxReceiver, + (grpc_core::RefCountedPtr, + TransactionReceiver::OnTransactCb), + (const, override)); + MOCK_METHOD(void*, GetRawBinder, (), (override)); + + MockBinder(); + MockWritableParcel& GetWriter() { return mock_input_; } + MockReadableParcel& GetReader() { return mock_output_; } + + private: + MockWritableParcel mock_input_; + MockReadableParcel mock_output_; +}; + +// TODO(waynetu): Implement transaction injection later for more thorough +// testing. +class MockTransactionReceiver : public TransactionReceiver { + public: + explicit MockTransactionReceiver(OnTransactCb transact_cb, + BinderTransportTxCode code, + MockReadableParcel* output) { + if (code == BinderTransportTxCode::SETUP_TRANSPORT) { + EXPECT_CALL(*output, ReadInt32).WillOnce([](int32_t* version) { + *version = 1; + return absl::OkStatus(); + }); + } + transact_cb(static_cast(code), output, /*uid=*/0) + .IgnoreError(); + } + + MOCK_METHOD(void*, GetRawBinder, (), (override)); +}; + +class MockWireWriter : public WireWriter { + public: + MOCK_METHOD(absl::Status, RpcCall, (std::unique_ptr), + (override)); + MOCK_METHOD(absl::Status, SendAck, (int64_t), (override)); + MOCK_METHOD(void, OnAckReceived, (int64_t), (override)); +}; + +class MockTransportStreamReceiver : public TransportStreamReceiver { + public: + MOCK_METHOD(void, RegisterRecvInitialMetadata, + (StreamIdentifier, InitialMetadataCallbackType), (override)); + MOCK_METHOD(void, RegisterRecvMessage, + (StreamIdentifier, MessageDataCallbackType), (override)); + MOCK_METHOD(void, RegisterRecvTrailingMetadata, + (StreamIdentifier, TrailingMetadataCallbackType), (override)); + MOCK_METHOD(void, NotifyRecvInitialMetadata, + (StreamIdentifier, absl::StatusOr), (override)); + MOCK_METHOD(void, NotifyRecvMessage, + (StreamIdentifier, absl::StatusOr), (override)); + MOCK_METHOD(void, NotifyRecvTrailingMetadata, + (StreamIdentifier, absl::StatusOr, int), (override)); + MOCK_METHOD(void, CancelStream, (StreamIdentifier), (override)); +}; + +} // namespace grpc_binder + +#endif // GRPC_TEST_CORE_TRANSPORT_BINDER_MOCK_OBJECTS_H diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index e79c61376ab..396a70209f2 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -960,6 +960,7 @@ include/grpcpp/channel.h \ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/create_channel.h \ +include/grpcpp/create_channel_binder.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/call_metric_recorder.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ @@ -1051,6 +1052,8 @@ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/authorization_policy_provider.h \ +include/grpcpp/security/binder_credentials.h \ +include/grpcpp/security/binder_security_policy.h \ include/grpcpp/security/credentials.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/tls_certificate_provider.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 3c732935f0c..4147fafc791 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -960,6 +960,7 @@ include/grpcpp/channel.h \ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/create_channel.h \ +include/grpcpp/create_channel_binder.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/call_metric_recorder.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ @@ -1051,6 +1052,8 @@ include/grpcpp/security/audit_logging.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/authorization_policy_provider.h \ +include/grpcpp/security/binder_credentials.h \ +include/grpcpp/security/binder_security_policy.h \ include/grpcpp/security/credentials.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/tls_certificate_provider.h \ @@ -1170,6 +1173,44 @@ src/core/ext/filters/stateful_session/stateful_session_filter.cc \ src/core/ext/filters/stateful_session/stateful_session_filter.h \ src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \ src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h \ +src/core/ext/transport/binder/client/binder_connector.cc \ +src/core/ext/transport/binder/client/binder_connector.h \ +src/core/ext/transport/binder/client/channel_create.cc \ +src/core/ext/transport/binder/client/channel_create_impl.cc \ +src/core/ext/transport/binder/client/channel_create_impl.h \ +src/core/ext/transport/binder/client/connection_id_generator.cc \ +src/core/ext/transport/binder/client/connection_id_generator.h \ +src/core/ext/transport/binder/client/endpoint_binder_pool.cc \ +src/core/ext/transport/binder/client/endpoint_binder_pool.h \ +src/core/ext/transport/binder/client/jni_utils.cc \ +src/core/ext/transport/binder/client/jni_utils.h \ +src/core/ext/transport/binder/client/security_policy_setting.cc \ +src/core/ext/transport/binder/client/security_policy_setting.h \ +src/core/ext/transport/binder/security_policy/binder_security_policy.cc \ +src/core/ext/transport/binder/server/binder_server.cc \ +src/core/ext/transport/binder/server/binder_server.h \ +src/core/ext/transport/binder/server/binder_server_credentials.cc \ +src/core/ext/transport/binder/transport/binder_stream.h \ +src/core/ext/transport/binder/transport/binder_transport.cc \ +src/core/ext/transport/binder/transport/binder_transport.h \ +src/core/ext/transport/binder/utils/binder_auto_utils.h \ +src/core/ext/transport/binder/utils/ndk_binder.cc \ +src/core/ext/transport/binder/utils/ndk_binder.h \ +src/core/ext/transport/binder/utils/transport_stream_receiver.h \ +src/core/ext/transport/binder/utils/transport_stream_receiver_impl.cc \ +src/core/ext/transport/binder/utils/transport_stream_receiver_impl.h \ +src/core/ext/transport/binder/wire_format/binder.h \ +src/core/ext/transport/binder/wire_format/binder_android.cc \ +src/core/ext/transport/binder/wire_format/binder_android.h \ +src/core/ext/transport/binder/wire_format/binder_constants.cc \ +src/core/ext/transport/binder/wire_format/binder_constants.h \ +src/core/ext/transport/binder/wire_format/transaction.cc \ +src/core/ext/transport/binder/wire_format/transaction.h \ +src/core/ext/transport/binder/wire_format/wire_reader.h \ +src/core/ext/transport/binder/wire_format/wire_reader_impl.cc \ +src/core/ext/transport/binder/wire_format/wire_reader_impl.h \ +src/core/ext/transport/binder/wire_format/wire_writer.cc \ +src/core/ext/transport/binder/wire_format/wire_writer.h \ src/core/ext/transport/chttp2/alpn/alpn.cc \ src/core/ext/transport/chttp2/alpn/alpn.h \ src/core/ext/transport/chttp2/client/chttp2_connector.cc \ @@ -2668,6 +2709,7 @@ src/core/load_balancing/xds/xds_override_host.h \ src/core/load_balancing/xds/xds_wrr_locality.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/plugin_registry/grpc_plugin_registry_extra.cc \ +src/core/resolver/binder/binder_resolver.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.h \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index ae593862758..cf962517d9e 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -975,6 +975,7 @@ src/core/ext/filters/stateful_session/stateful_session_filter.h \ src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \ src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h \ src/core/ext/transport/README.md \ +src/core/ext/transport/binder/README.md \ src/core/ext/transport/chttp2/README.md \ src/core/ext/transport/chttp2/alpn/alpn.cc \ src/core/ext/transport/chttp2/alpn/alpn.h \ @@ -2481,6 +2482,8 @@ src/core/load_balancing/xds/xds_wrr_locality.cc \ src/core/plugin_registry/grpc_plugin_registry.cc \ src/core/plugin_registry/grpc_plugin_registry_extra.cc \ src/core/resolver/README.md \ +src/core/resolver/binder/README.md \ +src/core/resolver/binder/binder_resolver.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/resolver/dns/c_ares/dns_resolver_ares.h \ src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h \ diff --git a/tools/internal_ci/linux/grpc_binder_transport_apk_build_in_docker.sh b/tools/internal_ci/linux/grpc_binder_transport_apk_build_in_docker.sh new file mode 100755 index 00000000000..300cace3a37 --- /dev/null +++ b/tools/internal_ci/linux/grpc_binder_transport_apk_build_in_docker.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Copyright 2021 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex + +echo $ANDROID_HOME +echo $ANDROID_NDK_HOME + +# Android platforms only works with Bazel >= 7.0 +export OVERRIDE_BAZEL_VERSION=7.3.1 + +python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path bazel_binder_example_app +bazel_binder_example_app/bazel_wrapper \ + --bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc \ + build \ + --extra_toolchains=@androidndk//:all \ + --android_platforms=//bazel/platforms/android:x86_64,//bazel/platforms/android:armeabi-v7a,//bazel/platforms/android:arm64-v8a \ + //examples/android/binder/java/io/grpc/binder/cpp/exampleclient:app \ + //examples/android/binder/java/io/grpc/binder/cpp/exampleserver:app + +# Make sure the Java code that will be invoked by binder transport +# implementation builds +python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path bazel_binder_connection_helper +bazel_binder_connection_helper/bazel_wrapper \ + --bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc \ + build \ + --define=use_strict_warning=true \ + @binder_transport_android_helper//io/grpc/binder/cpp:connection_helper diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 46054ee4dea..991313c58b5 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -1065,6 +1065,78 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "binder_resolver_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "binder_server_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "binder_transport_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -3123,6 +3195,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "endpoint_binder_pool_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -3479,6 +3575,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "fake_binder_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -11323,6 +11443,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "transport_stream_receiver_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false, @@ -11749,6 +11893,54 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "wire_reader_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "wire_writer_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": false + }, { "args": [], "benchmark": false,