OSDN Git Service

Add event_value to BluetoothClassicPairingEventReported
authorJack He <siyuanh@google.com>
Wed, 20 Mar 2019 11:04:36 +0000 (04:04 -0700)
committerJack He <siyuanh@google.com>
Wed, 20 Mar 2019 11:18:17 +0000 (04:18 -0700)
* Add an event_value field to log status value such as
 - encryption enabled state
 - simple pairing mode
 - secure connection host support
 - delete all flag
* Use the event_value field to log above information during
  classic pairing process instead

Bug: 128966402
Test: make
Change-Id: I2a87c3837754bfc5bcd55f72325400c428c2ca25

common/metrics.cc
common/metrics.h
stack/btu/btu_hcif.cc

index cd58d0e..4550eeb 100644 (file)
@@ -757,9 +757,8 @@ void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd,
   }
 }
 
-void LogClassicPairingEvent(const RawAddress& address, uint16_t handle,
-                            uint32_t hci_cmd, uint16_t hci_event,
-                            uint16_t cmd_status, uint16_t reason_code) {
+void LogClassicPairingEvent(const RawAddress& address, uint16_t handle, uint32_t hci_cmd, uint16_t hci_event,
+                            uint16_t cmd_status, uint16_t reason_code, int64_t event_value) {
   std::string obfuscated_id;
   if (!address.IsEmpty()) {
     obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
@@ -768,14 +767,12 @@ void LogClassicPairingEvent(const RawAddress& address, uint16_t handle,
   android::util::BytesField obfuscated_id_field(
       address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
       address.IsEmpty() ? 0 : obfuscated_id.size());
-  int ret = android::util::stats_write(
-      android::util::BLUETOOTH_CLASSIC_PAIRING_EVENT_REPORTED,
-      obfuscated_id_field, handle, hci_cmd, hci_event, cmd_status, reason_code);
+  int ret = android::util::stats_write(android::util::BLUETOOTH_CLASSIC_PAIRING_EVENT_REPORTED, obfuscated_id_field,
+                                       handle, hci_cmd, hci_event, cmd_status, reason_code, event_value);
   if (ret < 0) {
-    LOG(WARNING) << __func__ << ": failed for " << address << ", handle "
-                 << handle << ", hci_cmd " << loghex(hci_cmd) << ", hci_event "
-                 << loghex(hci_event) << ", cmd_status " << loghex(cmd_status)
-                 << ", reason " << loghex(reason_code) << ", error " << ret;
+    LOG(WARNING) << __func__ << ": failed for " << address << ", handle " << handle << ", hci_cmd " << loghex(hci_cmd)
+                 << ", hci_event " << loghex(hci_event) << ", cmd_status " << loghex(cmd_status) << ", reason "
+                 << loghex(reason_code) << ", event_value " << event_value << ", error " << ret;
   }
 }
 
index a39fd46..8d83cac 100644 (file)
@@ -421,10 +421,10 @@ void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd,
  * @param hci_event HCI event associated with this event
  * @param cmd_status Command status associated with this event
  * @param reason_code Reason code associated with this event
+ * @param event_value A status value related to this specific event
  */
-void LogClassicPairingEvent(const RawAddress& address, uint16_t handle,
-                            uint32_t hci_cmd, uint16_t hci_event,
-                            uint16_t cmd_status, uint16_t reason_code);
+void LogClassicPairingEvent(const RawAddress& address, uint16_t handle, uint32_t hci_cmd, uint16_t hci_event,
+                            uint16_t cmd_status, uint16_t reason_code, int64_t event_value);
 
 /**
  * Logs when certain Bluetooth SDP attributes are discovered
index 8243471..d9c31b6 100644 (file)
@@ -141,6 +141,7 @@ void btu_hcif_log_event_metrics(uint8_t evt_code, uint8_t* p_event) {
   uint16_t status = android::bluetooth::hci::STATUS_UNKNOWN;
   uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
   uint16_t handle = bluetooth::common::kUnknownConnectionHandle;
+  int64_t value = 0;
 
   RawAddress bda = RawAddress::kEmpty;
   switch (evt_code) {
@@ -154,31 +155,26 @@ void btu_hcif_log_event_metrics(uint8_t evt_code, uint8_t* p_event) {
     case HCI_KEYPRESS_NOTIFY_EVT:
     case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
       STREAM_TO_BDADDR(bda, p_event);
-      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
-                                                status, reason);
+      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code, status, reason, value);
       break;
     case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
     case HCI_RMT_NAME_REQUEST_COMP_EVT:
       STREAM_TO_UINT8(status, p_event);
       STREAM_TO_BDADDR(bda, p_event);
-      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
-                                                status, reason);
+      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code, status, reason, value);
       break;
     case HCI_AUTHENTICATION_COMP_EVT:
       STREAM_TO_UINT8(status, p_event);
       STREAM_TO_UINT16(handle, p_event);
       handle = HCID_GET_HANDLE(handle);
-      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
-                                                status, reason);
+      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code, status, reason, value);
       break;
     case HCI_ENCRYPTION_CHANGE_EVT: {
       uint8_t encryption_enabled;
       STREAM_TO_UINT8(status, p_event);
       STREAM_TO_UINT16(handle, p_event);
       STREAM_TO_UINT8(encryption_enabled, p_event);
-      // Use reason field to store encryption enabled
-      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
-                                                status, encryption_enabled);
+      bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code, status, reason, encryption_enabled);
       break;
     }
     case HCI_CONNECTION_COMP_EVT: {
@@ -644,53 +640,44 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, uint8_t* p_cmd,
       break;
     }
     case HCI_READ_LOCAL_OOB_DATA:
-      bluetooth::common::LogClassicPairingEvent(
-          RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
-          opcode, hci_event, cmd_status,
-          android::bluetooth::hci::STATUS_UNKNOWN);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle, opcode,
+                                                hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, 0);
       break;
     case HCI_WRITE_SIMPLE_PAIRING_MODE: {
       uint8_t simple_pairing_mode;
       STREAM_TO_UINT8(simple_pairing_mode, p_cmd);
-      // Use reason field to log simple pairing mode
-      bluetooth::common::LogClassicPairingEvent(
-          RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
-          opcode, hci_event, cmd_status, simple_pairing_mode);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle, opcode,
+                                                hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN,
+                                                simple_pairing_mode);
       break;
     }
     case HCI_WRITE_SECURE_CONNS_SUPPORT: {
       uint8_t secure_conn_host_support;
       STREAM_TO_UINT8(secure_conn_host_support, p_cmd);
-      // Use reason field to log secure connection host support
-      bluetooth::common::LogClassicPairingEvent(
-          RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
-          opcode, hci_event, cmd_status, secure_conn_host_support);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle, opcode,
+                                                hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN,
+                                                secure_conn_host_support);
       break;
     }
     case HCI_AUTHENTICATION_REQUESTED:
       STREAM_TO_UINT16(handle, p_cmd);
-      bluetooth::common::LogClassicPairingEvent(
-          RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
-          android::bluetooth::hci::STATUS_UNKNOWN);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
+                                                android::bluetooth::hci::STATUS_UNKNOWN, 0);
       break;
     case HCI_SET_CONN_ENCRYPTION: {
       STREAM_TO_UINT16(handle, p_cmd);
       uint8_t encryption_enable;
       STREAM_TO_UINT8(encryption_enable, p_cmd);
-      // Use reason field to log encryption enable
-      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, handle,
-                                                opcode, hci_event, cmd_status,
-                                                encryption_enable);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
+                                                android::bluetooth::hci::STATUS_UNKNOWN, encryption_enable);
       break;
     }
     case HCI_DELETE_STORED_LINK_KEY: {
       uint8_t delete_all_flag;
       STREAM_TO_BDADDR(bd_addr, p_cmd);
       STREAM_TO_UINT8(delete_all_flag, p_cmd);
-      // Use reason field to log delete_all_flag
-      bluetooth::common::LogClassicPairingEvent(
-          bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
-          hci_event, cmd_status, delete_all_flag);
+      bluetooth::common::LogClassicPairingEvent(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode, hci_event,
+                                                cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, delete_all_flag);
       break;
     }
     case HCI_RMT_NAME_REQUEST:
@@ -705,16 +692,14 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, uint8_t* p_cmd,
     case HCI_REM_OOB_DATA_REQ_REPLY:
     case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
       STREAM_TO_BDADDR(bd_addr, p_cmd);
-      bluetooth::common::LogClassicPairingEvent(
-          bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
-          hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
+      bluetooth::common::LogClassicPairingEvent(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode, hci_event,
+                                                cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, 0);
       break;
     case HCI_IO_CAP_REQ_NEG_REPLY:
       STREAM_TO_BDADDR(bd_addr, p_cmd);
       STREAM_TO_UINT8(reason, p_cmd);
-      bluetooth::common::LogClassicPairingEvent(
-          bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
-          hci_event, cmd_status, reason);
+      bluetooth::common::LogClassicPairingEvent(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode, hci_event,
+                                                cmd_status, reason, 0);
       break;
   }
 }
@@ -803,9 +788,8 @@ static void btu_hcif_log_command_complete_metrics(uint16_t opcode,
     case HCI_WRITE_SIMPLE_PAIRING_MODE:
     case HCI_WRITE_SECURE_CONNS_SUPPORT:
       STREAM_TO_UINT8(status, p_return_params);
-      bluetooth::common::LogClassicPairingEvent(
-          RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
-          opcode, hci_event, status, reason);
+      bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle, opcode,
+                                                hci_event, status, reason, 0);
       break;
     case HCI_LINK_KEY_REQUEST_REPLY:
     case HCI_LINK_KEY_REQUEST_NEG_REPLY:
@@ -819,9 +803,8 @@ static void btu_hcif_log_command_complete_metrics(uint16_t opcode,
     case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
       STREAM_TO_UINT8(status, p_return_params);
       STREAM_TO_BDADDR(bd_addr, p_return_params);
-      bluetooth::common::LogClassicPairingEvent(
-          bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
-          hci_event, status, reason);
+      bluetooth::common::LogClassicPairingEvent(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode, hci_event,
+                                                status, reason, 0);
       break;
   }
 }