OSDN Git Service

Add callbacks in LE link manager
authorHansong Zhang <hsz@google.com>
Thu, 14 Jan 2021 00:29:41 +0000 (16:29 -0800)
committerHansong Zhang <hsz@google.com>
Thu, 14 Jan 2021 18:02:05 +0000 (10:02 -0800)
Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: I69ee3d6c8e5173855a07c059294cc07b4ff93e7b

gd/l2cap/le/internal/link_manager.cc

index 4603197..9ae238c 100644 (file)
@@ -105,11 +105,22 @@ void LinkManager::OnLeConnectSuccess(hci::AddressWithType connecting_address_wit
                                      std::unique_ptr<hci::acl_manager::LeAclConnection> acl_connection) {
   // Same link should not be connected twice
   hci::AddressWithType connected_address_with_type = acl_connection->GetRemoteAddress();
+  uint16_t handle = acl_connection->GetHandle();
   ASSERT_LOG(GetLink(connected_address_with_type) == nullptr, "%s is connected twice without disconnection",
              acl_connection->GetRemoteAddress().ToString().c_str());
   links_.try_emplace(connected_address_with_type, l2cap_handler_, std::move(acl_connection), parameter_provider_,
                      dynamic_channel_service_manager_, fixed_channel_service_manager_, this);
   auto* link = GetLink(connected_address_with_type);
+
+  if (link_property_callback_handler_ != nullptr) {
+    link_property_callback_handler_->CallOn(
+        link_property_listener_,
+        &LinkPropertyListener::OnLinkConnected,
+        connected_address_with_type,
+        handle,
+        link->GetRole());
+  }
+
   // Allocate and distribute channels for all registered fixed channel services
   auto fixed_channel_services = fixed_channel_service_manager_->GetRegisteredServices();
   for (auto& fixed_channel_service : fixed_channel_services) {
@@ -132,8 +143,8 @@ void LinkManager::OnLeConnectSuccess(hci::AddressWithType connecting_address_wit
 void LinkManager::OnLeConnectFail(hci::AddressWithType address_with_type, hci::ErrorCode reason) {
   // Notify all pending links for this device
   auto pending_link = pending_links_.find(address_with_type);
-  if (pending_link == pending_links_.end()) {
-    // There is no pending link, exit
+  if (pending_link == pending_links_.end() && reason != hci::ErrorCode::UNKNOWN_CONNECTION) {
+    // There is no pending link, exit; UNKNOWN_CONNECTION means we cancelled
     LOG_INFO("Connection to %s failed without a pending link", address_with_type.ToString().c_str());
     return;
   }
@@ -162,6 +173,11 @@ void LinkManager::OnDisconnect(bluetooth::hci::AddressWithType address_with_type
   ASSERT_LOG(link != nullptr, "Device %s is disconnected but not in local database",
              address_with_type.ToString().c_str());
   links_.erase(address_with_type);
+
+  if (link_property_callback_handler_ != nullptr) {
+    link_property_callback_handler_->CallOn(
+        link_property_listener_, &LinkPropertyListener::OnLinkDisconnected, address_with_type);
+  }
 }
 
 void LinkManager::RegisterLinkPropertyListener(os::Handler* handler, LinkPropertyListener* listener) {