From 5b96667c28d868a3c93edec0b9d7242532fcfb78 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 8 Sep 2017 14:04:39 -0700 Subject: [PATCH] Ensure that services are cleaned from the GattServer HandleMap. The incorrect service handle was being plumbed up to onServiceDeleted. This was causing stale entries to stick around forever in the HandleMap, which could later cause failures to find callback references in ContextMap if the connection ID changed for a given device. Bug: 65463237 Test: unit tests modified and run Change-Id: I2e22858b447f4e6b5a4fbceee4c406191c84a67d --- bta/gatt/bta_gatts_act.cc | 2 +- test/suite/gatt/gatt_unittest.cc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bta/gatt/bta_gatts_act.cc b/bta/gatt/bta_gatts_act.cc index 583fabaf5..b328093b4 100644 --- a/bta/gatt/bta_gatts_act.cc +++ b/bta/gatt/bta_gatts_act.cc @@ -306,7 +306,7 @@ void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB* p_srvc_cb, tBTA_GATTS cb_data; cb_data.srvc_oper.server_if = p_rcb->gatt_if; - // cb_data.srvc_oper.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific; + cb_data.srvc_oper.service_id = p_srvc_cb->service_id; if (GATTS_DeleteService(p_rcb->gatt_if, &p_srvc_cb->service_uuid, p_srvc_cb->service_id)) { diff --git a/test/suite/gatt/gatt_unittest.cc b/test/suite/gatt/gatt_unittest.cc index 079a21311..bc4c29e89 100644 --- a/test/suite/gatt/gatt_unittest.cc +++ b/test/suite/gatt/gatt_unittest.cc @@ -98,16 +98,24 @@ TEST_F(GattTest, GattServerBuild) { gatt_server_interface()->add_service(server_if, service); semaphore_wait(service_added_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) << "Error adding service."; + EXPECT_TRUE(server_interface_id() == server_if) << "Wrong server_if added."; + int service_handle_added = service_handle(); // Stops server. gatt_server_interface()->stop_service(server_if, service_handle()); semaphore_wait(service_stopped_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) << "Error stopping server."; + EXPECT_TRUE(service_handle() == service_handle_added) + << "Wrong service handle stopped."; + EXPECT_TRUE(server_interface_id() == server_if) << "Wrong server_if stopped."; // Deletes service. gatt_server_interface()->delete_service(server_if, service_handle()); semaphore_wait(service_deleted_callback_sem_); EXPECT_TRUE(status() == BT_STATUS_SUCCESS) << "Error deleting service."; + EXPECT_TRUE(service_handle() == service_handle_added) + << "Wrong service handle deleted."; + EXPECT_TRUE(server_interface_id() == server_if) << "Wrong server_if deleted."; // Unregisters gatt server. No callback is expected. gatt_server_interface()->unregister_server(server_if); -- 2.11.0