hci: Stop the thread before hci_close()

Bug:36026072
Test: Switch users (toggle Bluetooth under load)
Change-Id: I3fb901b5c47021c708c1fb548858406225065d00
(cherry picked from commit e986c934fd91f870dda9e172acfcfb8844002e11)
diff --git a/hci/src/hci_layer.cc b/hci/src/hci_layer.cc
index 6c9d79c..fae92d3 100644
--- a/hci/src/hci_layer.cc
+++ b/hci/src/hci_layer.cc
@@ -226,13 +226,15 @@
   alarm_free(startup_timer);
   startup_timer = NULL;
 
-  hci_close();
-
+  // Stop the thread to prevent Send() calls.
   if (thread) {
     thread_stop(thread);
     thread_join(thread);
   }
 
+  // Close HCI to prevent callbacks.
+  hci_close();
+
   fixed_queue_free(command_queue, osi_free);
   command_queue = NULL;
   fixed_queue_free(packet_queue, buffer_allocator->free);