Merge "[bluetoothtb] Fix bug processing BT_PROPERTY_UUIDS"
diff --git a/bta/Android.bp b/bta/Android.bp
index 57f2b61..47ec8e1 100644
--- a/bta/Android.bp
+++ b/bta/Android.bp
@@ -143,5 +143,6 @@
         "libbluetooth-types",
         "libbt-protos-lite",
         "libosi",
+        "libbt-common",
     ],
 }
diff --git a/bta/ag/bta_ag_api.cc b/bta/ag/bta_ag_api.cc
index 7bd4752..727ad0f 100644
--- a/bta/ag/bta_ag_api.cc
+++ b/bta/ag/bta_ag_api.cc
@@ -62,7 +62,7 @@
     }
   }
   bta_sys_register(BTA_ID_AG, &bta_ag_reg);
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_api_enable, p_cback));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_api_enable, p_cback));
   return BTA_SUCCESS;
 }
 
@@ -77,7 +77,7 @@
  *
  ******************************************************************************/
 void BTA_AgDisable() {
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_api_disable));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_api_disable));
 }
 
 /*******************************************************************************
@@ -94,7 +94,7 @@
                     tBTA_AG_FEAT features,
                     const std::vector<std::string>& service_names,
                     uint8_t app_id) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(&bta_ag_api_register, services, sec_mask, features,
                             service_names, app_id));
 }
@@ -110,9 +110,9 @@
  *
  ******************************************************************************/
 void BTA_AgDeregister(uint16_t handle) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                              BTA_AG_API_DEREGISTER_EVT, tBTA_AG_DATA::kEmpty));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                            BTA_AG_API_DEREGISTER_EVT, tBTA_AG_DATA::kEmpty));
 }
 
 /*******************************************************************************
@@ -132,8 +132,8 @@
   tBTA_AG_DATA data = {};
   data.api_open.bd_addr = bd_addr;
   data.api_open.sec_mask = sec_mask;
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                                         BTA_AG_API_OPEN_EVT, data));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                                          BTA_AG_API_OPEN_EVT, data));
 }
 
 /*******************************************************************************
@@ -148,9 +148,9 @@
  *
  ******************************************************************************/
 void BTA_AgClose(uint16_t handle) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                              BTA_AG_API_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                               BTA_AG_API_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
 }
 
 /*******************************************************************************
@@ -165,9 +165,9 @@
  *
  ******************************************************************************/
 void BTA_AgAudioOpen(uint16_t handle) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                              BTA_AG_API_AUDIO_OPEN_EVT, tBTA_AG_DATA::kEmpty));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                            BTA_AG_API_AUDIO_OPEN_EVT, tBTA_AG_DATA::kEmpty));
 }
 
 /*******************************************************************************
@@ -182,7 +182,7 @@
  *
  ******************************************************************************/
 void BTA_AgAudioClose(uint16_t handle) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
                             BTA_AG_API_AUDIO_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
 }
@@ -201,8 +201,8 @@
  ******************************************************************************/
 void BTA_AgResult(uint16_t handle, tBTA_AG_RES result,
                   const tBTA_AG_RES_DATA& data) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_ag_api_result, handle, result, data));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&bta_ag_api_result, handle, result, data));
 }
 
 /*******************************************************************************
@@ -220,15 +220,15 @@
 void BTA_AgSetCodec(uint16_t handle, tBTA_AG_PEER_CODEC codec) {
   tBTA_AG_DATA data = {};
   data.api_setcodec.codec = codec;
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                                         BTA_AG_API_SETCODEC_EVT, data));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                                          BTA_AG_API_SETCODEC_EVT, data));
 }
 
 void BTA_AgSetScoAllowed(bool value) {
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_set_sco_allowed, value));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_set_sco_allowed, value));
 }
 
 void BTA_AgSetActiveDevice(const RawAddress& active_device_addr) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(&bta_ag_api_set_active_device, active_device_addr));
 }
diff --git a/bta/ag/bta_ag_rfc.cc b/bta/ag/bta_ag_rfc.cc
index 14f1116..d878afe 100644
--- a/bta/ag/bta_ag_rfc.cc
+++ b/bta/ag/bta_ag_rfc.cc
@@ -90,9 +90,9 @@
                  << handle << " peer_addr " << p_scb->peer_addr << " state "
                  << std::to_string(p_scb->state);
     }
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                                BTA_AG_RFC_DATA_EVT, tBTA_AG_DATA::kEmpty));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                                 BTA_AG_RFC_DATA_EVT, tBTA_AG_DATA::kEmpty));
   }
 }
 
@@ -155,7 +155,7 @@
 
   tBTA_AG_DATA data = {};
   data.rfc.port_handle = port_handle;
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, handle, event, data));
 }
 
@@ -371,7 +371,7 @@
     /* Close API was called while AG is in Opening state.               */
     /* Need to trigger the state machine to send callback to the app    */
     /* and move back to INIT state.                                     */
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         base::Bind(&bta_ag_sm_execute_by_handle, bta_ag_scb_to_idx(p_scb),
                    BTA_AG_RFC_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
diff --git a/bta/ag/bta_ag_sco.cc b/bta/ag/bta_ag_sco.cc
index 8e51e87..18191b9 100644
--- a/bta/ag/bta_ag_sco.cc
+++ b/bta/ag/bta_ag_sco.cc
@@ -134,9 +134,9 @@
   }
 
   if (handle != 0) {
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                                BTA_AG_SCO_OPEN_EVT, tBTA_AG_DATA::kEmpty));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                                 BTA_AG_SCO_OPEN_EVT, tBTA_AG_DATA::kEmpty));
   } else {
     /* no match found; disconnect sco, init sco variables */
     bta_ag_cb.sco.p_curr_scb = nullptr;
@@ -217,9 +217,9 @@
 
     bta_ag_cb.sco.p_curr_scb->inuse_codec = BTA_AG_CODEC_NONE;
 
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&bta_ag_sm_execute_by_handle, handle,
-                                BTA_AG_SCO_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&bta_ag_sm_execute_by_handle, handle,
+                                 BTA_AG_SCO_CLOSE_EVT, tBTA_AG_DATA::kEmpty));
   } else {
     /* no match found */
     APPL_TRACE_DEBUG("no scb for ag_sco_disc_cback");
@@ -373,7 +373,7 @@
                  << " is not active, active_device=" << active_device_addr;
     if (bta_ag_cb.sco.p_curr_scb != nullptr &&
         bta_ag_cb.sco.p_curr_scb->in_use && p_scb == bta_ag_cb.sco.p_curr_scb) {
-      do_in_bta_thread(
+      do_in_main_thread(
           FROM_HERE, base::Bind(&bta_ag_sm_execute, p_scb, BTA_AG_SCO_CLOSE_EVT,
                                 tBTA_AG_DATA::kEmpty));
     }
diff --git a/bta/ag/bta_ag_sdp.cc b/bta/ag/bta_ag_sdp.cc
index 2ae56a2..60b364a 100644
--- a/bta/ag/bta_ag_sdp.cc
+++ b/bta/ag/bta_ag_sdp.cc
@@ -88,8 +88,8 @@
       event = BTA_AG_DISC_INT_RES_EVT;
     }
     tBTA_AG_DATA disc_result = {.disc_result.status = status};
-    do_in_bta_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, idx,
-                                           event, disc_result));
+    do_in_main_thread(FROM_HERE, base::Bind(&bta_ag_sm_execute_by_handle, idx,
+                                            event, disc_result));
   }
 }
 
diff --git a/bta/dm/bta_dm_act.cc b/bta/dm/bta_dm_act.cc
index 3460ecc..add024c 100644
--- a/bta/dm/bta_dm_act.cc
+++ b/bta/dm/bta_dm_act.cc
@@ -2827,34 +2827,34 @@
   switch (p_data->event) {
     case BTM_BL_CONN_EVT:
       /* connection up */
-      do_in_bta_thread(FROM_HERE,
-                       base::Bind(bta_dm_acl_change, true, *p_data->conn.p_bda,
-                                  p_data->conn.transport, p_data->conn.handle));
+      do_in_main_thread(
+          FROM_HERE, base::Bind(bta_dm_acl_change, true, *p_data->conn.p_bda,
+                                p_data->conn.transport, p_data->conn.handle));
       break;
     case BTM_BL_DISCN_EVT:
       /* connection down */
-      do_in_bta_thread(
+      do_in_main_thread(
           FROM_HERE, base::Bind(bta_dm_acl_change, false, *p_data->discn.p_bda,
                                 p_data->discn.transport, p_data->discn.handle));
       break;
 
     case BTM_BL_UPDATE_EVT: {
       /* busy level update */
-      do_in_bta_thread(FROM_HERE, base::Bind(send_busy_level_update,
-                                             p_data->update.busy_level,
-                                             p_data->update.busy_level_flags));
+      do_in_main_thread(FROM_HERE, base::Bind(send_busy_level_update,
+                                              p_data->update.busy_level,
+                                              p_data->update.busy_level_flags));
       return;
     }
     case BTM_BL_ROLE_CHG_EVT: {
       const auto& tmp = p_data->role_chg;
-      do_in_bta_thread(FROM_HERE, base::Bind(handle_role_change, *tmp.p_bda,
-                                             tmp.new_role, tmp.hci_status));
+      do_in_main_thread(FROM_HERE, base::Bind(handle_role_change, *tmp.p_bda,
+                                              tmp.new_role, tmp.hci_status));
       return;
     }
 
     case BTM_BL_COLLISION_EVT:
       /* Collision report from Stack: Notify profiles */
-      do_in_bta_thread(
+      do_in_main_thread(
           FROM_HERE, base::Bind(bta_sys_notify_collision, *p_data->conn.p_bda));
       return;
   }
diff --git a/bta/dm/bta_dm_api.cc b/bta/dm/bta_dm_api.cc
index b3e3a46..419dda1 100644
--- a/bta/dm/bta_dm_api.cc
+++ b/bta/dm/bta_dm_api.cc
@@ -64,7 +64,7 @@
   /* if UUID list is not provided as static data */
   bta_sys_eir_register(bta_dm_eir_update_uuid);
 
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_enable, p_cback));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_enable, p_cback));
   return BTA_SUCCESS;
 }
 
@@ -79,19 +79,19 @@
  *
  ******************************************************************************/
 tBTA_STATUS BTA_DisableBluetooth(void) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_disable));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_disable));
   return BTA_SUCCESS;
 }
 
 /** Enables bluetooth device under test mode */
 void BTA_EnableTestMode(void) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(base::IgnoreResult(BTM_EnableTestMode)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(base::IgnoreResult(BTM_EnableTestMode)));
 }
 
 /** Disable bluetooth device under test mode */
 void BTA_DisableTestMode(void) {
-  do_in_bta_thread(FROM_HERE, base::Bind(BTM_DeviceReset, nullptr));
+  do_in_main_thread(FROM_HERE, base::Bind(BTM_DeviceReset, nullptr));
 }
 
 /** This function sets the Bluetooth name of local device */
@@ -99,7 +99,7 @@
   std::vector<uint8_t> name(BD_NAME_LEN);
   strlcpy((char*)name.data(), p_name, BD_NAME_LEN);
 
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_set_dev_name, name));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_set_dev_name, name));
 }
 
 /** This function sets the Bluetooth connectable, discoverable, pairable and
@@ -107,9 +107,9 @@
  */
 void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode,
                          uint8_t pairable_mode, uint8_t conn_paired_only) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_set_visibility, disc_mode, conn_mode,
-                              pairable_mode, conn_paired_only));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_set_visibility, disc_mode, conn_mode,
+                               pairable_mode, conn_paired_only));
 }
 
 /*******************************************************************************
@@ -211,20 +211,20 @@
 
 /** This function initiates a bonding procedure with a peer device */
 void BTA_DmBond(const RawAddress& bd_addr) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_bond, bd_addr, BTA_TRANSPORT_UNKNOWN));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_bond, bd_addr, BTA_TRANSPORT_UNKNOWN));
 }
 
 /** This function initiates a bonding procedure with a peer device */
 void BTA_DmBondByTransport(const RawAddress& bd_addr,
                            tBTA_TRANSPORT transport) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_bond, bd_addr, transport));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_bond, bd_addr, transport));
 }
 
 /** This function cancels the bonding procedure with a peer device
  */
 void BTA_DmBondCancel(const RawAddress& bd_addr) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_bond_cancel, bd_addr));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_bond_cancel, bd_addr));
 }
 
 /*******************************************************************************
@@ -250,7 +250,8 @@
     memcpy(msg->p_pin, p_pin, pin_len);
   }
 
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_pin_reply, base::Passed(&msg)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_pin_reply, base::Passed(&msg)));
 }
 
 /*******************************************************************************
@@ -267,7 +268,7 @@
  *
  ******************************************************************************/
 void BTA_DmLocalOob(void) {
-  do_in_bta_thread(FROM_HERE, base::Bind(BTM_ReadLocalOobData));
+  do_in_main_thread(FROM_HERE, base::Bind(BTM_ReadLocalOobData));
 }
 
 /*******************************************************************************
@@ -281,7 +282,7 @@
  *
  ******************************************************************************/
 void BTA_DmConfirm(const RawAddress& bd_addr, bool accept) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_confirm, bd_addr, accept));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_confirm, bd_addr, accept));
 }
 
 /*******************************************************************************
@@ -320,14 +321,14 @@
   memset(msg->features, 0, sizeof(msg->features));
   msg->pin_length = pin_length;
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_add_device, base::Passed(&msg)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_add_device, base::Passed(&msg)));
 }
 
 /** This function removes a device fromthe security database list of peer
  * device. It manages unpairing even while connected */
 tBTA_STATUS BTA_DmRemoveDevice(const RawAddress& bd_addr) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_remove_device, bd_addr));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_remove_device, bd_addr));
   return BTA_SUCCESS;
 }
 
@@ -440,8 +441,8 @@
  ******************************************************************************/
 void BTA_DmAddBleKey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE* p_le_key,
                      tBTA_LE_KEY_TYPE key_type) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_add_blekey, bd_addr, *p_le_key, key_type));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(bta_dm_add_blekey, bd_addr, *p_le_key, key_type));
 }
 
 /*******************************************************************************
@@ -461,8 +462,8 @@
  ******************************************************************************/
 void BTA_DmAddBleDevice(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
                         tBT_DEVICE_TYPE dev_type) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_add_ble_device, bd_addr,
-                                         addr_type, dev_type));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_add_ble_device, bd_addr,
+                                          addr_type, dev_type));
 }
 
 /*******************************************************************************
@@ -481,8 +482,8 @@
  ******************************************************************************/
 void BTA_DmBlePasskeyReply(const RawAddress& bd_addr, bool accept,
                            uint32_t passkey) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_passkey_reply, bd_addr,
-                                         accept, accept ? passkey : 0));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_passkey_reply, bd_addr,
+                                          accept, accept ? passkey : 0));
 }
 
 /*******************************************************************************
@@ -499,8 +500,8 @@
  *
  ******************************************************************************/
 void BTA_DmBleConfirmReply(const RawAddress& bd_addr, bool accept) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_ble_confirm_reply, bd_addr, accept));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_ble_confirm_reply, bd_addr, accept));
 }
 
 /*******************************************************************************
@@ -517,7 +518,7 @@
  ******************************************************************************/
 void BTA_DmBleSecurityGrant(const RawAddress& bd_addr,
                             tBTA_DM_BLE_SEC_GRANT res) {
-  do_in_bta_thread(FROM_HERE, base::Bind(BTM_SecurityGrant, bd_addr, res));
+  do_in_main_thread(FROM_HERE, base::Bind(BTM_SecurityGrant, bd_addr, res));
 }
 
 /*******************************************************************************
@@ -543,9 +544,9 @@
                                 uint16_t min_conn_int, uint16_t max_conn_int,
                                 uint16_t slave_latency,
                                 uint16_t supervision_tout) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_ble_set_conn_params, bd_addr, min_conn_int,
-                              max_conn_int, slave_latency, supervision_tout));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(bta_dm_ble_set_conn_params, bd_addr, min_conn_int,
+                            max_conn_int, slave_latency, supervision_tout));
 }
 
 /*******************************************************************************
@@ -562,13 +563,13 @@
  *
  ******************************************************************************/
 void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_set_conn_scan_params,
-                                         scan_interval, scan_window));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_set_conn_scan_params,
+                                          scan_interval, scan_window));
 }
 
 /** Set BLE connectable mode to auto connect */
 void BTA_DmBleStartAutoConn() {
-  do_in_bta_thread(FROM_HERE, base::Bind(BTM_BleStartAutoConn));
+  do_in_main_thread(FROM_HERE, base::Bind(BTM_BleStartAutoConn));
 }
 
 /*******************************************************************************
@@ -726,7 +727,7 @@
                                      uint16_t min_int, uint16_t max_int,
                                      uint16_t latency, uint16_t timeout,
                                      uint16_t min_ce_len, uint16_t max_ce_len) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(bta_dm_ble_update_conn_params, bd_addr, min_int,
                             max_int, latency, timeout, min_ce_len, max_ce_len));
 }
@@ -744,8 +745,8 @@
  ******************************************************************************/
 void BTA_DmBleConfigLocalPrivacy(bool privacy_enable) {
 #if (BLE_PRIVACY_SPT == TRUE)
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_ble_config_local_privacy, privacy_enable));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(bta_dm_ble_config_local_privacy, privacy_enable));
 #else
   UNUSED(privacy_enable);
 #endif
@@ -763,15 +764,15 @@
  *
  ******************************************************************************/
 void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK* p_cmpl_cback) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_ble_get_energy_info, p_cmpl_cback));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_ble_get_energy_info, p_cmpl_cback));
 }
 
 /** This function is to set maximum LE data packet size */
 void BTA_DmBleSetDataLength(const RawAddress& remote_device,
                             uint16_t tx_data_length) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ble_set_data_length,
-                                         remote_device, tx_data_length));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_set_data_length,
+                                          remote_device, tx_data_length));
 }
 
 /*******************************************************************************
@@ -800,8 +801,8 @@
                          tBTA_DM_ENCRYPT_CBACK* p_callback,
                          tBTA_DM_BLE_SEC_ACT sec_act) {
   APPL_TRACE_API("%s", __func__);
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_set_encryption, bd_addr,
-                                         transport, p_callback, sec_act));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_set_encryption, bd_addr,
+                                          transport, p_callback, sec_act));
 }
 
 /*******************************************************************************
@@ -819,7 +820,7 @@
  ******************************************************************************/
 void BTA_DmCloseACL(const RawAddress& bd_addr, bool remove_dev,
                     tBTA_TRANSPORT transport) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(bta_dm_close_acl, bd_addr, remove_dev, transport));
 }
 
@@ -841,7 +842,7 @@
 extern void BTA_DmBleObserve(bool start, uint8_t duration,
                              tBTA_DM_SEARCH_CBACK* p_results_cb) {
   APPL_TRACE_API("%s:start = %d ", __func__, start);
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(bta_dm_ble_observe, start, duration, p_results_cb));
 }
 
diff --git a/bta/dm/bta_dm_ci.cc b/bta/dm/bta_dm_ci.cc
index 968c3d5..45784c1 100644
--- a/bta/dm/bta_dm_ci.cc
+++ b/bta/dm/bta_dm_ci.cc
@@ -46,8 +46,8 @@
                       tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
 
 {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_ci_io_req_act, bd_addr, io_cap,
-                                         oob_data, auth_req));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ci_io_req_act, bd_addr, io_cap,
+                                          oob_data, auth_req));
 }
 
 /*******************************************************************************
@@ -71,7 +71,7 @@
   msg->c = c;
   msg->r = r;
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(bta_dm_ci_rmt_oob_act, base::Passed(&msg)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(bta_dm_ci_rmt_oob_act, base::Passed(&msg)));
 }
 
diff --git a/bta/dm/bta_dm_pm.cc b/bta/dm/bta_dm_pm.cc
index 20ccaef..c713e3d 100644
--- a/bta/dm/bta_dm_pm.cc
+++ b/bta/dm/bta_dm_pm.cc
@@ -838,8 +838,8 @@
 static void bta_dm_pm_btm_cback(const RawAddress& bd_addr,
                                 tBTM_PM_STATUS status, uint16_t value,
                                 uint8_t hci_status) {
-  do_in_bta_thread(FROM_HERE, base::Bind(bta_dm_pm_btm_status, bd_addr, status,
-                                         value, hci_status));
+  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_pm_btm_status, bd_addr, status,
+                                          value, hci_status));
 }
 
 /*******************************************************************************
@@ -879,7 +879,7 @@
   /* no more timers */
   if (i == BTA_DM_NUM_PM_TIMER) return;
 
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(bta_dm_pm_timer, bta_dm_cb.pm_timer[i].peer_bdaddr,
                             bta_dm_cb.pm_timer[i].pm_action[j]));
 }
diff --git a/bta/gatt/bta_gattc_act.cc b/bta/gatt/bta_gattc_act.cc
index d49cd7f..f8954cd 100644
--- a/bta/gatt/bta_gattc_act.cc
+++ b/bta/gatt/bta_gattc_act.cc
@@ -192,7 +192,8 @@
         /* BTA use the same client interface as BTE GATT statck */
         client_if = bta_gattc_cb.cl_rcb[i].client_if;
 
-        do_in_bta_thread(FROM_HERE, base::Bind(&bta_gattc_start_if, client_if));
+        do_in_main_thread(FROM_HERE,
+                          base::Bind(&bta_gattc_start_if, client_if));
 
         status = GATT_SUCCESS;
         break;
@@ -1076,8 +1077,8 @@
 
   VLOG(1) << __func__ << ": cif:" << +gattc_if;
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_gattc_process_enc_cmpl, gattc_if, bda));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&bta_gattc_process_enc_cmpl, gattc_if, bda));
 }
 
 /** process refresh API to delete cache and start a new discovery if currently
diff --git a/bta/gatt/bta_gattc_api.cc b/bta/gatt/bta_gattc_api.cc
index eac9769..efdb03f 100644
--- a/bta/gatt/bta_gattc_api.cc
+++ b/bta/gatt/bta_gattc_api.cc
@@ -62,7 +62,7 @@
     return;
   }
 
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_gattc_disable));
+  do_in_main_thread(FROM_HERE, base::Bind(&bta_gattc_disable));
   bta_sys_deregister(BTA_ID_GATTC);
 }
 
@@ -76,8 +76,9 @@
   if (!bta_sys_is_register(BTA_ID_GATTC))
     bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg);
 
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_gattc_register, Uuid::GetRandom(),
-                                         p_client_cb, std::move(cb)));
+  do_in_main_thread(
+      FROM_HERE, base::Bind(&bta_gattc_register, Uuid::GetRandom(), p_client_cb,
+                            std::move(cb)));
 }
 
 static void app_deregister_impl(tGATT_IF client_if) {
@@ -96,7 +97,7 @@
  *
  ******************************************************************************/
 void BTA_GATTC_AppDeregister(tGATT_IF client_if) {
-  do_in_bta_thread(FROM_HERE, base::Bind(&app_deregister_impl, client_if));
+  do_in_main_thread(FROM_HERE, base::Bind(&app_deregister_impl, client_if));
 }
 
 /*******************************************************************************
@@ -247,7 +248,7 @@
 }
 
 void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id, const Uuid& srvc_uuid) {
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE,
       base::Bind(
           base::IgnoreResult<tGATT_STATUS (*)(uint16_t, tGATT_DISC_TYPE,
@@ -734,6 +735,6 @@
  *
  ******************************************************************************/
 void BTA_GATTC_Refresh(const RawAddress& remote_bda) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&bta_gattc_process_api_refresh, remote_bda));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&bta_gattc_process_api_refresh, remote_bda));
 }
diff --git a/bta/gatt/bta_gatts_api.cc b/bta/gatt/bta_gatts_api.cc
index 67e65e1..ef00269 100644
--- a/bta/gatt/bta_gatts_api.cc
+++ b/bta/gatt/bta_gatts_api.cc
@@ -168,8 +168,9 @@
 extern void BTA_GATTS_AddService(tGATT_IF server_if,
                                  std::vector<btgatt_db_element_t> service,
                                  BTA_GATTS_AddServiceCb cb) {
-  do_in_bta_thread(FROM_HERE, base::Bind(&bta_gatts_add_service_impl, server_if,
-                                         std::move(service), std::move(cb)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&bta_gatts_add_service_impl, server_if,
+                               std::move(service), std::move(cb)));
 }
 
 /*******************************************************************************
diff --git a/bta/hearing_aid/hearing_aid_audio_source.cc b/bta/hearing_aid/hearing_aid_audio_source.cc
index e03b040..b56f83c 100644
--- a/bta/hearing_aid/hearing_aid_audio_source.cc
+++ b/bta/hearing_aid/hearing_aid_audio_source.cc
@@ -24,6 +24,8 @@
 #include <base/files/file_util.h>
 #include <include/hardware/bt_av.h>
 
+#include "common/time_util.h"
+
 using base::FilePath;
 extern const char* audio_ha_hw_dump_ctrl_event(tHEARING_AID_CTRL_CMD event);
 
@@ -67,7 +69,8 @@
   if (bytes_read < bytes_per_tick) {
     stats.media_read_total_underflow_bytes += bytes_per_tick - bytes_read;
     stats.media_read_total_underflow_count++;
-    stats.media_read_last_underflow_us = time_get_os_boottime_us();
+    stats.media_read_last_underflow_us =
+        bluetooth::common::time_get_os_boottime_us();
   }
 
   std::vector<uint8_t> data(p_buf, p_buf + bytes_read);
@@ -296,7 +299,7 @@
 }
 
 void HearingAidAudioSource::DebugDump(int fd) {
-  uint64_t now_us = time_get_os_boottime_us();
+  uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
   std::stringstream stream;
   stream << "  Hearing Aid Audio HAL:"
          << "\n    Counts (underflow)                                      : "
diff --git a/bta/jv/bta_jv_api.cc b/bta/jv/bta_jv_api.cc
index 4016586..6702e0d 100644
--- a/bta/jv/bta_jv_api.cc
+++ b/bta/jv/bta_jv_api.cc
@@ -75,7 +75,7 @@
 
   bta_jv_enabled = true;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_enable, p_cback));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_enable, p_cback));
   return BTA_JV_SUCCESS;
 }
 
@@ -85,7 +85,7 @@
 
   bta_jv_enabled = false;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_disable));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_disable));
 }
 
 /*******************************************************************************
@@ -140,8 +140,8 @@
     CHECK(false) << "Invalid conn_type=" << conn_type;
   }
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_get_channel_id, conn_type, channel, id, id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_get_channel_id, conn_type, channel, id, id));
 }
 
 /*******************************************************************************
@@ -161,7 +161,7 @@
 tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_free_scn, conn_type, channel));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_free_scn, conn_type, channel));
   return BTA_JV_SUCCESS;
 }
 
@@ -186,9 +186,9 @@
   Uuid* uuid_list_copy = new Uuid[num_uuid];
   memcpy(uuid_list_copy, p_uuid_list, num_uuid * sizeof(Uuid));
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_start_discovery, bd_addr, num_uuid,
-                        base::Owned(uuid_list_copy), rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_start_discovery, bd_addr, num_uuid,
+                         base::Owned(uuid_list_copy), rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -207,7 +207,7 @@
 tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_create_record, rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_create_record, rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -224,7 +224,7 @@
 tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_delete_record, handle));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_delete_record, handle));
   return BTA_JV_SUCCESS;
 }
 
@@ -245,8 +245,8 @@
                           uint32_t l2cap_socket_id) {
   VLOG(2) << __func__;
   CHECK(p_cback);
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_connect_le, remote_chan,
-                                   peer_bd_addr, p_cback, l2cap_socket_id));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_connect_le, remote_chan,
+                                    peer_bd_addr, p_cback, l2cap_socket_id));
 }
 
 /*******************************************************************************
@@ -271,10 +271,10 @@
   VLOG(2) << __func__;
   CHECK(p_cback);
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_l2cap_connect, conn_type, sec_mask, role,
-                        remote_psm, rx_mtu, peer_bd_addr, base::Passed(&cfg),
-                        base::Passed(&ertm_info), p_cback, l2cap_socket_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_l2cap_connect, conn_type, sec_mask, role,
+                         remote_psm, rx_mtu, peer_bd_addr, base::Passed(&cfg),
+                         base::Passed(&ertm_info), p_cback, l2cap_socket_id));
 }
 
 /*******************************************************************************
@@ -293,7 +293,7 @@
   if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
     return BTA_JV_FAILURE;
 
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, Bind(&bta_jv_l2cap_close, handle, &bta_jv_cb.l2c_cb[handle]));
   return BTA_JV_SUCCESS;
 }
@@ -312,7 +312,7 @@
 tBTA_JV_STATUS BTA_JvL2capCloseLE(uint32_t handle) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_close_fixed, handle));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_close_fixed, handle));
   return BTA_JV_SUCCESS;
 }
 
@@ -339,10 +339,10 @@
   VLOG(2) << __func__;
   CHECK(p_cback);
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_l2cap_start_server, conn_type, sec_mask, role,
-                        local_psm, rx_mtu, base::Passed(&cfg),
-                        base::Passed(&ertm_info), p_cback, l2cap_socket_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_l2cap_start_server, conn_type, sec_mask, role,
+                         local_psm, rx_mtu, base::Passed(&cfg),
+                         base::Passed(&ertm_info), p_cback, l2cap_socket_id));
 }
 
 /*******************************************************************************
@@ -363,8 +363,8 @@
                               uint32_t l2cap_socket_id) {
   VLOG(2) << __func__;
   CHECK(p_cback);
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_start_server_le, local_chan,
-                                   p_cback, l2cap_socket_id));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_start_server_le, local_chan,
+                                    p_cback, l2cap_socket_id));
 }
 
 /*******************************************************************************
@@ -382,8 +382,8 @@
                                      uint32_t l2cap_socket_id) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_l2cap_stop_server, local_psm, l2cap_socket_id));
+  do_in_main_thread(
+      FROM_HERE, Bind(&bta_jv_l2cap_stop_server, local_psm, l2cap_socket_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -402,7 +402,7 @@
                                        uint32_t l2cap_socket_id) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_stop_server_le, local_chan));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_stop_server_le, local_chan));
   return BTA_JV_SUCCESS;
 }
 
@@ -491,8 +491,8 @@
     return BTA_JV_FAILURE;
   }
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_write, handle, req_id, msg,
-                                   user_id, &bta_jv_cb.l2c_cb[handle]));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_write, handle, req_id, msg,
+                                    user_id, &bta_jv_cb.l2c_cb[handle]));
   return BTA_JV_SUCCESS;
 }
 
@@ -512,8 +512,8 @@
                            BT_HDR* msg, uint32_t user_id) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_write_fixed, channel, addr,
-                                   req_id, msg, user_id, p_cback));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_write_fixed, channel, addr,
+                                    req_id, msg, user_id, p_cback));
 }
 
 /*******************************************************************************
@@ -541,9 +541,9 @@
 
   if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_rfcomm_connect, sec_mask, role, remote_scn,
-                        peer_bd_addr, p_cback, rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_rfcomm_connect, sec_mask, role, remote_scn,
+                         peer_bd_addr, p_cback, rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -567,8 +567,8 @@
       si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
     return BTA_JV_FAILURE;
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_rfcomm_close, handle, rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_rfcomm_close, handle, rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -602,9 +602,9 @@
     max_session = BTA_JV_MAX_RFC_SR_SESSION;
   }
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_rfcomm_start_server, sec_mask, role, local_scn,
-                        max_session, p_cback, rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_rfcomm_start_server, sec_mask, role, local_scn,
+                         max_session, p_cback, rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -623,8 +623,8 @@
                                       uint32_t rfcomm_slot_id) {
   VLOG(2) << __func__;
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
   return BTA_JV_SUCCESS;
 }
 
@@ -675,8 +675,8 @@
   VLOG(2) << "write ok";
 
   tBTA_JV_RFC_CB* p_cb = &bta_jv_cb.rfc_cb[hi];
-  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_rfcomm_write, handle, req_id, p_cb,
-                                   &bta_jv_cb.port_cb[p_cb->rfc_hdl[si] - 1]));
+  do_in_main_thread(FROM_HERE, Bind(&bta_jv_rfcomm_write, handle, req_id, p_cb,
+                                    &bta_jv_cb.port_cb[p_cb->rfc_hdl[si] - 1]));
   return BTA_JV_SUCCESS;
 }
 
@@ -707,7 +707,7 @@
                                   tBTA_JV_CONN_STATE init_st) {
   VLOG(2) << __func__ << " handle=" << loghex(handle) << ", app_id:" << app_id;
 
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&bta_jv_set_pm_profile, handle, app_id, init_st));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&bta_jv_set_pm_profile, handle, app_id, init_st));
   return BTA_JV_SUCCESS;
 }
diff --git a/bta/sys/bta_sys_main.cc b/bta/sys/bta_sys_main.cc
index 3f68753..1036e74 100644
--- a/bta/sys/bta_sys_main.cc
+++ b/bta/sys/bta_sys_main.cc
@@ -525,15 +525,11 @@
  *
  ******************************************************************************/
 void bta_sys_sendmsg(void* p_msg) {
-  base::MessageLoop* bta_message_loop = get_message_loop();
-
-  if (!bta_message_loop || !bta_message_loop->task_runner().get()) {
-    APPL_TRACE_ERROR("%s: MessageLooper not initialized", __func__);
-    return;
+  if (do_in_main_thread(
+          FROM_HERE, base::Bind(&bta_sys_event, static_cast<BT_HDR*>(p_msg))) !=
+      BT_STATUS_SUCCESS) {
+    LOG(ERROR) << __func__ << ": do_in_main_thread failed";
   }
-
-  bta_message_loop->task_runner()->PostTask(
-      FROM_HERE, base::Bind(&bta_sys_event, static_cast<BT_HDR*>(p_msg)));
 }
 
 /*******************************************************************************
diff --git a/bta/test/bta_hf_client_test.cc b/bta/test/bta_hf_client_test.cc
index 107a2e5..9b9ade2 100644
--- a/bta/test/bta_hf_client_test.cc
+++ b/bta/test/bta_hf_client_test.cc
@@ -25,7 +25,7 @@
 class MessageLoop;
 }  // namespace base
 
-base::MessageLoop* get_message_loop() { return NULL; }
+base::MessageLoop* get_main_message_loop() { return NULL; }
 
 namespace {
 const RawAddress bdaddr1({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
diff --git a/btcore/src/module.cc b/btcore/src/module.cc
index 8f8e5f0..d226006 100644
--- a/btcore/src/module.cc
+++ b/btcore/src/module.cc
@@ -168,7 +168,7 @@
                            MessageLoopThread* callback_thread,
                            thread_fn callback)
       : module(module),
-        lifecycle_thread("module_wrapper"),
+        lifecycle_thread("bt_module_lifecycle_thread"),
         callback_thread(callback_thread),
         callback(callback),
         success(false) {}
diff --git a/btif/avrcp/avrcp_service.cc b/btif/avrcp/avrcp_service.cc
index e30ff64..f7a7c40 100644
--- a/btif/avrcp/avrcp_service.cc
+++ b/btif/avrcp/avrcp_service.cc
@@ -141,7 +141,7 @@
 
   void GetSongInfo(SongInfoCallback info_cb) override {
     auto cb_lambda = [](SongInfoCallback cb, SongInfo data) {
-      do_in_bta_thread(FROM_HERE, base::Bind(cb, data));
+      do_in_main_thread(FROM_HERE, base::Bind(cb, data));
     };
 
     auto bound_cb = base::Bind(cb_lambda, info_cb);
@@ -152,7 +152,7 @@
 
   void GetPlayStatus(PlayStatusCallback status_cb) override {
     auto cb_lambda = [](PlayStatusCallback cb, PlayStatus status) {
-      do_in_bta_thread(FROM_HERE, base::Bind(cb, status));
+      do_in_main_thread(FROM_HERE, base::Bind(cb, status));
     };
 
     auto bound_cb = base::Bind(cb_lambda, status_cb);
@@ -164,8 +164,8 @@
   void GetNowPlayingList(NowPlayingCallback now_playing_cb) override {
     auto cb_lambda = [](NowPlayingCallback cb, std::string curr_media_id,
                         std::vector<SongInfo> song_list) {
-      do_in_bta_thread(FROM_HERE,
-                       base::Bind(cb, curr_media_id, std::move(song_list)));
+      do_in_main_thread(FROM_HERE,
+                        base::Bind(cb, curr_media_id, std::move(song_list)));
     };
 
     auto bound_cb = base::Bind(cb_lambda, now_playing_cb);
@@ -177,8 +177,8 @@
   void GetMediaPlayerList(MediaListCallback list_cb) override {
     auto cb_lambda = [](MediaListCallback cb, uint16_t curr_player,
                         std::vector<MediaPlayerInfo> player_list) {
-      do_in_bta_thread(FROM_HERE,
-                       base::Bind(cb, curr_player, std::move(player_list)));
+      do_in_main_thread(FROM_HERE,
+                        base::Bind(cb, curr_player, std::move(player_list)));
     };
 
     auto bound_cb = base::Bind(cb_lambda, list_cb);
@@ -191,7 +191,7 @@
                       FolderItemsCallback folder_cb) override {
     auto cb_lambda = [](FolderItemsCallback cb,
                         std::vector<ListItem> item_list) {
-      do_in_bta_thread(FROM_HERE, base::Bind(cb, std::move(item_list)));
+      do_in_main_thread(FROM_HERE, base::Bind(cb, std::move(item_list)));
     };
 
     auto bound_cb = base::Bind(cb_lambda, folder_cb);
@@ -205,7 +205,7 @@
                         SetBrowsedPlayerCallback browse_cb) override {
     auto cb_lambda = [](SetBrowsedPlayerCallback cb, bool success,
                         std::string root_id, uint32_t num_items) {
-      do_in_bta_thread(FROM_HERE, base::Bind(cb, success, root_id, num_items));
+      do_in_main_thread(FROM_HERE, base::Bind(cb, success, root_id, num_items));
     };
 
     auto bound_cb = base::Bind(cb_lambda, browse_cb);
@@ -254,7 +254,7 @@
 
   void DeviceConnected(const RawAddress& bdaddr, VolumeChangedCb cb) override {
     auto cb_lambda = [](VolumeChangedCb cb, int8_t volume) {
-      do_in_bta_thread(FROM_HERE, base::Bind(cb, volume));
+      do_in_main_thread(FROM_HERE, base::Bind(cb, volume));
     };
 
     auto bound_cb = base::Bind(cb_lambda, cb);
@@ -347,9 +347,9 @@
   // This function may be called on any thread, we need to make sure that the
   // device update happens on the main thread.
   for (auto device : instance_->connection_handler_->GetListOfDevices()) {
-    do_in_bta_thread(FROM_HERE, base::Bind(&Device::SendMediaUpdate,
-                                           base::Unretained(device.get()),
-                                           track_changed, play_state, queue));
+    do_in_main_thread(FROM_HERE, base::Bind(&Device::SendMediaUpdate,
+                                            base::Unretained(device.get()),
+                                            track_changed, play_state, queue));
   }
 }
 
@@ -362,7 +362,7 @@
 
   // Ensure that the update is posted to the correct thread
   for (auto device : instance_->connection_handler_->GetListOfDevices()) {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         base::Bind(&Device::SendFolderUpdate, base::Unretained(device.get()),
                    available_players, addressed_players, uids));
@@ -400,17 +400,17 @@
     jni_message_loop_ = get_jni_message_loop();
   }
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&AvrcpService::Init, base::Unretained(instance_),
-                              media_interface, volume_interface));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&AvrcpService::Init, base::Unretained(instance_),
+                               media_interface, volume_interface));
 }
 
 bool AvrcpService::ServiceInterfaceImpl::ConnectDevice(
     const RawAddress& bdaddr) {
   std::lock_guard<std::mutex> lock(service_interface_lock_);
   CHECK(instance_ != nullptr);
-  do_in_bta_thread(FROM_HERE, base::Bind(&AvrcpService::ConnectDevice,
-                                         base::Unretained(instance_), bdaddr));
+  do_in_main_thread(FROM_HERE, base::Bind(&AvrcpService::ConnectDevice,
+                                          base::Unretained(instance_), bdaddr));
   return true;
 }
 
@@ -418,8 +418,8 @@
     const RawAddress& bdaddr) {
   std::lock_guard<std::mutex> lock(service_interface_lock_);
   CHECK(instance_ != nullptr);
-  do_in_bta_thread(FROM_HERE, base::Bind(&AvrcpService::DisconnectDevice,
-                                         base::Unretained(instance_), bdaddr));
+  do_in_main_thread(FROM_HERE, base::Bind(&AvrcpService::DisconnectDevice,
+                                          base::Unretained(instance_), bdaddr));
   return true;
 }
 
@@ -434,8 +434,8 @@
     jni_message_loop_ = nullptr;
   }
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&AvrcpService::Cleanup, base::Owned(instance_)));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&AvrcpService::Cleanup, base::Owned(instance_)));
 
   // Setting instance to nullptr here is fine since it will be deleted on the
   // other thread.
diff --git a/btif/src/bluetooth.cc b/btif/src/bluetooth.cc
index 4fb8f64..63bbab6 100644
--- a/btif/src/bluetooth.cc
+++ b/btif/src/bluetooth.cc
@@ -62,11 +62,11 @@
 #include "btif_storage.h"
 #include "btsnoop.h"
 #include "btsnoop_mem.h"
+#include "common/metrics.h"
 #include "device/include/interop.h"
 #include "osi/include/alarm.h"
 #include "osi/include/allocation_tracker.h"
 #include "osi/include/log.h"
-#include "osi/include/metrics.h"
 #include "osi/include/osi.h"
 #include "osi/include/wakelock.h"
 #include "stack_manager.h"
@@ -329,7 +329,7 @@
 }
 
 static void dumpMetrics(std::string* output) {
-  system_bt_osi::BluetoothMetricsLogger::GetInstance()->WriteString(output);
+  bluetooth::common::BluetoothMetricsLogger::GetInstance()->WriteString(output);
 }
 
 static const void* get_profile_interface(const char* profile_id) {
@@ -413,8 +413,32 @@
   return btif_le_test_mode(opcode, buf, len);
 }
 
+static bt_os_callouts_t* wakelock_os_callouts_saved = nullptr;
+
+static int acquire_wake_lock_cb(const char* lock_name) {
+  return do_in_jni_thread(
+      FROM_HERE, base::Bind(base::IgnoreResult(
+                                wakelock_os_callouts_saved->acquire_wake_lock),
+                            lock_name));
+}
+
+static int release_wake_lock_cb(const char* lock_name) {
+  return do_in_jni_thread(
+      FROM_HERE, base::Bind(base::IgnoreResult(
+                                wakelock_os_callouts_saved->release_wake_lock),
+                            lock_name));
+}
+
+static bt_os_callouts_t wakelock_os_callouts_jni = {
+    sizeof(wakelock_os_callouts_jni),
+    nullptr /* not used */,
+    acquire_wake_lock_cb,
+    release_wake_lock_cb,
+};
+
 static int set_os_callouts(bt_os_callouts_t* callouts) {
-  wakelock_set_os_callouts(callouts);
+  wakelock_os_callouts_saved = callouts;
+  wakelock_set_os_callouts(&wakelock_os_callouts_jni);
   return BT_STATUS_SUCCESS;
 }
 
diff --git a/btif/src/btif_a2dp_audio_interface.cc b/btif/src/btif_a2dp_audio_interface.cc
index ff03129..7e46818 100644
--- a/btif/src/btif_a2dp_audio_interface.cc
+++ b/btif/src/btif_a2dp_audio_interface.cc
@@ -40,12 +40,13 @@
 #include "btif_av.h"
 #include "btif_av_co.h"
 #include "btif_hf.h"
-#include "osi/include/metrics.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
 #include "osi/include/osi.h"
 #include "stack/include/btu.h"
 
-using system_bt_osi::A2dpSessionMetrics;
-using system_bt_osi::BluetoothMetricsLogger;
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
 
 using android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload;
 using android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost;
@@ -108,11 +109,11 @@
   }
   void LogAudioStart() {
     std::lock_guard<std::recursive_mutex> lock(lock_);
-    audio_start_time_ms_ = time_get_os_boottime_ms();
+    audio_start_time_ms_ = bluetooth::common::time_get_os_boottime_ms();
   }
   void LogAudioStop() {
     std::lock_guard<std::recursive_mutex> lock(lock_);
-    audio_stop_time_ms_ = time_get_os_boottime_ms();
+    audio_stop_time_ms_ = bluetooth::common::time_get_os_boottime_ms();
   }
   void LogAudioStopMetricsAndReset() {
     std::lock_guard<std::recursive_mutex> lock(lock_);
@@ -164,8 +165,8 @@
       const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
     LOG_ERROR(LOG_TAG, "%s", __func__);
     // Restart the session on the correct thread
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&btif_a2dp_audio_interface_restart_session));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&btif_a2dp_audio_interface_restart_session));
   }
 };
 sp<BluetoothAudioDeathRecipient> bluetoothAudioDeathRecipient =
@@ -300,7 +301,7 @@
 void btif_a2dp_audio_interface_start_session() {
   LOG_INFO(LOG_TAG, "%s", __func__);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   a2dp_offload_audio_stats.Reset();
   btif_a2dp_audio_interface_init();
   CHECK(btAudio != nullptr);
@@ -314,7 +315,7 @@
   LOG_INFO(LOG_TAG, "%s", __func__);
   a2dp_offload_audio_stats.LogAudioStopMetricsAndReset();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   a2dp_offload_audio_stats.Reset();
   if (btAudio == nullptr) return;
   auto ret = btAudio->endSession();
diff --git a/btif/src/btif_a2dp_sink.cc b/btif/src/btif_a2dp_sink.cc
index f8dccfb..109b208 100644
--- a/btif/src/btif_a2dp_sink.cc
+++ b/btif/src/btif_a2dp_sink.cc
@@ -122,8 +122,7 @@
 // Mutex for below data structures.
 static std::mutex g_mutex;
 
-static BtifA2dpSinkControlBlock btif_a2dp_sink_cb(
-    "btif_a2dp_sink_worker_thread");
+static BtifA2dpSinkControlBlock btif_a2dp_sink_cb("bt_a2dp_sink_worker_thread");
 
 static std::atomic<int> btif_a2dp_sink_state{BTIF_A2DP_SINK_STATE_OFF};
 
diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc
index 4fc8d0f..c6d5b55 100644
--- a/btif/src/btif_a2dp_source.cc
+++ b/btif/src/btif_a2dp_source.cc
@@ -40,15 +40,15 @@
 #include "btif_av_co.h"
 #include "btif_util.h"
 #include "common/message_loop_thread.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
 #include "osi/include/fixed_queue.h"
 #include "osi/include/log.h"
-#include "osi/include/metrics.h"
 #include "osi/include/osi.h"
-#include "osi/include/time.h"
 #include "uipc.h"
 
-using system_bt_osi::BluetoothMetricsLogger;
-using system_bt_osi::A2dpSessionMetrics;
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
 
 extern std::unique_ptr<tUIPC_STATE> a2dp_uipc;
 
@@ -221,7 +221,7 @@
 };
 
 static bluetooth::common::MessageLoopThread btif_a2dp_source_thread(
-    "btif_a2dp_source_thread");
+    "bt_a2dp_source_worker_thread");
 static BtifA2dpSource btif_a2dp_source_cb;
 
 static void btif_a2dp_source_init_delayed(void);
@@ -382,7 +382,7 @@
     btif_a2dp_audio_interface_start_session();
   } else {
     BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-        system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+        bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   }
 }
 
@@ -437,7 +437,7 @@
            btif_a2dp_source_cb.StateStr().c_str());
   if (!btif_av_is_a2dp_offload_enabled()) {
     BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-        system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+        bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   }
   if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateRunning) {
     btif_av_stream_stop(peer_address);
@@ -722,9 +722,11 @@
             btif_a2dp_source_alarm_cb, nullptr);
 
   btif_a2dp_source_cb.stats.Reset();
-  // Assign session_start_us to 1 when time_get_os_boottime_us() is 0 to
-  // indicate btif_a2dp_source_start_audio_req() has been called
-  btif_a2dp_source_cb.stats.session_start_us = time_get_os_boottime_us();
+  // Assign session_start_us to 1 when
+  // bluetooth::common::time_get_os_boottime_us() is 0 to indicate
+  // btif_a2dp_source_start_audio_req() has been called
+  btif_a2dp_source_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
   if (btif_a2dp_source_cb.stats.session_start_us == 0) {
     btif_a2dp_source_cb.stats.session_start_us = 1;
   }
@@ -744,7 +746,8 @@
 
   if (btif_av_is_a2dp_offload_enabled()) return;
 
-  btif_a2dp_source_cb.stats.session_end_us = time_get_os_boottime_us();
+  btif_a2dp_source_cb.stats.session_end_us =
+      bluetooth::common::time_get_os_boottime_us();
   btif_a2dp_source_update_metrics();
   btif_a2dp_source_accumulate_stats(&btif_a2dp_source_cb.stats,
                                     &btif_a2dp_source_cb.accumulated_stats);
@@ -793,7 +796,7 @@
 static void btif_a2dp_source_audio_handle_timer(void) {
   if (btif_av_is_a2dp_offload_enabled()) return;
 
-  uint64_t timestamp_us = time_get_os_boottime_us();
+  uint64_t timestamp_us = bluetooth::common::time_get_os_boottime_us();
   log_tstamps_us("A2DP Source tx timer", timestamp_us);
 
   if (!alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
@@ -831,7 +834,7 @@
         (len - bytes_read);
     btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
     btif_a2dp_source_cb.stats.media_read_last_underflow_us =
-        time_get_os_boottime_us();
+        bluetooth::common::time_get_os_boottime_us();
   }
 
   return bytes_read;
@@ -839,7 +842,7 @@
 
 static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
                                               uint32_t bytes_read) {
-  uint64_t now_us = time_get_os_boottime_us();
+  uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
   btif_a2dp_control_log_bytes_read(bytes_read);
 
   /* Check if timer was stopped (media task stopped) */
@@ -931,7 +934,7 @@
   btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
       fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
   btif_a2dp_source_cb.stats.tx_queue_last_flushed_us =
-      time_get_os_boottime_us();
+      bluetooth::common::time_get_os_boottime_us();
   fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);
 
   UIPC_Ioctl(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, nullptr);
@@ -947,7 +950,7 @@
 }
 
 BT_HDR* btif_a2dp_source_audio_readbuf(void) {
-  uint64_t now_us = time_get_os_boottime_us();
+  uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
   BT_HDR* p_buf =
       (BT_HDR*)fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue);
 
@@ -1014,7 +1017,7 @@
 void btif_a2dp_source_debug_dump(int fd) {
   btif_a2dp_source_accumulate_stats(&btif_a2dp_source_cb.stats,
                                     &btif_a2dp_source_cb.accumulated_stats);
-  uint64_t now_us = time_get_os_boottime_us();
+  uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
   BtifMediaStats* accumulated_stats = &btif_a2dp_source_cb.accumulated_stats;
   SchedulingStats* enqueue_stats = &accumulated_stats->tx_queue_enqueue_stats;
   SchedulingStats* dequeue_stats = &accumulated_stats->tx_queue_dequeue_stats;
@@ -1186,7 +1189,7 @@
   // mark the metric duration as invalid (-1) in this case
   if (stats.session_start_us != 0) {
     int64_t session_end_us = stats.session_end_us == 0
-                                 ? time_get_os_boottime_us()
+                                 ? bluetooth::common::time_get_os_boottime_us()
                                  : stats.session_end_us;
     if (static_cast<uint64_t>(session_end_us) > stats.session_start_us) {
       metrics.audio_duration_ms =
diff --git a/btif/src/btif_av.cc b/btif/src/btif_av.cc
index 4795d19..345f577 100644
--- a/btif/src/btif_av.cc
+++ b/btif/src/btif_av.cc
@@ -907,11 +907,11 @@
 
   btif_queue_cleanup(UUID_SERVCLASS_AUDIO_SOURCE);
 
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE,
       base::Bind(base::IgnoreResult(&BtifAvSource::SetActivePeer),
                  base::Unretained(&btif_av_source), RawAddress::kEmpty));
-  do_in_bta_thread(FROM_HERE, base::Bind(&btif_a2dp_source_cleanup));
+  do_in_main_thread(FROM_HERE, base::Bind(&btif_a2dp_source_cleanup));
 
   btif_disable_service(BTA_A2DP_SOURCE_SERVICE_ID);
   CleanupAllPeers();
@@ -1092,11 +1092,11 @@
 
   btif_queue_cleanup(UUID_SERVCLASS_AUDIO_SINK);
 
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE,
       base::Bind(base::IgnoreResult(&BtifAvSink::SetActivePeer),
                  base::Unretained(&btif_av_sink), RawAddress::kEmpty));
-  do_in_bta_thread(FROM_HERE, base::Bind(&btif_a2dp_sink_cleanup));
+  do_in_main_thread(FROM_HERE, base::Bind(&btif_a2dp_sink_cleanup));
 
   btif_disable_service(BTA_A2DP_SINK_SERVICE_ID);
   CleanupAllPeers();
@@ -1274,11 +1274,11 @@
 
   // Delete peers that are re-entering the Idle state
   if (peer_.IsSink()) {
-    do_in_bta_thread(FROM_HERE, base::Bind(&BtifAvSource::DeleteIdlePeers,
-                                           base::Unretained(&btif_av_source)));
+    do_in_main_thread(FROM_HERE, base::Bind(&BtifAvSource::DeleteIdlePeers,
+                                            base::Unretained(&btif_av_source)));
   } else if (peer_.IsSource()) {
-    do_in_bta_thread(FROM_HERE, base::Bind(&BtifAvSink::DeleteIdlePeers,
-                                           base::Unretained(&btif_av_sink)));
+    do_in_main_thread(FROM_HERE, base::Bind(&BtifAvSink::DeleteIdlePeers,
+                                            base::Unretained(&btif_av_sink)));
   }
 }
 
@@ -2475,16 +2475,16 @@
   BtifAvEvent btif_av_event(event, p_data, sizeof(tBTA_AV));
   BTIF_TRACE_EVENT("%s: event=%s", __func__, btif_av_event.ToString().c_str());
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&btif_av_handle_bta_av_event,
-                              AVDT_TSEP_SNK /* peer_sep */, btif_av_event));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&btif_av_handle_bta_av_event,
+                               AVDT_TSEP_SNK /* peer_sep */, btif_av_event));
 }
 
 static void bta_av_sink_callback(tBTA_AV_EVT event, tBTA_AV* p_data) {
   BtifAvEvent btif_av_event(event, p_data, sizeof(tBTA_AV));
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&btif_av_handle_bta_av_event,
-                              AVDT_TSEP_SRC /* peer_sep */, btif_av_event));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&btif_av_handle_bta_av_event,
+                               AVDT_TSEP_SRC /* peer_sep */, btif_av_event));
 }
 
 // TODO: All processing should be done on the JNI thread
@@ -2526,10 +2526,11 @@
       config_req.peer_address = p_data->avk_config.bd_addr;
       BtifAvEvent btif_av_event(BTIF_AV_SINK_CONFIG_REQ_EVT, &config_req,
                                 sizeof(config_req));
-      do_in_bta_thread(FROM_HERE, base::Bind(&btif_av_handle_event,
-                                             AVDT_TSEP_SRC,  // peer_sep
-                                             config_req.peer_address,
-                                             kBtaHandleUnknown, btif_av_event));
+      do_in_main_thread(FROM_HERE,
+                        base::Bind(&btif_av_handle_event,
+                                   AVDT_TSEP_SRC,  // peer_sep
+                                   config_req.peer_address, kBtaHandleUnknown,
+                                   btif_av_event));
       break;
     }
     default:
@@ -2649,7 +2650,7 @@
 
   BtifAvEvent btif_av_event(BTIF_AV_DISCONNECT_REQ_EVT, &peer_address,
                             sizeof(peer_address));
-  return do_in_bta_thread(
+  return do_in_main_thread(
       FROM_HERE, base::Bind(&btif_av_handle_event,
                             AVDT_TSEP_SNK,  // peer_sep
                             peer_address, kBtaHandleUnknown, btif_av_event));
@@ -2665,7 +2666,7 @@
 
   BtifAvEvent btif_av_event(BTIF_AV_DISCONNECT_REQ_EVT, &peer_address,
                             sizeof(peer_address));
-  return do_in_bta_thread(
+  return do_in_main_thread(
       FROM_HERE, base::Bind(&btif_av_handle_event,
                             AVDT_TSEP_SRC,  // peer_sep
                             peer_address, kBtaHandleUnknown, btif_av_event));
@@ -2679,9 +2680,9 @@
     return BT_STATUS_NOT_READY;
   }
 
-  return do_in_bta_thread(FROM_HERE, base::Bind(&set_active_peer_int,
-                                                AVDT_TSEP_SNK,  // peer_sep
-                                                peer_address));
+  return do_in_main_thread(FROM_HERE, base::Bind(&set_active_peer_int,
+                                                 AVDT_TSEP_SNK,  // peer_sep
+                                                 peer_address));
 }
 
 static bt_status_t codec_config_src(
@@ -2694,7 +2695,7 @@
     return BT_STATUS_NOT_READY;
   }
 
-  return do_in_bta_thread(
+  return do_in_main_thread(
       FROM_HERE, base::Bind(&BtifAvSource::UpdateCodecConfig,
                             base::Unretained(&btif_av_source), peer_address,
                             codec_preferences));
@@ -2702,14 +2703,14 @@
 
 static void cleanup_src(void) {
   BTIF_TRACE_EVENT("%s", __func__);
-  do_in_bta_thread(FROM_HERE, base::Bind(&BtifAvSource::Cleanup,
-                                         base::Unretained(&btif_av_source)));
+  do_in_main_thread(FROM_HERE, base::Bind(&BtifAvSource::Cleanup,
+                                          base::Unretained(&btif_av_source)));
 }
 
 static void cleanup_sink(void) {
   BTIF_TRACE_EVENT("%s", __func__);
-  do_in_bta_thread(FROM_HERE, base::Bind(&BtifAvSink::Cleanup,
-                                         base::Unretained(&btif_av_sink)));
+  do_in_main_thread(FROM_HERE, base::Bind(&BtifAvSink::Cleanup,
+                                          base::Unretained(&btif_av_sink)));
 }
 
 static const btav_source_interface_t bt_av_src_interface = {
@@ -2837,10 +2838,10 @@
                    peer_address.ToString().c_str(),
                    btif_av_event.ToString().c_str());
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&btif_av_handle_event,
-                              AVDT_TSEP_SNK,  // peer_sep
-                              peer_address, kBtaHandleUnknown, btif_av_event));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&btif_av_handle_event,
+                               AVDT_TSEP_SNK,  // peer_sep
+                               peer_address, kBtaHandleUnknown, btif_av_event));
 }
 
 static void btif_av_sink_dispatch_sm_event(const RawAddress& peer_address,
@@ -2850,10 +2851,10 @@
                    peer_address.ToString().c_str(),
                    btif_av_event.ToString().c_str());
 
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(&btif_av_handle_event,
-                              AVDT_TSEP_SRC,  // peer_sep
-                              peer_address, kBtaHandleUnknown, btif_av_event));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(&btif_av_handle_event,
+                               AVDT_TSEP_SRC,  // peer_sep
+                               peer_address, kBtaHandleUnknown, btif_av_event));
 }
 
 bt_status_t btif_av_source_execute_service(bool enable) {
diff --git a/btif/src/btif_ble_advertiser.cc b/btif/src/btif_ble_advertiser.cc
index d11e733..339b42a 100644
--- a/btif/src/btif_ble_advertiser.cc
+++ b/btif/src/btif_ble_advertiser.cc
@@ -93,7 +93,7 @@
   }
 
   void RegisterAdvertiser(IdStatusCallback cb) override {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE, Bind(&BleAdvertisingManager::RegisterAdvertiser,
                         BleAdvertisingManager::Get(),
                         Bind(&BleAdvertiserInterfaceImpl::RegisterAdvertiserCb,
@@ -101,7 +101,7 @@
   }
 
   void Unregister(uint8_t advertiser_id) override {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(
             [](uint8_t advertiser_id) {
@@ -116,10 +116,10 @@
 
   void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) override {
     if (!BleAdvertisingManager::IsInitialized()) return;
-    do_in_bta_thread(FROM_HERE,
-                     Bind(&BleAdvertisingManager::GetOwnAddress,
-                          BleAdvertisingManager::Get(), advertiser_id,
-                          jni_thread_wrapper(FROM_HERE, cb)));
+    do_in_main_thread(FROM_HERE,
+                      Bind(&BleAdvertisingManager::GetOwnAddress,
+                           BleAdvertisingManager::Get(), advertiser_id,
+                           jni_thread_wrapper(FROM_HERE, cb)));
   }
 
   void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
@@ -130,16 +130,16 @@
     tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
     parseParams(p_params, params);
 
-    do_in_bta_thread(FROM_HERE, Bind(&BleAdvertisingManager::SetParameters,
-                                     BleAdvertisingManager::Get(),
-                                     advertiser_id, base::Owned(p_params),
-                                     jni_thread_wrapper(FROM_HERE, cb)));
+    do_in_main_thread(FROM_HERE, Bind(&BleAdvertisingManager::SetParameters,
+                                      BleAdvertisingManager::Get(),
+                                      advertiser_id, base::Owned(p_params),
+                                      jni_thread_wrapper(FROM_HERE, cb)));
   }
 
   void SetData(int advertiser_id, bool set_scan_rsp, vector<uint8_t> data,
                StatusCallback cb) override {
     if (!BleAdvertisingManager::IsInitialized()) return;
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&BleAdvertisingManager::SetData, BleAdvertisingManager::Get(),
              advertiser_id, set_scan_rsp, std::move(data),
@@ -153,7 +153,7 @@
             << " ,enable: " << enable;
 
     if (!BleAdvertisingManager::IsInitialized()) return;
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&BleAdvertisingManager::Enable, BleAdvertisingManager::Get(),
              advertiser_id, enable, jni_thread_wrapper(FROM_HERE, cb), duration,
@@ -171,7 +171,7 @@
     tBTM_BLE_ADV_PARAMS* p_params = new tBTM_BLE_ADV_PARAMS;
     parseParams(p_params, params);
 
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&BleAdvertisingManager::StartAdvertising,
              BleAdvertisingManager::Get(), advertiser_id,
@@ -197,7 +197,7 @@
     tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
     parsePeriodicParams(p_periodic_params, periodic_params);
 
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&BleAdvertisingManager::StartAdvertisingSet,
              BleAdvertisingManager::Get(), jni_thread_wrapper(FROM_HERE, cb),
@@ -216,7 +216,7 @@
     tBLE_PERIODIC_ADV_PARAMS* p_periodic_params = new tBLE_PERIODIC_ADV_PARAMS;
     parsePeriodicParams(p_periodic_params, periodic_params);
 
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&BleAdvertisingManager::SetPeriodicAdvertisingParameters,
              BleAdvertisingManager::Get(), advertiser_id,
@@ -229,10 +229,10 @@
     VLOG(1) << __func__ << " advertiser_id: " << +advertiser_id;
 
     if (!BleAdvertisingManager::IsInitialized()) return;
-    do_in_bta_thread(FROM_HERE,
-                     Bind(&BleAdvertisingManager::SetPeriodicAdvertisingData,
-                          BleAdvertisingManager::Get(), advertiser_id,
-                          std::move(data), jni_thread_wrapper(FROM_HERE, cb)));
+    do_in_main_thread(FROM_HERE,
+                      Bind(&BleAdvertisingManager::SetPeriodicAdvertisingData,
+                           BleAdvertisingManager::Get(), advertiser_id,
+                           std::move(data), jni_thread_wrapper(FROM_HERE, cb)));
   }
 
   void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable,
@@ -241,10 +241,10 @@
             << " ,enable: " << enable;
 
     if (!BleAdvertisingManager::IsInitialized()) return;
-    do_in_bta_thread(FROM_HERE,
-                     Bind(&BleAdvertisingManager::SetPeriodicAdvertisingEnable,
-                          BleAdvertisingManager::Get(), advertiser_id, enable,
-                          jni_thread_wrapper(FROM_HERE, cb)));
+    do_in_main_thread(FROM_HERE,
+                      Bind(&BleAdvertisingManager::SetPeriodicAdvertisingEnable,
+                           BleAdvertisingManager::Get(), advertiser_id, enable,
+                           jni_thread_wrapper(FROM_HERE, cb)));
   }
 };
 
diff --git a/btif/src/btif_ble_scanner.cc b/btif/src/btif_ble_scanner.cc
index 493bd1c..ae529d5 100644
--- a/btif/src/btif_ble_scanner.cc
+++ b/btif/src/btif_ble_scanner.cc
@@ -206,31 +206,31 @@
   ~BleScannerInterfaceImpl(){};
 
   void RegisterScanner(RegisterCallback cb) override {
-    do_in_bta_thread(FROM_HERE,
-                     Bind(
-                         [](RegisterCallback cb) {
-                           BTA_GATTC_AppRegister(
-                               bta_cback,
-                               jni_thread_wrapper(FROM_HERE, std::move(cb)));
-                         },
-                         std::move(cb)));
+    do_in_main_thread(FROM_HERE,
+                      Bind(
+                          [](RegisterCallback cb) {
+                            BTA_GATTC_AppRegister(
+                                bta_cback,
+                                jni_thread_wrapper(FROM_HERE, std::move(cb)));
+                          },
+                          std::move(cb)));
   }
 
   void Unregister(int scanner_id) override {
-    do_in_bta_thread(FROM_HERE, Bind(&BTA_GATTC_AppDeregister, scanner_id));
+    do_in_main_thread(FROM_HERE, Bind(&BTA_GATTC_AppDeregister, scanner_id));
   }
 
   void Scan(bool start) override {
     do_in_jni_thread(Bind(
         [](bool start) {
           if (!start) {
-            do_in_bta_thread(FROM_HERE,
-                             Bind(&BTA_DmBleObserve, false, 0, nullptr));
+            do_in_main_thread(FROM_HERE,
+                              Bind(&BTA_DmBleObserve, false, 0, nullptr));
             return;
           }
 
           btif_gattc_init_dev_cb();
-          do_in_bta_thread(
+          do_in_main_thread(
               FROM_HERE, Bind(&BTA_DmBleObserve, true, 0, bta_scan_results_cb));
         },
         start));
@@ -243,22 +243,22 @@
     BTIF_TRACE_DEBUG("%s", __func__);
 
     if (filt_param && filt_param->dely_mode == 1) {
-      do_in_bta_thread(
+      do_in_main_thread(
           FROM_HERE, base::Bind(BTM_BleTrackAdvertiser, bta_track_adv_event_cb,
                                 client_if));
     }
 
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&BTM_BleAdvFilterParamSetup, action, filt_index,
-                                base::Passed(&filt_param),
-                                jni_thread_wrapper(FROM_HERE, std::move(cb))));
+    do_in_main_thread(
+        FROM_HERE, base::Bind(&BTM_BleAdvFilterParamSetup, action, filt_index,
+                              base::Passed(&filt_param),
+                              jni_thread_wrapper(FROM_HERE, std::move(cb))));
   }
 
   void ScanFilterAdd(int filter_index, std::vector<ApcfCommand> filters,
                      FilterConfigCallback cb) override {
     BTIF_TRACE_DEBUG("%s: %d", __func__, filter_index);
 
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         base::Bind(
             &BTM_LE_PF_set, filter_index, std::move(filters),
@@ -270,24 +270,24 @@
 
   void ScanFilterClear(int filter_index, FilterConfigCallback cb) override {
     BTIF_TRACE_DEBUG("%s: filter_index: %d", __func__, filter_index);
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&BTM_LE_PF_clear, filter_index,
-                                jni_thread_wrapper(
-                                    FROM_HERE, Bind(cb, BTM_BLE_PF_TYPE_ALL))));
+    do_in_main_thread(
+        FROM_HERE, base::Bind(&BTM_LE_PF_clear, filter_index,
+                              jni_thread_wrapper(
+                                  FROM_HERE, Bind(cb, BTM_BLE_PF_TYPE_ALL))));
   }
 
   void ScanFilterEnable(bool enable, EnableCallback cb) override {
     BTIF_TRACE_DEBUG("%s: enable: %d", __func__, enable);
 
     uint8_t action = enable ? 1 : 0;
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&BTM_BleEnableDisableFilterFeature, action,
-                                jni_thread_wrapper(FROM_HERE, std::move(cb))));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&BTM_BleEnableDisableFilterFeature, action,
+                                 jni_thread_wrapper(FROM_HERE, std::move(cb))));
   }
 
   void SetScanParameters(int scan_interval, int scan_window,
                          Callback cb) override {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE, base::Bind(&BTM_BleSetScanParams, scan_interval, scan_window,
                               BTM_BLE_SCAN_MODE_ACTI,
                               jni_thread_wrapper(FROM_HERE, std::move(cb))));
@@ -297,7 +297,7 @@
                               int batch_scan_trunc_max,
                               int batch_scan_notify_threshold,
                               Callback cb) override {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         base::Bind(&BTM_BleSetStorageConfig, (uint8_t)batch_scan_full_max,
                    (uint8_t)batch_scan_trunc_max,
@@ -308,21 +308,21 @@
 
   void BatchscanEnable(int scan_mode, int scan_interval, int scan_window,
                        int addr_type, int discard_rule, Callback cb) override {
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE, base::Bind(&BTM_BleEnableBatchScan, scan_mode, scan_interval,
                               scan_window, discard_rule, addr_type,
                               jni_thread_wrapper(FROM_HERE, cb)));
   }
 
   void BatchscanDisable(Callback cb) override {
-    do_in_bta_thread(FROM_HERE, base::Bind(&BTM_BleDisableBatchScan,
-                                           jni_thread_wrapper(FROM_HERE, cb)));
+    do_in_main_thread(FROM_HERE, base::Bind(&BTM_BleDisableBatchScan,
+                                            jni_thread_wrapper(FROM_HERE, cb)));
   }
 
   void BatchscanReadReports(int client_if, int scan_mode) override {
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(&BTM_BleReadScanReports, (uint8_t)scan_mode,
-                                Bind(bta_batch_scan_reports_cb, client_if)));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(&BTM_BleReadScanReports, (uint8_t)scan_mode,
+                                 Bind(bta_batch_scan_reports_cb, client_if)));
   }
 
   void StartSync(uint8_t sid, RawAddress address, uint16_t skip,
diff --git a/btif/src/btif_core.cc b/btif/src/btif_core.cc
index d2d8865..1072b52 100644
--- a/btif/src/btif_core.cc
+++ b/btif/src/btif_core.cc
@@ -128,7 +128,7 @@
  */
 static uint8_t btif_dut_mode = 0;
 
-static MessageLoopThread bt_jni_workqueue_thread("bt_jni_workqueue");
+static MessageLoopThread jni_thread("bt_jni_thread");
 static base::AtExitManager* exit_manager;
 static uid_set_t* uid_set;
 
@@ -222,7 +222,7 @@
  **/
 bt_status_t do_in_jni_thread(const tracked_objects::Location& from_here,
                              base::OnceClosure task) {
-  if (!bt_jni_workqueue_thread.DoInThread(from_here, std::move(task))) {
+  if (!jni_thread.DoInThread(from_here, std::move(task))) {
     LOG(ERROR) << __func__ << ": Post task to task runner failed!";
     return BT_STATUS_FAIL;
   }
@@ -234,12 +234,10 @@
 }
 
 bool is_on_jni_thread() {
-  return bt_jni_workqueue_thread.GetThreadId() == PlatformThread::CurrentId();
+  return jni_thread.GetThreadId() == PlatformThread::CurrentId();
 }
 
-base::MessageLoop* get_jni_message_loop() {
-  return bt_jni_workqueue_thread.message_loop();
-}
+base::MessageLoop* get_jni_message_loop() { return jni_thread.message_loop(); }
 
 /*******************************************************************************
  *
@@ -327,8 +325,8 @@
   LOG_INFO(LOG_TAG, "%s entered", __func__);
   exit_manager = new base::AtExitManager();
   bte_main_boot_entry();
-  bt_jni_workqueue_thread.StartUp();
-  bt_jni_workqueue_thread.DoInThread(FROM_HERE, base::Bind(btif_jni_associate));
+  jni_thread.StartUp();
+  jni_thread.DoInThread(FROM_HERE, base::Bind(btif_jni_associate));
   LOG_INFO(LOG_TAG, "%s finished", __func__);
   return BT_STATUS_SUCCESS;
 }
@@ -418,7 +416,7 @@
 bt_status_t btif_disable_bluetooth() {
   LOG_INFO(LOG_TAG, "%s entered", __func__);
 
-  do_in_bta_thread(FROM_HERE, base::Bind(&btm_ble_multi_adv_cleanup));
+  do_in_main_thread(FROM_HERE, base::Bind(&btm_ble_multi_adv_cleanup));
   // TODO(jpawlowski): this should do whole BTA_VendorCleanup(), but it would
   // kill the stack now.
 
@@ -468,12 +466,11 @@
 
 bt_status_t btif_cleanup_bluetooth() {
   LOG_INFO(LOG_TAG, "%s entered", __func__);
-  do_in_bta_thread(FROM_HERE, base::Bind(&BTA_VendorCleanup));
+  do_in_main_thread(FROM_HERE, base::Bind(&BTA_VendorCleanup));
   btif_dm_cleanup();
-  bt_jni_workqueue_thread.DoInThread(FROM_HERE,
-                                     base::BindOnce(btif_jni_disassociate));
+  jni_thread.DoInThread(FROM_HERE, base::BindOnce(btif_jni_disassociate));
   btif_queue_release();
-  bt_jni_workqueue_thread.ShutDown();
+  jni_thread.ShutDown();
   bte_main_cleanup();
   delete exit_manager;
   exit_manager = nullptr;
diff --git a/btif/src/btif_debug_btsnoop.cc b/btif/src/btif_debug_btsnoop.cc
index 1dcb835..3ebbe06 100644
--- a/btif/src/btif_debug_btsnoop.cc
+++ b/btif/src/btif_debug_btsnoop.cc
@@ -27,7 +27,6 @@
 #include "hci/include/btsnoop_mem.h"
 #include "internal_include/bt_target.h"
 #include "osi/include/ringbuffer.h"
-#include "osi/include/time.h"
 
 #define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) ((type) >> 8)
 
diff --git a/btif/src/btif_debug_conn.cc b/btif/src/btif_debug_conn.cc
index 6b4d96f..dc36c45 100644
--- a/btif/src/btif_debug_conn.cc
+++ b/btif/src/btif_debug_conn.cc
@@ -21,7 +21,7 @@
 #include <time.h>
 
 #include "btif/include/btif_debug_conn.h"
-#include "osi/include/time.h"
+#include "common/time_util.h"
 
 #define NUM_CONNECTION_EVENTS 16
 #define TEMP_BUFFER_SIZE 30
@@ -69,7 +69,7 @@
   next_event();
 
   conn_event_t* evt = &connection_events[current_event];
-  evt->ts = time_gettimeofday_us();
+  evt->ts = bluetooth::common::time_gettimeofday_us();
   evt->state = state;
   evt->disconnect_reason = disconnect_reason;
   evt->bda = bda;
diff --git a/btif/src/btif_dm.cc b/btif/src/btif_dm.cc
index 8a8da85..21bba34 100644
--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -59,12 +59,12 @@
 #include "btif_storage.h"
 #include "btif_util.h"
 #include "btu.h"
+#include "common/metrics.h"
 #include "device/include/controller.h"
 #include "device/include/interop.h"
 #include "internal_include/stack_config.h"
 #include "osi/include/allocator.h"
 #include "osi/include/log.h"
-#include "osi/include/metrics.h"
 #include "osi/include/osi.h"
 #include "osi/include/properties.h"
 #include "stack/btm/btm_int.h"
@@ -1338,7 +1338,7 @@
     } break;
 
     case BTA_DM_INQ_CMPL_EVT: {
-      do_in_bta_thread(
+      do_in_main_thread(
           FROM_HERE,
           base::Bind(&BTM_BleAdvFilterParamSetup, BTM_BLE_SCAN_COND_DELETE, 0,
                      nullptr, base::Bind(&bte_scan_filt_param_cfg_evt, 0)));
@@ -1360,7 +1360,7 @@
       if (!btif_dm_inquiry_in_progress) {
         btgatt_filt_param_setup_t adv_filt_param;
         memset(&adv_filt_param, 0, sizeof(btgatt_filt_param_setup_t));
-        do_in_bta_thread(
+        do_in_main_thread(
             FROM_HERE,
             base::Bind(&BTM_BleAdvFilterParamSetup, BTM_BLE_SCAN_COND_DELETE, 0,
                        nullptr, base::Bind(&bte_scan_filt_param_cfg_evt, 0)));
@@ -2137,7 +2137,7 @@
   BTIF_TRACE_EVENT("%s", __func__);
 
   /* Cleanup anything remaining on index 0 */
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE,
       base::Bind(&BTM_BleAdvFilterParamSetup, BTM_BLE_SCAN_COND_DELETE, 0,
                  nullptr, base::Bind(&bte_scan_filt_param_cfg_evt, 0)));
@@ -2150,7 +2150,7 @@
   adv_filt_param->list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
   adv_filt_param->rssi_low_thres = LOWEST_RSSI_VALUE;
   adv_filt_param->rssi_high_thres = LOWEST_RSSI_VALUE;
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(&BTM_BleAdvFilterParamSetup, BTM_BLE_SCAN_COND_ADD,
                             0, base::Passed(&adv_filt_param),
                             base::Bind(&bte_scan_filt_param_cfg_evt, 0)));
@@ -3230,26 +3230,26 @@
   int type;
   btif_get_device_type(bd_addr, &type);
 
-  system_bt_osi::device_type_t device_type;
+  bluetooth::common::device_type_t device_type;
   switch (type) {
     case BT_DEVICE_TYPE_BREDR:
-      device_type = system_bt_osi::DEVICE_TYPE_BREDR;
+      device_type = bluetooth::common::DEVICE_TYPE_BREDR;
       break;
     case BT_DEVICE_TYPE_BLE:
-      device_type = system_bt_osi::DEVICE_TYPE_LE;
+      device_type = bluetooth::common::DEVICE_TYPE_LE;
       break;
     case BT_DEVICE_TYPE_DUMO:
-      device_type = system_bt_osi::DEVICE_TYPE_DUMO;
+      device_type = bluetooth::common::DEVICE_TYPE_DUMO;
       break;
     default:
-      device_type = system_bt_osi::DEVICE_TYPE_UNKNOWN;
+      device_type = bluetooth::common::DEVICE_TYPE_UNKNOWN;
       break;
   }
 
   uint32_t cod = get_cod(&bd_addr);
   uint64_t ts =
       event->timestamp.tv_sec * 1000 + event->timestamp.tv_nsec / 1000000;
-  system_bt_osi::BluetoothMetricsLogger::GetInstance()->LogPairEvent(
+  bluetooth::common::BluetoothMetricsLogger::GetInstance()->LogPairEvent(
       0, ts, cod, device_type);
 }
 
diff --git a/btif/src/btif_gatt_client.cc b/btif/src/btif_gatt_client.cc
index 7e2d88b..ede334b 100644
--- a/btif/src/btif_gatt_client.cc
+++ b/btif/src/btif_gatt_client.cc
@@ -565,8 +565,8 @@
                                          uint8_t tx_phy, uint8_t rx_phy,
                                          uint16_t phy_options) {
   CHECK_BTGATT_INIT();
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options));
   return BT_STATUS_SUCCESS;
 }
 
@@ -574,8 +574,8 @@
     const RawAddress& bd_addr,
     base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) {
   CHECK_BTGATT_INIT();
-  do_in_bta_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr,
-                                   jni_thread_wrapper(FROM_HERE, cb)));
+  do_in_main_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr,
+                                    jni_thread_wrapper(FROM_HERE, cb)));
   return BT_STATUS_SUCCESS;
 }
 
diff --git a/btif/src/btif_gatt_server.cc b/btif/src/btif_gatt_server.cc
index 2c10842..d994d2a 100644
--- a/btif/src/btif_gatt_server.cc
+++ b/btif/src/btif_gatt_server.cc
@@ -425,8 +425,8 @@
                                                 uint8_t tx_phy, uint8_t rx_phy,
                                                 uint16_t phy_options) {
   CHECK_BTGATT_INIT();
-  do_in_bta_thread(FROM_HERE,
-                   Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options));
+  do_in_main_thread(FROM_HERE,
+                    Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options));
   return BT_STATUS_SUCCESS;
 }
 
@@ -434,8 +434,8 @@
     const RawAddress& bd_addr,
     base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) {
   CHECK_BTGATT_INIT();
-  do_in_bta_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr,
-                                   jni_thread_wrapper(FROM_HERE, cb)));
+  do_in_main_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr,
+                                    jni_thread_wrapper(FROM_HERE, cb)));
   return BT_STATUS_SUCCESS;
 }
 
diff --git a/btif/src/btif_hearing_aid.cc b/btif/src/btif_hearing_aid.cc
index 7244cf0..ec742fb 100644
--- a/btif/src/btif_hearing_aid.cc
+++ b/btif/src/btif_hearing_aid.cc
@@ -57,7 +57,7 @@
   void Init(HearingAidCallbacks* callbacks) override {
     DVLOG(2) << __func__;
     this->callbacks = callbacks;
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&HearingAid::Initialize, this,
              jni_thread_wrapper(FROM_HERE,
@@ -83,22 +83,22 @@
 
   void Connect(const RawAddress& address) override {
     DVLOG(2) << __func__ << " address: " << address;
-    do_in_bta_thread(FROM_HERE, Bind(&HearingAid::Connect,
-                                     Unretained(HearingAid::Get()), address));
+    do_in_main_thread(FROM_HERE, Bind(&HearingAid::Connect,
+                                      Unretained(HearingAid::Get()), address));
   }
 
   void Disconnect(const RawAddress& address) override {
     DVLOG(2) << __func__ << " address: " << address;
-    do_in_bta_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
-                                     Unretained(HearingAid::Get()), address));
+    do_in_main_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
+                                      Unretained(HearingAid::Get()), address));
     do_in_jni_thread(
         FROM_HERE, Bind(&btif_storage_remove_hearing_aid_white_list, address));
   }
 
   void SetVolume(int8_t volume) override {
     DVLOG(2) << __func__ << " volume: " << +volume;
-    do_in_bta_thread(FROM_HERE, Bind(&HearingAid::SetVolume,
-                                     Unretained(HearingAid::Get()), volume));
+    do_in_main_thread(FROM_HERE, Bind(&HearingAid::SetVolume,
+                                      Unretained(HearingAid::Get()), volume));
   }
 
   void RemoveDevice(const RawAddress& address) override {
@@ -106,8 +106,9 @@
 
     // RemoveDevice can be called on devices that don't have HA enabled
     if (HearingAid::IsInitialized()) {
-      do_in_bta_thread(FROM_HERE, Bind(&HearingAid::Disconnect,
-                                       Unretained(HearingAid::Get()), address));
+      do_in_main_thread(FROM_HERE,
+                        Bind(&HearingAid::Disconnect,
+                             Unretained(HearingAid::Get()), address));
     }
 
     do_in_jni_thread(FROM_HERE,
@@ -116,7 +117,7 @@
 
   void Cleanup(void) override {
     DVLOG(2) << __func__;
-    do_in_bta_thread(FROM_HERE, Bind(&HearingAid::CleanUp));
+    do_in_main_thread(FROM_HERE, Bind(&HearingAid::CleanUp));
   }
 
  private:
diff --git a/btif/src/btif_hf.cc b/btif/src/btif_hf.cc
index 038af2e..f5c971b 100644
--- a/btif/src/btif_hf.cc
+++ b/btif/src/btif_hf.cc
@@ -43,7 +43,7 @@
 #include "btif_hf.h"
 #include "btif_profile_queue.h"
 #include "btif_util.h"
-#include "osi/include/metrics.h"
+#include "common/metrics.h"
 
 namespace bluetooth {
 namespace headset {
@@ -331,7 +331,7 @@
         btif_hf_cb[idx].state = BTHF_CONNECTION_STATE_CONNECTED;
         btif_hf_cb[idx].peer_feat = 0;
         clear_phone_state_multihf(&btif_hf_cb[idx]);
-        system_bt_osi::BluetoothMetricsLogger::GetInstance()
+        bluetooth::common::BluetoothMetricsLogger::GetInstance()
             ->LogHeadsetProfileRfcConnection(p_data->open.service_id);
         bt_hf_callbacks->ConnectionStateCallback(
             btif_hf_cb[idx].state, &btif_hf_cb[idx].connected_bda);
diff --git a/btif/src/btif_pan.cc b/btif/src/btif_pan.cc
index b210989..fe10b49 100644
--- a/btif/src/btif_pan.cc
+++ b/btif/src/btif_pan.cc
@@ -369,8 +369,8 @@
   btpan_cb.flow = enable;
   if (enable) {
     btsock_thread_add_fd(pan_pth, btpan_cb.tap_fd, 0, SOCK_THREAD_FD_RD, 0);
-    do_in_bta_thread(FROM_HERE,
-                     base::Bind(btu_exec_tap_fd_read, btpan_cb.tap_fd));
+    do_in_main_thread(FROM_HERE,
+                      base::Bind(btu_exec_tap_fd_read, btpan_cb.tap_fd));
   }
 }
 
@@ -773,6 +773,6 @@
     btpan_tap_close(fd);
     btif_pan_close_all_conns();
   } else if (flags & SOCK_THREAD_FD_RD) {
-    do_in_bta_thread(FROM_HERE, base::Bind(btu_exec_tap_fd_read, fd));
+    do_in_main_thread(FROM_HERE, base::Bind(btu_exec_tap_fd_read, fd));
   }
 }
diff --git a/btif/src/btif_storage.cc b/btif/src/btif_storage.cc
index 22689f5..b067f3b 100644
--- a/btif/src/btif_storage.cc
+++ b/btif/src/btif_storage.cc
@@ -1523,7 +1523,7 @@
     RawAddress bd_addr;
     RawAddress::FromString(name, bd_addr);
     // add extracted information to BTA Hearing Aid
-    do_in_bta_thread(
+    do_in_main_thread(
         FROM_HERE,
         Bind(&HearingAid::AddFromStorage, bd_addr, psm, capabilities, codecs,
              audio_control_point_handle, volume_handle, hi_sync_id,
diff --git a/btif/src/stack_manager.cc b/btif/src/stack_manager.cc
index 518f1c5..60c2c0c 100644
--- a/btif/src/stack_manager.cc
+++ b/btif/src/stack_manager.cc
@@ -39,7 +39,7 @@
 
 using bluetooth::common::MessageLoopThread;
 
-static MessageLoopThread management_thread("stack_manager");
+static MessageLoopThread management_thread("bt_stack_manager_thread");
 
 // If initialized, any of the bluetooth API functions can be called.
 // (e.g. turning logging on and off, enabling/disabling the stack, etc)
diff --git a/common/Android.bp b/common/Android.bp
index 3454861..d33c751 100644
--- a/common/Android.bp
+++ b/common/Android.bp
@@ -2,10 +2,17 @@
     name: "libbt-common",
     defaults: ["fluoride_defaults"],
     host_supported: true,
-    include_dirs: ["system/bt"],
+    include_dirs: [
+        "system/bt",
+        "system/bt/stack/include",
+    ],
     srcs: [
         "message_loop_thread.cc",
-        "execution_barrier.cc",
+        "metrics.cc",
+        "time_util.cc",
+    ],
+    static_libs: [
+        "libbt-protos-lite",
     ],
 }
 
@@ -14,14 +21,27 @@
     test_suites: ["device-tests"],
     defaults: ["fluoride_defaults"],
     host_supported: true,
-    include_dirs: ["system/bt"],
+    include_dirs: [
+        "system/bt",
+        "system/bt/stack/include",
+    ],
     srcs : [
+        "leaky_bonded_queue_unittest.cc",
         "message_loop_thread_unittest.cc",
-        "execution_barrier_unittest.cc",
+        "metrics_unittest.cc",
+        "time_util_unittest.cc",
+    ],
+    shared_libs: [
+        "libprotobuf-cpp-lite",
     ],
     static_libs : [
+        "libgmock",
         "libbt-common",
-    ]
+        "libbt-protos-lite",
+    ],
+    sanitize: {
+        cfi: false,
+    },
 }
 
 cc_test {
@@ -56,4 +76,4 @@
         "libosi",
         "libbt-common"
     ],
-}
\ No newline at end of file
+}
diff --git a/common/benchmark/thread_performance_benchmark.cc b/common/benchmark/thread_performance_benchmark.cc
index 6574329..74f157f 100644
--- a/common/benchmark/thread_performance_benchmark.cc
+++ b/common/benchmark/thread_performance_benchmark.cc
@@ -19,22 +19,21 @@
 #include <base/run_loop.h>
 #include <base/threading/thread.h>
 #include <benchmark/benchmark.h>
+#include <future>
 #include <memory>
 #include <thread>
 
-#include "common/execution_barrier.h"
 #include "common/message_loop_thread.h"
 #include "osi/include/fixed_queue.h"
 #include "osi/include/thread.h"
 
 using ::benchmark::State;
-using bluetooth::common::ExecutionBarrier;
 using bluetooth::common::MessageLoopThread;
 
 #define NUM_MESSAGES_TO_SEND 100000
 
 volatile static int g_counter = 0;
-static std::unique_ptr<ExecutionBarrier> g_counter_barrier = nullptr;
+static std::unique_ptr<std::promise<void>> g_counter_promise = nullptr;
 
 void pthread_callback_batch(void* context) {
   auto queue = static_cast<fixed_queue_t*>(context);
@@ -42,16 +41,16 @@
   fixed_queue_dequeue(queue);
   g_counter++;
   if (g_counter >= NUM_MESSAGES_TO_SEND) {
-    g_counter_barrier->NotifyFinished();
+    g_counter_promise->set_value();
   }
 }
 
-void callback_sequential(void* context) { g_counter_barrier->NotifyFinished(); }
+void callback_sequential(void* context) { g_counter_promise->set_value(); }
 
 void callback_sequential_queue(fixed_queue_t* queue, void* context) {
   CHECK_NE(queue, nullptr);
   fixed_queue_dequeue(queue);
-  g_counter_barrier->NotifyFinished();
+  g_counter_promise->set_value();
 }
 
 void callback_batch(fixed_queue_t* queue, void* data) {
@@ -59,7 +58,7 @@
   fixed_queue_dequeue(queue);
   g_counter++;
   if (g_counter >= NUM_MESSAGES_TO_SEND) {
-    g_counter_barrier->NotifyFinished();
+    g_counter_promise->set_value();
   }
 }
 
@@ -67,19 +66,19 @@
  protected:
   void SetUp(State& st) override {
     benchmark::Fixture::SetUp(st);
-    set_up_barrier_ = std::make_unique<ExecutionBarrier>();
+    set_up_promise_ = std::make_unique<std::promise<void>>();
     g_counter = 0;
     bt_msg_queue_ = fixed_queue_new(SIZE_MAX);
   }
   void TearDown(State& st) override {
     fixed_queue_free(bt_msg_queue_, nullptr);
     bt_msg_queue_ = nullptr;
-    set_up_barrier_.reset(nullptr);
-    g_counter_barrier.reset(nullptr);
+    set_up_promise_.reset(nullptr);
+    g_counter_promise.reset(nullptr);
     benchmark::Fixture::TearDown(st);
   }
   fixed_queue_t* bt_msg_queue_ = nullptr;
-  std::unique_ptr<ExecutionBarrier> set_up_barrier_;
+  std::unique_ptr<std::promise<void>> set_up_promise_;
 };
 
 class BM_MessageLoop : public BM_ThreadPerformance {
@@ -97,8 +96,8 @@
     message_loop_ = new base::MessageLoop();
     run_loop_ = new base::RunLoop();
     message_loop_->task_runner()->PostTask(
-        FROM_HERE, base::BindOnce(&ExecutionBarrier::NotifyFinished,
-                                  base::Unretained(set_up_barrier_.get())));
+        FROM_HERE, base::BindOnce(&std::promise<void>::set_value,
+                                  base::Unretained(set_up_promise_.get())));
     run_loop_->Run();
     delete message_loop_;
     message_loop_ = nullptr;
@@ -115,9 +114,10 @@
  protected:
   void SetUp(State& st) override {
     BM_MessageLoop::SetUp(st);
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = thread_new("BM_MessageLoopOnOsiThread thread");
     thread_post(thread_, &BM_MessageLoop::RunThread, this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown(State& st) override {
@@ -134,23 +134,25 @@
 BENCHMARK_F(BM_MessageLoopOsiThread, batch_enque_dequeue)(State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_batch, bt_msg_queue_, nullptr));
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
 BENCHMARK_F(BM_MessageLoopOsiThread, sequential_execution)(State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_sequential, nullptr));
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -159,8 +161,9 @@
  protected:
   void SetUp(State& st) override {
     BM_MessageLoop::SetUp(st);
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = new std::thread(&BM_MessageLoop::RunThread, this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown(State& st) override {
@@ -178,23 +181,25 @@
 BENCHMARK_F(BM_MessageLoopStlThread, batch_enque_dequeue)(State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_batch, bt_msg_queue_, nullptr));
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
 BENCHMARK_F(BM_MessageLoopStlThread, sequential_execution)(State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_sequential, nullptr));
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -203,8 +208,9 @@
  protected:
   void SetUp(State& st) override {
     BM_MessageLoop::SetUp(st);
+    std::future<void> set_up_future = set_up_promise_->get_future();
     pthread_create(&thread_, nullptr, &BM_MessageLoop::RunPThread, (void*)this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown(State& st) override {
@@ -220,23 +226,25 @@
 BENCHMARK_F(BM_MessageLoopPosixThread, batch_enque_dequeue)(State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_batch, bt_msg_queue_, nullptr));
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
 BENCHMARK_F(BM_MessageLoopPosixThread, sequential_execution)(State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       message_loop_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_sequential, nullptr));
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -261,12 +269,13 @@
 (State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       thread_post(thread_, pthread_callback_batch, bt_msg_queue_);
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
@@ -274,9 +283,10 @@
 (State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       thread_post(thread_, callback_sequential, nullptr);
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -287,11 +297,12 @@
                                callback_batch, nullptr);
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
@@ -301,9 +312,10 @@
                                callback_sequential_queue, nullptr);
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -312,13 +324,14 @@
  protected:
   void SetUp(State& st) override {
     BM_ThreadPerformance::SetUp(st);
+    std::future<void> set_up_future = set_up_promise_->get_future();
     message_loop_thread_ =
         new MessageLoopThread("BM_MessageLooopThread thread");
     message_loop_thread_->StartUp();
     message_loop_thread_->DoInThread(
-        FROM_HERE, base::BindOnce(&ExecutionBarrier::NotifyFinished,
-                                  base::Unretained(set_up_barrier_.get())));
-    set_up_barrier_->WaitForExecution();
+        FROM_HERE, base::BindOnce(&std::promise<void>::set_value,
+                                  base::Unretained(set_up_promise_.get())));
+    set_up_future.wait();
   }
 
   void TearDown(State& st) override {
@@ -334,23 +347,25 @@
 BENCHMARK_F(BM_MessageLooopThread, batch_enque_dequeue)(State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       message_loop_thread_->DoInThread(
           FROM_HERE, base::BindOnce(&callback_batch, bt_msg_queue_, nullptr));
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
 BENCHMARK_F(BM_MessageLooopThread, sequential_execution)(State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       message_loop_thread_->DoInThread(
           FROM_HERE, base::BindOnce(&callback_sequential, nullptr));
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -359,12 +374,13 @@
  protected:
   void SetUp(State& st) override {
     BM_ThreadPerformance::SetUp(st);
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = new base::Thread("BM_LibChromeThread thread");
     thread_->Start();
     thread_->task_runner()->PostTask(
-        FROM_HERE, base::BindOnce(&ExecutionBarrier::NotifyFinished,
-                                  base::Unretained(set_up_barrier_.get())));
-    set_up_barrier_->WaitForExecution();
+        FROM_HERE, base::BindOnce(&std::promise<void>::set_value,
+                                  base::Unretained(set_up_promise_.get())));
+    set_up_future.wait();
   }
 
   void TearDown(State& st) override {
@@ -380,23 +396,25 @@
 BENCHMARK_F(BM_LibChromeThread, batch_enque_dequeue)(State& state) {
   for (auto _ : state) {
     g_counter = 0;
-    g_counter_barrier = std::make_unique<ExecutionBarrier>();
+    g_counter_promise = std::make_unique<std::promise<void>>();
+    std::future<void> counter_future = g_counter_promise->get_future();
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
       fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
       thread_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_batch, bt_msg_queue_, nullptr));
     }
-    g_counter_barrier->WaitForExecution();
+    counter_future.wait();
   }
 };
 
 BENCHMARK_F(BM_LibChromeThread, sequential_execution)(State& state) {
   for (auto _ : state) {
     for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
-      g_counter_barrier = std::make_unique<ExecutionBarrier>();
+      g_counter_promise = std::make_unique<std::promise<void>>();
+      std::future<void> counter_future = g_counter_promise->get_future();
       thread_->task_runner()->PostTask(
           FROM_HERE, base::BindOnce(&callback_sequential, nullptr));
-      g_counter_barrier->WaitForExecution();
+      counter_future.wait();
     }
   }
 };
@@ -411,4 +429,4 @@
     return 1;
   }
   ::benchmark::RunSpecifiedBenchmarks();
-}
\ No newline at end of file
+}
diff --git a/common/execution_barrier.cc b/common/execution_barrier.cc
deleted file mode 100644
index 8017b05..0000000
--- a/common/execution_barrier.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "execution_barrier.h"
-
-namespace bluetooth {
-
-namespace common {
-
-void ExecutionBarrier::WaitForExecution() {
-  std::unique_lock<std::mutex> lock(execution_mutex_);
-  while (!finished_) {
-    execution_cv_.wait(lock);
-  }
-}
-
-void ExecutionBarrier::NotifyFinished() {
-  std::unique_lock<std::mutex> lock(execution_mutex_);
-  finished_ = true;
-  execution_cv_.notify_all();
-}
-
-}  // namespace common
-
-}  // namespace bluetooth
\ No newline at end of file
diff --git a/common/execution_barrier.h b/common/execution_barrier.h
deleted file mode 100644
index 973fc44..0000000
--- a/common/execution_barrier.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <condition_variable>
-#include <memory>
-#include <mutex>
-
-#include <base/macros.h>
-
-namespace bluetooth {
-
-namespace common {
-
-/**
- * A utility to wait for an event on another thread
- *
- * This class can be used once only. This means that after the first time
- * NotifyFinished() is called, WaitForExecution() will no longer block. User
- * needs to create a new instance if another ExecutionBarrier is needed.
- *
- * No reset mechanism is provided for this class to avoid racy scenarios and
- * unsafe API usage
- *
- * Similar to std::experimental::barrier, but this can be used only once
- */
-class ExecutionBarrier final {
- public:
-  explicit ExecutionBarrier() : finished_(false){};
-
-  /**
-   * Blocks until NotifyFinished() is called on this object
-   *
-   */
-  void WaitForExecution();
-
-  /**
-   * Unblocks any caller who are blocked on WaitForExecution() method call
-   */
-  void NotifyFinished();
-
- private:
-  bool finished_;
-  std::mutex execution_mutex_;
-  std::condition_variable execution_cv_;
-
-  /**
-   * Prevent COPY and ASSIGN since many internal states cannot be copied or
-   * assigned
-   */
-  DISALLOW_COPY_AND_ASSIGN(ExecutionBarrier);
-};
-
-}  // namespace common
-
-}  // namespace bluetooth
\ No newline at end of file
diff --git a/common/execution_barrier_unittest.cc b/common/execution_barrier_unittest.cc
deleted file mode 100644
index ccb9bd0..0000000
--- a/common/execution_barrier_unittest.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <chrono>
-#include <thread>
-
-#include <gtest/gtest.h>
-
-#include "execution_barrier.h"
-
-using bluetooth::common::ExecutionBarrier;
-
-static constexpr int kSleepTimeMs = 100;
-static constexpr int kSchedulingDelayMaxMs = 5;
-
-TEST(ExecutionBarrierTest, test_two_threads_wait_before_execution) {
-  ExecutionBarrier execution_barrier;
-  std::thread caller1([&]() {
-    auto start = std::chrono::high_resolution_clock::now();
-    execution_barrier.WaitForExecution();
-    auto end = std::chrono::high_resolution_clock::now();
-    std::chrono::duration<double, std::milli> elapsed_ms = end - start;
-    EXPECT_NEAR(elapsed_ms.count(), kSleepTimeMs, kSchedulingDelayMaxMs);
-  });
-  std::thread executor([&]() {
-    // Wait for kSleepTimeMs so that caller1 starts waiting first
-    std::this_thread::sleep_for(std::chrono::milliseconds(kSleepTimeMs));
-    execution_barrier.NotifyFinished();
-  });
-  executor.join();
-  caller1.join();
-  // Further calls to WaitForExecution() no longer blocks
-  std::thread caller2([&]() {
-    auto start = std::chrono::high_resolution_clock::now();
-    execution_barrier.WaitForExecution();
-    auto end = std::chrono::high_resolution_clock::now();
-    std::chrono::duration<double, std::milli> elapsed_ms = end - start;
-    EXPECT_LT(elapsed_ms.count(), kSchedulingDelayMaxMs);
-  });
-  caller2.join();
-}
-
-TEST(ExecutionBarrierTest, test_two_threads_execution_before_wait) {
-  ExecutionBarrier execution_barrier;
-  std::thread executor([&]() { execution_barrier.NotifyFinished(); });
-  std::thread caller1([&]() {
-    // Wait for kSleepTimeMs so that executor finishes running first
-    std::this_thread::sleep_for(std::chrono::milliseconds(kSleepTimeMs));
-    auto start = std::chrono::high_resolution_clock::now();
-    execution_barrier.WaitForExecution();
-    auto end = std::chrono::high_resolution_clock::now();
-    std::chrono::duration<double, std::milli> elapsed_ms = end - start;
-    EXPECT_LT(elapsed_ms.count(), kSchedulingDelayMaxMs);
-  });
-  executor.join();
-  caller1.join();
-}
-
-TEST(ExecutionBarrierTest, test_two_callers_one_executor) {
-  ExecutionBarrier execution_barrier;
-  std::thread caller1([&]() {
-    auto start = std::chrono::high_resolution_clock::now();
-    execution_barrier.WaitForExecution();
-    auto end = std::chrono::high_resolution_clock::now();
-    std::chrono::duration<double, std::milli> elapsed_ms = end - start;
-    EXPECT_NEAR(elapsed_ms.count(), kSleepTimeMs, 5);
-  });
-  std::thread caller2([&]() {
-    auto start = std::chrono::high_resolution_clock::now();
-    execution_barrier.WaitForExecution();
-    auto end = std::chrono::high_resolution_clock::now();
-    std::chrono::duration<double, std::milli> elapsed_ms = end - start;
-    EXPECT_NEAR(elapsed_ms.count(), kSleepTimeMs, 5);
-  });
-  std::thread executor([&]() {
-    std::this_thread::sleep_for(std::chrono::milliseconds(kSleepTimeMs));
-    execution_barrier.NotifyFinished();
-  });
-  executor.join();
-  caller1.join();
-  caller2.join();
-}
diff --git a/osi/include/leaky_bonded_queue.h b/common/leaky_bonded_queue.h
similarity index 95%
rename from osi/include/leaky_bonded_queue.h
rename to common/leaky_bonded_queue.h
index 6861e8b..087b192 100644
--- a/osi/include/leaky_bonded_queue.h
+++ b/common/leaky_bonded_queue.h
@@ -21,7 +21,9 @@
 #include <mutex>
 #include <queue>
 
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
 
 /*
  *   LeakyBondedQueue<T>
@@ -86,8 +88,8 @@
 };
 
 /*
-* Definitions must be in the header for template classes
-*/
+ * Definitions must be in the header for template classes
+ */
 
 template <class T>
 LeakyBondedQueue<T>::LeakyBondedQueue(size_t capacity) {
@@ -155,4 +157,6 @@
   return queue_.empty();
 }
 
-}  // namespace system_bt_osi
+}  // namespace common
+
+}  // namespace bluetooth
diff --git a/osi/test/leaky_bonded_queue_test.cc b/common/leaky_bonded_queue_unittest.cc
similarity index 97%
rename from osi/test/leaky_bonded_queue_test.cc
rename to common/leaky_bonded_queue_unittest.cc
index 116676b..fcd55cd 100644
--- a/osi/test/leaky_bonded_queue_test.cc
+++ b/common/leaky_bonded_queue_unittest.cc
@@ -20,11 +20,11 @@
 
 #include <base/logging.h>
 
-#include "osi/include/leaky_bonded_queue.h"
+#include "common/leaky_bonded_queue.h"
 
 namespace testing {
 
-using system_bt_osi::LeakyBondedQueue;
+using bluetooth::common::LeakyBondedQueue;
 
 #define ITEM_EQ(a, b)                  \
   do {                                 \
@@ -239,4 +239,4 @@
   queue->Enqueue(item2);
   delete queue;
 }
-}
+}  // namespace testing
diff --git a/common/message_loop_thread.cc b/common/message_loop_thread.cc
index f320136..9bf25be 100644
--- a/common/message_loop_thread.cc
+++ b/common/message_loop_thread.cc
@@ -49,11 +49,11 @@
     LOG(WARNING) << __func__ << ": thread " << *this << " is already started";
     return;
   }
-  std::shared_ptr<ExecutionBarrier> start_up_barrier =
-      std::make_shared<ExecutionBarrier>();
-  thread_ =
-      new std::thread(&MessageLoopThread::RunThread, this, start_up_barrier);
-  start_up_barrier->WaitForExecution();
+  std::promise<void> start_up_promise;
+  std::future<void> start_up_future = start_up_promise.get_future();
+  thread_ = new std::thread(&MessageLoopThread::RunThread, this,
+                            std::move(start_up_promise));
+  start_up_future.wait();
 }
 
 bool MessageLoopThread::DoInThread(const tracked_objects::Location& from_here,
@@ -116,10 +116,9 @@
 }
 
 // Non API method, should not be protected by API mutex
-void MessageLoopThread::RunThread(
-    MessageLoopThread* thread,
-    std::shared_ptr<ExecutionBarrier> start_up_barrier) {
-  thread->Run(std::move(start_up_barrier));
+void MessageLoopThread::RunThread(MessageLoopThread* thread,
+                                  std::promise<void> start_up_promise) {
+  thread->Run(std::move(start_up_promise));
 }
 
 base::MessageLoop* MessageLoopThread::message_loop() const {
@@ -147,8 +146,7 @@
 }
 
 // Non API method, should NOT be protected by API mutex to avoid deadlock
-void MessageLoopThread::Run(
-    std::shared_ptr<ExecutionBarrier> start_up_barrier) {
+void MessageLoopThread::Run(std::promise<void> start_up_promise) {
   LOG(INFO) << __func__ << ": message loop starting for thread "
             << thread_name_;
   base::PlatformThread::SetName(thread_name_);
@@ -156,7 +154,7 @@
   run_loop_ = new base::RunLoop();
   thread_id_ = base::PlatformThread::CurrentId();
   linux_tid_ = static_cast<pid_t>(syscall(SYS_gettid));
-  start_up_barrier->NotifyFinished();
+  start_up_promise.set_value();
   // Blocking until ShutDown() is called
   run_loop_->Run();
   thread_id_ = -1;
diff --git a/common/message_loop_thread.h b/common/message_loop_thread.h
index ff4cc89..c342be4 100644
--- a/common/message_loop_thread.h
+++ b/common/message_loop_thread.h
@@ -17,6 +17,7 @@
 #pragma once
 
 #include <unistd.h>
+#include <future>
 #include <memory>
 #include <string>
 #include <thread>
@@ -27,8 +28,6 @@
 #include <base/threading/platform_thread.h>
 #include <base/tracked_objects.h>
 
-#include "common/execution_barrier.h"
-
 namespace bluetooth {
 
 namespace common {
@@ -138,19 +137,19 @@
    * This is used instead of a C++ lambda because of the use of std::shared_ptr
    *
    * @param context needs to be a pointer to an instance of MessageLoopThread
-   * @param start_up_barrier an ExecutionBarrier that is used to notify calling
+   * @param start_up_promise a std::promise that is used to notify calling
    * thread the completion of message loop start-up
    */
   static void RunThread(MessageLoopThread* context,
-                        std::shared_ptr<ExecutionBarrier> start_up_barrier);
+                        std::promise<void> start_up_promise);
 
   /**
    * Actual method to run the thread, blocking until ShutDown() is called
    *
-   * @param start_up_barrier an ExecutionBarrier that is used to notify calling
+   * @param start_up_promise a std::promise that is used to notify calling
    * thread the completion of message loop start-up
    */
-  void Run(std::shared_ptr<ExecutionBarrier> start_up_barrier);
+  void Run(std::promise<void> start_up_promise);
 
   mutable std::recursive_mutex api_mutex_;
   std::string thread_name_;
diff --git a/common/message_loop_thread_unittest.cc b/common/message_loop_thread_unittest.cc
index 28f5d9e..0924ebe 100644
--- a/common/message_loop_thread_unittest.cc
+++ b/common/message_loop_thread_unittest.cc
@@ -26,10 +26,8 @@
 #include <sys/capability.h>
 #include <syscall.h>
 
-#include "execution_barrier.h"
 #include "message_loop_thread.h"
 
-using bluetooth::common::ExecutionBarrier;
 using bluetooth::common::MessageLoopThread;
 
 /**
@@ -39,34 +37,28 @@
  public:
   void ShouldNotHappen() { FAIL() << "Should not happen"; }
 
-  void GetThreadId(base::PlatformThreadId* thread_id,
-                   std::shared_ptr<ExecutionBarrier> execution_barrier) {
-    *thread_id = base::PlatformThread::CurrentId();
-    execution_barrier->NotifyFinished();
+  void GetThreadId(std::promise<base::PlatformThreadId> thread_id_promise) {
+    thread_id_promise.set_value(base::PlatformThread::CurrentId());
   }
 
-  void GetLinuxTid(pid_t* tid,
-                   std::shared_ptr<ExecutionBarrier> execution_barrier) {
-    *tid = static_cast<pid_t>(syscall(SYS_gettid));
-    execution_barrier->NotifyFinished();
+  void GetLinuxTid(std::promise<pid_t> tid_promise) {
+    tid_promise.set_value(static_cast<pid_t>(syscall(SYS_gettid)));
   }
 
-  void GetName(std::string* name,
-               std::shared_ptr<ExecutionBarrier> execution_barrier) {
+  void GetName(std::promise<std::string> name_promise) {
     char my_name[256];
     pthread_getname_np(pthread_self(), my_name, sizeof(my_name));
-    name->append(my_name);
-    execution_barrier->NotifyFinished();
+    name_promise.set_value(my_name);
   }
 
-  void GetSchedulingPolicyAndPriority(
-      int* scheduling_policy, int* schedule_priority,
-      std::shared_ptr<ExecutionBarrier> execution_barrier) {
+  void GetSchedulingPolicyAndPriority(int* scheduling_policy,
+                                      int* schedule_priority,
+                                      std::promise<void> execution_promise) {
     *scheduling_policy = sched_getscheduler(0);
     struct sched_param param = {};
     ASSERT_EQ(sched_getparam(0, &param), 0);
     *schedule_priority = param.sched_priority;
-    execution_barrier->NotifyFinished();
+    execution_promise.set_value();
   }
 
  protected:
@@ -133,15 +125,14 @@
   MessageLoopThread message_loop_thread(name);
   message_loop_thread.StartUp();
   ASSERT_GE(message_loop_thread.GetThreadId(), 0);
-  std::shared_ptr<ExecutionBarrier> execution_barrier =
-      std::make_shared<ExecutionBarrier>();
-  std::string myName;
+  std::promise<std::string> name_promise;
+  std::future<std::string> name_future = name_promise.get_future();
   message_loop_thread.DoInThread(
       FROM_HERE,
-      base::Bind(&MessageLoopThreadTest::GetName, base::Unretained(this),
-                 &myName, execution_barrier));
-  execution_barrier->WaitForExecution();
-  ASSERT_EQ(name, myName);
+      base::BindOnce(&MessageLoopThreadTest::GetName, base::Unretained(this),
+                     std::move(name_promise)));
+  std::string my_name = name_future.get();
+  ASSERT_EQ(name, my_name);
   ASSERT_EQ(name, message_loop_thread.GetName());
 }
 
@@ -151,14 +142,14 @@
   message_loop_thread.StartUp();
   base::PlatformThreadId thread_id = message_loop_thread.GetThreadId();
   ASSERT_GE(thread_id, 0);
-  std::shared_ptr<ExecutionBarrier> execution_barrier =
-      std::make_shared<ExecutionBarrier>();
-  base::PlatformThreadId my_thread_id;
+  std::promise<base::PlatformThreadId> thread_id_promise;
+  std::future<base::PlatformThreadId> thread_id_future =
+      thread_id_promise.get_future();
   message_loop_thread.DoInThread(
       FROM_HERE,
-      base::Bind(&MessageLoopThreadTest::GetThreadId, base::Unretained(this),
-                 &my_thread_id, execution_barrier));
-  execution_barrier->WaitForExecution();
+      base::BindOnce(&MessageLoopThreadTest::GetThreadId,
+                     base::Unretained(this), std::move(thread_id_promise)));
+  base::PlatformThreadId my_thread_id = thread_id_future.get();
   ASSERT_EQ(thread_id, my_thread_id);
 }
 
@@ -187,26 +178,26 @@
       return;
     }
   }
-  std::shared_ptr<ExecutionBarrier> execution_barrier =
-      std::make_shared<ExecutionBarrier>();
+  std::promise<void> execution_promise;
+  std::future<void> execution_future = execution_promise.get_future();
   int scheduling_policy = -1;
   int scheduling_priority = -1;
   message_loop_thread.DoInThread(
       FROM_HERE,
-      base::Bind(&MessageLoopThreadTest::GetSchedulingPolicyAndPriority,
-                 base::Unretained(this), &scheduling_policy,
-                 &scheduling_priority, execution_barrier));
-  execution_barrier->WaitForExecution();
+      base::BindOnce(&MessageLoopThreadTest::GetSchedulingPolicyAndPriority,
+                     base::Unretained(this), &scheduling_policy,
+                     &scheduling_priority, std::move(execution_promise)));
+  execution_future.wait();
   ASSERT_EQ(scheduling_policy, SCHED_FIFO);
   // Internal implementation verified here
   ASSERT_EQ(scheduling_priority, 1);
-  execution_barrier = std::make_shared<ExecutionBarrier>();
-  pid_t linux_tid = -1;
+  std::promise<pid_t> tid_promise;
+  std::future<pid_t> tid_future = tid_promise.get_future();
   message_loop_thread.DoInThread(
       FROM_HERE,
-      base::Bind(&MessageLoopThreadTest::GetLinuxTid, base::Unretained(this),
-                 &linux_tid, execution_barrier));
-  execution_barrier->WaitForExecution();
+      base::BindOnce(&MessageLoopThreadTest::GetLinuxTid,
+                     base::Unretained(this), std::move(tid_promise)));
+  pid_t linux_tid = tid_future.get();
   ASSERT_GT(linux_tid, 0);
   ASSERT_EQ(sched_getscheduler(linux_tid), SCHED_FIFO);
   struct sched_param param = {};
@@ -256,4 +247,4 @@
   // String representation should look the same when thread is not running
   ASSERT_STREQ(thread_string_after_shutdown.c_str(),
                thread_string_before_start.c_str());
-}
\ No newline at end of file
+}
diff --git a/osi/src/metrics.cc b/common/metrics.cc
similarity index 95%
rename from osi/src/metrics.cc
rename to common/metrics.cc
index 73450b9..ace021b 100644
--- a/osi/src/metrics.cc
+++ b/common/metrics.cc
@@ -15,7 +15,6 @@
  *  limitations under the License.
  *
  ******************************************************************************/
-#define LOG_TAG "bt_osi_metrics"
 
 #include <unistd.h>
 #include <algorithm>
@@ -32,15 +31,16 @@
 #include <include/hardware/bt_av.h>
 
 #include "bluetooth/metrics/bluetooth.pb.h"
-#include "osi/include/leaky_bonded_queue.h"
-#include "osi/include/log.h"
 #include "osi/include/osi.h"
-#include "osi/include/time.h"
 #include "stack/include/btm_api_types.h"
 
-#include "osi/include/metrics.h"
+#include "leaky_bonded_queue.h"
+#include "metrics.h"
+#include "time_util.h"
 
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
 
 using bluetooth::metrics::BluetoothMetricsProto::A2DPSession;
 using bluetooth::metrics::BluetoothMetricsProto::A2dpSourceCodec;
@@ -52,24 +52,18 @@
     BluetoothSession_DisconnectReasonType;
 using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo;
 using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo_DeviceType;
-using bluetooth::metrics::BluetoothMetricsProto::PairEvent;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
-using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
-using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
 using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MIN;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MAX;
 using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_ARRAYSIZE;
 using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_IsValid;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
-/*
- * Get current OS boot time in millisecond
- */
-static int64_t time_get_os_boottime_ms(void) {
-  return time_get_os_boottime_us() / 1000;
-}
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MAX;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MIN;
+using bluetooth::metrics::BluetoothMetricsProto::PairEvent;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
+using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
+using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
 
 static float combine_averages(float avg_a, int64_t ct_a, float avg_b,
                               int64_t ct_b) {
@@ -359,7 +353,7 @@
                            0);
   }
   if (timestamp_ms == 0) {
-    timestamp_ms = time_get_os_boottime_ms();
+    timestamp_ms = bluetooth::common::time_get_os_boottime_ms();
   }
   pimpl_->bluetooth_session_start_time_ms_ = timestamp_ms;
   pimpl_->bluetooth_session_ = new BluetoothSession();
@@ -374,7 +368,7 @@
     return;
   }
   if (timestamp_ms == 0) {
-    timestamp_ms = time_get_os_boottime_ms();
+    timestamp_ms = bluetooth::common::time_get_os_boottime_ms();
   }
   int64_t session_duration_sec =
       (timestamp_ms - pimpl_->bluetooth_session_start_time_ms_) / 1000;
@@ -458,11 +452,11 @@
 
 void BluetoothMetricsLogger::WriteString(std::string* serialized) {
   std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_);
-  LOG_DEBUG(LOG_TAG, "%s building metrics", __func__);
+  LOG(INFO) << __func__ << ": building metrics";
   Build();
-  LOG_DEBUG(LOG_TAG, "%s serializing metrics", __func__);
+  LOG(INFO) << __func__ << ": serializing metrics";
   if (!pimpl_->bluetooth_log_->SerializeToString(serialized)) {
-    LOG_ERROR(LOG_TAG, "%s: error serializing metrics", __func__);
+    LOG(ERROR) << __func__ << ": error serializing metrics";
   }
   // Always clean up log objects
   pimpl_->bluetooth_log_->Clear();
@@ -479,8 +473,9 @@
   ssize_t ret;
   OSI_NO_INTR(ret = write(fd, protoBase64.c_str(), protoBase64.size()));
   if (ret == -1) {
-    LOG_ERROR(LOG_TAG, "%s: error writing to dumpsys fd: %s (%d)", __func__,
-              strerror(errno), errno);
+    LOG(ERROR) << __func__
+               << ": error writing to dumpsys fd: " << strerror(errno) << " ("
+               << std::to_string(errno) << ")";
   }
 }
 
@@ -493,7 +488,8 @@
     new_bt_session->clear_rfcomm_session();
     LogBluetoothSessionEnd(DISCONNECT_REASON_METRICS_DUMP, 0);
     pimpl_->bluetooth_session_ = new_bt_session;
-    pimpl_->bluetooth_session_start_time_ms_ = time_get_os_boottime_ms();
+    pimpl_->bluetooth_session_start_time_ms_ =
+        bluetooth::common::time_get_os_boottime_ms();
     pimpl_->a2dp_session_metrics_ = A2dpSessionMetrics();
   }
 }
@@ -571,4 +567,6 @@
   pimpl_->scan_event_queue_->Clear();
 }
 
-}  // namespace system_bt_osi
+}  // namespace common
+
+}  // namespace bluetooth
diff --git a/osi/include/metrics.h b/common/metrics.h
similarity index 98%
rename from osi/include/metrics.h
rename to common/metrics.h
index 504a16a..b441801 100644
--- a/osi/include/metrics.h
+++ b/common/metrics.h
@@ -23,7 +23,9 @@
 #include <memory>
 #include <string>
 
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
 
 // Typedefs to hide protobuf definition to the rest of stack
 
@@ -76,7 +78,7 @@
  *    buffer_underruns_count: number of times there was no enough
  *                            audio data to add to the media buffer.
  * NOTE: Negative values are invalid
-*/
+ */
 class A2dpSessionMetrics {
  public:
   A2dpSessionMetrics() {}
@@ -273,4 +275,7 @@
   struct impl;
   std::unique_ptr<impl> const pimpl_;
 };
-}
+
+}  // namespace common
+
+}  // namespace bluetooth
diff --git a/osi/test/metrics_test.cc b/common/metrics_unittest.cc
similarity index 94%
rename from osi/test/metrics_test.cc
rename to common/metrics_unittest.cc
index bfb548f..03a427a 100644
--- a/osi/test/metrics_test.cc
+++ b/common/metrics_unittest.cc
@@ -28,13 +28,15 @@
 #include <include/hardware/bt_av.h>
 
 #include "bluetooth/metrics/bluetooth.pb.h"
-#include "osi/include/metrics.h"
-#include "osi/include/time.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
 
 #define BTM_COD_MAJOR_AUDIO_TEST 0x04
 
 namespace testing {
 
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
 using bluetooth::metrics::BluetoothMetricsProto::A2DPSession;
 using bluetooth::metrics::BluetoothMetricsProto::A2dpSourceCodec;
 using bluetooth::metrics::BluetoothMetricsProto::BluetoothLog;
@@ -45,29 +47,20 @@
     BluetoothSession_DisconnectReasonType;
 using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo;
 using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo_DeviceType;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
 using bluetooth::metrics::BluetoothMetricsProto::PairEvent;
 using bluetooth::metrics::BluetoothMetricsProto::RFCommSession;
 using bluetooth::metrics::BluetoothMetricsProto::ScanEvent;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
 using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
 using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
 using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
-using system_bt_osi::BluetoothMetricsLogger;
-using system_bt_osi::A2dpSessionMetrics;
 
 namespace {
 const size_t kMaxEventGenerationLimit = 5000;
 }
 
-/*
- * Get current OS boot time in ms
- */
-static int64_t time_get_os_boottime_ms(void) {
-  return time_get_os_boottime_us() / 1000;
-}
-
 static void sleep_ms(int64_t t) {
   std::this_thread::sleep_for(std::chrono::milliseconds(t));
 }
@@ -429,7 +422,7 @@
           42, DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR)));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogPairEvent(
-      35, 12345, 42, system_bt_osi::DEVICE_TYPE_BREDR);
+      35, 12345, 42, bluetooth::common::DEVICE_TYPE_BREDR);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -441,7 +434,7 @@
                     "TEST_REQ", "TEST_NAME", 12345));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
-      system_bt_osi::WAKE_EVENT_ACQUIRED, "TEST_REQ", "TEST_NAME", 12345);
+      bluetooth::common::WAKE_EVENT_ACQUIRED, "TEST_REQ", "TEST_NAME", 12345);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -455,8 +448,8 @@
   UpdateLog();
   for (size_t i = 0; i < kMaxEventGenerationLimit; ++i) {
     BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
-        i % 2 == 0 ? system_bt_osi::WAKE_EVENT_ACQUIRED
-                   : system_bt_osi::WAKE_EVENT_RELEASED,
+        i % 2 == 0 ? bluetooth::common::WAKE_EVENT_ACQUIRED
+                   : bluetooth::common::WAKE_EVENT_RELEASED,
         "TEST_REQ", "TEST_NAME", i);
   }
   std::string msg_str;
@@ -467,12 +460,14 @@
 TEST_F(BluetoothMetricsLoggerTest, ScanEventTest) {
   scan_events_.push_back(MakeScanEvent(
       ScanEvent_ScanEventType::ScanEvent_ScanEventType_SCAN_EVENT_STOP,
-      "TEST_INITIATOR", ScanEvent_ScanTechnologyType::
-                            ScanEvent_ScanTechnologyType_SCAN_TECH_TYPE_BREDR,
+      "TEST_INITIATOR",
+      ScanEvent_ScanTechnologyType::
+          ScanEvent_ScanTechnologyType_SCAN_TECH_TYPE_BREDR,
       42, 123456));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogScanEvent(
-      false, "TEST_INITIATOR", system_bt_osi::SCAN_TECH_TYPE_BREDR, 42, 123456);
+      false, "TEST_INITIATOR", bluetooth::common::SCAN_TECH_TYPE_BREDR, 42,
+      123456);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -488,9 +483,9 @@
       nullptr, nullptr, nullptr));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 123456);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE, 123456);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 133456);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -506,7 +501,8 @@
       nullptr, nullptr, nullptr));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, time_get_os_boottime_ms());
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE,
+      bluetooth::common::time_get_os_boottime_ms());
   sleep_ms(1000);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -530,10 +526,10 @@
       nullptr, nullptr, nullptr));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, 0);
   sleep_ms(1000);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE, 0);
   sleep_ms(2000);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -601,13 +597,13 @@
       info, nullptr, session));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 123456);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 123456);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
-      BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+      BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 133456);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -662,9 +658,9 @@
       info, nullptr, session));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
-      BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+      BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
   sleep_ms(1000);
   std::string msg_str;
@@ -686,7 +682,7 @@
   sleep_ms(1000);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   msg_str.clear();
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -731,13 +727,13 @@
       info, nullptr, session));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
-      BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+      BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
   sleep_ms(1000);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -762,11 +758,11 @@
       nullptr, nullptr, session));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   sleep_ms(1000);
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   msg_str.clear();
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -892,9 +888,9 @@
       info, nullptr, nullptr));
   UpdateLog();
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
-      system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+      bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
-      BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+      BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
   sleep_ms(1000);
   std::string msg_str;
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -917,7 +913,7 @@
   BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
   sleep_ms(1000);
   BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
-      system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+      bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
   msg_str.clear();
   BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
   EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -1009,4 +1005,4 @@
   EXPECT_EQ(metrics->headset_profile_connection_stats_size(), 0);
   delete metrics;
 }
-}
+}  // namespace testing
diff --git a/common/test/thread_performance_test.cc b/common/test/thread_performance_test.cc
index a9b0525..dc6a53f 100644
--- a/common/test/thread_performance_test.cc
+++ b/common/test/thread_performance_test.cc
@@ -22,21 +22,20 @@
 #include <gtest/gtest.h>
 #include <unistd.h>
 #include <chrono>
+#include <future>
 #include <iostream>
 #include <thread>
 
-#include "common/execution_barrier.h"
 #include "common/message_loop_thread.h"
 #include "osi/include/fixed_queue.h"
 #include "osi/include/thread.h"
 
-using bluetooth::common::ExecutionBarrier;
 using bluetooth::common::MessageLoopThread;
 
 #define NUM_MESSAGES_TO_SEND 100000
 
 volatile static int g_counter = 0;
-static std::unique_ptr<ExecutionBarrier> g_counter_barrier = nullptr;
+static std::unique_ptr<std::promise<void>> g_counter_promise = nullptr;
 
 void callback_batch(fixed_queue_t* queue, void* data) {
   if (queue != nullptr) {
@@ -44,25 +43,25 @@
   }
   g_counter++;
   if (g_counter >= NUM_MESSAGES_TO_SEND) {
-    g_counter_barrier->NotifyFinished();
+    g_counter_promise->set_value();
   }
 }
 
 class PerformanceTest : public testing::Test {
  protected:
   void SetUp() override {
-    set_up_barrier_ = std::make_unique<ExecutionBarrier>();
+    set_up_promise_ = std::make_unique<std::promise<void>>();
     g_counter = 0;
     bt_msg_queue_ = fixed_queue_new(SIZE_MAX);
   }
   void TearDown() override {
     fixed_queue_free(bt_msg_queue_, nullptr);
     bt_msg_queue_ = nullptr;
-    set_up_barrier_.reset(nullptr);
-    g_counter_barrier.reset(nullptr);
+    set_up_promise_.reset(nullptr);
+    g_counter_promise.reset(nullptr);
   }
   fixed_queue_t* bt_msg_queue_ = nullptr;
-  std::unique_ptr<ExecutionBarrier> set_up_barrier_ = nullptr;
+  std::unique_ptr<std::promise<void>> set_up_promise_ = nullptr;
 };
 
 class MessageLoopPerformanceTest : public PerformanceTest {
@@ -80,8 +79,8 @@
     message_loop_ = new base::MessageLoop();
     run_loop_ = new base::RunLoop();
     message_loop_->task_runner()->PostTask(
-        FROM_HERE, base::Bind(&ExecutionBarrier::NotifyFinished,
-                              base::Unretained(set_up_barrier_.get())));
+        FROM_HERE, base::Bind(&std::promise<void>::set_value,
+                              base::Unretained(set_up_promise_.get())));
     run_loop_->Run();
     delete message_loop_;
     message_loop_ = nullptr;
@@ -98,9 +97,10 @@
  protected:
   void SetUp() override {
     MessageLoopPerformanceTest::SetUp();
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = thread_new("OsiThreadMessageLoopPerformanceTest thread");
     thread_post(thread_, &MessageLoopPerformanceTest::RunThread, this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown() override {
@@ -116,7 +116,8 @@
 
 TEST_F(OsiThreadMessageLoopPerformanceTest, message_loop_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
   std::chrono::steady_clock::time_point start_time =
       std::chrono::steady_clock::now();
 
@@ -125,7 +126,7 @@
     message_loop_->task_runner()->PostTask(
         FROM_HERE, base::Bind(&callback_batch, bt_msg_queue_, nullptr));
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
@@ -141,8 +142,9 @@
  protected:
   void SetUp() override {
     MessageLoopPerformanceTest::SetUp();
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = new std::thread(&MessageLoopPerformanceTest::RunThread, this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown() override {
@@ -159,7 +161,8 @@
 
 TEST_F(StlThreadMessageLoopPerformanceTest, stl_thread_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
   std::chrono::steady_clock::time_point start_time =
       std::chrono::steady_clock::now();
 
@@ -168,7 +171,7 @@
     message_loop_->task_runner()->PostTask(
         FROM_HERE, base::Bind(&callback_batch, bt_msg_queue_, nullptr));
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
@@ -185,9 +188,10 @@
  protected:
   void SetUp() override {
     MessageLoopPerformanceTest::SetUp();
+    std::future<void> set_up_future = set_up_promise_->get_future();
     pthread_create(&thread_, nullptr, &MessageLoopPerformanceTest::RunPThread,
                    (void*)this);
-    set_up_barrier_->WaitForExecution();
+    set_up_future.wait();
   }
 
   void TearDown() override {
@@ -202,7 +206,8 @@
 
 TEST_F(PosixThreadMessageLoopPerformanceTest, stl_thread_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
 
   std::chrono::steady_clock::time_point start_time =
       std::chrono::steady_clock::now();
@@ -212,7 +217,7 @@
     message_loop_->task_runner()->PostTask(
         FROM_HERE, base::Bind(&callback_batch, bt_msg_queue_, nullptr));
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
@@ -242,7 +247,8 @@
 
 TEST_F(ReactorPerformanceTest, reactor_thread_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
   fixed_queue_register_dequeue(bt_msg_queue_, thread_get_reactor(thread_),
                                callback_batch, nullptr);
 
@@ -252,7 +258,7 @@
   for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) {
     fixed_queue_enqueue(bt_msg_queue_, (void*)&g_counter);
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
@@ -268,13 +274,14 @@
  protected:
   void SetUp() override {
     PerformanceTest::SetUp();
+    std::future<void> set_up_future = set_up_promise_->get_future();
     worker_thread_ =
         new MessageLoopThread("WorkerThreadPerformanceTest thread");
     worker_thread_->StartUp();
     worker_thread_->DoInThread(
-        FROM_HERE, base::Bind(&ExecutionBarrier::NotifyFinished,
-                              base::Unretained(set_up_barrier_.get())));
-    set_up_barrier_->WaitForExecution();
+        FROM_HERE, base::Bind(&std::promise<void>::set_value,
+                              base::Unretained(set_up_promise_.get())));
+    set_up_future.wait();
   }
 
   void TearDown() override {
@@ -289,7 +296,8 @@
 
 TEST_F(WorkerThreadPerformanceTest, worker_thread_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
 
   std::chrono::steady_clock::time_point start_time =
       std::chrono::steady_clock::now();
@@ -299,7 +307,7 @@
     worker_thread_->DoInThread(
         FROM_HERE, base::Bind(&callback_batch, bt_msg_queue_, nullptr));
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
@@ -315,12 +323,13 @@
  protected:
   void SetUp() override {
     PerformanceTest::SetUp();
+    std::future<void> set_up_future = set_up_promise_->get_future();
     thread_ = new base::Thread("LibChromeThreadPerformanceTest thread");
     thread_->Start();
     thread_->task_runner()->PostTask(
-        FROM_HERE, base::Bind(&ExecutionBarrier::NotifyFinished,
-                              base::Unretained(set_up_barrier_.get())));
-    set_up_barrier_->WaitForExecution();
+        FROM_HERE, base::Bind(&std::promise<void>::set_value,
+                              base::Unretained(set_up_promise_.get())));
+    set_up_future.wait();
   }
 
   void TearDown() override {
@@ -335,7 +344,8 @@
 
 TEST_F(LibChromeThreadPerformanceTest, worker_thread_speed_test) {
   g_counter = 0;
-  g_counter_barrier = std::make_unique<ExecutionBarrier>();
+  g_counter_promise = std::make_unique<std::promise<void>>();
+  std::future<void> counter_future = g_counter_promise->get_future();
 
   std::chrono::steady_clock::time_point start_time =
       std::chrono::steady_clock::now();
@@ -345,7 +355,7 @@
     thread_->task_runner()->PostTask(
         FROM_HERE, base::Bind(&callback_batch, bt_msg_queue_, nullptr));
   }
-  g_counter_barrier->WaitForExecution();
+  counter_future.wait();
 
   std::chrono::steady_clock::time_point end_time =
       std::chrono::steady_clock::now();
diff --git a/osi/src/time.cc b/common/time_util.cc
similarity index 73%
rename from osi/src/time.cc
rename to common/time_util.cc
index 1a47504..273be18 100644
--- a/osi/src/time.cc
+++ b/common/time_util.cc
@@ -16,28 +16,32 @@
  *
  ******************************************************************************/
 
-#define LOG_TAG "bt_osi_time"
-
 #include <sys/time.h>
 #include <time.h>
 
-#include "osi/include/time.h"
+#include "common/time_util.h"
 
-uint32_t time_get_os_boottime_ms(void) {
-  return (uint32_t)(time_get_os_boottime_us() / 1000);
-}
+namespace bluetooth {
 
-uint64_t time_get_os_boottime_us(void) {
-  struct timespec ts_now;
+namespace common {
+
+uint64_t time_get_os_boottime_ms() { return time_get_os_boottime_us() / 1000; }
+
+uint64_t time_get_os_boottime_us() {
+  struct timespec ts_now = {};
   clock_gettime(CLOCK_BOOTTIME, &ts_now);
 
   return ((uint64_t)ts_now.tv_sec * 1000000L) +
          ((uint64_t)ts_now.tv_nsec / 1000);
 }
 
-uint64_t time_gettimeofday_us(void) {
-  struct timeval tv;
-  gettimeofday(&tv, NULL);
+uint64_t time_gettimeofday_us() {
+  struct timeval tv = {};
+  gettimeofday(&tv, nullptr);
   return static_cast<uint64_t>(tv.tv_sec) * 1000000ULL +
          static_cast<uint64_t>(tv.tv_usec);
 }
+
+}  // namespace common
+
+}  // namespace bluetooth
\ No newline at end of file
diff --git a/common/time_util.h b/common/time_util.h
new file mode 100644
index 0000000..70a64d2
--- /dev/null
+++ b/common/time_util.h
@@ -0,0 +1,38 @@
+/******************************************************************************
+ *
+ *  Copyright 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <cstdint>
+
+namespace bluetooth {
+
+namespace common {
+
+// Get the OS boot time in milliseconds.
+uint64_t time_get_os_boottime_ms();
+
+// Get the OS boot time in microseconds.
+uint64_t time_get_os_boottime_us();
+
+// Get the current wall clock time in microseconds.
+uint64_t time_gettimeofday_us();
+
+}  // namespace common
+
+}  // namespace bluetooth
diff --git a/common/time_util_unittest.cc b/common/time_util_unittest.cc
new file mode 100644
index 0000000..77e205d
--- /dev/null
+++ b/common/time_util_unittest.cc
@@ -0,0 +1,146 @@
+/******************************************************************************
+ *
+ *  Copyright 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <gtest/gtest.h>
+
+#include "common/time_util.h"
+
+// Generous upper bound: 10 seconds
+static const uint32_t TEST_TIME_DELTA_UPPER_BOUND_MS = 10 * 1000;
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms() is
+// not zero.
+//
+TEST(TimeTest, test_time_get_os_boottime_ms_not_zero) {
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+  ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us() is
+// not zero.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_not_zero) {
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+  ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms()
+// is monotonically increasing within reasonable boundries.
+//
+TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) {
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+  uint64_t t2 = bluetooth::common::time_get_os_boottime_ms();
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us()
+// is monotonically increasing within reasonable boundries.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) {
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+  uint64_t t2 = bluetooth::common::time_get_os_boottime_us();
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms()
+// is increasing.
+//
+TEST(TimeTest, test_time_get_os_boottime_ms_increases_lower_bound) {
+  static const uint32_t TEST_TIME_SLEEP_MS = 100;
+  struct timespec delay = {};
+
+  delay.tv_sec = TEST_TIME_SLEEP_MS / 1000;
+  delay.tv_nsec = 1000 * 1000 * (TEST_TIME_SLEEP_MS % 1000);
+
+  // Take two timestamps with sleep in-between
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+  int err = nanosleep(&delay, &delay);
+  uint64_t t2 = bluetooth::common::time_get_os_boottime_ms();
+
+  ASSERT_EQ(err, 0);
+  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_MS);
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us()
+// is increasing.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) {
+  static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
+  struct timespec delay = {};
+
+  delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
+  delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
+
+  // Take two timestamps with sleep in-between
+  uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+  int err = nanosleep(&delay, &delay);
+  uint64_t t2 = bluetooth::common::time_get_os_boottime_us();
+
+  ASSERT_EQ(err, 0);
+  ASSERT_GT(t2, t1);
+  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us() is
+// not zero.
+//
+TEST(TimeTest, test_time_gettimeofday_us_not_zero) {
+  uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+  ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us()
+// is monotonically increasing within reasonable boundaries.
+//
+TEST(TimeTest, test_time_gettimeofday_us_increases_upper_bound) {
+  uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+  uint64_t t2 = bluetooth::common::time_gettimeofday_us();
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us()
+// is increasing.
+//
+TEST(TimeTest, test_time_gettimeofday_us_increases_lower_bound) {
+  static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
+  struct timespec delay = {};
+
+  delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
+  delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
+
+  // Take two timestamps with sleep in-between
+  uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+  int err = nanosleep(&delay, &delay);
+  uint64_t t2 = bluetooth::common::time_gettimeofday_us();
+
+  ASSERT_EQ(err, 0);
+  ASSERT_GT(t2, t1);
+  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
diff --git a/hci/include/hci_layer.h b/hci/include/hci_layer.h
index 59ee443..c732e0c 100644
--- a/hci/include/hci_layer.h
+++ b/hci/include/hci_layer.h
@@ -91,7 +91,7 @@
     const btsnoop_t* btsnoop_interface,
     const packet_fragmenter_t* packet_fragmenter_interface);
 
-void post_to_hci_message_loop(const tracked_objects::Location& from_here,
-                              BT_HDR* p_msg);
+void post_to_main_message_loop(const tracked_objects::Location& from_here,
+                               BT_HDR* p_msg);
 
 void hci_layer_cleanup_interface();
diff --git a/hci/src/btsnoop.cc b/hci/src/btsnoop.cc
index 9812b61..6938725 100644
--- a/hci/src/btsnoop.cc
+++ b/hci/src/btsnoop.cc
@@ -36,12 +36,12 @@
 #include <unistd.h>
 
 #include "bt_types.h"
+#include "common/time_util.h"
 #include "hci/include/btsnoop.h"
 #include "hci/include/btsnoop_mem.h"
 #include "hci_layer.h"
 #include "osi/include/log.h"
 #include "osi/include/properties.h"
-#include "osi/include/time.h"
 #include "stack_config.h"
 
 // The number of of packets per btsnoop file before we rotate to the next
@@ -129,7 +129,7 @@
   uint8_t* p = const_cast<uint8_t*>(buffer->data + buffer->offset);
 
   std::lock_guard<std::mutex> lock(btsnoop_mutex);
-  uint64_t timestamp_us = time_gettimeofday_us();
+  uint64_t timestamp_us = bluetooth::common::time_gettimeofday_us();
   btsnoop_mem_capture(buffer, timestamp_us);
 
   if (logfile_fd == INVALID_FD) return;
diff --git a/hci/src/hci_layer.cc b/hci/src/hci_layer.cc
index 6ffd58c..a2b2797 100644
--- a/hci/src/hci_layer.cc
+++ b/hci/src/hci_layer.cc
@@ -92,7 +92,7 @@
 static const packet_fragmenter_t* packet_fragmenter;
 
 static future_t* startup_future;
-static MessageLoopThread thread("hci_thread");  // We own this
+static MessageLoopThread hci_thread("bt_hci_thread");
 
 static alarm_t* startup_timer;
 
@@ -135,7 +135,7 @@
     transmit_fragment, dispatch_reassembled, fragmenter_transmit_finished};
 
 void initialization_complete() {
-  thread.DoInThread(FROM_HERE, base::Bind(&event_finish_startup, nullptr));
+  hci_thread.DoInThread(FROM_HERE, base::Bind(&event_finish_startup, nullptr));
 }
 
 void hci_event_received(const tracked_objects::Location& from_here,
@@ -192,12 +192,12 @@
     goto error;
   }
 
-  thread.StartUp();
-  if (!thread.IsRunning()) {
+  hci_thread.StartUp();
+  if (!hci_thread.IsRunning()) {
     LOG_ERROR(LOG_TAG, "%s unable to start thread.", __func__);
     goto error;
   }
-  if (!thread.EnableRealTimeScheduling()) {
+  if (!hci_thread.EnableRealTimeScheduling()) {
     LOG_ERROR(LOG_TAG, "%s unable to make thread RT.", __func__);
     goto error;
   }
@@ -218,7 +218,7 @@
 
   packet_fragmenter->init(&packet_fragmenter_callbacks);
 
-  thread.DoInThread(FROM_HERE, base::Bind(&hci_initialize));
+  hci_thread.DoInThread(FROM_HERE, base::Bind(&hci_initialize));
 
   LOG_DEBUG(LOG_TAG, "%s starting async portion", __func__);
   return local_startup_future;
@@ -241,7 +241,7 @@
     startup_timer = NULL;
   }
 
-  thread.ShutDown();
+  hci_thread.ShutDown();
 
   // Close HCI to prevent callbacks.
   hci_close();
@@ -374,7 +374,7 @@
 
   std::lock_guard<std::mutex> command_credits_lock(command_credits_mutex);
   if (command_credits > 0) {
-    if (!thread.DoInThread(FROM_HERE, std::move(callback))) {
+    if (!hci_thread.DoInThread(FROM_HERE, std::move(callback))) {
       // HCI Layer was shut down or not running
       buffer_allocator->free(wait_entry->command);
       osi_free(wait_entry);
@@ -401,7 +401,8 @@
 }
 
 static void enqueue_packet(void* packet) {
-  if (!thread.DoInThread(FROM_HERE, base::Bind(&event_packet_ready, packet))) {
+  if (!hci_thread.DoInThread(FROM_HERE,
+                             base::Bind(&event_packet_ready, packet))) {
     // HCI Layer was shut down or not running
     buffer_allocator->free(packet);
     return;
@@ -541,7 +542,7 @@
 void process_command_credits(int credits) {
   std::lock_guard<std::mutex> command_credits_lock(command_credits_mutex);
 
-  if (!thread.IsRunning()) {
+  if (!hci_thread.IsRunning()) {
     // HCI Layer was shut down or not running
     return;
   }
@@ -550,7 +551,7 @@
   command_credits = credits - get_num_waiting_commands();
 
   while (command_credits > 0 && !command_queue.empty()) {
-    if (!thread.DoInThread(FROM_HERE, std::move(command_queue.front()))) {
+    if (!hci_thread.DoInThread(FROM_HERE, std::move(command_queue.front()))) {
       LOG(ERROR) << __func__ << ": failed to enqueue command";
     }
     command_queue.pop();
diff --git a/main/bte_main.cc b/main/bte_main.cc
index f3cca3e..04e564f 100644
--- a/main/bte_main.cc
+++ b/main/bte_main.cc
@@ -91,22 +91,18 @@
  *
  * Function         post_to_hci_message_loop
  *
- * Description      Post an HCI event to the hci message queue
+ * Description      Post an HCI event to the main thread
  *
  * Returns          None
  *
  *****************************************************************************/
-void post_to_hci_message_loop(const tracked_objects::Location& from_here,
-                              BT_HDR* p_msg) {
-  base::MessageLoop* hci_message_loop = get_message_loop();
-  if (!hci_message_loop || !hci_message_loop->task_runner().get()) {
-    LOG_ERROR(LOG_TAG, "%s: HCI message loop not running, accessed from %s",
-              __func__, from_here.ToString().c_str());
-    return;
+void post_to_main_message_loop(const tracked_objects::Location& from_here,
+                               BT_HDR* p_msg) {
+  if (do_in_main_thread(from_here, base::Bind(&btu_hci_msg_process, p_msg)) !=
+      BT_STATUS_SUCCESS) {
+    LOG(ERROR) << __func__ << ": do_in_main_thread failed from "
+               << from_here.ToString();
   }
-
-  hci_message_loop->task_runner()->PostTask(
-      from_here, base::Bind(&btu_hci_msg_process, p_msg));
 }
 
 /******************************************************************************
@@ -127,7 +123,7 @@
     return;
   }
 
-  hci->set_data_cb(base::Bind(&post_to_hci_message_loop));
+  hci->set_data_cb(base::Bind(&post_to_main_message_loop));
 
   module_init(get_module(STACK_CONFIG_MODULE));
 }
diff --git a/osi/Android.bp b/osi/Android.bp
index 19f2ff4..490ee36 100644
--- a/osi/Android.bp
+++ b/osi/Android.bp
@@ -54,7 +54,6 @@
         "src/future.cc",
         "src/hash_map_utils.cc",
         "src/list.cc",
-        "src/metrics.cc",
         "src/mutex.cc",
         "src/osi.cc",
         "src/properties.cc",
@@ -65,7 +64,6 @@
         "src/socket_utils/socket_local_client.cc",
         "src/socket_utils/socket_local_server.cc",
         "src/thread.cc",
-        "src/time.cc",
         "src/wakelock.cc",
     ],
     shared_libs: [
@@ -104,16 +102,13 @@
         "test/fixed_queue_test.cc",
         "test/future_test.cc",
         "test/hash_map_utils_test.cc",
-        "test/leaky_bonded_queue_test.cc",
         "test/list_test.cc",
-        "test/metrics_test.cc",
         "test/properties_test.cc",
         "test/rand_test.cc",
         "test/reactor_test.cc",
         "test/ringbuffer_test.cc",
         "test/semaphore_test.cc",
         "test/thread_test.cc",
-        "test/time_test.cc",
         "test/wakelock_test.cc",
     ],
     shared_libs: [
diff --git a/osi/include/alarm.h b/osi/include/alarm.h
index 2d07b9a..2db228b 100644
--- a/osi/include/alarm.h
+++ b/osi/include/alarm.h
@@ -20,7 +20,6 @@
 
 #include <stdbool.h>
 #include <stdint.h>
-#include "osi/include/time.h"
 
 typedef struct alarm_t alarm_t;
 typedef struct fixed_queue_t fixed_queue_t;
diff --git a/osi/include/time.h b/osi/include/time.h
deleted file mode 100644
index f3f233c..0000000
--- a/osi/include/time.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/******************************************************************************
- *
- *  Copyright 2015 Google, Inc.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#pragma once
-
-#include <stdint.h>
-
-// Get the OS boot time in milliseconds.
-//
-// NOTE: The return value will rollover every 49.7 days,
-// hence it cannot be used for absolute time comparison.
-// Relative time comparison using 32-bits integers such
-// as (t2_u32 - t1_u32 < delta_u32) should work as expected as long
-// as there is no multiple rollover between t2_u32 and t1_u32.
-//
-// TODO: This function's return type should be modified to |uint64_t|.
-// Be careful: some of the code that is using it assumes the return type
-// is uint32_t.
-uint32_t time_get_os_boottime_ms(void);
-
-// Get the OS boot time in microseconds.
-uint64_t time_get_os_boottime_us(void);
-
-// Get the current wall clock time in microseconds.
-uint64_t time_gettimeofday_us(void);
diff --git a/osi/src/alarm.cc b/osi/src/alarm.cc
index 25b1458..75857b7 100644
--- a/osi/src/alarm.cc
+++ b/osi/src/alarm.cc
@@ -46,13 +46,12 @@
 #include "osi/include/semaphore.h"
 #include "osi/include/thread.h"
 #include "osi/include/wakelock.h"
+#include "stack/include/btu.h"
 
 using base::Bind;
 using base::CancelableClosure;
 using base::MessageLoop;
 
-extern base::MessageLoop* get_message_loop();
-
 // Callback and timer threads should run at RT priority in order to ensure they
 // meet audio deadlines.  Use this priority for all audio/timer related thread.
 static const int THREAD_RT_PRIORITY = 1;
@@ -643,15 +642,15 @@
 
     // Enqueue the alarm for processing
     if (alarm->for_msg_loop) {
-      if (!get_message_loop()) {
+      if (!get_main_message_loop()) {
         LOG_ERROR(LOG_TAG, "%s: message loop already NULL. Alarm: %s", __func__,
                   alarm->stats.name);
         continue;
       }
 
       alarm->closure.i.Reset(Bind(alarm_ready_mloop, alarm));
-      get_message_loop()->task_runner()->PostTask(FROM_HERE,
-                                                  alarm->closure.i.callback());
+      get_main_message_loop()->task_runner()->PostTask(
+          FROM_HERE, alarm->closure.i.callback());
     } else {
       fixed_queue_enqueue(alarm->queue, alarm);
     }
diff --git a/osi/src/wakelock.cc b/osi/src/wakelock.cc
index aec9ea9..44f5960 100644
--- a/osi/src/wakelock.cc
+++ b/osi/src/wakelock.cc
@@ -34,15 +34,15 @@
 #include <string>
 
 #include "base/logging.h"
+#include "common/metrics.h"
 #include "osi/include/alarm.h"
 #include "osi/include/allocator.h"
 #include "osi/include/log.h"
-#include "osi/include/metrics.h"
 #include "osi/include/osi.h"
 #include "osi/include/thread.h"
 #include "osi/include/wakelock.h"
 
-using system_bt_osi::BluetoothMetricsLogger;
+using bluetooth::common::BluetoothMetricsLogger;
 
 static bt_os_callouts_t* wakelock_os_callouts = NULL;
 static bool is_native = true;
@@ -281,7 +281,7 @@
   wakelock_stats.last_acquired_timestamp_ms = just_now_ms;
 
   BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
-      system_bt_osi::WAKE_EVENT_ACQUIRED, "", "", just_now_ms);
+      bluetooth::common::WAKE_EVENT_ACQUIRED, "", "", just_now_ms);
 }
 
 //
@@ -323,7 +323,7 @@
   wakelock_stats.total_acquired_interval_ms += delta_ms;
 
   BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
-      system_bt_osi::WAKE_EVENT_RELEASED, "", "", just_now_ms);
+      bluetooth::common::WAKE_EVENT_RELEASED, "", "", just_now_ms);
 }
 
 void wakelock_debug_dump(int fd) {
diff --git a/osi/test/alarm_test.cc b/osi/test/alarm_test.cc
index df6592a..20fd7d6 100644
--- a/osi/test/alarm_test.cc
+++ b/osi/test/alarm_test.cc
@@ -42,7 +42,7 @@
 
 static base::MessageLoop* message_loop_;
 
-base::MessageLoop* get_message_loop() { return message_loop_; }
+base::MessageLoop* get_main_message_loop() { return message_loop_; }
 
 class AlarmTest : public AlarmTestHarness {
  protected:
diff --git a/osi/test/time_test.cc b/osi/test/time_test.cc
deleted file mode 100644
index f14842d..0000000
--- a/osi/test/time_test.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-/******************************************************************************
- *
- *  Copyright 2015 Google, Inc.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at:
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- ******************************************************************************/
-
-#include <gtest/gtest.h>
-
-#include "AllocationTestHarness.h"
-
-#include "osi/include/time.h"
-
-// Generous upper bound: 10 seconds
-static const uint32_t TEST_TIME_DELTA_UPPER_BOUND_MS = 10 * 1000;
-
-class TimeTest : public AllocationTestHarness {};
-
-//
-// Test that the return value of time_get_os_boottime_ms() is not zero.
-//
-// NOTE: For now this test is disabled, because the return value
-// of time_get_os_boottime_ms() is 32-bits integer that could wrap-around
-// in 49.7 days. It should be re-enabled if/after the wrap-around issue
-// is resolved (e.g., if the return value is 64-bits integer).
-//
-#if 0
-TEST_F(TimeTest, test_time_get_os_boottime_ms_not_zero) {
-  uint32_t t1 = time_get_os_boottime_ms();
-  ASSERT_TRUE(t1 > 0);
-}
-#endif
-
-//
-// Test that the return value of time_get_os_boottime_us() is not zero.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_not_zero) {
-  uint64_t t1 = time_get_os_boottime_us();
-  ASSERT_TRUE(t1 > 0);
-}
-
-//
-// Test that the return value of time_get_os_boottime_ms()
-// is monotonically increasing within reasonable boundries.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) {
-  uint32_t t1 = time_get_os_boottime_ms();
-  uint32_t t2 = time_get_os_boottime_ms();
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
-}
-
-//
-// Test that the return value of time_get_os_boottime_us()
-// is monotonically increasing within reasonable boundries.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) {
-  uint64_t t1 = time_get_os_boottime_us();
-  uint64_t t2 = time_get_os_boottime_us();
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// Test that the return value of time_get_os_boottime_ms()
-// is increasing.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_ms_increases_lower_bound) {
-  static const uint32_t TEST_TIME_SLEEP_MS = 100;
-  struct timespec delay;
-
-  delay.tv_sec = TEST_TIME_SLEEP_MS / 1000;
-  delay.tv_nsec = 1000 * 1000 * (TEST_TIME_SLEEP_MS % 1000);
-
-  // Take two timestamps with sleep in-between
-  uint32_t t1 = time_get_os_boottime_ms();
-  int err = nanosleep(&delay, &delay);
-  uint32_t t2 = time_get_os_boottime_ms();
-
-  ASSERT_TRUE(err == 0);
-  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_MS);
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
-}
-
-//
-// Test that the return value of time_get_os_boottime_us()
-// is increasing.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) {
-  static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
-  struct timespec delay;
-
-  delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
-  delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
-
-  // Take two timestamps with sleep in-between
-  uint64_t t1 = time_get_os_boottime_us();
-  int err = nanosleep(&delay, &delay);
-  uint64_t t2 = time_get_os_boottime_us();
-
-  ASSERT_TRUE(err == 0);
-  ASSERT_TRUE(t2 > t1);
-  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// Test that the return value of time_gettimeofday_us() is not zero.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_not_zero) {
-  uint64_t t1 = time_gettimeofday_us();
-  ASSERT_TRUE(t1 > 0);
-}
-
-//
-// Test that the return value of time_gettimeofday_us()
-// is monotonically increasing within reasonable boundaries.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_increases_upper_bound) {
-  uint64_t t1 = time_gettimeofday_us();
-  uint64_t t2 = time_gettimeofday_us();
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// Test that the return value of time_gettimeofday_us()
-// is increasing.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_increases_lower_bound) {
-  static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
-  struct timespec delay;
-
-  delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
-  delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
-
-  // Take two timestamps with sleep in-between
-  uint64_t t1 = time_gettimeofday_us();
-  int err = nanosleep(&delay, &delay);
-  uint64_t t2 = time_gettimeofday_us();
-
-  ASSERT_TRUE(err == 0);
-  ASSERT_TRUE(t2 > t1);
-  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
-  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
diff --git a/profile/avrcp/connection_handler.cc b/profile/avrcp/connection_handler.cc
index f6ed849..b65d4c7 100644
--- a/profile/avrcp/connection_handler.cc
+++ b/profile/avrcp/connection_handler.cc
@@ -273,13 +273,20 @@
       device_map_.erase(handle);
     } break;
 
-    case AVRC_BROWSE_OPEN_IND_EVT:
+    case AVRC_BROWSE_OPEN_IND_EVT: {
       LOG(INFO) << __PRETTY_FUNCTION__ << ": Browse Open Event";
       // NOTE (apanicke): We don't need to explicitly handle this message
       // since the AVCTP Layer will still send us browsing messages
       // regardless. It would be useful to note this though for future
       // compatibility issues.
-      break;
+      if (device_map_.find(handle) == device_map_.end()) {
+        LOG(WARNING) << "Browse Opened received from device that doesn't exist";
+        return;
+      }
+
+      auto browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
+      device_map_[handle]->SetBrowseMtu(browse_mtu);
+    } break;
     case AVRC_BROWSE_CLOSE_IND_EVT:
       LOG(INFO) << __PRETTY_FUNCTION__ << ": Browse Close Event";
       break;
@@ -357,13 +364,20 @@
       device_map_.erase(handle);
     } break;
 
-    case AVRC_BROWSE_OPEN_IND_EVT:
+    case AVRC_BROWSE_OPEN_IND_EVT: {
       LOG(INFO) << __PRETTY_FUNCTION__ << ": Browse Open Event";
       // NOTE (apanicke): We don't need to explicitly handle this message
       // since the AVCTP Layer will still send us browsing messages
       // regardless. It would be useful to note this though for future
       // compatibility issues.
-      break;
+      if (device_map_.find(handle) == device_map_.end()) {
+        LOG(WARNING) << "Browse Opened received from device that doesn't exist";
+        return;
+      }
+
+      auto browse_mtu = avrc_->GetBrowseMtu(handle) - AVCT_HDR_LEN;
+      device_map_[handle]->SetBrowseMtu(browse_mtu);
+    } break;
     case AVRC_BROWSE_CLOSE_IND_EVT:
       LOG(INFO) << __PRETTY_FUNCTION__ << ": Browse Close Event";
       break;
diff --git a/profile/avrcp/device.cc b/profile/avrcp/device.cc
index 8efadc8..67186cf 100644
--- a/profile/avrcp/device.cc
+++ b/profile/avrcp/device.cc
@@ -59,6 +59,11 @@
   volume_interface_ = volume_interface;
 }
 
+void Device::SetBrowseMtu(uint16_t browse_mtu) {
+  DEVICE_LOG(INFO) << __PRETTY_FUNCTION__ << ": browse_mtu = " << browse_mtu;
+  browse_mtu_ = browse_mtu;
+}
+
 bool Device::IsActive() const {
   return address_ == a2dp_interface_->active_peer();
 }
@@ -1031,7 +1036,7 @@
       // right now we always use folders of mixed type
       FolderItem folder_item(vfs_ids_.get_uid(folder.media_id), 0x00,
                              folder.is_playable, folder.name);
-      builder->AddFolder(folder_item);
+      if (!builder->AddFolder(folder_item)) break;
     } else if (items[i].type == ListItem::SONG) {
       auto song = items[i].song;
       auto title =
@@ -1048,7 +1053,9 @@
             filter_attributes_requested(song, pkt->GetAttributesRequested());
       }
 
-      builder->AddSong(song_item);
+      // If we fail to add a song, don't accidentally add one later that might
+      // fit.
+      if (!builder->AddSong(song_item)) break;
     }
   }
 
@@ -1081,7 +1088,10 @@
       item.attributes_ =
           filter_attributes_requested(song, pkt->GetAttributesRequested());
     }
-    builder->AddSong(item);
+
+    // If we fail to add a song, don't accidentally add one later that might
+    // fit.
+    if (!builder->AddSong(item)) break;
   }
 
   send_message(label, true, std::move(builder));
diff --git a/profile/avrcp/device.h b/profile/avrcp/device.h
index 1be19c0..363f68d 100644
--- a/profile/avrcp/device.h
+++ b/profile/avrcp/device.h
@@ -91,6 +91,12 @@
                           VolumeInterface* volume_interface);
 
   /**
+   * Set the maximum size of a AVRCP Browsing Packet. This is done after the
+   * connection of the Browsing channel.
+   */
+  void SetBrowseMtu(uint16_t browse_mtu);
+
+  /**
    * Notify the device that metadata, play_status, and/or queue have updated
    * via a boolean. Each boolean represents whether its respective content has
    * updated.
diff --git a/profile/avrcp/tests/avrcp_device_test.cc b/profile/avrcp/tests/avrcp_device_test.cc
index 56f03e4..2c588ae 100644
--- a/profile/avrcp/tests/avrcp_device_test.cc
+++ b/profile/avrcp/tests/avrcp_device_test.cc
@@ -527,16 +527,24 @@
       base::Bind([](MockFunction<void(uint8_t, bool, const AvrcpResponse&)>* a,
                     uint8_t b, bool c, AvrcpResponse d) { a->Call(b, c, d); },
                  &response_cb);
-  Device device(RawAddress::kAny, true, cb, 0xFFFF, truncated_packet->size());
+
+  Device device(RawAddress::kAny, true, cb, 0xFFFF,
+                truncated_packet->size() + FolderItem::kHeaderSize() + 5);
   device.RegisterInterfaces(&interface, &a2dp_interface, nullptr);
 
   FolderInfo info0 = {"test_id0", true, "Test Folder0"};
   FolderInfo info1 = {"test_id1", true, "Test Folder1"};
-  FolderInfo info2 = {"test_id1", true, "Truncated folder"};
+  FolderInfo info2 = {"test_id2", true, "Truncated folder"};
+  // Used to ensure that adding an item that would fit in the MTU fails if
+  // adding a large item failed.
+  FolderInfo small_info = {"test_id2", true, "Small"};
+
   ListItem item0 = {ListItem::FOLDER, info0, SongInfo()};
   ListItem item1 = {ListItem::FOLDER, info1, SongInfo()};
-  ListItem item2 = {ListItem::FOLDER, info1, SongInfo()};
-  std::vector<ListItem> list0 = {item0, item1, item2};
+  ListItem item2 = {ListItem::FOLDER, info2, SongInfo()};
+  ListItem item3 = {ListItem::FOLDER, small_info, SongInfo()};
+
+  std::vector<ListItem> list0 = {item0, item1, item2, item3};
   EXPECT_CALL(interface, GetFolderItems(_, "", _))
       .WillRepeatedly(InvokeCb<2>(list0));
 
diff --git a/stack/Android.bp b/stack/Android.bp
index 4a122de..4baebe3 100644
--- a/stack/Android.bp
+++ b/stack/Android.bp
@@ -274,6 +274,7 @@
         "liblog",
         "libgmock",
         "libosi",
+        "libbt-common",
         "libbt-protos-lite",
     ],
     sanitize: {
diff --git a/stack/a2dp/a2dp_aac_encoder.cc b/stack/a2dp/a2dp_aac_encoder.cc
index 65b81de..f6c68a6 100644
--- a/stack/a2dp/a2dp_aac_encoder.cc
+++ b/stack/a2dp/a2dp_aac_encoder.cc
@@ -27,6 +27,7 @@
 
 #include "a2dp_aac.h"
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
@@ -125,7 +126,8 @@
     aacEncClose(&a2dp_aac_encoder_cb.aac_handle);
   memset(&a2dp_aac_encoder_cb, 0, sizeof(a2dp_aac_encoder_cb));
 
-  a2dp_aac_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+  a2dp_aac_encoder_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
 
   a2dp_aac_encoder_cb.read_callback = read_callback;
   a2dp_aac_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/stack/a2dp/a2dp_sbc_encoder.cc b/stack/a2dp/a2dp_sbc_encoder.cc
index 3161362..c814253 100644
--- a/stack/a2dp/a2dp_sbc_encoder.cc
+++ b/stack/a2dp/a2dp_sbc_encoder.cc
@@ -28,6 +28,7 @@
 #include "a2dp_sbc.h"
 #include "a2dp_sbc_up_sample.h"
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "embdrv/sbc/encoder/include/sbc_encoder.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
@@ -137,7 +138,8 @@
                            a2dp_source_enqueue_callback_t enqueue_callback) {
   memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
 
-  a2dp_sbc_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+  a2dp_sbc_encoder_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
 
   a2dp_sbc_encoder_cb.read_callback = read_callback;
   a2dp_sbc_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/stack/a2dp/a2dp_vendor_aptx_encoder.cc b/stack/a2dp/a2dp_vendor_aptx_encoder.cc
index 1b65776..0d605c0 100644
--- a/stack/a2dp/a2dp_vendor_aptx_encoder.cc
+++ b/stack/a2dp/a2dp_vendor_aptx_encoder.cc
@@ -26,6 +26,7 @@
 #include "a2dp_vendor.h"
 #include "a2dp_vendor_aptx.h"
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
@@ -174,7 +175,8 @@
     a2dp_source_enqueue_callback_t enqueue_callback) {
   memset(&a2dp_aptx_encoder_cb, 0, sizeof(a2dp_aptx_encoder_cb));
 
-  a2dp_aptx_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+  a2dp_aptx_encoder_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
 
   a2dp_aptx_encoder_cb.read_callback = read_callback;
   a2dp_aptx_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc b/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
index dc045e3..fb782dd 100644
--- a/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
+++ b/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
@@ -26,6 +26,7 @@
 #include "a2dp_vendor.h"
 #include "a2dp_vendor_aptx_hd.h"
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
@@ -174,7 +175,8 @@
     a2dp_source_enqueue_callback_t enqueue_callback) {
   memset(&a2dp_aptx_hd_encoder_cb, 0, sizeof(a2dp_aptx_hd_encoder_cb));
 
-  a2dp_aptx_hd_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+  a2dp_aptx_hd_encoder_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
 
   a2dp_aptx_hd_encoder_cb.read_callback = read_callback;
   a2dp_aptx_hd_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/stack/a2dp/a2dp_vendor_ldac_encoder.cc b/stack/a2dp/a2dp_vendor_ldac_encoder.cc
index 6c01db1..bd1653b 100644
--- a/stack/a2dp/a2dp_vendor_ldac_encoder.cc
+++ b/stack/a2dp/a2dp_vendor_ldac_encoder.cc
@@ -33,6 +33,7 @@
 #include "a2dp_vendor_ldac.h"
 #include "a2dp_vendor_ldac_abr.h"
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
 
@@ -285,7 +286,8 @@
     a2dp_ldac_abr_free_handle(a2dp_ldac_encoder_cb.ldac_abr_handle);
   memset(&a2dp_ldac_encoder_cb, 0, sizeof(a2dp_ldac_encoder_cb));
 
-  a2dp_ldac_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+  a2dp_ldac_encoder_cb.stats.session_start_us =
+      bluetooth::common::time_get_os_boottime_us();
 
   a2dp_ldac_encoder_cb.read_callback = read_callback;
   a2dp_ldac_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc
index 603adb4..a7d5052 100644
--- a/stack/btm/btm_ble_gap.cc
+++ b/stack/btm/btm_ble_gap.cc
@@ -513,8 +513,8 @@
   if (btm_cb.cmn_ble_vsc_cb.version_supported >=
       BTM_VSC_CHIP_CAPABILITY_M_VERSION) {
     STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.total_trackable_advertisers, p);
-    STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p);
-    STREAM_TO_UINT16(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p);
+    STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.extended_scan_support, p);
+    STREAM_TO_UINT8(btm_cb.cmn_ble_vsc_cb.debug_logging_supported, p);
   }
   btm_cb.cmn_ble_vsc_cb.values_read = true;
 
diff --git a/stack/btm/btm_devctl.cc b/stack/btm/btm_devctl.cc
index f99ee5d..a52c2b5 100644
--- a/stack/btm/btm_devctl.cc
+++ b/stack/btm/btm_devctl.cc
@@ -43,7 +43,7 @@
 
 #include "gatt_int.h"
 
-extern bluetooth::common::MessageLoopThread bt_workqueue_thread;
+extern bluetooth::common::MessageLoopThread bt_startup_thread;
 
 /******************************************************************************/
 /*               L O C A L    D A T A    D E F I N I T I O N S                */
@@ -231,7 +231,7 @@
   btm_db_reset();
 
   module_start_up_callbacked_wrapper(get_module(CONTROLLER_MODULE),
-                                     &bt_workqueue_thread, reset_complete);
+                                     &bt_startup_thread, reset_complete);
 }
 
 /*******************************************************************************
diff --git a/stack/btm/btm_inq.cc b/stack/btm/btm_inq.cc
index 383d290..1a5d7f5 100644
--- a/stack/btm/btm_inq.cc
+++ b/stack/btm/btm_inq.cc
@@ -30,9 +30,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "common/time_util.h"
 #include "device/include/controller.h"
 #include "osi/include/osi.h"
-#include "osi/include/time.h"
 
 #include "advertise_data_parser.h"
 #include "bt_common.h"
@@ -1324,7 +1324,7 @@
   uint16_t xx;
   tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db;
   tINQ_DB_ENT* p_old = btm_cb.btm_inq_vars.inq_db;
-  uint32_t ot = 0xFFFFFFFF;
+  uint64_t ot = UINT64_MAX;
 
   for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
     if (!p_ent->in_use) {
@@ -1738,7 +1738,7 @@
       p_cur->dev_class[2] = dc[2];
       p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID;
 
-      p_i->time_of_resp = time_get_os_boottime_ms();
+      p_i->time_of_resp = bluetooth::common::time_get_os_boottime_ms();
 
       if (p_i->inq_count != p_inq->inq_counter)
         p_inq->inq_cmpl_info.num_resp++; /* A new response was found */
diff --git a/stack/btm/btm_int_types.h b/stack/btm/btm_int_types.h
index 95acb5d..c4398a6 100644
--- a/stack/btm/btm_int_types.h
+++ b/stack/btm/btm_int_types.h
@@ -210,7 +210,7 @@
 } tINQ_BDADDR;
 
 typedef struct {
-  uint32_t time_of_resp;
+  uint64_t time_of_resp;
   uint32_t
       inq_count; /* "timestamps" the entry with a particular inquiry count   */
                  /* Used for determining if a response has already been      */
@@ -801,8 +801,7 @@
 
   tBTM_SEC_DEV_REC* p_collided_dev_rec;
   alarm_t* sec_collision_timer;
-  uint32_t collision_start_time;
-  uint32_t max_collision_delay;
+  uint64_t collision_start_time;
   uint32_t dev_rec_count; /* Counter used for device record timestamp */
   uint8_t security_mode;
   bool pairing_disabled;
diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc
index 54415ff..4fb497f 100644
--- a/stack/btm/btm_sec.cc
+++ b/stack/btm/btm_sec.cc
@@ -28,10 +28,10 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "common/time_util.h"
 #include "device/include/controller.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
-#include "osi/include/time.h"
 
 #include "bt_types.h"
 #include "bt_utils.h"
@@ -2688,7 +2688,6 @@
 void btm_sec_init(uint8_t sec_mode) {
   btm_cb.security_mode = sec_mode;
   btm_cb.pairing_bda = RawAddress::kAny;
-  btm_cb.max_collision_delay = BTM_SEC_MAX_COLLISION_DELAY;
 }
 
 /*******************************************************************************
@@ -3677,10 +3676,10 @@
   tBTM_SEC_DEV_REC* p_dev_rec;
 
   if (!btm_cb.collision_start_time)
-    btm_cb.collision_start_time = time_get_os_boottime_ms();
+    btm_cb.collision_start_time = bluetooth::common::time_get_os_boottime_ms();
 
-  if ((time_get_os_boottime_ms() - btm_cb.collision_start_time) <
-      btm_cb.max_collision_delay) {
+  if ((bluetooth::common::time_get_os_boottime_ms() -
+       btm_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) {
     if (handle == BTM_SEC_INVALID_HANDLE) {
       p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING);
       if (p_dev_rec == NULL)
diff --git a/stack/btu/btu_hcif.cc b/stack/btu/btu_hcif.cc
index e2d8a2f..f1d413d 100644
--- a/stack/btu/btu_hcif.cc
+++ b/stack/btu/btu_hcif.cc
@@ -421,9 +421,9 @@
 
 static void btu_hcif_command_complete_evt_with_cb(BT_HDR* response,
                                                   void* context) {
-  do_in_bta_thread(FROM_HERE,
-                   base::Bind(btu_hcif_command_complete_evt_with_cb_on_task,
-                              response, context));
+  do_in_main_thread(FROM_HERE,
+                    base::Bind(btu_hcif_command_complete_evt_with_cb_on_task,
+                               response, context));
 }
 
 static void btu_hcif_command_status_evt_with_cb_on_task(uint8_t status,
@@ -454,7 +454,7 @@
     return;
   }
 
-  do_in_bta_thread(
+  do_in_main_thread(
       FROM_HERE, base::Bind(btu_hcif_command_status_evt_with_cb_on_task, status,
                             command, context));
 }
@@ -1027,8 +1027,8 @@
 }
 
 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context) {
-  do_in_bta_thread(FROM_HERE, base::Bind(btu_hcif_command_complete_evt_on_task,
-                                         response, context));
+  do_in_main_thread(FROM_HERE, base::Bind(btu_hcif_command_complete_evt_on_task,
+                                          response, context));
 }
 
 /*******************************************************************************
@@ -1202,8 +1202,8 @@
 
 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
                                         void* context) {
-  do_in_bta_thread(FROM_HERE, base::Bind(btu_hcif_command_status_evt_on_task,
-                                         status, command, context));
+  do_in_main_thread(FROM_HERE, base::Bind(btu_hcif_command_status_evt_on_task,
+                                          status, command, context));
 }
 
 /*******************************************************************************
diff --git a/stack/btu/btu_init.cc b/stack/btu/btu_init.cc
index 866bf83..e70ca7a 100644
--- a/stack/btu/btu_init.cc
+++ b/stack/btu/btu_init.cc
@@ -38,7 +38,7 @@
 
 using bluetooth::common::MessageLoopThread;
 
-MessageLoopThread bt_workqueue_thread("bt_workqueue");
+MessageLoopThread bt_startup_thread("bt_startup_thread");
 
 void btu_task_start_up(void* context);
 void btu_task_shut_down(void* context);
@@ -101,19 +101,17 @@
  *****************************************************************************/
 void BTU_StartUp() {
   btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
-  bt_workqueue_thread.StartUp();
-  if (!bt_workqueue_thread.EnableRealTimeScheduling()) {
-    LOG(ERROR) << __func__
-               << ": Unable to set real time scheduling policy for"
-                  " bt_workqueue thread";
+  bt_startup_thread.StartUp();
+  if (!bt_startup_thread.EnableRealTimeScheduling()) {
+    LOG(ERROR) << __func__ << ": Unable to set real time scheduling policy for "
+               << bt_startup_thread;
     BTU_ShutDown();
     return;
   }
-  if (!bt_workqueue_thread.DoInThread(FROM_HERE,
-                                      base::Bind(btu_task_start_up, nullptr))) {
-    LOG(ERROR) << __func__
-               << ": Unable to continue start-up on bt_workqueue"
-                  " thread";
+  if (!bt_startup_thread.DoInThread(FROM_HERE,
+                                    base::Bind(btu_task_start_up, nullptr))) {
+    LOG(ERROR) << __func__ << ": Unable to continue start-up on "
+               << bt_startup_thread;
     BTU_ShutDown();
     return;
   }
@@ -121,5 +119,5 @@
 
 void BTU_ShutDown() {
   btu_task_shut_down(nullptr);
-  bt_workqueue_thread.ShutDown();
+  bt_startup_thread.ShutDown();
 }
diff --git a/stack/btu/btu_task.cc b/stack/btu/btu_task.cc
index 736d30d..a197701 100644
--- a/stack/btu/btu_task.cc
+++ b/stack/btu/btu_task.cc
@@ -43,7 +43,7 @@
 /* Define BTU storage area */
 uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
 
-static MessageLoopThread btu_message_loop_thread("btu_message_loop");
+static MessageLoopThread main_thread("bt_main_thread");
 
 void btu_hci_msg_process(BT_HDR* p_msg) {
   /* Determine the input message type. */
@@ -79,13 +79,14 @@
   }
 }
 
-base::MessageLoop* get_message_loop() {
-  return btu_message_loop_thread.message_loop();
+base::MessageLoop* get_main_message_loop() {
+  return main_thread.message_loop();
 }
 
-bt_status_t do_in_bta_thread(const tracked_objects::Location& from_here,
-                             base::OnceClosure task) {
-  if (!btu_message_loop_thread.DoInThread(from_here, std::move(task))) {
+bt_status_t do_in_main_thread(const tracked_objects::Location& from_here,
+                              base::OnceClosure task) {
+  if (!main_thread.DoInThread(from_here, std::move(task))) {
+    LOG(ERROR) << __func__ << ": failed from " << from_here.ToString();
     return BT_STATUS_FAIL;
   }
   return BT_STATUS_SUCCESS;
@@ -111,11 +112,11 @@
    */
   module_init(get_module(BTE_LOGMSG_MODULE));
 
-  btu_message_loop_thread.StartUp();
-  if (!btu_message_loop_thread.IsRunning()) {
+  main_thread.StartUp();
+  if (!main_thread.IsRunning()) {
     LOG(FATAL) << __func__ << ": unable to start btu message loop thread.";
   }
-  if (!btu_message_loop_thread.EnableRealTimeScheduling()) {
+  if (!main_thread.EnableRealTimeScheduling()) {
     LOG(FATAL) << __func__ << ": unable to enable real time scheduling";
   }
   if (do_in_jni_thread(FROM_HERE, base::Bind(btif_init_ok, 0, nullptr)) !=
@@ -126,7 +127,7 @@
 
 void btu_task_shut_down(UNUSED_ATTR void* context) {
   // Shutdown message loop on task completed
-  btu_message_loop_thread.ShutDown();
+  main_thread.ShutDown();
 
   module_clean_up(get_module(BTE_LOGMSG_MODULE));
 
diff --git a/stack/include/a2dp_aac_encoder.h b/stack/include/a2dp_aac_encoder.h
index 5adf218..143a577 100644
--- a/stack/include/a2dp_aac_encoder.h
+++ b/stack/include/a2dp_aac_encoder.h
@@ -22,7 +22,6 @@
 #define A2DP_AAC_ENCODER_H
 
 #include "a2dp_codec_api.h"
-#include "osi/include/time.h"
 
 // Loads the A2DP AAC encoder.
 // Return true on success, otherwise false.
diff --git a/stack/include/a2dp_codec_api.h b/stack/include/a2dp_codec_api.h
index f5e1573..a9e78e6 100644
--- a/stack/include/a2dp_codec_api.h
+++ b/stack/include/a2dp_codec_api.h
@@ -34,7 +34,6 @@
 #include "a2dp_api.h"
 #include "audio_a2dp_hw/include/audio_a2dp_hw.h"
 #include "avdt_api.h"
-#include "osi/include/time.h"
 
 class tBT_A2DP_OFFLOAD;
 
diff --git a/stack/include/a2dp_sbc_encoder.h b/stack/include/a2dp_sbc_encoder.h
index d97e78c..0acf16f 100644
--- a/stack/include/a2dp_sbc_encoder.h
+++ b/stack/include/a2dp_sbc_encoder.h
@@ -25,7 +25,6 @@
 #define A2DP_SBC_ENCODER_H
 
 #include "a2dp_codec_api.h"
-#include "osi/include/time.h"
 
 // Loads the A2DP SBC encoder.
 // Return true on success, otherwise false.
diff --git a/stack/include/a2dp_vendor_aptx_encoder.h b/stack/include/a2dp_vendor_aptx_encoder.h
index 585819d..c0954fa 100644
--- a/stack/include/a2dp_vendor_aptx_encoder.h
+++ b/stack/include/a2dp_vendor_aptx_encoder.h
@@ -22,7 +22,6 @@
 #define A2DP_VENDOR_APTX_ENCODER_H
 
 #include "a2dp_codec_api.h"
-#include "osi/include/time.h"
 
 // Loads the A2DP aptX encoder.
 // Return true on success, otherwise false.
diff --git a/stack/include/a2dp_vendor_aptx_hd_encoder.h b/stack/include/a2dp_vendor_aptx_hd_encoder.h
index c7b5de3..84ef8a0 100644
--- a/stack/include/a2dp_vendor_aptx_hd_encoder.h
+++ b/stack/include/a2dp_vendor_aptx_hd_encoder.h
@@ -22,7 +22,6 @@
 #define A2DP_VENDOR_APTX_HD_ENCODER_H
 
 #include "a2dp_codec_api.h"
-#include "osi/include/time.h"
 
 // Loads the A2DP aptX-HD encoder.
 // Return true on success, otherwise false.
diff --git a/stack/include/a2dp_vendor_ldac_encoder.h b/stack/include/a2dp_vendor_ldac_encoder.h
index 9980f39..f5e320a 100644
--- a/stack/include/a2dp_vendor_ldac_encoder.h
+++ b/stack/include/a2dp_vendor_ldac_encoder.h
@@ -22,7 +22,6 @@
 #define A2DP_VENDOR_LDAC_ENCODER_H
 
 #include "a2dp_codec_api.h"
-#include "osi/include/time.h"
 
 // Loads the A2DP LDAC encoder.
 // Return true on success, otherwise false.
diff --git a/stack/include/btu.h b/stack/include/btu.h
index 505df69..00a690c 100644
--- a/stack/include/btu.h
+++ b/stack/include/btu.h
@@ -57,9 +57,9 @@
 /* Functions provided by btu_task.cc
  ***********************************
 */
-base::MessageLoop* get_message_loop();
-bt_status_t do_in_bta_thread(const tracked_objects::Location& from_here,
-                             base::OnceClosure task);
+base::MessageLoop* get_main_message_loop();
+bt_status_t do_in_main_thread(const tracked_objects::Location& from_here,
+                              base::OnceClosure task);
 
 void BTU_StartUp(void);
 void BTU_ShutDown(void);
diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc
index 34184738..06ef7e8 100644
--- a/stack/l2cap/l2c_csm.cc
+++ b/stack/l2cap/l2c_csm.cc
@@ -30,6 +30,7 @@
 #include "bt_target.h"
 #include "btm_int.h"
 #include "btu.h"
+#include "common/time_util.h"
 #include "hcidefs.h"
 #include "hcimsgs.h"
 #include "l2c_int.h"
@@ -816,7 +817,8 @@
           }
 
 #if (L2CAP_ERTM_STATS == TRUE)
-          p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
+          p_ccb->fcrb.connect_tick_count =
+              bluetooth::common::time_get_os_boottime_ms();
 #endif
           /* See if we can forward anything on the hold queue */
           if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
@@ -904,7 +906,8 @@
       if (p_ccb->fcrb.wait_ack) l2c_fcr_start_timer(p_ccb);
 
 #if (L2CAP_ERTM_STATS == TRUE)
-      p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
+      p_ccb->fcrb.connect_tick_count =
+          bluetooth::common::time_get_os_boottime_ms();
 #endif
 
       /* See if we can forward anything on the hold queue */
diff --git a/stack/l2cap/l2c_fcr.cc b/stack/l2cap/l2c_fcr.cc
index b20b9c1..d543ec4 100644
--- a/stack/l2cap/l2c_fcr.cc
+++ b/stack/l2cap/l2c_fcr.cc
@@ -34,6 +34,7 @@
 #include "btm_api.h"
 #include "btm_int.h"
 #include "btu.h"
+#include "common/time_util.h"
 #include "hcimsgs.h"
 #include "l2c_api.h"
 #include "l2c_int.h"
@@ -231,7 +232,8 @@
 #if (L2CAP_ERTM_STATS == TRUE)
   if ((p_ccb->local_cid >= L2CAP_BASE_APPL_CID) &&
       (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE)) {
-    uint32_t dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count;
+    uint64_t dur = bluetooth::common::time_get_os_boottime_ms() -
+                   p_ccb->fcrb.connect_tick_count;
     size_t p_str_size = 120;
     char* p_str = (char*)osi_malloc(p_str_size);
     uint16_t i;
@@ -1786,7 +1788,9 @@
        * to include extra 4 octets at the end.
        */
       p = ((uint8_t*)(p_wack + 1)) + p_wack->offset + p_wack->len;
-      UINT32_TO_STREAM(p, time_get_os_boottime_ms());
+      // Have to cast to uint32_t which wraps in 49.7 days
+      UINT32_TO_STREAM(p, static_cast<uint32_t>(
+                              bluetooth::common::time_get_os_boottime_ms()));
 #endif
       /* We will not save the FCS in case we reconfigure and change options */
       if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS) p_wack->len -= L2CAP_FCS_LEN;
@@ -2377,7 +2381,9 @@
         }
 
         STREAM_TO_UINT32(timestamp, p);
-        delay = time_get_os_boottime_ms() - timestamp;
+        delay = static_cast<uint32_t>(
+                    bluetooth::common::time_get_os_boottime_ms()) -
+                timestamp;
 
         p_ccb->fcrb.ack_delay_avg[index] += delay;
         if (delay > p_ccb->fcrb.ack_delay_max[index])
@@ -2398,7 +2404,7 @@
     p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
 
     /* calculate throughput */
-    timestamp = time_get_os_boottime_ms();
+    timestamp = bluetooth::common::time_get_os_boottime_ms();
     if (timestamp - p_ccb->fcrb.throughput_start > 0)
       p_ccb->fcrb.throughput[index] /=
           (timestamp - p_ccb->fcrb.throughput_start);
diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h
index b024637..d32c56f 100644
--- a/stack/l2cap/l2c_int.h
+++ b/stack/l2cap/l2c_int.h
@@ -212,7 +212,7 @@
   alarm_t* mon_retrans_timer; /* Timer Monitor or Retransmission */
 
 #if (L2CAP_ERTM_STATS == TRUE)
-  uint32_t connect_tick_count;  /* Time channel was established */
+  uint64_t connect_tick_count;  /* Time channel was established */
   uint32_t ertm_pkt_counts[2];  /* Packets sent and received */
   uint32_t ertm_byte_counts[2]; /* Bytes   sent and received */
   uint32_t s_frames_sent[4];    /* S-frames sent (RR, REJ, RNR, SREJ) */
diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc
index 380f5bf..3275d77 100644
--- a/stack/rfcomm/rfc_l2cap_if.cc
+++ b/stack/rfcomm/rfc_l2cap_if.cc
@@ -26,8 +26,8 @@
 #include "bt_target.h"
 
 #include "bt_common.h"
+#include "common/time_util.h"
 #include "osi/include/osi.h"
-#include "osi/include/time.h"
 
 #include "bt_utils.h"
 #include "l2c_api.h"
@@ -105,7 +105,9 @@
           "LCID(0x%x), acceptor's LCID(0x%x)",
           p_mcb->lcid, p_mcb->pending_lcid);
 
-      rfc_timer_start(p_mcb, (uint16_t)(time_get_os_boottime_ms() % 10 + 2));
+      rfc_timer_start(
+          p_mcb,
+          (uint16_t)(bluetooth::common::time_get_os_boottime_ms() % 10 + 2));
       return;
     } else {
       /* we cannot accept connection request from peer at this state */
diff --git a/stack/sdp/sdp_db.cc b/stack/sdp/sdp_db.cc
index d8cee9a..28eae10 100644
--- a/stack/sdp/sdp_db.cc
+++ b/stack/sdp/sdp_db.cc
@@ -792,34 +792,33 @@
  ******************************************************************************/
 bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id) {
 #if (SDP_SERVER_ENABLED == TRUE)
-  uint16_t xx, yy;
   tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0];
   uint8_t* pad_ptr;
   uint32_t len; /* Number of bytes in the entry */
 
   /* Find the record in the database */
-  for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) {
+  for (uint16_t xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) {
     if (p_rec->record_handle == handle) {
       tSDP_ATTRIBUTE* p_attr = &p_rec->attribute[0];
 
       SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle);
       /* Found it. Now, find the attribute */
-      for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
+      for (uint16_t yy = 0; yy < p_rec->num_attributes; yy++, p_attr++) {
         if (p_attr->id == attr_id) {
           pad_ptr = p_attr->value_ptr;
           len = p_attr->len;
 
           if (len) {
-            for (yy = 0; yy < p_rec->num_attributes; yy++) {
-              if (p_rec->attribute[yy].value_ptr > pad_ptr)
-                p_rec->attribute[yy].value_ptr -= len;
+            for (uint16_t zz = 0; zz < p_rec->num_attributes; zz++) {
+              if (p_rec->attribute[zz].value_ptr > pad_ptr)
+                p_rec->attribute[zz].value_ptr -= len;
             }
           }
 
           /* Found it. Shift everything up one */
           p_rec->num_attributes--;
 
-          for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++) {
+          for (uint16_t zz = xx; zz < p_rec->num_attributes; zz++, p_attr++) {
             *p_attr = *(p_attr + 1);
           }
 
@@ -827,7 +826,9 @@
           if (len) {
             xx =
                 (p_rec->free_pad_ptr - ((pad_ptr + len) - &p_rec->attr_pad[0]));
-            for (yy = 0; yy < xx; yy++, pad_ptr++) *pad_ptr = *(pad_ptr + len);
+            for (uint16_t zz = 0; zz < xx; zz++, pad_ptr++) {
+              *pad_ptr = *(pad_ptr + len);
+            }
             p_rec->free_pad_ptr -= len;
           }
           return (true);
diff --git a/stack/test/common/mock_btu_layer.cc b/stack/test/common/mock_btu_layer.cc
index f5bbf7a..6d7abe9 100644
--- a/stack/test/common/mock_btu_layer.cc
+++ b/stack/test/common/mock_btu_layer.cc
@@ -18,4 +18,4 @@
 
 #include <base/message_loop/message_loop.h>
 
-base::MessageLoop* get_message_loop() { return nullptr; }
\ No newline at end of file
+base::MessageLoop* get_main_message_loop() { return nullptr; }
\ No newline at end of file
diff --git a/stack/test/stack_btu_test.cc b/stack/test/stack_btu_test.cc
index d048b89..3b0c898 100644
--- a/stack/test/stack_btu_test.cc
+++ b/stack/test/stack_btu_test.cc
@@ -60,7 +60,6 @@
 TimeoutHelper helper;
 
 // External function definitions
-void btu_message_loop_run(void* context);
 void btu_task_start_up(void* context);
 void btu_task_shut_down(void* context);
 
@@ -83,7 +82,7 @@
 bool module_init(module_t const*) { return true; };
 void module_clean_up(module_t const*){};
 
-bluetooth::common::MessageLoopThread bt_workqueue_thread("test alarm thread");
+bluetooth::common::MessageLoopThread bt_startup_thread("test alarm thread");
 
 class BtuMessageLoopTest : public testing::Test {
  public:
@@ -93,7 +92,7 @@
   virtual void SetUp() {
     // Initialize alarms to prevent btu_task_shut_down from crashing
     alarm_new("test alarm");
-    bt_workqueue_thread.StartUp();
+    bt_startup_thread.StartUp();
     // btu_task_start_up calls btif_transfer_context to let the stack know
     // start up is finished
     btu_task_start_up(nullptr);
@@ -104,14 +103,14 @@
   virtual void TearDown() {
     btu_task_shut_down(nullptr);
     alarm_cleanup();
-    bt_workqueue_thread.ShutDown();
+    bt_startup_thread.ShutDown();
   }
 
   void Fail(std::string message) { FAIL() << message; }
 };
 
 TEST_F(BtuMessageLoopTest, send_message) {
-  message_loop = get_message_loop();
+  message_loop = get_main_message_loop();
   EXPECT_FALSE(message_loop == nullptr);
 
   EXPECT_CALL(*this, TestCallback()).Times(1);