mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Add new rpcs.
PiperOrigin-RevId: 878124598
This commit is contained in:
committed by
Copybara-Service
parent
93cb147c82
commit
115fa39dd3
@@ -243,9 +243,11 @@ class NearbyShareCertificateManagerImplTest
|
||||
|
||||
void VerifyCertificatesUpload(bool expected_force_update_contacts) {
|
||||
FakeNearbyIdentityClient* identity_client = GetIdentityClient();
|
||||
ASSERT_FALSE(identity_client->publish_device_requests().empty());
|
||||
std::vector<PublishDeviceRequest> publish_device_requests =
|
||||
identity_client->publish_device_requests();
|
||||
ASSERT_FALSE(publish_device_requests.empty());
|
||||
const PublishDeviceRequest& publish_device_request =
|
||||
identity_client->publish_device_requests().back();
|
||||
publish_device_requests.back();
|
||||
EXPECT_EQ(publish_device_request.device().name(),
|
||||
absl::StrCat("devices/", kDeviceId));
|
||||
EXPECT_EQ(publish_device_request.device()
|
||||
|
||||
@@ -39,6 +39,7 @@ cc_library(
|
||||
"//sharing:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//google/nearby/identity/v1:binding_cc_proto",
|
||||
"//google/nearby/identity/v1:rpcs_cc_proto",
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:mac_address",
|
||||
@@ -75,6 +76,7 @@ cc_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":platform",
|
||||
"//google/nearby/identity/v1:binding_cc_proto",
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "google/nearby/identity/v1/binding.pb.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
@@ -36,12 +37,23 @@ using ::google::nearby::identity::v1::PublishDeviceRequest;
|
||||
using ::google::nearby::identity::v1::PublishDeviceResponse;
|
||||
using ::google::nearby::identity::v1::QuerySharedCredentialsRequest;
|
||||
using ::google::nearby::identity::v1::QuerySharedCredentialsResponse;
|
||||
using ::google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsRequest;
|
||||
using ::google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsResponse;
|
||||
using ::google::nearby::identity::v1::InitiateBindingRequest;
|
||||
using ::google::nearby::identity::v1::InitiateBindingResponse;
|
||||
using ::google::nearby::identity::v1::JoinBindingRequest;
|
||||
using ::google::nearby::identity::v1::JoinBindingResponse;
|
||||
using ::google::nearby::identity::v1::DeleteBindingRequest;
|
||||
using ::google::nearby::identity::v1::DeleteBindingResponse;
|
||||
|
||||
void FakeNearbyShareClient::ListContactPeople(
|
||||
proto::ListContactPeopleRequest request,
|
||||
absl::AnyInvocable<void(
|
||||
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
|
||||
callback) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
list_contact_people_requests_.emplace_back(request);
|
||||
if (list_contact_people_responses_.empty()) {
|
||||
std::move(callback)(absl::NotFoundError(""));
|
||||
@@ -52,6 +64,57 @@ void FakeNearbyShareClient::ListContactPeople(
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyShareClient::InitiateBinding(
|
||||
InitiateBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<InitiateBindingResponse>& response) &&>
|
||||
callback) {
|
||||
absl::StatusOr<InitiateBindingResponse> response = absl::NotFoundError("");
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
initiate_binding_requests_.emplace_back(request);
|
||||
if (!initiate_binding_responses_.empty()) {
|
||||
response = initiate_binding_responses_[0];
|
||||
initiate_binding_responses_.erase(initiate_binding_responses_.begin());
|
||||
}
|
||||
}
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyShareClient::JoinBinding(
|
||||
JoinBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<JoinBindingResponse>& response) &&>
|
||||
callback) {
|
||||
absl::StatusOr<JoinBindingResponse> response = absl::NotFoundError("");
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
join_binding_requests_.emplace_back(request);
|
||||
if (!join_binding_responses_.empty()) {
|
||||
response = join_binding_responses_[0];
|
||||
join_binding_responses_.erase(join_binding_responses_.begin());
|
||||
}
|
||||
}
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyShareClient::DeleteBinding(
|
||||
DeleteBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<DeleteBindingResponse>& response) &&>
|
||||
callback) {
|
||||
absl::StatusOr<DeleteBindingResponse> response = absl::NotFoundError("");
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
delete_binding_requests_.emplace_back(request);
|
||||
if (!delete_binding_responses_.empty()) {
|
||||
response = delete_binding_responses_[0];
|
||||
delete_binding_responses_.erase(delete_binding_responses_.begin());
|
||||
}
|
||||
}
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyIdentityClient::QuerySharedCredentials(
|
||||
QuerySharedCredentialsRequest request,
|
||||
absl::AnyInvocable<
|
||||
@@ -102,6 +165,26 @@ void FakeNearbyIdentityClient::GetAccountInfo(
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyIdentityClient::QuerySharedCredentialsWithBindingIds(
|
||||
QuerySharedCredentialsWithBindingIdsRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<QuerySharedCredentialsWithBindingIdsResponse>&
|
||||
response) &&>
|
||||
callback) {
|
||||
absl::StatusOr<QuerySharedCredentialsWithBindingIdsResponse> response =
|
||||
absl::NotFoundError("");
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
query_shared_credentials_with_binding_ids_requests_.emplace_back(request);
|
||||
if (!query_shared_credentials_with_binding_ids_responses_.empty()) {
|
||||
response = query_shared_credentials_with_binding_ids_responses_[0];
|
||||
query_shared_credentials_with_binding_ids_responses_.erase(
|
||||
query_shared_credentials_with_binding_ids_responses_.begin());
|
||||
}
|
||||
}
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
std::unique_ptr<nearby::sharing::api::SharingRpcClient>
|
||||
FakeNearbyShareClientFactory::CreateInstance() {
|
||||
auto instance = std::make_unique<FakeNearbyShareClient>();
|
||||
|
||||
@@ -37,13 +37,15 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
|
||||
FakeNearbyShareClient() = default;
|
||||
~FakeNearbyShareClient() override = default;
|
||||
|
||||
std::vector<nearby::sharing::proto::ListContactPeopleRequest>&
|
||||
std::vector<nearby::sharing::proto::ListContactPeopleRequest>
|
||||
list_contact_people_requests() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return list_contact_people_requests_;
|
||||
}
|
||||
|
||||
void SetListContactPeopleResponses(
|
||||
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>> responses) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
list_contact_people_responses_ = responses;
|
||||
}
|
||||
|
||||
@@ -53,10 +55,89 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
|
||||
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
|
||||
callback) override;
|
||||
|
||||
std::vector<google::nearby::identity::v1::InitiateBindingRequest>
|
||||
initiate_binding_requests() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return initiate_binding_requests_;
|
||||
}
|
||||
|
||||
void SetInitiateBindingResponses(
|
||||
std::vector<absl::StatusOr<google::nearby::identity::v1::
|
||||
InitiateBindingResponse>>
|
||||
responses) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
initiate_binding_responses_ = responses;
|
||||
}
|
||||
|
||||
void InitiateBinding(
|
||||
google::nearby::identity::v1::InitiateBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
InitiateBindingResponse>& response) &&>
|
||||
callback) override;
|
||||
|
||||
std::vector<google::nearby::identity::v1::JoinBindingRequest>
|
||||
join_binding_requests() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return join_binding_requests_;
|
||||
}
|
||||
|
||||
void SetJoinBindingResponses(
|
||||
std::vector<absl::StatusOr<google::nearby::identity::v1::
|
||||
JoinBindingResponse>>
|
||||
responses) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
join_binding_responses_ = responses;
|
||||
}
|
||||
|
||||
void JoinBinding(
|
||||
google::nearby::identity::v1::JoinBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
JoinBindingResponse>& response) &&>
|
||||
callback) override;
|
||||
|
||||
std::vector<google::nearby::identity::v1::DeleteBindingRequest>
|
||||
delete_binding_requests() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return delete_binding_requests_;
|
||||
}
|
||||
|
||||
void SetDeleteBindingResponses(
|
||||
std::vector<absl::StatusOr<google::nearby::identity::v1::
|
||||
DeleteBindingResponse>>
|
||||
responses) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
delete_binding_responses_ = responses;
|
||||
}
|
||||
|
||||
void DeleteBinding(
|
||||
google::nearby::identity::v1::DeleteBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
DeleteBindingResponse>& response) &&>
|
||||
callback) override;
|
||||
|
||||
private:
|
||||
absl::Mutex mutex_;
|
||||
std::vector<nearby::sharing::proto::ListContactPeopleRequest>
|
||||
list_contact_people_requests_;
|
||||
list_contact_people_requests_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>>
|
||||
list_contact_people_responses_;
|
||||
list_contact_people_responses_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<google::nearby::identity::v1::InitiateBindingRequest>
|
||||
initiate_binding_requests_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<
|
||||
absl::StatusOr<google::nearby::identity::v1::InitiateBindingResponse>>
|
||||
initiate_binding_responses_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<google::nearby::identity::v1::JoinBindingRequest>
|
||||
join_binding_requests_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<absl::StatusOr<google::nearby::identity::v1::JoinBindingResponse>>
|
||||
join_binding_responses_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<google::nearby::identity::v1::DeleteBindingRequest>
|
||||
delete_binding_requests_ ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<
|
||||
absl::StatusOr<google::nearby::identity::v1::DeleteBindingResponse>>
|
||||
delete_binding_responses_ ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
// A fake implementation of the Nearby Identity RPC client that stores all
|
||||
@@ -67,13 +148,13 @@ class FakeNearbyIdentityClient
|
||||
FakeNearbyIdentityClient() = default;
|
||||
~FakeNearbyIdentityClient() override = default;
|
||||
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>&
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>
|
||||
publish_device_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return publish_device_requests_;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>&
|
||||
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>
|
||||
query_shared_credentials_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return query_shared_credentials_requests_;
|
||||
@@ -110,7 +191,7 @@ class FakeNearbyIdentityClient
|
||||
query_shared_credentials_responses_ = responses;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::GetAccountInfoRequest>&
|
||||
std::vector<google::nearby::identity::v1::GetAccountInfoRequest>
|
||||
get_account_info_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return get_account_info_requests_;
|
||||
@@ -130,6 +211,32 @@ class FakeNearbyIdentityClient
|
||||
get_account_info_response_ = response;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsRequest>
|
||||
query_shared_credentials_with_binding_ids_requests()
|
||||
ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return query_shared_credentials_with_binding_ids_requests_;
|
||||
}
|
||||
|
||||
void QuerySharedCredentialsWithBindingIds(
|
||||
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
|
||||
request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsResponse>& response) &&>
|
||||
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
||||
|
||||
void SetQuerySharedCredentialsWithBindingIdsResponse(
|
||||
std::vector<absl::StatusOr<
|
||||
google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsResponse>>
|
||||
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
query_shared_credentials_with_binding_ids_responses_ = responses;
|
||||
}
|
||||
|
||||
private:
|
||||
absl::Mutex mutex_;
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>
|
||||
@@ -148,6 +255,15 @@ class FakeNearbyIdentityClient
|
||||
get_account_info_requests_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::StatusOr<google::nearby::identity::v1::GetAccountInfoResponse>
|
||||
get_account_info_response_ ABSL_GUARDED_BY(mutex_);
|
||||
|
||||
std::vector<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest>
|
||||
query_shared_credentials_with_binding_ids_requests_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<absl::StatusOr<google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsResponse>>
|
||||
query_shared_credentials_with_binding_ids_responses_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
class FakeNearbyShareClientFactory
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "google/nearby/identity/v1/binding.pb.h"
|
||||
#include "google/nearby/identity/v1/rpcs.pb.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/status/statusor.h"
|
||||
@@ -53,6 +54,15 @@ class IdentityRpcClient {
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
GetAccountInfoResponse>& response) &&>
|
||||
callback) = 0;
|
||||
|
||||
virtual void QuerySharedCredentialsWithBindingIds(
|
||||
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
|
||||
request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::
|
||||
QuerySharedCredentialsWithBindingIdsResponse>& response) &&>
|
||||
callback) = 0;
|
||||
};
|
||||
|
||||
// SharingRpcClient is used to access Nearby Share backend APIs.
|
||||
@@ -67,6 +77,27 @@ class SharingRpcClient {
|
||||
absl::AnyInvocable<void(
|
||||
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
|
||||
callback) = 0;
|
||||
|
||||
virtual void InitiateBinding(
|
||||
google::nearby::identity::v1::InitiateBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
InitiateBindingResponse>& response) &&>
|
||||
callback) = 0;
|
||||
|
||||
virtual void JoinBinding(
|
||||
google::nearby::identity::v1::JoinBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
JoinBindingResponse>& response) &&>
|
||||
callback) = 0;
|
||||
|
||||
virtual void DeleteBinding(
|
||||
google::nearby::identity::v1::DeleteBindingRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
DeleteBindingResponse>& response) &&>
|
||||
callback) = 0;
|
||||
};
|
||||
|
||||
// Interface for creating SharingRpcClient instances. Because each
|
||||
|
||||
Reference in New Issue
Block a user