Don't destroy BTIF Device Management state during shutdown

Don't call btif_dm_cleanup() during stack shutdown stage,
because it will destroy/free internal state that might be used
later in the shutdown process.
Instead, btif_dm_cleanup() should happen during the stack
cleanup stage.

Also, added an unit test to capture the original issue.

Bug: 27856457
Change-Id: I8575537ad744cf4e6770046b779b6a53de93d66e
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index c3a164d..ab69f1f 100644
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -534,8 +534,6 @@
     }
     else
     {
-        btif_dm_cleanup();
-
         /* cleanup rfcomm & l2cap api */
         btif_sock_cleanup();
 
@@ -561,17 +559,11 @@
     BTIF_TRACE_DEBUG("BTIF DISABLE BLUETOOTH");
 
     btif_dm_on_disable();
-    btif_dm_cleanup();
     /* cleanup rfcomm & l2cap api */
     btif_sock_cleanup();
     btif_pan_cleanup();
     BTA_DisableBluetooth();
 
-    if (uid_set) {
-        uid_set_destroy(uid_set);
-        uid_set = NULL;
-    }
-
     return BT_STATUS_SUCCESS;
 }
 
@@ -620,6 +612,8 @@
 {
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
+    btif_dm_cleanup();
+
     btif_transfer_context(btif_jni_disassociate, 0, NULL, 0, NULL);
 
     btif_queue_release();