[binder] Fix Android guard in binder server (#27326)

Android-related binder classes are only available if
GPR_SUPPORT_BINDER_TRANSPORT is defined. Thus, BinderServerCredentials
should only work if GPR_SUPPORT_BINDER_TRANSPORT (instead of
GPR_ANDROID) is defined as well.
pull/27331/head
Ta-Wei Tu 3 years ago committed by GitHub
parent 188f6be8f2
commit d24f89d79d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/transport/binder/client/channel_create.h
  2. 4
      src/core/ext/transport/binder/server/binder_server_credentials.cc
  3. 7
      test/core/transport/binder/end2end/binder_server_test.cc

@ -19,8 +19,6 @@
#ifdef GPR_ANDROID #ifdef GPR_ANDROID
#include <grpc/support/port_platform.h>
#include <jni.h> #include <jni.h>
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"

@ -26,7 +26,7 @@ namespace {
class BinderServerCredentialsImpl final : public ServerCredentials { class BinderServerCredentialsImpl final : public ServerCredentials {
public: public:
#ifdef GPR_ANDROID #ifdef GPR_SUPPORT_BINDER_TRANSPORT
int AddPortToServer(const std::string& addr, grpc_server* server) override { int AddPortToServer(const std::string& addr, grpc_server* server) override {
return grpc_core::AddBinderPort( return grpc_core::AddBinderPort(
std::string(addr), server, std::string(addr), server,
@ -40,7 +40,7 @@ class BinderServerCredentialsImpl final : public ServerCredentials {
grpc_server* /*server*/) override { grpc_server* /*server*/) override {
return 0; return 0;
} }
#endif // GPR_ANDROID #endif // GPR_SUPPORT_BINDER_TRANSPORT
void SetAuthMetadataProcessor( void SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& /*processor*/) override { const std::shared_ptr<AuthMetadataProcessor>& /*processor*/) override {

@ -96,8 +96,9 @@ class BinderServerTest : public ::testing::Test {
static void TearDownTestSuite() { grpc_shutdown(); } static void TearDownTestSuite() { grpc_shutdown(); }
}; };
#ifndef GPR_ANDROID #ifndef GPR_SUPPORT_BINDER_TRANSPORT
TEST(BinderServerCredentialsTest, FailedInNonAndroidEnvironments) { TEST(BinderServerCredentialsTest,
FailedInEnvironmentsNotSupportingBinderTransport) {
grpc::ServerBuilder server_builder; grpc::ServerBuilder server_builder;
grpc::testing::TestServiceImpl service; grpc::testing::TestServiceImpl service;
server_builder.RegisterService(&service); server_builder.RegisterService(&service);
@ -105,7 +106,7 @@ TEST(BinderServerCredentialsTest, FailedInNonAndroidEnvironments) {
"binder://fail", grpc::experimental::BinderServerCredentials()); "binder://fail", grpc::experimental::BinderServerCredentials());
EXPECT_EQ(server_builder.BuildAndStart(), nullptr); EXPECT_EQ(server_builder.BuildAndStart(), nullptr);
} }
#endif // !GPR_ANDROID #endif // !GPR_SUPPORT_BINDER_TRANSPORT
TEST_F(BinderServerTest, BuildAndStart) { TEST_F(BinderServerTest, BuildAndStart) {
grpc::ServerBuilder server_builder; grpc::ServerBuilder server_builder;

Loading…
Cancel
Save