Snap for 7242881 from f859dd16035e320ce10b678807f3209113376b41 to sdk-release

Change-Id: I5d7a39ad1caed1557acbd09be3e2506b3ecd7a45
diff --git a/bta/hh/bta_hh_act.cc b/bta/hh/bta_hh_act.cc
index 4a1a879..ec3e0d5 100644
--- a/bta/hh/bta_hh_act.cc
+++ b/bta/hh/bta_hh_act.cc
@@ -499,21 +499,23 @@
                    base::StringPrintf("le local initiated"));
 
   } else {
-    /* found an active connection */
     const uint8_t hid_handle =
         (p_data != nullptr) ? static_cast<uint8_t>(p_data->hdr.layer_specific)
                             : p_cb->hid_handle;
-    LOG_DEBUG("Host initiating close to classic device:%s",
-              PRIVATE_ADDRESS(p_cb->addr));
     tHID_STATUS status = HID_HostCloseDev(hid_handle);
     if (status != HID_SUCCESS) {
       LOG_WARN("Failed closing classic device:%s status:%s",
                PRIVATE_ADDRESS(p_cb->addr), hid_status_text(status).c_str());
-      tBTA_HH bta_hh = {
-          .dev_status = {.status = BTA_HH_ERR, .handle = hid_handle},
-      };
-      (*bta_hh_cb.p_cback)(BTA_HH_CLOSE_EVT, &bta_hh);
+    } else {
+      LOG_DEBUG("Host initiated close to classic device:%s",
+                PRIVATE_ADDRESS(p_cb->addr));
     }
+    tBTA_HH bta_hh = {
+        .dev_status = {.status =
+                           (status == HID_SUCCESS) ? BTA_HH_OK : BTA_HH_ERR,
+                       .handle = hid_handle},
+    };
+    (*bta_hh_cb.p_cback)(BTA_HH_CLOSE_EVT, &bta_hh);
     BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                    base::StringPrintf("classic local reason %s",
                                       hid_status_text(status).c_str()));
diff --git a/bta/include/bta_hh_api.h b/bta/include/bta_hh_api.h
index b2f63cb..2df707f 100644
--- a/bta/include/bta_hh_api.h
+++ b/bta/include/bta_hh_api.h
@@ -18,7 +18,9 @@
 #ifndef BTA_HH_API_H
 #define BTA_HH_API_H
 
+#include <base/strings/stringprintf.h>
 #include <cstdint>
+#include <string>
 
 #include "bta/include/bta_api.h"
 #include "stack/include/hiddefs.h"
@@ -220,6 +222,11 @@
 
   uint8_t flag;
   tBTA_HH_DEV_DESCR descriptor;
+
+  std::string ToString() const {
+    return base::StringPrintf("%04x::%04x::%04x", vendor_id, product_id,
+                              version);
+  }
 } tBTA_HH_DEV_DSCP_INFO;
 
 /* callback event data for BTA_HH_OPEN_EVT */
diff --git a/bta/test/common/mock_stack_acl.cc b/bta/test/common/mock_stack_acl.cc
index 450475c..b0975b1 100644
--- a/bta/test/common/mock_stack_acl.cc
+++ b/bta/test/common/mock_stack_acl.cc
@@ -66,6 +66,11 @@
   mock_function_count_map[__func__]++;
   return false;
 }
+bool BTM_IsPhy2mSupported(const RawAddress& remote_bda,
+                          tBT_TRANSPORT transport) {
+  mock_function_count_map[__func__]++;
+  return false;
+}
 bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr,
                                   RawAddress& conn_addr,
                                   tBLE_ADDR_TYPE* p_addr_type) {
@@ -211,7 +216,11 @@
   mock_function_count_map[__func__]++;
   return 0;
 }
-uint16_t btm_get_acl_disc_reason_code(void) {
+tHCI_REASON btm_get_acl_disc_reason_code(void) {
+  mock_function_count_map[__func__]++;
+  return HCI_SUCCESS;
+}
+uint8_t BTM_GetPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
   mock_function_count_map[__func__]++;
   return 0;
 }
@@ -242,6 +251,9 @@
                             tBLE_ADDR_TYPE* p_addr_type) {
   mock_function_count_map[__func__]++;
 }
+void BTM_RequestPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
+  mock_function_count_map[__func__]++;
+}
 void BTM_acl_after_controller_started(const controller_t* controller) {
   mock_function_count_map[__func__]++;
 }
diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h
index ce6e546..2f78128 100644
--- a/btif/include/btif_hh.h
+++ b/btif/include/btif_hh.h
@@ -46,7 +46,7 @@
  *  Type definitions and return values
  ******************************************************************************/
 
-typedef enum {
+typedef enum : unsigned {
   BTIF_HH_DISABLED = 0,
   BTIF_HH_ENABLED,
   BTIF_HH_DISABLING,
@@ -56,6 +56,25 @@
   BTIF_HH_DEV_DISCONNECTED
 } BTIF_HH_STATUS;
 
+#define CASE_RETURN_TEXT(code) \
+  case code:                   \
+    return #code
+
+inline std::string btif_hh_status_text(const BTIF_HH_STATUS& status) {
+  switch (status) {
+    CASE_RETURN_TEXT(BTIF_HH_DISABLED);
+    CASE_RETURN_TEXT(BTIF_HH_ENABLED);
+    CASE_RETURN_TEXT(BTIF_HH_DISABLING);
+    CASE_RETURN_TEXT(BTIF_HH_DEV_UNKNOWN);
+    CASE_RETURN_TEXT(BTIF_HH_DEV_CONNECTING);
+    CASE_RETURN_TEXT(BTIF_HH_DEV_CONNECTED);
+    CASE_RETURN_TEXT(BTIF_HH_DEV_DISCONNECTED);
+    default:
+      return std::string("UNKNOWN[%hhu]", status);
+  }
+}
+#undef CASE_RETURN_TEXT
+
 typedef struct {
   bthh_connection_state_t dev_status;
   uint8_t dev_handle;
diff --git a/btif/src/btif_dm.cc b/btif/src/btif_dm.cc
index 8fca442..365aeff 100644
--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -1542,11 +1542,16 @@
       btm_set_bond_type_dev(p_data->link_down.bd_addr,
                             tBTM_SEC_DEV_REC::BOND_TYPE_UNKNOWN);
       btif_av_acl_disconnected(bd_addr);
-      BTIF_TRACE_DEBUG(
-          "BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
       invoke_acl_state_changed_cb(BT_STATUS_SUCCESS, bd_addr,
                                   BT_ACL_STATE_DISCONNECTED,
                                   static_cast<bt_hci_error_code_t>(btm_get_acl_disc_reason_code()));
+      LOG_DEBUG(
+          "Sent BT_ACL_STATE_DISCONNECTED upward as ACL link down event "
+          "device:%s reason:%s",
+          PRIVATE_ADDRESS(bd_addr),
+          hci_reason_code_text(
+              static_cast<tHCI_REASON>(btm_get_acl_disc_reason_code()))
+              .c_str());
       break;
 
     case BTA_DM_BLE_KEY_EVT:
diff --git a/btif/src/btif_sdp_server.cc b/btif/src/btif_sdp_server.cc
index a0a5a80..08f307d 100644
--- a/btif/src/btif_sdp_server.cc
+++ b/btif/src/btif_sdp_server.cc
@@ -541,8 +541,8 @@
                              (uint8_t*)rec->hdr.service_name);
 
   /* Add in the Bluetooth Profile Descriptor List */
-  status &= SDP_AddProfileDescriptorList(sdp_handle, service,
-                                         rec->hdr.profile_version);
+  status &= SDP_AddProfileDescriptorList(
+      sdp_handle, UUID_SERVCLASS_PHONE_ACCESS, rec->hdr.profile_version);
 
   /* Make the service browseable */
   status &=
diff --git a/gd/common/Android.bp b/gd/common/Android.bp
index dde5359..ff2492a 100644
--- a/gd/common/Android.bp
+++ b/gd/common/Android.bp
@@ -8,16 +8,6 @@
 }
 
 filegroup {
-    name: "BluetoothCommonSourcesForRootCanal",
-    srcs: [
-        "init_flags.cc",
-        "metric_id_manager.cc",
-        "strings.cc",
-        "stop_watch.cc",
-    ],
-}
-
-filegroup {
     name: "BluetoothCommonSources",
     srcs: [
         "init_flags.cc",
diff --git a/gd/hci/acl_manager/classic_acl_connection.cc b/gd/hci/acl_manager/classic_acl_connection.cc
index 0d5f68a..52b24ba 100644
--- a/gd/hci/acl_manager/classic_acl_connection.cc
+++ b/gd/hci/acl_manager/classic_acl_connection.cc
@@ -275,7 +275,6 @@
 
   void on_read_remote_supported_features_status(CommandStatusView view) {
     ASSERT_LOG(view.IsValid(), "Bad status packet!");
-    LOG_INFO("UNIMPLEMENTED called: %s", hci::ErrorCodeText(view.GetStatus()).c_str());
   }
 
   void on_read_remote_extended_features_status(CommandStatusView view) {
diff --git a/gd/hci/class_of_device.cc b/gd/hci/class_of_device.cc
index fa27092..3163613 100644
--- a/gd/hci/class_of_device.cc
+++ b/gd/hci/class_of_device.cc
@@ -115,14 +115,12 @@
 }
 
 std::optional<ClassOfDevice> ClassOfDevice::FromLegacyConfigString(const std::string& str) {
-  auto num_64bit = common::Uint64FromString(str);
-  if (!num_64bit) {
+  char* ptr = nullptr;
+  auto num = std::strtoull(str.data(), &ptr, 10);
+  if (num > 0xffffff) {
     return std::nullopt;
   }
-  if (!common::IsNumberInNumericLimits<uint32_t>(*num_64bit)) {
-    return std::nullopt;
-  }
-  return FromUint32Legacy(static_cast<uint32_t>(*num_64bit));
+  return FromUint32Legacy(static_cast<uint32_t>(num));
 }
 
 uint32_t ClassOfDevice::ToUint32Legacy() const {
diff --git a/gd/hci/hci_layer.cc b/gd/hci/hci_layer.cc
index 8fea49a..a6474b1 100644
--- a/gd/hci/hci_layer.cc
+++ b/gd/hci/hci_layer.cc
@@ -49,8 +49,8 @@
   ASSERT(reset_complete.GetStatus() == ErrorCode::SUCCESS);
 }
 
-static void on_hci_timeout(OpCode op_code) {
-  ASSERT_LOG(false, "Timed out waiting for 0x%02hx (%s)", op_code, OpCodeText(op_code).c_str());
+static void abort_after_time_out(OpCode op_code) {
+  ASSERT_LOG(false, "Done waiting for debug information after HCI timeout (%s)", OpCodeText(op_code).c_str());
 }
 
 class CommandQueueEntry {
@@ -87,12 +87,14 @@
 struct HciLayer::impl {
   impl(hal::HciHal* hal, HciLayer& module) : hal_(hal), module_(module) {
     hci_timeout_alarm_ = new Alarm(module.GetHandler());
+    hci_abort_alarm_ = new Alarm(module.GetHandler());
   }
 
   ~impl() {
     incoming_acl_buffer_.Clear();
     incoming_iso_buffer_.Clear();
     delete hci_timeout_alarm_;
+    delete hci_abort_alarm_;
     command_queue_.clear();
   }
 
@@ -167,6 +169,21 @@
     send_next_command();
   }
 
+  void on_hci_timeout(OpCode op_code) {
+    LOG_ERROR("Timed out waiting for 0x%02hx (%s)", op_code, OpCodeText(op_code).c_str());
+
+    LOG_ERROR("Flushing %zd waiting commands", command_queue_.size());
+    // Clear any waiting commands (there is an abort coming anyway)
+    command_queue_.clear();
+    command_credits_ = 1;
+    waiting_command_ = OpCode::NONE;
+    enqueue_command(
+        ControllerDebugInfoBuilder::Create(), module_.GetHandler()->BindOnce(&fail_if_reset_complete_not_success));
+    // Don't time out for this one;
+    hci_timeout_alarm_->Cancel();
+    hci_abort_alarm_->Schedule(BindOnce(&abort_after_time_out, op_code), kHciTimeoutRestartMs);
+  }
+
   void send_next_command() {
     if (command_credits_ == 0) {
       return;
@@ -187,7 +204,7 @@
     OpCode op_code = cmd_view.GetOpCode();
     waiting_command_ = op_code;
     command_credits_ = 0;  // Only allow one outstanding command
-    hci_timeout_alarm_->Schedule(BindOnce(&on_hci_timeout, op_code), kHciTimeoutMs);
+    hci_timeout_alarm_->Schedule(BindOnce(&impl::on_hci_timeout, common::Unretained(this), op_code), kHciTimeoutMs);
   }
 
   void register_event(EventCode event, ContextualCallback<void(EventView)> handler) {
@@ -291,6 +308,7 @@
   OpCode waiting_command_{OpCode::NONE};
   uint8_t command_credits_{1};  // Send reset first
   Alarm* hci_timeout_alarm_{nullptr};
+  Alarm* hci_abort_alarm_{nullptr};
 
   // Acl packets
   BidiQueue<AclView, AclBuilder> acl_queue_{3 /* TODO: Set queue depth */};
diff --git a/gd/hci/hci_layer.h b/gd/hci/hci_layer.h
index 4db0c19..895bb6c 100644
--- a/gd/hci/hci_layer.h
+++ b/gd/hci/hci_layer.h
@@ -100,6 +100,7 @@
   }
 
   static constexpr std::chrono::milliseconds kHciTimeoutMs = std::chrono::milliseconds(2000);
+  static constexpr std::chrono::milliseconds kHciTimeoutRestartMs = std::chrono::milliseconds(5000);
 
   static const ModuleFactory Factory;
 
diff --git a/gd/hci/hci_layer_test.cc b/gd/hci/hci_layer_test.cc
index 7ea31e4..83db622 100644
--- a/gd/hci/hci_layer_test.cc
+++ b/gd/hci/hci_layer_test.cc
@@ -545,6 +545,26 @@
   ASSERT_NE(event_status, std::future_status::ready);
 }
 
+TEST_F(HciTest, hciTimeOut) {
+  auto event_future = upper->GetReceivedEventFuture();
+  auto reset_command_future = hal->GetSentCommandFuture();
+  upper->SendHciCommandExpectingComplete(ResetBuilder::Create());
+  auto reset_command_sent_status = reset_command_future.wait_for(kTimeout);
+  ASSERT_EQ(reset_command_sent_status, std::future_status::ready);
+  auto reset = hal->GetSentCommand();
+  ASSERT_TRUE(reset.IsValid());
+  ASSERT_EQ(reset.GetOpCode(), OpCode::RESET);
+
+  auto debug_command_future = hal->GetSentCommandFuture();
+  auto event_status = event_future.wait_for(HciLayer::kHciTimeoutMs);
+  ASSERT_NE(event_status, std::future_status::ready);
+  auto debug_command_sent_status = debug_command_future.wait_for(kTimeout);
+  ASSERT_EQ(debug_command_sent_status, std::future_status::ready);
+  auto debug = hal->GetSentCommand();
+  ASSERT_TRUE(debug.IsValid());
+  ASSERT_EQ(debug.GetOpCode(), OpCode::CONTROLLER_DEBUG_INFO);
+}
+
 TEST_F(HciTest, noOpCredits) {
   ASSERT_EQ(0, hal->GetNumSentCommands());
 
diff --git a/gd/hci/hci_packets.pdl b/gd/hci/hci_packets.pdl
index 3a59fd1..b4653d6 100644
--- a/gd/hci/hci_packets.pdl
+++ b/gd/hci/hci_packets.pdl
@@ -4772,11 +4772,10 @@
 }
 
 packet ControllerDebugInfo : VendorCommand (op_code = CONTROLLER_DEBUG_INFO) {
-  _payload_,  // placeholder (unimplemented)
 }
 
 packet ControllerDebugInfoComplete : CommandComplete (command_op_code = CONTROLLER_DEBUG_INFO) {
-  _payload_,  // placeholder (unimplemented)
+  status : ErrorCode,
 }
 
 packet ControllerA2DPOpcode : VendorCommand (op_code = CONTROLLER_A2DP_OPCODE) {
diff --git a/gd/rust/common/Android.bp b/gd/rust/common/Android.bp
index b0d9873..d5b30f6 100644
--- a/gd/rust/common/Android.bp
+++ b/gd/rust/common/Android.bp
@@ -26,7 +26,7 @@
             rustlibs: [
                 "libandroid_logger",
             ],
-            static_libs: ["libbt_common_sys_prop_cxx"],
+            whole_static_libs: ["libbt_common_sys_prop_cxx"],
             shared_libs: [
                 "libcutils",
             ],
@@ -79,5 +79,4 @@
     shared_libs: [
         "libcutils",
     ],
-    whole_static_libs: ["libcxxbridge05"],
 }
diff --git a/gd/rust/hal/Android.bp b/gd/rust/hal/Android.bp
index 7f916ef..571a8bd 100644
--- a/gd/rust/hal/Android.bp
+++ b/gd/rust/hal/Android.bp
@@ -36,7 +36,7 @@
     ],
     target: {
         android: {
-            static_libs: ["libbt_hidl_hal_cxx"],
+            whole_static_libs: ["libbt_hidl_hal_cxx"],
             shared_libs: [
                 "android.hardware.bluetooth@1.0",
                 "android.hardware.bluetooth@1.1",
diff --git a/gd/rust/shim/Android.bp b/gd/rust/shim/Android.bp
index 4cd5905..9887a61 100644
--- a/gd/rust/shim/Android.bp
+++ b/gd/rust/shim/Android.bp
@@ -48,7 +48,7 @@
     proc_macros: [
         "libpaste",
     ],
-    static_libs: [
+    whole_static_libs: [
         "libbt_callbacks_cxx",
     ],
 }
diff --git a/main/shim/acl.cc b/main/shim/acl.cc
index af2b069..dd27f3c 100644
--- a/main/shim/acl.cc
+++ b/main/shim/acl.cc
@@ -306,7 +306,7 @@
 
   void Shutdown() {
     Disconnect();
-    LOG_INFO("Shutdown ACL connection handle:0x%04x", handle_);
+    LOG_INFO("Shutdown and disconnect ACL connection handle:0x%04x", handle_);
   }
 
  protected:
@@ -703,6 +703,27 @@
     promise.set_value();
   }
 
+  void FinalShutdown(std::promise<void> promise) {
+    if (!handle_to_classic_connection_map_.empty()) {
+      for (auto& connection : handle_to_classic_connection_map_) {
+        connection.second->Shutdown();
+      }
+      handle_to_classic_connection_map_.clear();
+      LOG_INFO("Cleared all classic connections count:%zu",
+               handle_to_classic_connection_map_.size());
+    }
+
+    if (!handle_to_le_connection_map_.empty()) {
+      for (auto& connection : handle_to_le_connection_map_) {
+        connection.second->Shutdown();
+      }
+      handle_to_le_connection_map_.clear();
+      LOG_INFO("Cleared all le connections count:%zu",
+               handle_to_le_connection_map_.size());
+    }
+    promise.set_value();
+  }
+
   void HoldMode(HciHandle handle, uint16_t max_interval,
                 uint16_t min_interval) {
     ASSERT_LOG(IsClassicAcl(handle), "handle %d is not a classic connection",
@@ -1329,6 +1350,26 @@
   }
 }
 
+void shim::legacy::Acl::FinalShutdown() {
+  std::promise<void> promise;
+  auto future = promise.get_future();
+  GetAclManager()->UnregisterCallbacks(this, std::move(promise));
+  future.wait();
+  LOG_DEBUG("Unregistered classic callbacks from gd acl manager");
+
+  promise = std::promise<void>();
+  future = promise.get_future();
+  GetAclManager()->UnregisterLeCallbacks(this, std::move(promise));
+  future.wait();
+  LOG_DEBUG("Unregistered le callbacks from gd acl manager");
+
+  promise = std::promise<void>();
+  future = promise.get_future();
+  handler_->CallOn(pimpl_.get(), &Acl::impl::FinalShutdown, std::move(promise));
+  future.wait();
+  LOG_INFO("Unregistered and cleared any orphaned ACL connections");
+}
+
 void shim::legacy::Acl::ClearAcceptList() {
   handler_->CallOn(pimpl_.get(), &Acl::impl::clear_acceptlist);
 }
diff --git a/main/shim/acl.h b/main/shim/acl.h
index ea822fa..2a2db86 100644
--- a/main/shim/acl.h
+++ b/main/shim/acl.h
@@ -90,6 +90,7 @@
   void DumpConnectionHistory(int fd) const;
 
   void Shutdown();
+  void FinalShutdown();
 
   void ClearAcceptList();
 
diff --git a/main/shim/stack.cc b/main/shim/stack.cc
index 6b9e9ca..9337a67 100644
--- a/main/shim/stack.cc
+++ b/main/shim/stack.cc
@@ -193,8 +193,13 @@
   if (!common::init_flags::gd_core_is_enabled()) {
     bluetooth::shim::hci_on_shutting_down();
   }
-  delete acl_;
-  acl_ = nullptr;
+
+  // Make sure gd acl flag is enabled and we started it up
+  if (common::init_flags::gd_acl_is_enabled() && acl_ != nullptr) {
+    acl_->FinalShutdown();
+    delete acl_;
+    acl_ = nullptr;
+  }
 
   ASSERT_LOG(is_running_, "%s Gd stack not running", __func__);
   is_running_ = false;
diff --git a/main/test/common/mock_stack_acl.cc b/main/test/common/mock_stack_acl.cc
index c9061f2..4f02cfb 100644
--- a/main/test/common/mock_stack_acl.cc
+++ b/main/test/common/mock_stack_acl.cc
@@ -210,9 +210,9 @@
   mock_function_count_map[__func__]++;
   return 0;
 }
-uint16_t btm_get_acl_disc_reason_code(void) {
+tHCI_REASON btm_get_acl_disc_reason_code(void) {
   mock_function_count_map[__func__]++;
-  return 0;
+  return HCI_SUCCESS;
 }
 uint8_t BTM_SetTraceLevel(uint8_t new_level) {
   mock_function_count_map[__func__]++;
diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc
index 92ec9cc..b690840 100644
--- a/stack/acl/btm_acl.cc
+++ b/stack/acl/btm_acl.cc
@@ -1206,7 +1206,7 @@
  * Returns          true if connection is up, else false.
  *
  ******************************************************************************/
-uint16_t btm_get_acl_disc_reason_code(void) {
+tHCI_REASON btm_get_acl_disc_reason_code(void) {
   return btm_cb.acl_cb_.get_disconnect_reason();
 }
 
@@ -1238,6 +1238,73 @@
 
 /*******************************************************************************
  *
+ * Function         BTM_IsPhy2mSupported
+ *
+ * Description      This function is called to check PHY 2M support
+ *                  from peer device
+ * Returns          True when PHY 2M supported false otherwise
+ *
+ ******************************************************************************/
+bool BTM_IsPhy2mSupported(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
+  tACL_CONN* p;
+  BTM_TRACE_DEBUG("BTM_IsPhy2mSupported");
+  p = internal_.btm_bda_to_acl(remote_bda, transport);
+  if (p == (tACL_CONN*)NULL) {
+    BTM_TRACE_DEBUG("BTM_IsPhy2mSupported: no connection");
+    return false;
+  }
+
+  if (!p->peer_le_features_valid) {
+    LOG_WARN(
+        "Checking remote features but remote feature read is "
+        "incomplete");
+  }
+  return HCI_LE_2M_PHY_SUPPORTED(p->peer_le_features);
+}
+
+/*******************************************************************************
+ *
+ * Function         BTM_RequestPeerSCA
+ *
+ * Description      This function is called to request sleep clock accuracy
+ *                  from peer device
+ *
+ ******************************************************************************/
+void BTM_RequestPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
+  tACL_CONN* p;
+  p = internal_.btm_bda_to_acl(remote_bda, transport);
+  if (p == (tACL_CONN*)NULL) {
+    LOG_WARN("Unable to find active acl");
+    return;
+  }
+
+  btsnd_hcic_req_peer_sca(p->hci_handle);
+}
+
+/*******************************************************************************
+ *
+ * Function         BTM_GetPeerSCA
+ *
+ * Description      This function is called to get peer sleep clock accuracy
+ *
+ * Returns          SCA or 0xFF if SCA was never previously requested, request
+ *                  is not supported by peer device or ACL does not exist
+ *
+ ******************************************************************************/
+uint8_t BTM_GetPeerSCA(const RawAddress& remote_bda, tBT_TRANSPORT transport) {
+  tACL_CONN* p;
+  p = internal_.btm_bda_to_acl(remote_bda, transport);
+  if (p != (tACL_CONN*)NULL) {
+    return (p->sca);
+  }
+  LOG_WARN("Unable to find active acl");
+
+  /* If here, no BD Addr found */
+  return (0xFF);
+}
+
+/*******************************************************************************
+ *
  * Function         btm_rejectlist_role_change_device
  *
  * Description      This function is used to rejectlist the device if the role
diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc
index bf33d6d..cd7671b 100644
--- a/stack/btm/btm_sec.cc
+++ b/stack/btm/btm_sec.cc
@@ -1489,8 +1489,8 @@
   /* we will process one after another */
   if ((p_dev_rec->p_callback) ||
       (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE)) {
-    BTM_TRACE_EVENT("security_flags:x%x, sec_flags:x%x", security_required,
-                    p_dev_rec->sec_flags);
+    LOG_DEBUG("security_flags:x%x, sec_flags:x%x", security_required,
+              p_dev_rec->sec_flags);
     rc = BTM_CMD_STARTED;
     if ((btm_cb.security_mode == BTM_SEC_MODE_SERVICE) ||
         (BTM_SM4_KNOWN == p_dev_rec->sm4) ||
diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc
index 3d56bba..31a30a4 100644
--- a/stack/hid/hidh_conn.cc
+++ b/stack/hid/hidh_conn.cc
@@ -452,7 +452,7 @@
 static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
   uint8_t dhandle;
   tHID_CONN* p_hcon = NULL;
-  uint16_t disc_res = HCI_SUCCESS;
+  tHCI_REASON disc_res = HCI_SUCCESS;
   uint16_t hid_close_evt_reason;
 
   /* Find CCB based on CID */
diff --git a/stack/include/acl_api.h b/stack/include/acl_api.h
index 5c1bdc2..b4829d8 100644
--- a/stack/include/acl_api.h
+++ b/stack/include/acl_api.h
@@ -298,7 +298,7 @@
 
 uint8_t btm_handle_to_acl_index(uint16_t hci_handle);
 
-uint16_t btm_get_acl_disc_reason_code(void);
+tHCI_REASON btm_get_acl_disc_reason_code(void);
 
 extern tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr,
                                   tBT_TRANSPORT transport);
diff --git a/stack/include/btm_api.h b/stack/include/btm_api.h
index 83f1305..008f870 100644
--- a/stack/include/btm_api.h
+++ b/stack/include/btm_api.h
@@ -752,6 +752,41 @@
 
 /*******************************************************************************
  *
+ * Function         BTM_IsPhy2mSupported
+ *
+ * Description      This function is called to check PHY 2M support
+ *                  from peer device
+ * Returns          True when PHY 2M supported false otherwise
+ *
+ ******************************************************************************/
+bool BTM_IsPhy2mSupported(const RawAddress& remote_bda, tBT_TRANSPORT transport);
+
+/*******************************************************************************
+ *
+ * Function         BTM_RequestPeerSCA
+ *
+ * Description      This function is called to request sleep clock accuracy
+ *                  from peer device
+ *
+ ******************************************************************************/
+extern void BTM_RequestPeerSCA(const RawAddress& remote_bda,
+                               tBT_TRANSPORT transport);
+
+/*******************************************************************************
+ *
+ * Function         BTM_GetPeerSCA
+ *
+ * Description      This function is called to get peer sleep clock accuracy
+ *
+ * Returns          SCA or 0xFF if SCA was never previously requested, request
+ *                  is not supported by peer device or ACL does not exist
+ *
+ ******************************************************************************/
+extern uint8_t BTM_GetPeerSCA(const RawAddress& remote_bda,
+                              tBT_TRANSPORT transport);
+
+/*******************************************************************************
+ *
  * Function         BTM_DeleteStoredLinkKey
  *
  * Description      This function is called to delete link key for the specified
diff --git a/vendor_libs/test_vendor_lib/Android.bp b/vendor_libs/test_vendor_lib/Android.bp
index d57a822..160dca8 100644
--- a/vendor_libs/test_vendor_lib/Android.bp
+++ b/vendor_libs/test_vendor_lib/Android.bp
@@ -50,7 +50,6 @@
         "model/setup/test_model.cc",
         ":BluetoothPacketSources",
         ":BluetoothHciClassSources",
-        ":BluetoothCommonSourcesForRootCanal",
     ],
     cflags: [
         "-fvisibility=hidden",