Remove presence_identity struct.

PiperOrigin-RevId: 468032143
This commit is contained in:
Xin He
2022-08-16 14:56:38 -07:00
committed by Copybara-Service
parent 0849bc7598
commit f166f1e22c
17 changed files with 29 additions and 131 deletions
-1
View File
@@ -77,7 +77,6 @@ cc_library(
"//internal/platform:cancellation_flag",
"//internal/platform:uuid",
"//internal/proto:credential_cc_proto",
"//presence:credential",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",
],
@@ -22,7 +22,6 @@
#include "internal/platform/exception.h"
#include "internal/proto/credential.pb.h"
#include "presence/presence_identity.h"
namespace location {
namespace nearby {
-14
View File
@@ -58,7 +58,6 @@ cc_library(
"status.h",
],
deps = [
":credential",
"//net/proto2/util/public:differencer",
"//internal/platform:base",
"//internal/proto:credential_cc_proto",
@@ -68,17 +67,6 @@ cc_library(
],
)
cc_library(
name = "credential",
srcs = ["presence_identity.cc"],
hdrs = [
"presence_identity.h",
],
visibility = [
"//third_party/nearby:__subpackages__",
],
)
cc_test(
name = "types_test",
size = "small",
@@ -96,7 +84,6 @@ cc_test(
],
shard_count = 6,
deps = [
":credential",
":types",
"//internal/proto:credential_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -114,7 +101,6 @@ cc_test(
],
shard_count = 6,
deps = [
":credential",
"//internal/platform:uuid",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//internal/proto:credential_cc_proto",
+4 -2
View File
@@ -17,15 +17,17 @@
namespace nearby {
namespace presence {
using ::nearby::internal::IdentityType;
DiscoveryFilter::DiscoveryFilter(
const std::vector<PresenceAction>& actions,
const std::vector<PresenceIdentity>& identities,
const std::vector<IdentityType>& identities,
const std::vector<PresenceZone>& zones) noexcept
: actions_(actions), identities_(identities), zones_(zones) {}
std::vector<PresenceAction> DiscoveryFilter::GetActions() const {
return actions_;
}
std::vector<PresenceIdentity> DiscoveryFilter::GetIdentities() const {
std::vector<IdentityType> DiscoveryFilter::GetIdentities() const {
return identities_;
}
std::vector<PresenceZone> DiscoveryFilter::GetZones() const { return zones_; }
+4 -4
View File
@@ -17,23 +17,23 @@
#include <vector>
#include "internal/proto/credential.pb.h"
#include "presence/presence_action.h"
#include "presence/presence_identity.h"
#include "presence/presence_zone.h"
namespace nearby {
namespace presence {
class DiscoveryFilter {
public:
DiscoveryFilter(const std::vector<PresenceAction>& = {},
const std::vector<PresenceIdentity>& = {},
const std::vector<::nearby::internal::IdentityType>& = {},
const std::vector<PresenceZone>& = {}) noexcept;
std::vector<PresenceAction> GetActions() const;
std::vector<PresenceIdentity> GetIdentities() const;
std::vector<::nearby::internal::IdentityType> GetIdentities() const;
std::vector<PresenceZone> GetZones() const;
private:
const std::vector<PresenceAction> actions_;
const std::vector<PresenceIdentity> identities_;
const std::vector<::nearby::internal::IdentityType> identities_;
const std::vector<PresenceZone> zones_;
};
+3 -2
View File
@@ -22,9 +22,10 @@ namespace nearby {
namespace presence {
namespace {
using ::nearby::internal::IdentityType;
const PresenceAction kTestAction = {1};
const PresenceIdentity kTestIdentity = {
PresenceIdentity::IdentityType::kTrusted};
const IdentityType kTestIdentity = {IdentityType::IDENTITY_TYPE_TRUSTED};
TEST(DiscoveryFilterTest, DefaultConstructorWorks) {
DiscoveryFilter filter;
-1
View File
@@ -49,7 +49,6 @@ cc_library(
"//internal/platform/implementation:comm",
"//internal/platform/implementation:types",
"//internal/proto:credential_cc_proto",
"//presence:credential",
"//presence:types",
"//presence/implementation/mediums",
"//third_party/tink/cc/subtle",
@@ -23,7 +23,6 @@
#include "presence/data_element.h"
#include "presence/implementation/advertisement_factory.h"
#include "presence/implementation/credential_manager.h"
#include "presence/presence_identity.h"
namespace nearby {
namespace presence {
@@ -17,7 +17,6 @@
#include "absl/strings/string_view.h"
#include "internal/platform/logging.h"
#include "presence/implementation/encryption.h"
#include "presence/presence_identity.h"
namespace nearby {
namespace presence {
@@ -23,7 +23,6 @@
#include "absl/strings/string_view.h"
#include "internal/platform/implementation/credential_storage.h"
#include "internal/proto/credential.pb.h"
#include "presence/presence_identity.h"
namespace nearby {
namespace presence {
@@ -26,7 +26,6 @@
#include "internal/platform/credential_storage.h"
#include "internal/proto/credential.pb.h"
#include "presence/implementation/credential_manager.h"
#include "presence/presence_identity.h"
namespace nearby {
namespace presence {
+6 -4
View File
@@ -19,6 +19,8 @@
namespace nearby {
namespace presence {
using ::nearby::internal::IdentityType;
void PresenceClient::StartDiscovery(const DiscoveryFilter& filter,
const DiscoveryOptions& options,
ResultCallback callback) {}
@@ -33,16 +35,16 @@ std::vector<PresenceDevice> PresenceClient::GetCachedDevices(
return std::vector<PresenceDevice>{};
}
void PresenceClient::StartBroadcast(const PresenceIdentity& identity,
void PresenceClient::StartBroadcast(const IdentityType& identity,
const std::vector<PresenceAction>& actions,
const BroadcastOptions& options,
ResultCallback callback) {}
void PresenceClient::UpdateBroadcastActions(
const PresenceIdentity& identity,
const std::vector<PresenceAction>& actions, ResultCallback callback) {}
const IdentityType& identity, const std::vector<PresenceAction>& actions,
ResultCallback callback) {}
void PresenceClient::StopBroadcast(const PresenceIdentity& identity,
void PresenceClient::StopBroadcast(const IdentityType& identity,
ResultCallback callback) {}
} // namespace presence
+4 -3
View File
@@ -116,7 +116,7 @@ class PresenceClient {
* should call {@linkStatus#startResolutionForResult} to get the users
* consents/permissions before retrying the request.
*/
void StartBroadcast(const PresenceIdentity& identity,
void StartBroadcast(const ::nearby::internal::IdentityType& identity,
const std::vector<PresenceAction>& actions,
const BroadcastOptions& options, ResultCallback callback);
@@ -129,7 +129,7 @@ class PresenceClient {
* should call {@link Status#startResolutionForResult} to get the users
* consents/permissions before retrying the request.
*/
void UpdateBroadcastActions(const PresenceIdentity& identity,
void UpdateBroadcastActions(const ::nearby::internal::IdentityType& identity,
const std::vector<PresenceAction>& actions,
ResultCallback callback);
@@ -140,7 +140,8 @@ class PresenceClient {
* <p>This should be invoked after the use case has been fulfilled and the
* device no longer needs remote devices to know that it is nearby.
*/
void StopBroadcast(const PresenceIdentity& identity, ResultCallback callback);
void StopBroadcast(const ::nearby::internal::IdentityType& identity,
ResultCallback callback);
};
} // namespace presence
-28
View File
@@ -1,28 +0,0 @@
// Copyright 2020 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 "presence/presence_identity.h"
namespace nearby {
namespace presence {
PresenceIdentity::PresenceIdentity(IdentityType identity_type) noexcept
: identity_type_(identity_type) {}
PresenceIdentity::IdentityType PresenceIdentity::GetIdentityType() const {
return identity_type_;
}
} // namespace presence
} // namespace nearby
-40
View File
@@ -1,40 +0,0 @@
// Copyright 2020 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_PRESENCE_PRESENCE_IDENTITY_H_
#define THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_IDENTITY_H_
namespace nearby {
namespace presence {
class PresenceIdentity {
public:
enum class IdentityType { kPrivate = 0, kTrusted, kPublic, kProvisioned };
PresenceIdentity(IdentityType type = IdentityType::kPrivate) noexcept;
IdentityType GetIdentityType() const;
private:
const IdentityType identity_type_;
};
inline bool operator==(const PresenceIdentity& i1, const PresenceIdentity& i2) {
return i1.GetIdentityType() == i2.GetIdentityType();
}
inline bool operator!=(const PresenceIdentity& i1, const PresenceIdentity& i2) {
return !(i1 == i2);
}
} // namespace presence
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_IDENTITY_H_
+8 -26
View File
@@ -12,47 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "presence/presence_identity.h"
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/proto/credential.pb.h"
namespace nearby {
namespace presence {
namespace {
constexpr PresenceIdentity::IdentityType kDefaultIdentityType =
PresenceIdentity::IdentityType::kPrivate;
constexpr PresenceIdentity::IdentityType kTestIdentityType =
PresenceIdentity::IdentityType::kTrusted;
using ::nearby::internal::IdentityType;
TEST(PresenceIdentityTest, DefaultIsError) {
PresenceIdentity identity;
EXPECT_EQ(identity.GetIdentityType(), kDefaultIdentityType);
}
TEST(PresenceIdentityTest, DefaultEquals) {
PresenceIdentity identity1;
PresenceIdentity identity2;
EXPECT_EQ(identity1, identity2);
}
constexpr IdentityType kTestIdentityType = IdentityType::IDENTITY_TYPE_TRUSTED;
TEST(PresenceIdentityTest, ExplicitInitEquals) {
PresenceIdentity identity1 = {kTestIdentityType};
PresenceIdentity identity2 = {kTestIdentityType};
IdentityType identity1 = {kTestIdentityType};
IdentityType identity2 = {kTestIdentityType};
EXPECT_EQ(identity1, identity2);
EXPECT_EQ(identity1.GetIdentityType(), kTestIdentityType);
EXPECT_EQ(identity1, kTestIdentityType);
}
TEST(PresenceIdentityTest, ExplicitInitNotEquals) {
PresenceIdentity identity1 = {kTestIdentityType};
PresenceIdentity identity2;
EXPECT_NE(identity1, identity2);
}
TEST(PresenceIdentityTest, CopyInitEquals) {
PresenceIdentity identity1 = {kTestIdentityType};
PresenceIdentity identity2 = {identity1};
IdentityType identity1 = {kTestIdentityType};
IdentityType identity2 = {identity1};
EXPECT_EQ(identity1, identity2);
}
-1
View File
@@ -16,7 +16,6 @@
#include <vector>
#include "absl/types/variant.h"
#include "presence/presence_identity.h"
#include "presence/scan_request.h"
namespace nearby {