Serialize stack shutdown, state change callback and cleanup

Use Case: Bluetooth On/Off scenario, User switch

Steps:
1. Turn ON Bluetooth
2. Switch user
Also observed on occurrence of enable/disable timeout during On/Off testing.

Failure: Crash while sending state change HAL callback.

Root Cause: In the event when stack cleanup is queued to stack manager
thread when stack shutdown is being processed, stack cleanup starts
execution as soon as stack shutdown is finished.
If the function event_signal_stack_down posted to btif thread at the
end of stack shutdown is executed after stack cleanup crash occurs.

Fix: Serialized the execution of stack shutdown, state change callback
execution and stack cleanup to happen in same order.

Test: code compilation.

Change-Id: Ic96205b5c304acb44eab53f4e2cb150726643bda
(cherry picked from commit 16e112b1861d8f1147325372608c905627e00e88)
diff --git a/btif/src/stack_manager.c b/btif/src/stack_manager.c
index e132221..288f697 100644
--- a/btif/src/stack_manager.c
+++ b/btif/src/stack_manager.c
@@ -178,7 +178,9 @@
   module_shut_down(get_module(CONTROLLER_MODULE)); // Doesn't do any work, just puts it in a restartable state
 
   LOG_INFO(LOG_TAG, "%s finished", __func__);
+  hack_future = future_new();
   btif_thread_post(event_signal_stack_down, NULL);
+  future_await(hack_future);
 }
 
 static void ensure_stack_is_not_running(void) {
@@ -224,6 +226,7 @@
 
 static void event_signal_stack_down(UNUSED_ATTR void *context) {
   HAL_CBACK(bt_hal_cbacks, adapter_state_changed_cb, BT_STATE_OFF);
+  future_ready(stack_manager_get_hack_future(), FUTURE_SUCCESS);
 }
 
 static void ensure_manager_initialized(void) {