mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Add Fast Pair Preferences.
PiperOrigin-RevId: 538597935
This commit is contained in:
committed by
Copybara-Service
parent
c786b07fcf
commit
2027fed32f
@@ -7,6 +7,7 @@ cc_library(
|
||||
"battery_notification.cc",
|
||||
"fast_pair_device.cc",
|
||||
"fast_pair_http_result.cc",
|
||||
"fast_pair_prefs.cc",
|
||||
"pair_failure.cc",
|
||||
"protocol.cc",
|
||||
],
|
||||
@@ -17,6 +18,7 @@ cc_library(
|
||||
"constant.h",
|
||||
"fast_pair_device.h",
|
||||
"fast_pair_http_result.h",
|
||||
"fast_pair_prefs.h",
|
||||
"non_discoverable_advertisement.h",
|
||||
"pair_failure.h",
|
||||
"protocol.h",
|
||||
@@ -27,6 +29,8 @@ cc_library(
|
||||
deps = [
|
||||
"//internal/crypto",
|
||||
"//internal/platform:logging",
|
||||
"//internal/preferences",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/strings",
|
||||
@@ -94,3 +98,18 @@ cc_test(
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "fast_pair_prefs_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"fast_pair_prefs_test.cc",
|
||||
],
|
||||
shard_count = 16,
|
||||
deps = [
|
||||
":common",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2023 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 "fastpair/common/fast_pair_prefs.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
namespace prefs {
|
||||
namespace {
|
||||
using json = ::nlohmann::json;
|
||||
}
|
||||
|
||||
const char kNearbyFastPairUsersName[] = "nearby_fastpair.users";
|
||||
|
||||
void RegisterNearbyFastPairPrefs(
|
||||
preferences::PreferencesManager* preferences_manager) {
|
||||
preferences_manager->Set(kNearbyFastPairUsersName, json::object());
|
||||
}
|
||||
|
||||
} // namespace prefs
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright 2023 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_FASTPAIR_COMMON_FASTPAIR_PREFS_H_
|
||||
#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FASTPAIR_PREFS_H_
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "internal/preferences/preferences_manager.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
namespace prefs {
|
||||
|
||||
ABSL_CONST_INIT extern const char kNearbyFastPairUsersName[];
|
||||
|
||||
void RegisterNearbyFastPairPrefs(
|
||||
preferences::PreferencesManager* preferences_manager);
|
||||
|
||||
} // namespace prefs
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FASTPAIR_PREFS_H_
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2023 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 "fastpair/common/fast_pair_prefs.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace fastpair {
|
||||
namespace prefs {
|
||||
namespace {
|
||||
|
||||
using json = ::nlohmann::json;
|
||||
|
||||
constexpr char kPreferencesFilePath[] = "Google/Nearby/Preferences";
|
||||
|
||||
TEST(FastPairPreference, RegisterNearbyFastPairPrefs) {
|
||||
auto preferences_manager =
|
||||
std::make_unique<preferences::PreferencesManager>(kPreferencesFilePath);
|
||||
RegisterNearbyFastPairPrefs(preferences_manager.get());
|
||||
EXPECT_TRUE(
|
||||
preferences_manager->Get(kNearbyFastPairUsersName, json()).empty());
|
||||
|
||||
json value = {{"current_user", "abc@gmail.com"}};
|
||||
preferences_manager->Set(kNearbyFastPairUsersName, value);
|
||||
auto result = preferences_manager->Get(kNearbyFastPairUsersName, json());
|
||||
ASSERT_FALSE(result.empty());
|
||||
auto val = result["current_user"];
|
||||
EXPECT_EQ(val.get<std::string>(), "abc@gmail.com");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace prefs
|
||||
} // namespace fastpair
|
||||
} // namespace nearby
|
||||
Reference in New Issue
Block a user