From eb10950f89a900afd4a4b37f9f6eaab74f80800a Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Mon, 25 Sep 2023 16:18:31 +0000 Subject: [PATCH] [Fast Pair] Check for empty callback in gatt_service_client_impl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent crash if |GattDiscoveryCompleteForService| gets called more than once with a valid FP service. BUG=b:300596153 TEST=Unit tests and manual test initial FP with Pixel Buds A and JBL TUNE230NC TWS. (cherry picked from commit b2dbd2d9fb96d13b6a0a1cdc9c280ddc75eb83ac) Change-Id: Ic1e7a5de3054ff540835b8431d27e6b7130408f6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4873848 Commit-Queue: Katherine Lai Reviewed-by: Juliet Lévesque Cr-Original-Commit-Position: refs/heads/main@{#1198599} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4889800 Bot-Commit: Rubber Stamper Auto-Submit: Katherine Lai Commit-Queue: Juliet Lévesque Cr-Commit-Position: refs/branch-heads/5993@{#782} Cr-Branched-From: 511350718e646be62331ae9d7213d10ec320d514-refs/heads/main@{#1192594} --- .../fast_pair_gatt_service_client_impl.cc | 2 +- .../fast_pair_gatt_service_client_impl_unittest.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc index 15d34c3e36db7c..5199785bd054ec 100644 --- a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc +++ b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.cc @@ -524,7 +524,7 @@ void FastPairGattServiceClientImpl::GattDiscoveryCompleteForService( if (pair_failure.has_value()) { NotifyInitializedError(pair_failure.value()); - } else { + } else if (on_initialized_callback_) { is_initialized_ = true; RecordGattInitializationStep( FastPairGattConnectionSteps::kConnectionEstablished); diff --git a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl_unittest.cc b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl_unittest.cc index 1436d3958a2b89..66750eb7e6b2b6 100644 --- a/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl_unittest.cc +++ b/ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl_unittest.cc @@ -1291,5 +1291,15 @@ TEST_F(FastPairGattServiceClientTest, WriteEmptyPersonalizedName) { WritePersonalizedName(empty); } +// Regression test for b/300596153 +TEST_F(FastPairGattServiceClientTest, + NoCrashWhenGattDiscoveryCompleteForServiceCalledTwice) { + SuccessfulGattConnectionSetUp(); + NotifyGattDiscoveryCompleteForService( + ash::quick_pair::kFastPairBluetoothUuid); + NotifyGattDiscoveryCompleteForService( + ash::quick_pair::kFastPairBluetoothUuid); +} + } // namespace quick_pair } // namespace ash