Implement Protocol, Constant

PiperOrigin-RevId: 494858330
This commit is contained in:
Qin Wang
2022-12-12 16:21:35 -08:00
committed by Copybara-Service
parent d1ddee09f0
commit f73b23e720
6 changed files with 138 additions and 5 deletions
+18
View File
@@ -0,0 +1,18 @@
licenses(["notice"])
cc_library(
name = "common",
srcs = [
"protocol.cc",
],
hdrs = [
"constant.h",
"protocol.h",
],
visibility = [
"//fastpair:__subpackages__",
],
deps = [
"@com_google_absl//absl/container:flat_hash_map",
],
)
+38
View File
@@ -0,0 +1,38 @@
// Copyright 2022 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_CONSTANT_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_CONSTANT_H_
namespace location {
namespace nearby {
namespace fastpair {
constexpr char kServiceId[] = "Fast Pair";
constexpr char kFastPairServiceUuid[] = "0000FE2C-0000-1000-8000-00805F9B34FB";
const char kKeyBasedPairingCharacteristicUuidV1[] = "1234";
const char kKeyBasedPairingCharacteristicUuidV2[] =
"FE2C1234-8366-4814-8EB0-01DE32100BEA";
const char kPasskeyCharacteristicUuidV1[] = "1235";
const char kPasskeyCharacteristicUuidV2[] =
"FE2C1235-8366-4814-8EB0-01DE32100BEA";
const char kAccountKeyCharacteristicUuidV1[] = "1236";
const char kAccountKeyCharacteristicUuidV2[] =
"FE2C1236-8366-4814-8EB0-01DE32100BEA";
} // namespace fastpair
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_CONSTANT_H_
+41
View File
@@ -0,0 +1,41 @@
// Copyright 2022 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/protocol.h"
#include <ostream>
namespace location {
namespace nearby {
namespace fastpair {
std::ostream& operator<<(std::ostream& stream, Protocol protocol) {
switch (protocol) {
case Protocol::kFastPairInitialPairing:
stream << "[Fast Pair Initial Pairing]";
break;
case Protocol::kFastPairRetroactivePairing:
stream << "[Fast Pair Retroactive Pairing]";
break;
case Protocol::kFastPairSubsequentPairing:
stream << "[Fast Pair Subsequent Pairing]";
break;
}
return stream;
}
} // namespace fastpair
} // namespace nearby
} // namespace location
+38
View File
@@ -0,0 +1,38 @@
// Copyright 2022 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_PROTOCOL_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_PROTOCOL_H_
#include <ostream>
namespace location {
namespace nearby {
namespace fastpair {
// Pairing scenarios
enum class Protocol {
// Google Fast Pair
kFastPairInitialPairing = 0,
kFastPairRetroactivePairing = 1,
kFastPairSubsequentPairing = 2,
};
std::ostream& operator<<(std::ostream& stream, Protocol protocol);
} // namespace fastpair
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_PROTOCOL_H_
+2
View File
@@ -23,9 +23,11 @@ cc_library(
"fast_pair_scanner_impl.h",
],
visibility = [
"//:__subpackages__",
"//fastpair:__subpackages__",
],
deps = [
"//fastpair/common",
"//fastpair/internal/ble",
"//internal/platform:base",
"//internal/platform:comm",
@@ -18,17 +18,13 @@
#include "absl/functional/bind_front.h"
#include "absl/strings/escaping.h"
#include "fastpair/common/constant.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace fastpair {
namespace {
constexpr char kServiceId[] = "Fast Pair";
constexpr char kFastPairServiceUuid[] =
"0000FE2C-0000-1000-8000-00805F9B34FB";
} // namespace
bool FastPairScannerImpl::StartScanning() {
if (ble_.Enable() &&