Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1a2fc9e authored by weichinweng's avatar weichinweng Committed by Weichin Weng
Browse files

Bluetooth hal metrics: Add LogBluetoothHalCrashReason

Add LogBluetoothHalCrashReason function to collect Bluetooth hal crash
reason.

Bug: 174284338
Tag: #feature
Test: atest BluetoothInstrumentationTests
Change-Id: Ibbc465d3145068fdc7f743b67ae4278b4cdf2430
parent d9279d66
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -878,6 +878,28 @@ void LogManufacturerInfo(const RawAddress& address,
  }
}

void LogBluetoothHalCrashReason(const RawAddress& address, uint32_t error_code,
                                uint32_t vendor_error_code) {
  std::string obfuscated_id;
  int metric_id = 0;
  if (!address.IsEmpty()) {
    obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
    metric_id = MetricIdAllocator::GetInstance().AllocateId(address);
  }
  // nullptr and size 0 represent missing value for obfuscated_id
  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_HAL_CRASH_REASON_REPORTED, metric_id,
      obfuscated_id_field, error_code, vendor_error_code);
  if (ret < 0) {
    LOG(WARNING) << __func__ << ": failed for " << address << ", error_code "
                 << loghex(error_code) << ", vendor_error_code "
                 << loghex(vendor_error_code) << ", error " << ret;
  }
}

}  // namespace common

}  // namespace bluetooth
+10 −0
Original line number Diff line number Diff line
@@ -479,6 +479,16 @@ void LogManufacturerInfo(const RawAddress& address,
                         const std::string& model,
                         const std::string& hardware_version,
                         const std::string& software_version);

/**
 * Logs when received Bluetooth HAL crash reason report.
 *
 * @param address current connected address.
 * @param error_code the crash reason from bluetooth hal
 * @param vendor_error_code the vendor crash reason from bluetooth Firmware
 */
void LogBluetoothHalCrashReason(const RawAddress& address, uint32_t error_code,
                                uint32_t vendor_error_code);
}  // namespace common

}  // namespace bluetooth
+12 −3
Original line number Diff line number Diff line
@@ -187,6 +187,10 @@ void hal_service_died() {
    }
    return;
  }
  // The Bluetooth hal suddenly died and no root inflammation packet received.
  // Record it with "Default" code.
  bluetooth::common::LogBluetoothHalCrashReason(
      RawAddress::kEmpty, 0x00 /*Default*/, 0x00 /*Default*/);
  abort();
}

@@ -591,9 +595,14 @@ bool hci_is_root_inflammation_event_received() {
}

void handle_root_inflammation_event() {
  LOG(ERROR) << __func__
             << ": Root inflammation event! setting timer to restart.";
  // TODO(ugoyu) Report to bluetooth metrics here
  LOG(ERROR)
      << __func__
      << ": Root inflammation event! setting timer to restart. error_code: "
      << loghex(root_inflamed_error_code)
      << " vendor _error_code: " << loghex(root_inflamed_vendor_error_code);
  bluetooth::common::LogBluetoothHalCrashReason(
      RawAddress::kEmpty, root_inflamed_error_code,
      root_inflamed_vendor_error_code);
  {
    // Try to stop hci command and startup timers
    std::unique_lock<std::recursive_timed_mutex> lock(