From: Jeremy Klein Date: Fri, 8 Sep 2017 21:04:39 +0000 (-0700) Subject: Ensure that services are cleaned from the GattServer HandleMap. X-Git-Tag: android-x86-9.0-r1~186^2~4^2~2^2~116^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5b96667c28;p=android-x86%2Fsystem-bt.git 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 --- 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);