diff --git a/fastpair/handshake/BUILD b/fastpair/handshake/BUILD index 526c8873..2b6b079e 100644 --- a/fastpair/handshake/BUILD +++ b/fastpair/handshake/BUILD @@ -43,7 +43,6 @@ cc_library( "//fastpair/repository", "//fastpair/server_access", "//internal/base:bluetooth_address", - "//internal/platform:base", "//internal/platform:comm", "//internal/platform:logging", "//internal/platform:types", @@ -54,6 +53,8 @@ cc_library( "@com_google_absl//absl/functional:bind_front", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/time", + "@com_google_absl//absl/types:span", ], ) @@ -120,6 +121,7 @@ cc_test( "//internal/platform/implementation/g3", # build_cleaner: keep "//internal/test", "@com_github_protobuf_matchers//protobuf-matchers", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_googletest//:gtest_main", diff --git a/fastpair/handshake/fake_fast_pair_gatt_service_client.h b/fastpair/handshake/fake_fast_pair_gatt_service_client.h index 2274034e..019e2e0d 100644 --- a/fastpair/handshake/fake_fast_pair_gatt_service_client.h +++ b/fastpair/handshake/fake_fast_pair_gatt_service_client.h @@ -43,26 +43,28 @@ class FakeFastPairGattServiceClient : public FastPairGattServiceClient { WriteResponseCallback write_response_callback) override { key_based_write_response_callback_ = std::move(write_response_callback); } + void WritePasskeyAsync( uint8_t message_type, uint32_t passkey, const FastPairDataEncryptor& fast_pair_data_encryptor, WriteResponseCallback write_response_callback) override { passkey_write_response_callback_ = std::move(write_response_callback); } + void RunOnGattClientInitializedCallback( - std::optional failure = absl::nullopt) { + std::optional failure = std::nullopt) { std::move(on_initialized_callback_)(failure); } void RunWriteResponseCallback( absl::string_view value, - std::optional failure = absl::nullopt) { + std::optional failure = std::nullopt) { std::move(key_based_write_response_callback_)(value, failure); } void RunWritePasskeyCallback( absl::string_view value, - std::optional failure = absl::nullopt) { + std::optional failure = std::nullopt) { std::move(passkey_write_response_callback_)(value, failure); } diff --git a/fastpair/handshake/fast_pair_gatt_service_client_impl.cc b/fastpair/handshake/fast_pair_gatt_service_client_impl.cc index bb0685f5..4c0e2d04 100644 --- a/fastpair/handshake/fast_pair_gatt_service_client_impl.cc +++ b/fastpair/handshake/fast_pair_gatt_service_client_impl.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -27,7 +28,11 @@ #include "absl/functional/any_invocable.h" #include "absl/functional/bind_front.h" #include "absl/strings/string_view.h" +#include "absl/time/time.h" +#include "absl/types/span.h" #include "fastpair/common/constant.h" +#include "fastpair/common/fast_pair_device.h" +#include "fastpair/common/pair_failure.h" #include "fastpair/handshake/fast_pair_data_encryptor.h" #include "fastpair/handshake/fast_pair_gatt_service_client.h" #include "internal/base/bluetooth_address.h" @@ -168,7 +173,7 @@ void FastPairGattServiceClientImpl::GetFastPairGattCharacteristics() { } is_initialized_ = true; - std::move(on_gatt_initialized_callback_)(absl::nullopt); + std::move(on_gatt_initialized_callback_)(std::nullopt); } std::optional @@ -340,7 +345,7 @@ void FastPairGattServiceClientImpl::WritePasskeyAsync( // Subscribe the notification once the passkey characteristic's value changed if (SubscribePasskeyCharacteristic()) { is_passkey_notification_subscribed_ = true; - // Write passkey confonirmation request to the passkey characteristic + // Write passkey confirmation request to the passkey characteristic WritePasskeyCharacteristic( std::string(data_to_write_vec.begin(), data_to_write_vec.end())); } diff --git a/fastpair/handshake/fast_pair_gatt_service_client_impl_test.cc b/fastpair/handshake/fast_pair_gatt_service_client_impl_test.cc index 07f36962..f6750688 100644 --- a/fastpair/handshake/fast_pair_gatt_service_client_impl_test.cc +++ b/fastpair/handshake/fast_pair_gatt_service_client_impl_test.cc @@ -15,17 +15,21 @@ #include "fastpair/handshake/fast_pair_gatt_service_client_impl.h" #include +#include #include #include #include #include "gtest/gtest.h" +#include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" #include "fastpair/common/constant.h" #include "fastpair/common/fast_pair_device.h" #include "fastpair/common/pair_failure.h" +#include "fastpair/common/protocol.h" #include "fastpair/handshake/fake_fast_pair_data_encryptor.h" +#include "fastpair/handshake/fast_pair_gatt_service_client.h" #include "internal/platform/ble_v2.h" #include "internal/platform/bluetooth_adapter.h" #include "internal/platform/byte_array.h" @@ -188,18 +192,16 @@ class FastPairGattServiceClientTest : public testing::Test { passkey_characteristic_.value(), false, {}); } - absl::optional GetInitializedCallbackResult() { + std::optional GetInitializedCallbackResult() { return initalized_failure_; } void WriteTestCallback(absl::string_view response, - absl::optional failure) { + std::optional failure) { write_failure_ = failure; } - absl::optional GetWriteCallbackResult() { - return write_failure_; - } + std::optional GetWriteCallbackResult() { return write_failure_; } void WriteRequestToKeyBased() { gatt_client_->WriteRequestAsync( @@ -240,8 +242,8 @@ class FastPairGattServiceClientTest : public testing::Test { private: std::optional key_based_characteristic_; std::optional passkey_characteristic_; - absl::optional initalized_failure_; - absl::optional write_failure_; + std::optional initalized_failure_; + std::optional write_failure_; Property properties_ = Property::kWrite | Property::kNotify; Permission permissions_ = Permission::kWrite; }; @@ -277,7 +279,7 @@ TEST_F(FastPairGattServiceClientTest, SuccessfulWriteKeyBaseCharacteristics) { InitializeFastPairGattServiceClient(); WriteRequestToKeyBased(); EXPECT_EQ(TriggerKeyBasedGattChanged(), absl::OkStatus()); - EXPECT_EQ(GetWriteCallbackResult(), absl::nullopt); + EXPECT_EQ(GetWriteCallbackResult(), std::nullopt); } TEST_F(FastPairGattServiceClientTest, SuccessfulWritePasskeyCharacteristics) { @@ -285,7 +287,7 @@ TEST_F(FastPairGattServiceClientTest, SuccessfulWritePasskeyCharacteristics) { InitializeFastPairGattServiceClient(); WriteRequestToPasskey(); EXPECT_EQ(TriggerPasskeyGattChanged(), absl::OkStatus()); - EXPECT_EQ(GetWriteCallbackResult(), absl::nullopt); + EXPECT_EQ(GetWriteCallbackResult(), std::nullopt); } TEST_F(FastPairGattServiceClientTest, FailedSubscribeKeybaseCharacteristic) { @@ -297,7 +299,7 @@ TEST_F(FastPairGattServiceClientTest, FailedSubscribeKeybaseCharacteristic) { PairFailure::kKeyBasedPairingCharacteristicSubscription); WriteRequestToPasskey(); EXPECT_EQ(TriggerPasskeyGattChanged(), absl::OkStatus()); - EXPECT_EQ(GetWriteCallbackResult(), absl::nullopt); + EXPECT_EQ(GetWriteCallbackResult(), std::nullopt); } TEST_F(FastPairGattServiceClientTest, FailedSubscribePasskeyCharacteristic) { @@ -306,7 +308,7 @@ TEST_F(FastPairGattServiceClientTest, FailedSubscribePasskeyCharacteristic) { RemoveDiscoveredPasskeyCharacteristic(); WriteRequestToKeyBased(); EXPECT_EQ(TriggerKeyBasedGattChanged(), absl::OkStatus()); - EXPECT_EQ(GetWriteCallbackResult(), absl::nullopt); + EXPECT_EQ(GetWriteCallbackResult(), std::nullopt); WriteRequestToPasskey(); EXPECT_EQ(GetWriteCallbackResult(), PairFailure::kPasskeyCharacteristicSubscription); diff --git a/fastpair/handshake/fast_pair_handshake_lookup.cc b/fastpair/handshake/fast_pair_handshake_lookup.cc index cad7e193..a137280d 100644 --- a/fastpair/handshake/fast_pair_handshake_lookup.cc +++ b/fastpair/handshake/fast_pair_handshake_lookup.cc @@ -20,6 +20,7 @@ #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "fastpair/handshake/fast_pair_handshake_impl.h" +#include "internal/platform/logging.h" namespace nearby { namespace fastpair {