OSDN Git Service

hci: Cancel timer before running callbacks
authorMyles Watson <mylesgw@google.com>
Thu, 23 Mar 2017 18:49:13 +0000 (11:49 -0700)
committerMyles Watson <mylesgw@google.com>
Thu, 23 Mar 2017 23:35:33 +0000 (23:35 +0000)
Bug: 36507488
Test: Turn Bluetooth on/off, scan for devices
Change-Id: Ia9334d83b2191504acdab50f777b6d10073226e0

hci/src/hci_layer.cc

index 9ac3b70..f898980 100644 (file)
@@ -440,10 +440,13 @@ static bool filter_incoming_event(BT_HDR* packet) {
                  "0x%04x).",
                  __func__, opcode);
       }
-    } else if (wait_entry->complete_callback) {
-      wait_entry->complete_callback(packet, wait_entry->context);
-    } else if (wait_entry->complete_future) {
-      future_ready(wait_entry->complete_future, packet);
+    } else {
+      update_command_response_timer();
+      if (wait_entry->complete_callback) {
+        wait_entry->complete_callback(packet, wait_entry->context);
+      } else if (wait_entry->complete_future) {
+        future_ready(wait_entry->complete_future, packet);
+      }
     }
 
     goto intercepted;
@@ -457,14 +460,17 @@ static bool filter_incoming_event(BT_HDR* packet) {
     // command complete event
 
     wait_entry = get_waiting_command(opcode);
-    if (!wait_entry)
+    if (!wait_entry) {
       LOG_WARN(
           LOG_TAG,
           "%s command status event with no matching command. opcode: 0x%04x",
           __func__, opcode);
-    else if (wait_entry->status_callback)
-      wait_entry->status_callback(status, wait_entry->command,
-                                  wait_entry->context);
+    } else {
+      update_command_response_timer();
+      if (wait_entry->status_callback)
+        wait_entry->status_callback(status, wait_entry->command,
+                                    wait_entry->context);
+    }
 
     goto intercepted;
   }
@@ -472,8 +478,6 @@ static bool filter_incoming_event(BT_HDR* packet) {
   return false;
 
 intercepted:
-  update_command_response_timer();
-
   if (wait_entry) {
     // If it has a callback, it's responsible for freeing the packet
     if (event_code == HCI_COMMAND_STATUS_EVT ||