mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
added top level stubs to match upstream
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 "connections/implementation/analytics/analytics_recorder_impl.h"
|
||||||
|
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 CONNECTIONS_IMPLEMENTATION_ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
|
||||||
|
#define CONNECTIONS_IMPLEMENTATION_ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/time/time.h"
|
||||||
|
#include "connections/implementation/analytics/analytics_recorder.h"
|
||||||
|
#include "location/nearby/analytics/cpp/logging/event_logger.h"
|
||||||
|
#include "proto/connections_enums.pb.h"
|
||||||
|
|
||||||
|
namespace nearby::analytics {
|
||||||
|
|
||||||
|
class AnalyticsRecorderImpl : public AnalyticsRecorder {
|
||||||
|
public:
|
||||||
|
explicit AnalyticsRecorderImpl(EventLogger* event_logger = nullptr)
|
||||||
|
: event_logger_(event_logger) {}
|
||||||
|
~AnalyticsRecorderImpl() override = default;
|
||||||
|
|
||||||
|
void OnStartAdvertising(
|
||||||
|
connections::Strategy strategy,
|
||||||
|
const std::vector<location::nearby::proto::connections::Medium>& mediums,
|
||||||
|
AdvertisingMetadataParams* advertising_metadata_params) override {}
|
||||||
|
void OnStopAdvertising() override {}
|
||||||
|
int GetNextAdvertisingUpdateIndex() override { return 0; }
|
||||||
|
void OnStartedIncomingConnectionListening(
|
||||||
|
connections::Strategy strategy) override {}
|
||||||
|
void OnStoppedIncomingConnectionListening() override {}
|
||||||
|
void OnStartDiscovery(
|
||||||
|
connections::Strategy strategy,
|
||||||
|
const std::vector<location::nearby::proto::connections::Medium>& mediums,
|
||||||
|
DiscoveryMetadataParams* discovery_metadata_params) override {}
|
||||||
|
void OnStopDiscovery() override {}
|
||||||
|
int GetNextDiscoveryUpdateIndex() override { return 0; }
|
||||||
|
void OnEndpointFound(
|
||||||
|
location::nearby::proto::connections::Medium medium) override {}
|
||||||
|
void OnRequestConnection(const connections::Strategy& strategy,
|
||||||
|
const std::string& endpoint_id) override {}
|
||||||
|
void OnConnectionRequestReceived(
|
||||||
|
const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnConnectionRequestSent(const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnRemoteEndpointAccepted(
|
||||||
|
const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnLocalEndpointAccepted(
|
||||||
|
const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnRemoteEndpointRejected(
|
||||||
|
const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnLocalEndpointRejected(
|
||||||
|
const std::string& remote_endpoint_id) override {}
|
||||||
|
void OnIncomingConnectionAttempt(
|
||||||
|
location::nearby::proto::connections::ConnectionAttemptType type,
|
||||||
|
location::nearby::proto::connections::Medium medium,
|
||||||
|
location::nearby::proto::connections::ConnectionAttemptResult result,
|
||||||
|
absl::Duration duration, const std::string& connection_token,
|
||||||
|
ConnectionAttemptMetadataParams* connection_attempt_metadata_params)
|
||||||
|
override {}
|
||||||
|
void OnOutgoingConnectionAttempt(
|
||||||
|
const std::string& remote_endpoint_id,
|
||||||
|
location::nearby::proto::connections::ConnectionAttemptType type,
|
||||||
|
location::nearby::proto::connections::Medium medium,
|
||||||
|
location::nearby::proto::connections::ConnectionAttemptResult result,
|
||||||
|
absl::Duration duration, const std::string& connection_token,
|
||||||
|
ConnectionAttemptMetadataParams* connection_attempt_metadata_params)
|
||||||
|
override {}
|
||||||
|
void OnConnectionEstablished(
|
||||||
|
const std::string& endpoint_id,
|
||||||
|
location::nearby::proto::connections::Medium medium,
|
||||||
|
const std::string& connection_token) override {}
|
||||||
|
void OnConnectionClosed(
|
||||||
|
const std::string& endpoint_id,
|
||||||
|
location::nearby::proto::connections::Medium medium,
|
||||||
|
location::nearby::proto::connections::DisconnectionReason reason,
|
||||||
|
SafeDisconnectionResult result) override {}
|
||||||
|
void OnIncomingPayloadStarted(const std::string& endpoint_id,
|
||||||
|
std::int64_t payload_id,
|
||||||
|
connections::PayloadType type,
|
||||||
|
std::int64_t total_size_bytes) override {}
|
||||||
|
void OnPayloadChunkReceived(const std::string& endpoint_id,
|
||||||
|
std::int64_t payload_id,
|
||||||
|
std::int64_t chunk_size_bytes) override {}
|
||||||
|
void OnIncomingPayloadDone(
|
||||||
|
const std::string& endpoint_id, std::int64_t payload_id,
|
||||||
|
location::nearby::proto::connections::PayloadStatus status,
|
||||||
|
location::nearby::proto::connections::OperationResultCode
|
||||||
|
operation_result_code) override {}
|
||||||
|
void OnOutgoingPayloadStarted(const std::vector<std::string>& endpoint_ids,
|
||||||
|
std::int64_t payload_id,
|
||||||
|
connections::PayloadType type,
|
||||||
|
std::int64_t total_size_bytes) override {}
|
||||||
|
void OnPayloadChunkSent(const std::string& endpoint_id,
|
||||||
|
std::int64_t payload_id,
|
||||||
|
std::int64_t chunk_size_bytes) override {}
|
||||||
|
void OnOutgoingPayloadDone(
|
||||||
|
const std::string& endpoint_id, std::int64_t payload_id,
|
||||||
|
location::nearby::proto::connections::PayloadStatus status,
|
||||||
|
location::nearby::proto::connections::OperationResultCode
|
||||||
|
operation_result_code) override {}
|
||||||
|
void OnBandwidthUpgradeStarted(
|
||||||
|
const std::string& endpoint_id,
|
||||||
|
location::nearby::proto::connections::Medium from_medium,
|
||||||
|
location::nearby::proto::connections::Medium to_medium,
|
||||||
|
location::nearby::proto::connections::ConnectionAttemptDirection
|
||||||
|
direction,
|
||||||
|
const std::string& connection_token) override {}
|
||||||
|
void UpdateBwUpgradeNetworkInfo(const std::string& endpoint_id,
|
||||||
|
int num_interfaces,
|
||||||
|
int num_ipv6_only_interfaces) override {}
|
||||||
|
void OnBandwidthUpgradeError(
|
||||||
|
const std::string& endpoint_id,
|
||||||
|
location::nearby::proto::connections::BandwidthUpgradeResult result,
|
||||||
|
location::nearby::proto::connections::BandwidthUpgradeErrorStage
|
||||||
|
error_stage,
|
||||||
|
location::nearby::proto::connections::OperationResultCode
|
||||||
|
operation_result_code) override {}
|
||||||
|
void OnBandwidthUpgradeSuccess(const std::string& endpoint_id) override {}
|
||||||
|
void OnErrorCode(const ErrorCodeParams& params) override {}
|
||||||
|
void LogStartSession() override {}
|
||||||
|
void LogSession() override {}
|
||||||
|
bool IsSessionLogged() override { return false; }
|
||||||
|
location::nearby::proto::connections::OperationResultCategory
|
||||||
|
GetOperationResultCategory(
|
||||||
|
location::nearby::proto::connections::OperationResultCode result_code)
|
||||||
|
override {
|
||||||
|
return location::nearby::proto::connections::CATEGORY_UNKNOWN;
|
||||||
|
}
|
||||||
|
void Sync() override {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventLogger* event_logger_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::analytics
|
||||||
|
|
||||||
|
#endif // CONNECTIONS_IMPLEMENTATION_ANALYTICS_ANALYTICS_RECORDER_IMPL_H_
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "resources_cc_proto",
|
||||||
|
hdrs = ["resources.pb.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["//location/nearby/sharing/lib/rpc:sharing_rpc_client"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "rpcs_cc_proto",
|
||||||
|
hdrs = ["rpcs.pb.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [":resources_cc_proto"],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 GOOGLE_NEARBY_IDENTITY_V1_RESOURCES_PB_H_
|
||||||
|
#define GOOGLE_NEARBY_IDENTITY_V1_RESOURCES_PB_H_
|
||||||
|
|
||||||
|
#include "location/nearby/sharing/lib/rpc/identity_rpc_types.h"
|
||||||
|
|
||||||
|
#endif // GOOGLE_NEARBY_IDENTITY_V1_RESOURCES_PB_H_
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 GOOGLE_NEARBY_IDENTITY_V1_RPCS_PB_H_
|
||||||
|
#define GOOGLE_NEARBY_IDENTITY_V1_RPCS_PB_H_
|
||||||
|
|
||||||
|
#include "google/nearby/identity/v1/resources.pb.h"
|
||||||
|
|
||||||
|
#endif // GOOGLE_NEARBY_IDENTITY_V1_RPCS_PB_H_
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "timestamp_cc_proto",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@com_google_protobuf//:protobuf"],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "event_logger",
|
||||||
|
hdrs = ["event_logger.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_ANALYTICS_CPP_LOGGING_EVENT_LOGGER_H_
|
||||||
|
#define LOCATION_NEARBY_ANALYTICS_CPP_LOGGING_EVENT_LOGGER_H_
|
||||||
|
|
||||||
|
namespace location::nearby::analytics::proto {
|
||||||
|
class ConnectionsLog;
|
||||||
|
} // namespace location::nearby::analytics::proto
|
||||||
|
|
||||||
|
namespace nearby::sharing::analytics::proto {
|
||||||
|
class SharingLog;
|
||||||
|
} // namespace nearby::sharing::analytics::proto
|
||||||
|
|
||||||
|
namespace nearby::analytics {
|
||||||
|
|
||||||
|
class EventLogger {
|
||||||
|
public:
|
||||||
|
virtual ~EventLogger() = default;
|
||||||
|
|
||||||
|
virtual void Log(
|
||||||
|
const location::nearby::analytics::proto::ConnectionsLog& message) = 0;
|
||||||
|
virtual void Log(
|
||||||
|
const nearby::sharing::analytics::proto::SharingLog& message) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::analytics
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_ANALYTICS_CPP_LOGGING_EVENT_LOGGER_H_
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "connections_log_cc_proto",
|
||||||
|
hdrs = ["connections_log.pb.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "sharing_log_cc_proto",
|
||||||
|
hdrs = ["sharing_log.pb.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_ANALYTICS_CPP_PROTO_CONNECTIONS_LOG_PB_H_
|
||||||
|
#define LOCATION_NEARBY_ANALYTICS_CPP_PROTO_CONNECTIONS_LOG_PB_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace location::nearby::analytics::proto {
|
||||||
|
|
||||||
|
class ConnectionsLog {
|
||||||
|
public:
|
||||||
|
std::string SerializeAsString() const { return {}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace location::nearby::analytics::proto
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_ANALYTICS_CPP_PROTO_CONNECTIONS_LOG_PB_H_
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_ANALYTICS_CPP_PROTO_SHARING_LOG_PB_H_
|
||||||
|
#define LOCATION_NEARBY_ANALYTICS_CPP_PROTO_SHARING_LOG_PB_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace nearby::sharing::analytics::proto {
|
||||||
|
|
||||||
|
class SharingLog {
|
||||||
|
public:
|
||||||
|
std::string SerializeAsString() const { return {}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing::analytics::proto
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_ANALYTICS_CPP_PROTO_SHARING_LOG_PB_H_
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "account_manager",
|
||||||
|
hdrs = ["account_manager.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"@com_google_absl//absl/functional:any_invocable",
|
||||||
|
"@com_google_absl//absl/status",
|
||||||
|
"@com_google_absl//absl/status:statusor",
|
||||||
|
"@com_google_absl//absl/strings:string_view",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_ACCOUNT_ACCOUNT_MANAGER_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_ACCOUNT_ACCOUNT_MANAGER_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/functional/any_invocable.h"
|
||||||
|
#include "absl/status/status.h"
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
|
namespace nearby::sharing {
|
||||||
|
|
||||||
|
struct AccountInfo {
|
||||||
|
std::string id;
|
||||||
|
std::string email;
|
||||||
|
std::string display_name;
|
||||||
|
std::string given_name;
|
||||||
|
std::string picture_url;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum AuthStatus {
|
||||||
|
SUCCESS = 0,
|
||||||
|
ERROR = 1,
|
||||||
|
UNSUPPORTED = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
class SigninAttempt {
|
||||||
|
public:
|
||||||
|
virtual ~SigninAttempt() = default;
|
||||||
|
|
||||||
|
virtual std::string Start(
|
||||||
|
absl::AnyInvocable<void(AuthStatus, absl::string_view, absl::string_view,
|
||||||
|
const AccountInfo&)>
|
||||||
|
callback) = 0;
|
||||||
|
virtual void Close() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AccountManager {
|
||||||
|
public:
|
||||||
|
using Account = AccountInfo;
|
||||||
|
|
||||||
|
class Observer {
|
||||||
|
public:
|
||||||
|
virtual ~Observer() = default;
|
||||||
|
virtual void OnLoginSucceeded(absl::string_view account_id) {}
|
||||||
|
virtual void OnLogoutSucceeded(absl::string_view account_id,
|
||||||
|
bool credential_error) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual ~AccountManager() = default;
|
||||||
|
|
||||||
|
virtual std::optional<Account> GetCurrentAccount() = 0;
|
||||||
|
virtual std::unique_ptr<SigninAttempt> Login(absl::string_view client_id,
|
||||||
|
absl::string_view client_secret) = 0;
|
||||||
|
virtual void Logout(absl::AnyInvocable<void(absl::Status)> logout_callback) = 0;
|
||||||
|
virtual bool GetAccessToken(
|
||||||
|
absl::AnyInvocable<void(absl::StatusOr<std::string>)> callback) = 0;
|
||||||
|
virtual std::pair<std::string, std::string> GetOAuthClientCredential() = 0;
|
||||||
|
virtual void AddObserver(Observer* observer) = 0;
|
||||||
|
virtual void RemoveObserver(Observer* observer) = 0;
|
||||||
|
virtual void SaveAccountPrefs(absl::string_view user_id,
|
||||||
|
absl::string_view client_id,
|
||||||
|
absl::string_view client_secret) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_ACCOUNT_ACCOUNT_MANAGER_H_
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "sharing_rpc_client",
|
||||||
|
hdrs = [
|
||||||
|
"identity_rpc_types.h",
|
||||||
|
"sharing_rpc_client.h",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//sharing/proto:share_cc_proto",
|
||||||
|
"@com_google_absl//absl/status:statusor",
|
||||||
|
"@com_google_absl//absl/time",
|
||||||
|
"@com_google_protobuf//:protobuf",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "grpc_async_client_factory",
|
||||||
|
hdrs = ["grpc_async_client_factory.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
":sharing_rpc_client",
|
||||||
|
"//location/nearby/sharing/lib/account:account_manager",
|
||||||
|
"//sharing/analytics",
|
||||||
|
"@com_google_absl//absl/status",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_RPC_GRPC_ASYNC_CLIENT_FACTORY_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_RPC_GRPC_ASYNC_CLIENT_FACTORY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "absl/status/status.h"
|
||||||
|
#include "internal/platform/clock.h"
|
||||||
|
#include "location/nearby/sharing/lib/account/account_manager.h"
|
||||||
|
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
|
||||||
|
#include "sharing/analytics/analytics_recorder.h"
|
||||||
|
|
||||||
|
namespace nearby::sharing::platform::common {
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
class NoOpSharingRpcClient : public nearby::sharing::api::SharingRpcClient {
|
||||||
|
public:
|
||||||
|
void ListContactPeople(
|
||||||
|
nearby::sharing::proto::ListContactPeopleRequest request,
|
||||||
|
ListContactPeopleCallback callback) override {
|
||||||
|
static_cast<void>(request);
|
||||||
|
callback(nearby::sharing::proto::ListContactPeopleResponse());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class NoOpIdentityRpcClient : public nearby::sharing::api::IdentityRpcClient {
|
||||||
|
public:
|
||||||
|
void QuerySharedCredentials(
|
||||||
|
google::nearby::identity::v1::QuerySharedCredentialsRequest request,
|
||||||
|
absl::Duration timeout, QuerySharedCredentialsCallback callback) override {
|
||||||
|
static_cast<void>(request);
|
||||||
|
static_cast<void>(timeout);
|
||||||
|
callback(google::nearby::identity::v1::QuerySharedCredentialsResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuerySharedCredentialsWithBindingIds(
|
||||||
|
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
|
||||||
|
request,
|
||||||
|
absl::Duration timeout,
|
||||||
|
QuerySharedCredentialsWithBindingIdsCallback callback) override {
|
||||||
|
static_cast<void>(request);
|
||||||
|
static_cast<void>(timeout);
|
||||||
|
callback(google::nearby::identity::v1::
|
||||||
|
QuerySharedCredentialsWithBindingIdsResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PublishDevice(
|
||||||
|
google::nearby::identity::v1::PublishDeviceRequest request,
|
||||||
|
absl::Duration timeout, PublishDeviceCallback callback) override {
|
||||||
|
static_cast<void>(request);
|
||||||
|
static_cast<void>(timeout);
|
||||||
|
callback(google::nearby::identity::v1::PublishDeviceResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetAccountInfo(
|
||||||
|
google::nearby::identity::v1::GetAccountInfoRequest request,
|
||||||
|
absl::Duration timeout, GetAccountInfoCallback callback) override {
|
||||||
|
static_cast<void>(request);
|
||||||
|
static_cast<void>(timeout);
|
||||||
|
callback(google::nearby::identity::v1::GetAccountInfoResponse());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace internal
|
||||||
|
|
||||||
|
class GrpcAsyncClientFactory {
|
||||||
|
public:
|
||||||
|
GrpcAsyncClientFactory(AccountManager* account_manager, Clock* clock,
|
||||||
|
analytics::AnalyticsRecorder* analytics_recorder) {
|
||||||
|
static_cast<void>(account_manager);
|
||||||
|
static_cast<void>(clock);
|
||||||
|
static_cast<void>(analytics_recorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<nearby::sharing::api::SharingRpcClient> CreateInstance() {
|
||||||
|
return std::make_unique<internal::NoOpSharingRpcClient>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
|
||||||
|
CreateIdentityInstance() {
|
||||||
|
return std::make_unique<internal::NoOpIdentityRpcClient>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing::platform::common
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_RPC_GRPC_ASYNC_CLIENT_FACTORY_H_
|
||||||
|
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_RPC_IDENTITY_RPC_TYPES_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_RPC_IDENTITY_RPC_TYPES_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "google/protobuf/timestamp.pb.h"
|
||||||
|
|
||||||
|
namespace google::nearby::identity::v1 {
|
||||||
|
|
||||||
|
class SharedCredential {
|
||||||
|
public:
|
||||||
|
enum DataType {
|
||||||
|
DATA_TYPE_UNKNOWN = 0,
|
||||||
|
DATA_TYPE_PUBLIC_CERTIFICATE = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_id(uint64_t id) { id_ = id; }
|
||||||
|
uint64_t id() const { return id_; }
|
||||||
|
void set_data(std::string data) { data_ = std::move(data); }
|
||||||
|
const std::string& data() const { return data_; }
|
||||||
|
void set_data_type(DataType data_type) { data_type_ = data_type; }
|
||||||
|
DataType data_type() const { return data_type_; }
|
||||||
|
google::protobuf::Timestamp* mutable_expiration_time() {
|
||||||
|
return &expiration_time_;
|
||||||
|
}
|
||||||
|
const google::protobuf::Timestamp& expiration_time() const {
|
||||||
|
return expiration_time_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint64_t id_ = 0;
|
||||||
|
std::string data_;
|
||||||
|
DataType data_type_ = DATA_TYPE_UNKNOWN;
|
||||||
|
google::protobuf::Timestamp expiration_time_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PerVisibilitySharedCredentials {
|
||||||
|
public:
|
||||||
|
enum Visibility {
|
||||||
|
VISIBILITY_UNKNOWN = 0,
|
||||||
|
VISIBILITY_SELF = 1,
|
||||||
|
VISIBILITY_CONTACTS = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_visibility(Visibility visibility) { visibility_ = visibility; }
|
||||||
|
Visibility visibility() const { return visibility_; }
|
||||||
|
SharedCredential* add_shared_credentials() {
|
||||||
|
shared_credentials_.emplace_back();
|
||||||
|
return &shared_credentials_.back();
|
||||||
|
}
|
||||||
|
const std::vector<SharedCredential>& shared_credentials() const {
|
||||||
|
return shared_credentials_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Visibility visibility_ = VISIBILITY_UNKNOWN;
|
||||||
|
std::vector<SharedCredential> shared_credentials_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Device {
|
||||||
|
public:
|
||||||
|
enum Contact {
|
||||||
|
CONTACT_UNKNOWN = 0,
|
||||||
|
CONTACT_GOOGLE_CONTACT = 1,
|
||||||
|
CONTACT_GOOGLE_CONTACT_LATEST = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_name(std::string name) { name_ = std::move(name); }
|
||||||
|
const std::string& name() const { return name_; }
|
||||||
|
void set_display_name(std::string display_name) {
|
||||||
|
display_name_ = std::move(display_name);
|
||||||
|
}
|
||||||
|
const std::string& display_name() const { return display_name_; }
|
||||||
|
void set_contact(Contact contact) { contact_ = contact; }
|
||||||
|
Contact contact() const { return contact_; }
|
||||||
|
PerVisibilitySharedCredentials* add_per_visibility_shared_credentials() {
|
||||||
|
per_visibility_shared_credentials_.emplace_back();
|
||||||
|
return &per_visibility_shared_credentials_.back();
|
||||||
|
}
|
||||||
|
const std::vector<PerVisibilitySharedCredentials>&
|
||||||
|
per_visibility_shared_credentials() const {
|
||||||
|
return per_visibility_shared_credentials_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
std::string display_name_;
|
||||||
|
Contact contact_ = CONTACT_UNKNOWN;
|
||||||
|
std::vector<PerVisibilitySharedCredentials> per_visibility_shared_credentials_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QuerySharedCredentialsRequest {
|
||||||
|
public:
|
||||||
|
void set_name(std::string name) { name_ = std::move(name); }
|
||||||
|
const std::string& name() const { return name_; }
|
||||||
|
void set_page_token(std::string page_token) {
|
||||||
|
page_token_ = std::move(page_token);
|
||||||
|
}
|
||||||
|
const std::string& page_token() const { return page_token_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
std::string page_token_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QuerySharedCredentialsResponse {
|
||||||
|
public:
|
||||||
|
SharedCredential* add_shared_credentials() {
|
||||||
|
shared_credentials_.emplace_back();
|
||||||
|
return &shared_credentials_.back();
|
||||||
|
}
|
||||||
|
const std::vector<SharedCredential>& shared_credentials() const {
|
||||||
|
return shared_credentials_;
|
||||||
|
}
|
||||||
|
void set_next_page_token(std::string next_page_token) {
|
||||||
|
next_page_token_ = std::move(next_page_token);
|
||||||
|
}
|
||||||
|
const std::string& next_page_token() const { return next_page_token_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<SharedCredential> shared_credentials_;
|
||||||
|
std::string next_page_token_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QuerySharedCredentialsWithBindingIdsRequest
|
||||||
|
: public QuerySharedCredentialsRequest {};
|
||||||
|
|
||||||
|
class QuerySharedCredentialsWithBindingIdsResponse
|
||||||
|
: public QuerySharedCredentialsResponse {};
|
||||||
|
|
||||||
|
class PublishDeviceRequest {
|
||||||
|
public:
|
||||||
|
Device* mutable_device() { return &device_; }
|
||||||
|
const Device& device() const { return device_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Device device_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PublishDeviceResponse {
|
||||||
|
public:
|
||||||
|
enum ContactUpdate {
|
||||||
|
CONTACT_UPDATE_UNKNOWN = 0,
|
||||||
|
CONTACT_UPDATE_REMOVED = 1,
|
||||||
|
CONTACT_UPDATE_ADDED = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
void add_contact_updates(ContactUpdate contact_update) {
|
||||||
|
contact_updates_.push_back(contact_update);
|
||||||
|
}
|
||||||
|
const std::vector<ContactUpdate>& contact_updates() const {
|
||||||
|
return contact_updates_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ContactUpdate> contact_updates_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GetAccountInfoRequest {};
|
||||||
|
|
||||||
|
class AccountInfo {
|
||||||
|
public:
|
||||||
|
enum Capability {
|
||||||
|
CAPABILITY_UNSPECIFIED = 0,
|
||||||
|
CAPABILITY_UNKNOWN = 0,
|
||||||
|
CAPABILITY_TITANIUM = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
void add_capabilities(Capability capability) {
|
||||||
|
capabilities_.push_back(capability);
|
||||||
|
}
|
||||||
|
const std::vector<Capability>& capabilities() const { return capabilities_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Capability> capabilities_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GetAccountInfoResponse {
|
||||||
|
public:
|
||||||
|
AccountInfo* mutable_account_info() { return &account_info_; }
|
||||||
|
const AccountInfo& account_info() const { return account_info_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
AccountInfo account_info_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace google::nearby::identity::v1
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_RPC_IDENTITY_RPC_TYPES_H_
|
||||||
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_RPC_SHARING_RPC_CLIENT_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_RPC_SHARING_RPC_CLIENT_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
|
#include "absl/time/time.h"
|
||||||
|
#include "location/nearby/sharing/lib/rpc/identity_rpc_types.h"
|
||||||
|
#include "sharing/proto/contact_rpc.pb.h"
|
||||||
|
|
||||||
|
namespace nearby::sharing::api {
|
||||||
|
|
||||||
|
class SharingRpcClient {
|
||||||
|
public:
|
||||||
|
using ListContactPeopleCallback = std::function<void(
|
||||||
|
const absl::StatusOr<nearby::sharing::proto::ListContactPeopleResponse>&)>;
|
||||||
|
|
||||||
|
virtual ~SharingRpcClient() = default;
|
||||||
|
|
||||||
|
virtual void ListContactPeople(
|
||||||
|
nearby::sharing::proto::ListContactPeopleRequest request,
|
||||||
|
ListContactPeopleCallback callback) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IdentityRpcClient {
|
||||||
|
public:
|
||||||
|
static constexpr absl::Duration kTimeout = absl::Seconds(30);
|
||||||
|
|
||||||
|
using QuerySharedCredentialsCallback = std::function<void(
|
||||||
|
const absl::StatusOr<
|
||||||
|
google::nearby::identity::v1::QuerySharedCredentialsResponse>&)>;
|
||||||
|
using QuerySharedCredentialsWithBindingIdsCallback = std::function<void(
|
||||||
|
const absl::StatusOr<google::nearby::identity::v1::
|
||||||
|
QuerySharedCredentialsWithBindingIdsResponse>&)>;
|
||||||
|
using PublishDeviceCallback = std::function<void(
|
||||||
|
const absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>&)>;
|
||||||
|
using GetAccountInfoCallback = std::function<void(
|
||||||
|
const absl::StatusOr<
|
||||||
|
google::nearby::identity::v1::GetAccountInfoResponse>&)>;
|
||||||
|
|
||||||
|
virtual ~IdentityRpcClient() = default;
|
||||||
|
|
||||||
|
virtual void QuerySharedCredentials(
|
||||||
|
google::nearby::identity::v1::QuerySharedCredentialsRequest request,
|
||||||
|
absl::Duration timeout, QuerySharedCredentialsCallback callback) = 0;
|
||||||
|
virtual void QuerySharedCredentialsWithBindingIds(
|
||||||
|
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
|
||||||
|
request,
|
||||||
|
absl::Duration timeout,
|
||||||
|
QuerySharedCredentialsWithBindingIdsCallback callback) = 0;
|
||||||
|
virtual void PublishDevice(
|
||||||
|
google::nearby::identity::v1::PublishDeviceRequest request,
|
||||||
|
absl::Duration timeout, PublishDeviceCallback callback) = 0;
|
||||||
|
virtual void GetAccountInfo(
|
||||||
|
google::nearby::identity::v1::GetAccountInfoRequest request,
|
||||||
|
absl::Duration timeout, GetAccountInfoCallback callback) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing::api
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_RPC_SHARING_RPC_CLIENT_H_
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "sync_binding_prefs_cc_proto",
|
||||||
|
hdrs = ["sync_binding_prefs.pb.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "sync_manager",
|
||||||
|
hdrs = ["sync_manager.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
":sync_binding_prefs_cc_proto",
|
||||||
|
"//internal/base:file_path",
|
||||||
|
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
|
||||||
|
"//sharing/internal/api:platform",
|
||||||
|
"@com_google_absl//absl/functional:any_invocable",
|
||||||
|
"@com_google_absl//absl/status",
|
||||||
|
"@com_google_absl//absl/status:statusor",
|
||||||
|
"@com_google_absl//absl/strings",
|
||||||
|
"@com_google_absl//absl/strings:string_view",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_BINDING_PREFS_PB_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_BINDING_PREFS_PB_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace nearby::sharing::sync {
|
||||||
|
|
||||||
|
class SyncBinding {
|
||||||
|
public:
|
||||||
|
enum SourceDeviceType {
|
||||||
|
SOURCE_DEVICE_TYPE_UNKNOWN = 0,
|
||||||
|
SOURCE_DEVICE_TYPE_PHONE = 1,
|
||||||
|
SOURCE_DEVICE_TYPE_TABLET = 2,
|
||||||
|
SOURCE_DEVICE_TYPE_LAPTOP = 3,
|
||||||
|
SOURCE_DEVICE_TYPE_CAR = 4,
|
||||||
|
SOURCE_DEVICE_TYPE_FOLDABLE = 5,
|
||||||
|
SOURCE_DEVICE_TYPE_XR = 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_binding_id(std::string binding_id) {
|
||||||
|
binding_id_ = std::move(binding_id);
|
||||||
|
}
|
||||||
|
void set_binding_id(std::string_view binding_id) {
|
||||||
|
binding_id_ = std::string(binding_id);
|
||||||
|
}
|
||||||
|
const std::string& binding_id() const { return binding_id_; }
|
||||||
|
void set_source_name(std::string source_name) {
|
||||||
|
source_name_ = std::move(source_name);
|
||||||
|
}
|
||||||
|
void set_source_name(std::string_view source_name) {
|
||||||
|
source_name_ = std::string(source_name);
|
||||||
|
}
|
||||||
|
const std::string& source_name() const { return source_name_; }
|
||||||
|
void set_destination_directory(std::string destination_directory) {
|
||||||
|
destination_directory_ = std::move(destination_directory);
|
||||||
|
}
|
||||||
|
void set_destination_directory(std::string_view destination_directory) {
|
||||||
|
destination_directory_ = std::string(destination_directory);
|
||||||
|
}
|
||||||
|
const std::string& destination_directory() const {
|
||||||
|
return destination_directory_;
|
||||||
|
}
|
||||||
|
void set_source_device_type(SourceDeviceType source_device_type) {
|
||||||
|
source_device_type_ = source_device_type;
|
||||||
|
}
|
||||||
|
SourceDeviceType source_device_type() const { return source_device_type_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string binding_id_;
|
||||||
|
std::string source_name_;
|
||||||
|
std::string destination_directory_;
|
||||||
|
SourceDeviceType source_device_type_ = SOURCE_DEVICE_TYPE_UNKNOWN;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SyncBindingPrefs {
|
||||||
|
public:
|
||||||
|
static const SyncBindingPrefs& default_instance() {
|
||||||
|
static const SyncBindingPrefs* prefs = new SyncBindingPrefs();
|
||||||
|
return *prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncBinding* add_sync_bindings() {
|
||||||
|
sync_bindings_.emplace_back();
|
||||||
|
return &sync_bindings_.back();
|
||||||
|
}
|
||||||
|
const std::vector<SyncBinding>& sync_bindings() const {
|
||||||
|
return sync_bindings_;
|
||||||
|
}
|
||||||
|
const SyncBinding& sync_bindings(int index) const {
|
||||||
|
return sync_bindings_.at(index);
|
||||||
|
}
|
||||||
|
int sync_bindings_size() const {
|
||||||
|
return static_cast<int>(sync_bindings_.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SerializeToString(std::string* output) const {
|
||||||
|
if (output == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
output->clear();
|
||||||
|
for (const SyncBinding& binding : sync_bindings_) {
|
||||||
|
output->append(Escape(binding.binding_id()));
|
||||||
|
output->push_back('\t');
|
||||||
|
output->append(Escape(binding.source_name()));
|
||||||
|
output->push_back('\t');
|
||||||
|
output->append(Escape(binding.destination_directory()));
|
||||||
|
output->push_back('\t');
|
||||||
|
output->append(std::to_string(static_cast<int>(binding.source_device_type())));
|
||||||
|
output->push_back('\n');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParseFromString(const std::string& input) {
|
||||||
|
sync_bindings_.clear();
|
||||||
|
size_t start = 0;
|
||||||
|
while (start < input.size()) {
|
||||||
|
size_t end = input.find('\n', start);
|
||||||
|
std::string line = input.substr(start, end == std::string::npos
|
||||||
|
? std::string::npos
|
||||||
|
: end - start);
|
||||||
|
if (!line.empty()) {
|
||||||
|
std::vector<std::string> fields;
|
||||||
|
size_t field_start = 0;
|
||||||
|
while (fields.size() < 4) {
|
||||||
|
size_t field_end = line.find('\t', field_start);
|
||||||
|
fields.push_back(Unescape(line.substr(
|
||||||
|
field_start, field_end == std::string::npos
|
||||||
|
? std::string::npos
|
||||||
|
: field_end - field_start)));
|
||||||
|
if (field_end == std::string::npos) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
field_start = field_end + 1;
|
||||||
|
}
|
||||||
|
if (fields.size() != 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SyncBinding binding;
|
||||||
|
binding.set_binding_id(fields[0]);
|
||||||
|
binding.set_source_name(fields[1]);
|
||||||
|
binding.set_destination_directory(fields[2]);
|
||||||
|
binding.set_source_device_type(
|
||||||
|
static_cast<SyncBinding::SourceDeviceType>(std::stoi(fields[3])));
|
||||||
|
sync_bindings_.push_back(std::move(binding));
|
||||||
|
}
|
||||||
|
if (end == std::string::npos) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
start = end + 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::string Escape(const std::string& value) {
|
||||||
|
std::string escaped;
|
||||||
|
for (char c : value) {
|
||||||
|
if (c == '\\' || c == '\t' || c == '\n') {
|
||||||
|
escaped.push_back('\\');
|
||||||
|
}
|
||||||
|
if (c == '\t') {
|
||||||
|
escaped.push_back('t');
|
||||||
|
} else if (c == '\n') {
|
||||||
|
escaped.push_back('n');
|
||||||
|
} else {
|
||||||
|
escaped.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string Unescape(const std::string& value) {
|
||||||
|
std::string unescaped;
|
||||||
|
bool escaping = false;
|
||||||
|
for (char c : value) {
|
||||||
|
if (escaping) {
|
||||||
|
if (c == 't') {
|
||||||
|
unescaped.push_back('\t');
|
||||||
|
} else if (c == 'n') {
|
||||||
|
unescaped.push_back('\n');
|
||||||
|
} else {
|
||||||
|
unescaped.push_back(c);
|
||||||
|
}
|
||||||
|
escaping = false;
|
||||||
|
} else if (c == '\\') {
|
||||||
|
escaping = true;
|
||||||
|
} else {
|
||||||
|
unescaped.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unescaped;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<SyncBinding> sync_bindings_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SyncConfigPrefs {
|
||||||
|
public:
|
||||||
|
bool SerializeToString(std::string* output) const {
|
||||||
|
if (output == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
output->clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParseFromString(const std::string& input) {
|
||||||
|
return input.empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing::sync
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_BINDING_PREFS_PB_H_
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_MANAGER_H_
|
||||||
|
#define LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_MANAGER_H_
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "absl/functional/any_invocable.h"
|
||||||
|
#include "absl/status/status.h"
|
||||||
|
#include "absl/status/statusor.h"
|
||||||
|
#include "absl/strings/str_cat.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
#include "internal/base/file_path.h"
|
||||||
|
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
|
||||||
|
#include "location/nearby/sharing/lib/sync/sync_binding_prefs.pb.h"
|
||||||
|
#include "sharing/internal/api/preference_manager.h"
|
||||||
|
|
||||||
|
namespace nearby::sharing {
|
||||||
|
|
||||||
|
class SyncManager {
|
||||||
|
public:
|
||||||
|
SyncManager(api::IdentityRpcClient* identity_client,
|
||||||
|
api::PreferenceManager* preference_manager)
|
||||||
|
: identity_client_(identity_client), preference_manager_(preference_manager) {}
|
||||||
|
|
||||||
|
explicit SyncManager(api::PreferenceManager* preference_manager)
|
||||||
|
: SyncManager(nullptr, preference_manager) {}
|
||||||
|
|
||||||
|
void AsyncInitiateSyncBinding(
|
||||||
|
absl::AnyInvocable<void(absl::StatusOr<std::string>)> callback) {
|
||||||
|
static_cast<void>(identity_client_);
|
||||||
|
if (callback) {
|
||||||
|
std::move(callback)(absl::UnavailableError(
|
||||||
|
"Sync binding RPC is not available in this build"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSyncBinding(const sync::SyncBinding& binding) {
|
||||||
|
if (preference_manager_ == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sync::SyncBindingPrefs prefs =
|
||||||
|
preference_manager_->GetSyncBindingValue().value_or(
|
||||||
|
sync::SyncBindingPrefs());
|
||||||
|
sync::SyncBinding* stored = prefs.add_sync_bindings();
|
||||||
|
*stored = binding;
|
||||||
|
preference_manager_->SetSyncBindingValue(prefs);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<sync::SyncBinding> GetSyncBinding(
|
||||||
|
absl::string_view binding_id) const {
|
||||||
|
if (preference_manager_ == nullptr) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
std::optional<sync::SyncBindingPrefs> prefs =
|
||||||
|
preference_manager_->GetSyncBindingValue();
|
||||||
|
if (!prefs.has_value()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
for (const sync::SyncBinding& binding : prefs->sync_bindings()) {
|
||||||
|
if (binding.binding_id() == binding_id) {
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsFileSyncBinding(absl::string_view binding_id) const {
|
||||||
|
return GetSyncBinding(binding_id).has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<sync::SyncConfigPrefs> GetSyncConfig(
|
||||||
|
absl::string_view binding_id) const {
|
||||||
|
static_cast<void>(binding_id);
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
absl::StatusOr<FilePath> UpdateSyncBindingDestinationDirectory(
|
||||||
|
absl::string_view binding_id, FilePath save_path) {
|
||||||
|
if (preference_manager_ == nullptr) {
|
||||||
|
return absl::FailedPreconditionError("Preference manager is unavailable");
|
||||||
|
}
|
||||||
|
sync::SyncBindingPrefs prefs =
|
||||||
|
preference_manager_->GetSyncBindingValue().value_or(
|
||||||
|
sync::SyncBindingPrefs());
|
||||||
|
std::optional<FilePath> original_path;
|
||||||
|
sync::SyncBindingPrefs updated_prefs;
|
||||||
|
for (const sync::SyncBinding& binding : prefs.sync_bindings()) {
|
||||||
|
sync::SyncBinding* updated_binding = updated_prefs.add_sync_bindings();
|
||||||
|
*updated_binding = binding;
|
||||||
|
if (binding.binding_id() == binding_id) {
|
||||||
|
original_path = FilePath(binding.destination_directory());
|
||||||
|
updated_binding->set_destination_directory(save_path.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!original_path.has_value()) {
|
||||||
|
return absl::NotFoundError(
|
||||||
|
absl::StrCat("Sync binding not found: ", binding_id));
|
||||||
|
}
|
||||||
|
preference_manager_->SetSyncBindingValue(updated_prefs);
|
||||||
|
return *original_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
api::IdentityRpcClient* identity_client_;
|
||||||
|
api::PreferenceManager* preference_manager_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nearby::sharing
|
||||||
|
|
||||||
|
#endif // LOCATION_NEARBY_SHARING_LIB_SYNC_SYNC_MANAGER_H_
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "highway_fingerprint",
|
||||||
|
hdrs = ["highway_fingerprint.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"@com_google_absl//absl/hash",
|
||||||
|
"@com_google_absl//absl/strings:string_view",
|
||||||
|
],
|
||||||
|
)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2026 Google LLC
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// https://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 THIRD_PARTY_NEARBY_SHARING_LINUX_STUBS_HIGHWAY_FINGERPRINT_H_
|
||||||
|
#define THIRD_PARTY_NEARBY_SHARING_LINUX_STUBS_HIGHWAY_FINGERPRINT_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "absl/hash/hash.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
|
||||||
|
namespace util_hash {
|
||||||
|
|
||||||
|
inline uint64_t HighwayFingerprint64(absl::string_view input) {
|
||||||
|
return absl::Hash<absl::string_view>{}(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace util_hash
|
||||||
|
|
||||||
|
#endif // THIRD_PARTY_NEARBY_SHARING_LINUX_STUBS_HIGHWAY_FINGERPRINT_H_
|
||||||
Reference in New Issue
Block a user