diff --git a/sharing/flags/generated/nearby_sharing_feature_flags.h b/sharing/flags/generated/nearby_sharing_feature_flags.h index e3f8cc80..6d39f6df 100755 --- a/sharing/flags/generated/nearby_sharing_feature_flags.h +++ b/sharing/flags/generated/nearby_sharing_feature_flags.h @@ -12,14 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -/************* DO NOT EDIT ******************* - * After updating nearby_sharing_feature.gcl, regenerate this file by running: - * blaze build - * //third_party/nearby/sharing/flags:nearby_sharing_feature_flags_cpp_consts - * Copy the generated file here: - * blaze-genfiles/third_party/nearby/sharing/flags/nearby_sharing_feature_flags.h - **********************************************/ - +// Mendel flags, auto-generated. DO NOT EDIT. #ifndef THIRD_PARTY_NEARBY_SHARING_FLAGS_NEARBY_SHARING_FEATURE_FLAGS_H_ #define THIRD_PARTY_NEARBY_SHARING_FLAGS_NEARBY_SHARING_FEATURE_FLAGS_H_ @@ -83,6 +76,9 @@ constexpr auto kUseGrpcClient = // When true, dedup discovered endpoints. constexpr auto kApplyEndpointsDedup = flags::Flag(kConfigPackage, "45656298", false); +// When true, call the 3P Nearby Identity API instead of the 1P private API +constexpr auto kCallNearbyIdentityApi = + flags::Flag(kConfigPackage, "45667328", false); // When true, dedup in UnregisterShareTarget. constexpr auto kDedupInUnregisterShareTarget = flags::Flag(kConfigPackage, "45664277", false); @@ -130,6 +126,7 @@ inline absl::btree_map&> GetBoolFlags() { {45409033, kShowAutoUpdateSetting}, {45630055, kUseGrpcClient}, {45656298, kApplyEndpointsDedup}, + {45667328, kCallNearbyIdentityApi}, {45664277, kDedupInUnregisterShareTarget}, {45657036, kDeleteUnexpectedReceivedFileFix}, {45665616, kHonor3PClientIdAndSecret}, diff --git a/sharing/internal/api/BUILD b/sharing/internal/api/BUILD index 4330013f..9c79d487 100644 --- a/sharing/internal/api/BUILD +++ b/sharing/internal/api/BUILD @@ -40,6 +40,7 @@ cc_library( deps = [ "//internal/platform:types", "//internal/platform/implementation:account_manager", + "//proto/identity/v1:rpcs_cc_proto", "//sharing/analytics", "//sharing/proto:share_cc_proto", "@com_google_absl//absl/functional:any_invocable", diff --git a/sharing/internal/api/fake_nearby_share_client.cc b/sharing/internal/api/fake_nearby_share_client.cc index ec9e3455..ac69fefd 100644 --- a/sharing/internal/api/fake_nearby_share_client.cc +++ b/sharing/internal/api/fake_nearby_share_client.cc @@ -69,11 +69,38 @@ void FakeNearbyShareClient::ListPublicCertificates( std::move(callback)(response); } +void FakeNearbyIdentityClient::QuerySharedCredentials( + const google::nearby::identity::v1::QuerySharedCredentialsRequest& request, + absl::AnyInvocable< + void(const absl::StatusOr< + google::nearby::identity::v1::QuerySharedCredentialsResponse>& + response) &&> + callback) { + query_shared_credentials_requests_.emplace_back(request); + std::move(callback)(query_shared_credentials_response_); +} + +void FakeNearbyIdentityClient::PublishDevice( + const google::nearby::identity::v1::PublishDeviceRequest& request, + absl::AnyInvocable< + void(const absl::StatusOr< + google::nearby::identity::v1::PublishDeviceResponse>& response) &&> + callback) { + publish_device_requests_.emplace_back(request); + std::move(callback)(publish_device_response_); +} + std::unique_ptr FakeNearbyShareClientFactory::CreateInstance() { auto instance = std::make_unique(); instances_.push_back(instance.get()); + return instance; +} +std::unique_ptr +FakeNearbyShareClientFactory::CreateIdentityInstance() { + auto instance = std::make_unique(); + identity_instances_.push_back(instance.get()); return instance; } diff --git a/sharing/internal/api/fake_nearby_share_client.h b/sharing/internal/api/fake_nearby_share_client.h index 22028a45..33947371 100644 --- a/sharing/internal/api/fake_nearby_share_client.h +++ b/sharing/internal/api/fake_nearby_share_client.h @@ -71,7 +71,6 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient { list_public_certificates_responses_ = responses; } - private: void UpdateDevice( const proto::UpdateDeviceRequest& request, absl::AnyInvocable< @@ -103,6 +102,59 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient { list_public_certificates_responses_; }; +// A fake implementation of the Nearby Identity RPC client that stores all +// request data. Only use in unit tests. +class FakeNearbyIdentityClient + : public nearby::sharing::api::IdentityRpcClient { + public: + FakeNearbyIdentityClient() = default; + ~FakeNearbyIdentityClient() override = default; + + std::vector& + publish_device_requests() { + return publish_device_requests_; + } + + void PublishDevice( + const google::nearby::identity::v1::PublishDeviceRequest& request, + absl::AnyInvocable< + void(const absl::StatusOr& response) &&> + callback) override; + + void SetPublishDeviceResponse( + absl::StatusOr + response) { + publish_device_response_ = response; + } + + void QuerySharedCredentials( + const google::nearby::identity::v1::QuerySharedCredentialsRequest& + request, + absl::AnyInvocable< + void(const absl::StatusOr< + google::nearby::identity::v1::QuerySharedCredentialsResponse>& + response) &&> + callback) override; + + void SetQuerySharedCredentialsResponse( + absl::StatusOr< + google::nearby::identity::v1::QuerySharedCredentialsResponse> + response) { + query_shared_credentials_response_ = response; + } + + std::vector + publish_device_requests_; + absl::StatusOr + publish_device_response_; + + std::vector + query_shared_credentials_requests_; + absl::StatusOr + query_shared_credentials_response_; +}; + class FakeNearbyShareClientFactory : public nearby::sharing::api::SharingRpcClientFactory { public: @@ -112,6 +164,9 @@ class FakeNearbyShareClientFactory public: // Returns all FakeNearbyShareClient instances created by CreateInstance(). std::vector& instances() { return instances_; } + std::vector& identity_instances() { + return identity_instances_; + } nearby::sharing::api::SharingRpcNotifier* GetRpcNotifier() const override { return nullptr; } @@ -121,7 +176,11 @@ class FakeNearbyShareClientFactory std::unique_ptr CreateInstance() override; + std::unique_ptr + CreateIdentityInstance() override; + std::vector instances_; + std::vector identity_instances_; }; } // namespace sharing diff --git a/sharing/internal/api/sharing_rpc_client.h b/sharing/internal/api/sharing_rpc_client.h index 09b27d98..026f301c 100644 --- a/sharing/internal/api/sharing_rpc_client.h +++ b/sharing/internal/api/sharing_rpc_client.h @@ -19,6 +19,7 @@ #include "absl/functional/any_invocable.h" #include "absl/status/statusor.h" +#include "proto/identity/v1/rpcs.pb.h" #include "sharing/internal/api/sharing_rpc_notifier.h" #include "sharing/proto/certificate_rpc.pb.h" #include "sharing/proto/contact_rpc.pb.h" @@ -26,6 +27,29 @@ namespace nearby::sharing::api { +// IdentityRpcClient is used to access Nearby Identity backend APIs. +class IdentityRpcClient { + public: + IdentityRpcClient() = default; + virtual ~IdentityRpcClient() = default; + + virtual void QuerySharedCredentials( + const google::nearby::identity::v1::QuerySharedCredentialsRequest& + request, + absl::AnyInvocable< + void(const absl::StatusOr< + google::nearby::identity::v1::QuerySharedCredentialsResponse>& + response) &&> + callback) = 0; + + virtual void PublishDevice( + const google::nearby::identity::v1::PublishDeviceRequest& request, + absl::AnyInvocable< + void(const absl::StatusOr& response) &&> + callback) = 0; +}; + // SharingRpcClient is used to access Nearby Share backend APIs. class SharingRpcClient { public: @@ -64,6 +88,7 @@ class SharingRpcClientFactory { virtual ~SharingRpcClientFactory() = default; virtual std::unique_ptr CreateInstance() = 0; + virtual std::unique_ptr CreateIdentityInstance() = 0; virtual api::SharingRpcNotifier* GetRpcNotifier() const = 0; };