Add PairFailure to track errors for fast pair pairing

PiperOrigin-RevId: 513053149
This commit is contained in:
Qin Wang
2023-02-28 15:18:36 -08:00
committed by Copybara-Service
parent d750e54bc8
commit f9dec58aff
3 changed files with 176 additions and 1 deletions
+4 -1
View File
@@ -5,12 +5,14 @@ cc_library(
srcs = [
"fast_pair_device.cc",
"fast_pair_http_result.cc",
"pair_failure.cc",
"protocol.cc",
],
hdrs = [
"constant.h",
"fast_pair_device.h",
"fast_pair_http_result.h",
"pair_failure.h",
"protocol.h",
],
visibility = [
@@ -19,11 +21,12 @@ cc_library(
deps = [
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
],
)
cc_test(
name = "unit_test",
name = "fast_pair_device_test",
size = "small",
srcs = [
"fast_pair_device_test.cc",
+95
View File
@@ -0,0 +1,95 @@
// 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/pair_failure.h"
#include <ostream>
namespace nearby {
namespace fastpair {
std::ostream& operator<<(std::ostream& stream, PairFailure failure) {
switch (failure) {
case PairFailure::kCreateGattConnection:
stream << "[Failed to create a GATT connection to the device]";
break;
case PairFailure::kGattServiceDiscovery:
stream << "[Failed to find the expected GATT service]";
break;
case PairFailure::kGattServiceDiscoveryTimeout:
stream << "[Timed out while starting discovery of GATT service]";
break;
case PairFailure::kDataEncryptorRetrieval:
stream << "[Failed to retrieve the data encryptor]";
break;
case PairFailure::kKeyBasedPairingCharacteristicDiscovery:
stream << "[Failed to find the Key-based pairing GATT characteristic]";
break;
case PairFailure::kPasskeyCharacteristicDiscovery:
stream << "[Failed to find the Passkey GATT characteristic]";
break;
case PairFailure::kAccountKeyCharacteristicDiscovery:
stream << "[Failed to find the Account Key GATT characteristic]";
break;
case PairFailure::kKeyBasedPairingCharacteristicSubscription:
stream << "[Failed to start a subscription on the Key-based pairing "
"GATT characteristic]";
break;
case PairFailure::kPasskeyCharacteristicSubscription:
stream << "[Failed to start a subscription on the Passkey GATT "
"characteristic]";
break;
case PairFailure::kKeyBasedPairingCharacteristicSubscriptionTimeout:
stream << "[Timed out while starting a subscription on the Key-based "
"pairing GATT characteristic]";
break;
case PairFailure::kPasskeyCharacteristicSubscriptionTimeout:
stream << "[Timed out while starting a subscription on the Passkey "
"GATT characteristic]";
break;
case PairFailure::kKeyBasedPairingCharacteristicWrite:
stream
<< "[Failed to write to the Key-based pairing GATT characteristic]";
break;
case PairFailure::kPasskeyPairingCharacteristicWrite:
stream << "[Failed to write to the Passkey GATT characteristic]";
break;
case PairFailure::kKeyBasedPairingResponseTimeout:
stream << "[Timed out while waiting for the Key-based Pairing response]";
break;
case PairFailure::kPasskeyResponseTimeout:
stream << "[Timed out while waiting for the Passkey response]";
break;
case PairFailure::kKeybasedPairingResponseDecryptFailure:
stream << "[Failed to decrypt Key-based Pairing response]";
break;
case PairFailure::kIncorrectKeyBasedPairingResponseType:
stream << "[Incorrect Key-based response message type]";
break;
case PairFailure::kPasskeyDecryptFailure:
stream << "[Failed to decrypt Passkey response]";
break;
case PairFailure::kIncorrectPasskeyResponseType:
stream << "[Incorrect Passkey response message type]";
break;
case PairFailure::kPasskeyMismatch:
stream << "[Passkeys did not match]";
break;
}
return stream;
}
} // namespace fastpair
} // namespace nearby
+77
View File
@@ -0,0 +1,77 @@
// 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_PAIR_FAILURE_H_
#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_PAIR_FAILURE_H_
#include <ostream>
namespace nearby {
namespace fastpair {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class PairFailure {
// Failed to create a GATT connection to the device.
kCreateGattConnection = 0,
// Failed to find the expected GATT service.
kGattServiceDiscovery = 1,
// Timed out while starting discovery of GATT service.
kGattServiceDiscoveryTimeout = 2,
// Failed to retrieve the data encryptor.
kDataEncryptorRetrieval = 3,
// Failed to find the Key-based pairing GATT characteristic.
kKeyBasedPairingCharacteristicDiscovery = 4,
// Failed to find the Passkey GATT characteristic.
kPasskeyCharacteristicDiscovery = 5,
// Failed to find the Account Key GATT characteristic.
kAccountKeyCharacteristicDiscovery = 6,
// Failed to subscribe the notification on the Key-based pairing GATT
// characteristic.
kKeyBasedPairingCharacteristicSubscription = 7,
// Failed to start a notify session on the Passkey GATT characteristic.
kPasskeyCharacteristicSubscription = 8,
// Timed out while waiting to start a notify session on the Key-based pairing
// GATT characteristic.
kKeyBasedPairingCharacteristicSubscriptionTimeout = 9,
// / Timed out while waiting to start a notify session on the Passkey GATT
// characteristic.
kPasskeyCharacteristicSubscriptionTimeout = 10,
// Failed to write to the Key-based pairing GATT characteristic.
kKeyBasedPairingCharacteristicWrite = 11,
// Failed to write to the Passkey GATT characteristic.
kPasskeyPairingCharacteristicWrite = 12,
// Timed out while waiting for the Key-based Pairing response.
kKeyBasedPairingResponseTimeout = 13,
// Timed out while waiting for the Passkey response.
kPasskeyResponseTimeout = 14,
// Failed to decrypt Key-based response message.
kKeybasedPairingResponseDecryptFailure = 15,
// Incorrect Key-based response message type.
kIncorrectKeyBasedPairingResponseType = 16,
// Failed to decrypt Passkey response message.
kPasskeyDecryptFailure = 17,
// Incorrect Passkey response message type.
kIncorrectPasskeyResponseType = 18,
// Passkeys did not match.
kPasskeyMismatch = 19,
kMaxValue = kPasskeyMismatch,
};
std::ostream& operator<<(std::ostream& stream, PairFailure failure);
} // namespace fastpair
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_PAIR_FAILURE_H_