Add manager_app_id to scan and broadcast requests

PiperOrigin-RevId: 485745403
This commit is contained in:
Hai Shang
2022-11-02 18:14:27 -07:00
committed by Copybara-Service
parent c4dc132f50
commit b056e6561a
6 changed files with 29 additions and 3 deletions
+1
View File
@@ -89,6 +89,7 @@ cc_test(
":types",
"//internal/proto:credential_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:variant",
"@com_google_googletest//:gtest_main",
],
+3
View File
@@ -48,6 +48,9 @@ struct PresenceBroadcast {
// Account name used to select private credentials.
std::string account_name;
// Manager app id, used to select private credentials.
std::string manager_app_id;
};
std::vector<BroadcastSection> sections;
+6 -2
View File
@@ -92,7 +92,7 @@ inline bool operator==(const LegacyPresenceScanFilter& a,
return false;
for (int i = 0; i < a.remote_public_credentials.size(); ++i) {
if (a.remote_public_credentials[i].SerializeAsString() !=
b.remote_public_credentials[i].SerializeAsString())
b.remote_public_credentials[i].SerializeAsString())
return false;
}
return true;
@@ -111,6 +111,9 @@ struct ScanRequest {
// to broadcast.
std::string account_name;
// Specifies which manager app to use to get credendentials for scan.
std::string manager_app_id;
// Used to specify which types of remote PublicCredential to use during the
// scan. If empty, use all available types of remote PublicCredential.
std::vector<nearby::internal::IdentityType> identity_types;
@@ -134,7 +137,8 @@ inline bool operator==(const ScanRequest& a, const ScanRequest& b) {
return a.scan_only_when_screen_on == b.scan_only_when_screen_on &&
a.power_mode == b.power_mode && a.scan_type == b.scan_type &&
a.use_ble == b.use_ble && a.account_name == b.account_name &&
a.identity_types == b.identity_types;
a.identity_types == b.identity_types &&
a.manager_app_id == b.manager_app_id;
}
inline bool operator!=(const ScanRequest& a, const ScanRequest& b) {
+6
View File
@@ -77,6 +77,12 @@ ScanRequestBuilder& ScanRequestBuilder::SetOnlyScreenOnScan(
return *this;
}
ScanRequestBuilder& ScanRequestBuilder::SetManagerAppId(
absl::string_view manager_app_id) {
request_.manager_app_id = std::string(manager_app_id);
return *this;
}
ScanRequest ScanRequestBuilder::Build() { return this->request_; }
} // namespace presence
+1
View File
@@ -44,6 +44,7 @@ class ScanRequestBuilder {
scan_filters);
ScanRequestBuilder& SetUseBle(bool use_ble);
ScanRequestBuilder& SetOnlyScreenOnScan(bool screen_on_only_scan);
ScanRequestBuilder& SetManagerAppId(absl::string_view manager_app_id);
ScanRequest Build();
inline bool operator==(const ScanRequestBuilder& other) const {
return request_ == other.request_;
+12 -1
View File
@@ -19,6 +19,7 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "internal/proto/credential.pb.h"
#include "presence/power_mode.h"
#include "presence/scan_request.h"
@@ -29,12 +30,13 @@ namespace {
using ::nearby::internal::IdentityType;
constexpr char kAccountName[] = "Google User";
constexpr absl::string_view kAccountName = "Google User";
constexpr bool kUseBle = true;
constexpr bool kOnlyScreenOnScan = true;
const IdentityType kIdentity = IdentityType::IDENTITY_TYPE_PRIVATE;
const ScanType kScanType = ScanType::kPresenceScan;
const PowerMode powerMode = PowerMode::kLowLatency;
constexpr absl::string_view kManagerAppId = "Google App Manager";
DataElement CreateTestDataElement() {
return {DataElement::kTxPowerFieldType, "1"};
}
@@ -149,6 +151,13 @@ TEST(ScanRequestBuilderTest, TestSetUseBle) {
EXPECT_EQ(sr.use_ble, kUseBle);
}
TEST(ScanRequestBuilderTest, TestSetManagerAppId) {
ScanRequestBuilder builder;
builder.SetManagerAppId(kManagerAppId);
ScanRequest sr = builder.Build();
EXPECT_EQ(sr.manager_app_id, kManagerAppId);
}
TEST(ScanRequestBuilderTest, TestSetOnlyScreenOnScan) {
ScanRequestBuilder builder;
builder.SetOnlyScreenOnScan(kOnlyScreenOnScan);
@@ -162,11 +171,13 @@ TEST(ScanRequestBuilderTest, TestChainCalls) {
.SetPowerMode(powerMode)
.SetOnlyScreenOnScan(kOnlyScreenOnScan)
.SetUseBle(kUseBle)
.SetManagerAppId(kManagerAppId)
.Build();
EXPECT_EQ(sr.account_name, kAccountName);
EXPECT_EQ(sr.scan_only_when_screen_on, kOnlyScreenOnScan);
EXPECT_EQ(sr.power_mode, powerMode);
EXPECT_EQ(sr.use_ble, kUseBle);
EXPECT_EQ(sr.manager_app_id, kManagerAppId);
}
TEST(ScanRequestBuilderTest, TestCopy) {