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

Commit 472cf804 authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge "system/gd/os: Migrate to libbluetooth_log" into main am: 85ebd101 am: d68d9136

parents 36601721 d68d9136
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ cc_library {
        "com.android.btservices",
        "com.android.btservices",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libbase",
        "libcutils",
        "libcutils",
        "liblog",
        "liblog",
    ],
    ],
+108 −93
Original line number Original line Diff line number Diff line
@@ -20,17 +20,35 @@


#include "os/metrics.h"
#include "os/metrics.h"


#include <bluetooth/log.h>
#include <statslog_bt.h>
#include <statslog_bt.h>


#include "common/audit_log.h"
#include "common/audit_log.h"
#include "metrics/metrics_state.h"
#include "common/metric_id_manager.h"
#include "common/metric_id_manager.h"
#include "common/strings.h"
#include "common/strings.h"
#include "hci/hci_packets.h"
#include "hci/hci_packets.h"
#include "metrics/metrics_state.h"
#include "os/log.h"
#include "os/log.h"


namespace bluetooth {
namespace fmt {
template <>
struct formatter<android::bluetooth::DirectionEnum>
    : enum_formatter<android::bluetooth::DirectionEnum> {};
template <>
struct formatter<android::bluetooth::SocketConnectionstateEnum>
    : enum_formatter<android::bluetooth::SocketConnectionstateEnum> {};
template <>
struct formatter<android::bluetooth::SocketRoleEnum>
    : enum_formatter<android::bluetooth::SocketRoleEnum> {};
template <>
struct formatter<android::bluetooth::DeviceInfoSrcEnum>
    : enum_formatter<android::bluetooth::DeviceInfoSrcEnum> {};
template <>
struct formatter<android::bluetooth::AddressTypeEnum>
    : enum_formatter<android::bluetooth::AddressTypeEnum> {};
}  // namespace fmt


namespace bluetooth {
namespace os {
namespace os {


using bluetooth::common::MetricIdManager;
using bluetooth::common::MetricIdManager;
@@ -70,17 +88,17 @@ void LogMetricLinkLayerConnectionEvent(
      reason_code,
      reason_code,
      metric_id);
      metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed to log status %s , reason %s, from cmd %s, event %s,  ble_event %s, for %s, handle %d, type %s, "
        "Failed to log status {} , reason {}, from cmd {}, event {},  ble_event {}, for {}, handle "
        "error %d",
        "{}, type {}, error {}",
        common::ToHexString(cmd_status).c_str(),
        common::ToHexString(cmd_status),
        common::ToHexString(reason_code).c_str(),
        common::ToHexString(reason_code),
        common::ToHexString(hci_cmd).c_str(),
        common::ToHexString(hci_cmd),
        common::ToHexString(hci_event).c_str(),
        common::ToHexString(hci_event),
        common::ToHexString(hci_ble_event).c_str(),
        common::ToHexString(hci_ble_event),
        address ? ADDRESS_TO_LOGGABLE_CSTR(*address) : "(NULL)",
        address ? ADDRESS_TO_LOGGABLE_CSTR(*address) : "(NULL)",
        connection_handle,
        connection_handle,
        common::ToHexString(link_type).c_str(),
        common::ToHexString(link_type),
        ret);
        ret);
  }
  }
}
}
@@ -88,7 +106,7 @@ void LogMetricLinkLayerConnectionEvent(
void LogMetricHciTimeoutEvent(uint32_t hci_cmd) {
void LogMetricHciTimeoutEvent(uint32_t hci_cmd) {
  int ret = stats_write(BLUETOOTH_HCI_TIMEOUT_REPORTED, static_cast<int64_t>(hci_cmd));
  int ret = stats_write(BLUETOOTH_HCI_TIMEOUT_REPORTED, static_cast<int64_t>(hci_cmd));
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN("Failed for opcode %s, error %d", common::ToHexString(hci_cmd).c_str(), ret);
    log::warn("Failed for opcode {}, error {}", common::ToHexString(hci_cmd), ret);
  }
  }
}
}


@@ -96,13 +114,14 @@ void LogMetricRemoteVersionInfo(
    uint16_t handle, uint8_t status, uint8_t version, uint16_t manufacturer_name, uint16_t subversion) {
    uint16_t handle, uint8_t status, uint8_t version, uint16_t manufacturer_name, uint16_t subversion) {
  int ret = stats_write(BLUETOOTH_REMOTE_VERSION_INFO_REPORTED, handle, status, version, manufacturer_name, subversion);
  int ret = stats_write(BLUETOOTH_REMOTE_VERSION_INFO_REPORTED, handle, status, version, manufacturer_name, subversion);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for handle %d, status %s, version %s, manufacturer_name %s, subversion %s, error %d",
        "Failed for handle {}, status {}, version {}, manufacturer_name {}, subversion {}, error "
        "{}",
        handle,
        handle,
        common::ToHexString(status).c_str(),
        common::ToHexString(status),
        common::ToHexString(version).c_str(),
        common::ToHexString(version),
        common::ToHexString(manufacturer_name).c_str(),
        common::ToHexString(manufacturer_name),
        common::ToHexString(subversion).c_str(),
        common::ToHexString(subversion),
        ret);
        ret);
  }
  }
}
}
@@ -117,10 +136,10 @@ void LogMetricA2dpAudioUnderrunEvent(
  int ret = stats_write(
  int ret = stats_write(
      BLUETOOTH_A2DP_AUDIO_UNDERRUN_REPORTED, byteField, encoding_interval_nanos, num_missing_pcm_bytes, metric_id);
      BLUETOOTH_A2DP_AUDIO_UNDERRUN_REPORTED, byteField, encoding_interval_nanos, num_missing_pcm_bytes, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, encoding_interval_nanos %s, num_missing_pcm_bytes %d, error %d",
        "Failed for {}, encoding_interval_nanos {}, num_missing_pcm_bytes {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        std::to_string(encoding_interval_nanos).c_str(),
        std::to_string(encoding_interval_nanos),
        num_missing_pcm_bytes,
        num_missing_pcm_bytes,
        ret);
        ret);
  }
  }
@@ -147,11 +166,11 @@ void LogMetricA2dpAudioOverrunEvent(
      num_dropped_encoded_bytes,
      num_dropped_encoded_bytes,
      metric_id);
      metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed to log for %s, encoding_interval_nanos %s, num_dropped_buffers %d, "
        "Failed to log for {}, encoding_interval_nanos {}, num_dropped_buffers {}, "
        "num_dropped_encoded_frames %d, num_dropped_encoded_bytes %d, error %d",
        "num_dropped_encoded_frames {}, num_dropped_encoded_bytes {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        std::to_string(encoding_interval_nanos).c_str(),
        std::to_string(encoding_interval_nanos),
        num_dropped_buffers,
        num_dropped_buffers,
        num_dropped_encoded_frames,
        num_dropped_encoded_frames,
        num_dropped_encoded_bytes,
        num_dropped_encoded_bytes,
@@ -167,8 +186,8 @@ void LogMetricA2dpPlaybackEvent(const Address& address, int playback_state, int


  int ret = stats_write(BLUETOOTH_A2DP_PLAYBACK_STATE_CHANGED, byteField, playback_state, audio_coding_mode, metric_id);
  int ret = stats_write(BLUETOOTH_A2DP_PLAYBACK_STATE_CHANGED, byteField, playback_state, audio_coding_mode, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed to log for %s, playback_state %d, audio_coding_mode %d,error %d",
        "Failed to log for {}, playback_state {}, audio_coding_mode {},error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        playback_state,
        playback_state,
        audio_coding_mode,
        audio_coding_mode,
@@ -203,11 +222,11 @@ void LogMetricReadRssiResult(const Address& address, uint16_t handle, uint32_t c
  }
  }
  int ret = stats_write(BLUETOOTH_DEVICE_RSSI_REPORTED, byteField, handle, cmd_status, rssi, metric_id);
  int ret = stats_write(BLUETOOTH_DEVICE_RSSI_REPORTED, byteField, handle, cmd_status, rssi, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, handle %d, status %s, rssi %d dBm, error %d",
        "Failed for {}, handle {}, status {}, rssi {} dBm, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        handle,
        handle,
        common::ToHexString(cmd_status).c_str(),
        common::ToHexString(cmd_status),
        rssi,
        rssi,
        ret);
        ret);
  }
  }
@@ -227,11 +246,11 @@ void LogMetricReadFailedContactCounterResult(
      failed_contact_counter,
      failed_contact_counter,
      metric_id);
      metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, handle %d, status %s, failed_contact_counter %d packets, error %d",
        "Failed for {}, handle {}, status {}, failed_contact_counter {} packets, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        handle,
        handle,
        common::ToHexString(cmd_status).c_str(),
        common::ToHexString(cmd_status),
        failed_contact_counter,
        failed_contact_counter,
        ret);
        ret);
  }
  }
@@ -246,11 +265,11 @@ void LogMetricReadTxPowerLevelResult(
  int ret = stats_write(
  int ret = stats_write(
      BLUETOOTH_DEVICE_TX_POWER_LEVEL_REPORTED, byteField, handle, cmd_status, transmit_power_level, metric_id);
      BLUETOOTH_DEVICE_TX_POWER_LEVEL_REPORTED, byteField, handle, cmd_status, transmit_power_level, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, handle %d, status %s, transmit_power_level %d packets, error %d",
        "Failed for {}, handle {}, status {}, transmit_power_level {} packets, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        handle,
        handle,
        common::ToHexString(cmd_status).c_str(),
        common::ToHexString(cmd_status),
        transmit_power_level,
        transmit_power_level,
        ret);
        ret);
  }
  }
@@ -265,12 +284,12 @@ void LogMetricSmpPairingEvent(
  int ret =
  int ret =
      stats_write(BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, byteField, smp_cmd, direction, smp_fail_reason, metric_id);
      stats_write(BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, byteField, smp_cmd, direction, smp_fail_reason, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, smp_cmd %s, direction %d, smp_fail_reason %s, error %d",
        "Failed for {}, smp_cmd {}, direction {}, smp_fail_reason {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        common::ToHexString(smp_cmd).c_str(),
        common::ToHexString(smp_cmd),
        direction,
        direction,
        common::ToHexString(smp_fail_reason).c_str(),
        common::ToHexString(smp_fail_reason),
        ret);
        ret);
  }
  }
}
}
@@ -298,16 +317,16 @@ void LogMetricClassicPairingEvent(
      event_value,
      event_value,
      metric_id);
      metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, handle %d, hci_cmd %s, hci_event %s, cmd_status %s, "
        "Failed for {}, handle {}, hci_cmd {}, hci_event {}, cmd_status {}, reason {}, event_value "
        "reason %s, event_value %s, error %d",
        "{}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        handle,
        handle,
        common::ToHexString(hci_cmd).c_str(),
        common::ToHexString(hci_cmd),
        common::ToHexString(hci_event).c_str(),
        common::ToHexString(hci_event),
        common::ToHexString(cmd_status).c_str(),
        common::ToHexString(cmd_status),
        common::ToHexString(reason_code).c_str(),
        common::ToHexString(reason_code),
        std::to_string(event_value).c_str(),
        std::to_string(event_value),
        ret);
        ret);
  }
  }


@@ -330,11 +349,11 @@ void LogMetricSdpAttribute(
  int ret =
  int ret =
      stats_write(BLUETOOTH_SDP_ATTRIBUTE_REPORTED, byteField, protocol_uuid, attribute_id, attribute_field, metric_id);
      stats_write(BLUETOOTH_SDP_ATTRIBUTE_REPORTED, byteField, protocol_uuid, attribute_id, attribute_field, metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, protocol_uuid %s, attribute_id %s, error %d",
        "Failed for {}, protocol_uuid {}, attribute_id {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        common::ToHexString(protocol_uuid).c_str(),
        common::ToHexString(protocol_uuid),
        common::ToHexString(attribute_id).c_str(),
        common::ToHexString(attribute_id),
        ret);
        ret);
  }
  }
}
}
@@ -366,15 +385,15 @@ void LogMetricSocketConnectionState(
      socket_role,
      socket_role,
      metric_id);
      metric_id);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, port %d, type %d, state %d, tx_bytes %s, rx_bytes %s, uid %d, server_port %d, "
        "Failed for {}, port {}, type {}, state {}, tx_bytes {}, rx_bytes {}, uid {}, server_port "
        "socket_role %d, error %d",
        "{}, socket_role {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        port,
        port,
        type,
        type,
        connection_state,
        connection_state,
        std::to_string(tx_bytes).c_str(),
        std::to_string(tx_bytes),
        std::to_string(rx_bytes).c_str(),
        std::to_string(rx_bytes),
        uid,
        uid,
        server_port,
        server_port,
        socket_role,
        socket_role,
@@ -410,17 +429,17 @@ void LogMetricManufacturerInfo(
      address.address[4],
      address.address[4],
      address.address[3]);
      address.address[3]);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, source_type %d, source_name %s, manufacturer %s, model %s, "
        "Failed for {}, source_type {}, source_name {}, manufacturer {}, model {}, "
        "hardware_version %s, "
        "hardware_version {}, software_version {}, MAC address type {} MAC address prefix {} {} "
        "software_version %s, MAC address type %d MAC address prefix %d %d %d, error %d",
        "{}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        source_type,
        source_type,
        source_name.c_str(),
        source_name,
        manufacturer.c_str(),
        manufacturer,
        model.c_str(),
        model,
        hardware_version.c_str(),
        hardware_version,
        software_version.c_str(),
        software_version,
        address_type,
        address_type,
        address.address[5],
        address.address[5],
        address.address[4],
        address.address[4],
@@ -436,11 +455,11 @@ void LogMetricBluetoothHalCrashReason(
  int ret =
  int ret =
      stats_write(BLUETOOTH_HAL_CRASH_REASON_REPORTED, 0 /* metric_id */, byteField, error_code, vendor_error_code);
      stats_write(BLUETOOTH_HAL_CRASH_REASON_REPORTED, 0 /* metric_id */, byteField, error_code, vendor_error_code);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for %s, error_code %s, vendor_error_code %s, error %d",
        "Failed for {}, error_code {}, vendor_error_code {}, error {}",
        ADDRESS_TO_LOGGABLE_CSTR(address),
        ADDRESS_TO_LOGGABLE_CSTR(address),
        common::ToHexString(error_code).c_str(),
        common::ToHexString(error_code),
        common::ToHexString(vendor_error_code).c_str(),
        common::ToHexString(vendor_error_code),
        ret);
        ret);
  }
  }
}
}
@@ -449,11 +468,10 @@ void LogMetricBluetoothLocalSupportedFeatures(uint32_t page_num, uint64_t featur
  int ret = stats_write(
  int ret = stats_write(
      BLUETOOTH_LOCAL_SUPPORTED_FEATURES_REPORTED, page_num, static_cast<int64_t>(features));
      BLUETOOTH_LOCAL_SUPPORTED_FEATURES_REPORTED, page_num, static_cast<int64_t>(features));
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for LogMetricBluetoothLocalSupportedFeatures, "
        "Failed for LogMetricBluetoothLocalSupportedFeatures, page_num {}, features {}, error {}",
        "page_num %d, features %s, error %d",
        page_num,
        page_num,
        std::to_string(features).c_str(),
        std::to_string(features),
        ret);
        ret);
  }
  }
}
}
@@ -472,9 +490,9 @@ void LogMetricBluetoothLocalVersions(
      static_cast<int32_t>(hci_version),
      static_cast<int32_t>(hci_version),
      static_cast<int32_t>(hci_revision));
      static_cast<int32_t>(hci_revision));
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for LogMetricBluetoothLocalVersions, "
        "Failed for LogMetricBluetoothLocalVersions, lmp_manufacturer_name {}, lmp_version {}, "
        "lmp_manufacturer_name %d, lmp_version %hhu, lmp_subversion %d, hci_version %hhu, hci_revision %d, error %d",
        "lmp_subversion {}, hci_version {}, hci_revision {}, error {}",
        lmp_manufacturer_name,
        lmp_manufacturer_name,
        lmp_version,
        lmp_version,
        lmp_subversion,
        lmp_subversion,
@@ -492,9 +510,9 @@ void LogMetricBluetoothDisconnectionReasonReported(
  }
  }
  int ret = stats_write(BLUETOOTH_DISCONNECTION_REASON_REPORTED, reason, metric_id, connection_handle);
  int ret = stats_write(BLUETOOTH_DISCONNECTION_REASON_REPORTED, reason, metric_id, connection_handle);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for LogMetricBluetoothDisconnectionReasonReported, "
        "Failed for LogMetricBluetoothDisconnectionReasonReported, reason {}, metric_id {}, "
        "reason %d, metric_id %d, connection_handle %d, error %d",
        "connection_handle {}, error {}",
        reason,
        reason,
        metric_id,
        metric_id,
        connection_handle,
        connection_handle,
@@ -515,12 +533,12 @@ void LogMetricBluetoothRemoteSupportedFeatures(
      static_cast<int64_t>(features),
      static_cast<int64_t>(features),
      connection_handle);
      connection_handle);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed for LogMetricBluetoothRemoteSupportedFeatures, "
        "Failed for LogMetricBluetoothRemoteSupportedFeatures, metric_id {}, page {}, features {}, "
        "metric_id %d, page %d, features %s, connection_handle %d, error %d",
        "connection_handle {}, error {}",
        metric_id,
        metric_id,
        page,
        page,
        std::to_string(features).c_str(),
        std::to_string(features),
        connection_handle,
        connection_handle,
        ret);
        ret);
  }
  }
@@ -529,9 +547,7 @@ void LogMetricBluetoothRemoteSupportedFeatures(
void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {
void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {
  int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
  int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn("Failed counter metrics for {}, count {}, error {}", key, std::to_string(count), ret);
        "Failed counter metrics for %d, count %s, error %d",
        key, std::to_string(count).c_str(), ret);
  }
  }
}
}


@@ -564,15 +580,14 @@ void LogMetricBluetoothLEConnection(os::LEConnectionSessionOptions session_optio
      session_options.is_cancelled);
      session_options.is_cancelled);


  if (ret < 0) {
  if (ret < 0) {
    LOG_WARN(
    log::warn(
        "Failed BluetoothLeSessionConnected - Address: %s, ACL Connection State: %s, Origin Type:  "
        "Failed BluetoothLeSessionConnected - Address: {}, ACL Connection State: {}, Origin Type:  "
        "%s",
        "{}",
        ADDRESS_TO_LOGGABLE_CSTR(session_options.remote_address),
        ADDRESS_TO_LOGGABLE_CSTR(session_options.remote_address),
        common::ToHexString(session_options.acl_connection_state).c_str(),
        common::ToHexString(session_options.acl_connection_state),
        common::ToHexString(session_options.origin_type).c_str());
        common::ToHexString(session_options.origin_type));
  }
  }
}
}


}  // namespace os
}  // namespace os
}  // namespace bluetooth
}  // namespace bluetooth
+18 −11
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


#include "os/system_properties.h"
#include "os/system_properties.h"


#include <bluetooth/log.h>
#include <cutils/properties.h>
#include <cutils/properties.h>


#include <array>
#include <array>
@@ -38,12 +39,15 @@ std::optional<std::string> GetSystemProperty(const std::string& property) {


bool SetSystemProperty(const std::string& property, const std::string& value) {
bool SetSystemProperty(const std::string& property, const std::string& value) {
  if (value.size() >= PROPERTY_VALUE_MAX) {
  if (value.size() >= PROPERTY_VALUE_MAX) {
    LOG_ERROR("Property value's maximum size is %d, but %zu chars were given", PROPERTY_VALUE_MAX - 1, value.size());
    log::error(
        "Property value's maximum size is {}, but {} chars were given",
        PROPERTY_VALUE_MAX - 1,
        value.size());
    return false;
    return false;
  }
  }
  auto ret = property_set(property.c_str(), value.c_str());
  auto ret = property_set(property.c_str(), value.c_str());
  if (ret != 0) {
  if (ret != 0) {
    LOG_ERROR("Set property %s failed with error code %d", property.c_str(), ret);
    log::error("Set property {} failed with error code {}", property, ret);
    return false;
    return false;
  }
  }
  return true;
  return true;
@@ -52,14 +56,14 @@ bool SetSystemProperty(const std::string& property, const std::string& value) {
bool IsRootCanalEnabled() {
bool IsRootCanalEnabled() {
  auto value = GetSystemProperty("ro.vendor.build.fingerprint");
  auto value = GetSystemProperty("ro.vendor.build.fingerprint");
  if (value.has_value()) {
  if (value.has_value()) {
    LOG_INFO("ro.vendor.build.fingerprint='%s', length=%zu", value->c_str(), value->length());
    log::info("ro.vendor.build.fingerprint='{}', length={}", value->c_str(), value->length());
  } else {
  } else {
    LOG_INFO("ro.vendor.build.fingerprint is not found");
    log::info("ro.vendor.build.fingerprint is not found");
  }
  }
  // aosp_cf_x86_64_phone is just one platform that currently runs root canal
  // aosp_cf_x86_64_phone is just one platform that currently runs root canal
  // When other platforms appears, or there is a better signal, add them here
  // When other platforms appears, or there is a better signal, add them here
  if (value->find("generic/aosp_cf_x86_64_phone") == std::string::npos) {
  if (value->find("generic/aosp_cf_x86_64_phone") == std::string::npos) {
    LOG_INFO("Not on generic/aosp_cf_x86_64_phone and hence not root canal");
    log::info("Not on generic/aosp_cf_x86_64_phone and hence not root canal");
    return false;
    return false;
  }
  }
  return true;
  return true;
@@ -68,21 +72,24 @@ bool IsRootCanalEnabled() {
int GetAndroidVendorReleaseVersion() {
int GetAndroidVendorReleaseVersion() {
  auto value = GetSystemProperty("ro.vendor.build.version.release_or_codename");
  auto value = GetSystemProperty("ro.vendor.build.version.release_or_codename");
  if (!value) {
  if (!value) {
    LOG_INFO("ro.vendor.build.version.release_or_codename does not exist");
    log::info("ro.vendor.build.version.release_or_codename does not exist");
    return 0;
    return 0;
  }
  }
  LOG_INFO("ro.vendor.build.version.release_or_codename='%s', length=%zu", value->c_str(), value->length());
  log::info(
      "ro.vendor.build.version.release_or_codename='{}', length={}",
      value->c_str(),
      value->length());
  auto int_value = common::Int64FromString(*value);
  auto int_value = common::Int64FromString(*value);
  if (int_value) {
  if (int_value) {
    return static_cast<int>(*int_value);
    return static_cast<int>(*int_value);
  }
  }
  LOG_INFO("value '%s' cannot be parsed to int", value->c_str());
  log::info("value '{}' cannot be parsed to int", value->c_str());
  if (value->empty()) {
  if (value->empty()) {
    LOG_INFO("value '%s' is empty", value->c_str());
    log::info("value '{}' is empty", value->c_str());
    return 0;
    return 0;
  }
  }
  if (value->length() > 1) {
  if (value->length() > 1) {
    LOG_INFO("value '%s' length is %zu, which is > 1", value->c_str(), value->length());
    log::info("value '{}' length is {}, which is > 1", value->c_str(), value->length());
  }
  }
  char release_code = toupper(value->at(0));
  char release_code = toupper(value->at(0));
  switch (release_code) {
  switch (release_code) {
+10 −9
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <aidl/android/system/suspend/IWakeLock.h>
#include <aidl/android/system/suspend/IWakeLock.h>
#include <android/binder_ibinder.h>
#include <android/binder_ibinder.h>
#include <android/binder_manager.h>
#include <android/binder_manager.h>
#include <bluetooth/log.h>
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>


@@ -66,7 +67,7 @@ struct WakelockNative::Impl {
  Impl() : suspend_death_recipient(AIBinder_DeathRecipient_new(onSuspendDeath)) {}
  Impl() : suspend_death_recipient(AIBinder_DeathRecipient_new(onSuspendDeath)) {}


  std::function<void(void)> onDeath = [this] {
  std::function<void(void)> onDeath = [this] {
    LOG_ERROR("ISystemSuspend HAL service died!");
    log::error("ISystemSuspend HAL service died!");
    this->suspend_service = nullptr;
    this->suspend_service = nullptr;
  };
  };


@@ -76,7 +77,7 @@ struct WakelockNative::Impl {
};
};


void WakelockNative::Initialize() {
void WakelockNative::Initialize() {
  LOG_INFO("Initializing native wake locks");
  log::info("Initializing native wake locks");
  const std::string suspendInstance = std::string() + ISystemSuspend::descriptor + "/default";
  const std::string suspendInstance = std::string() + ISystemSuspend::descriptor + "/default";
  pimpl_->suspend_service = ISystemSuspend::fromBinder(
  pimpl_->suspend_service = ISystemSuspend::fromBinder(
      ndk::SpAIBinder(AServiceManager_waitForService(suspendInstance.c_str())));
      ndk::SpAIBinder(AServiceManager_waitForService(suspendInstance.c_str())));
@@ -89,19 +90,19 @@ void WakelockNative::Initialize() {


WakelockNative::StatusCode WakelockNative::Acquire(const std::string& lock_name) {
WakelockNative::StatusCode WakelockNative::Acquire(const std::string& lock_name) {
  if (!pimpl_->suspend_service) {
  if (!pimpl_->suspend_service) {
    LOG_ERROR("lock not acquired, ISystemService is not available");
    log::error("lock not acquired, ISystemService is not available");
    return StatusCode::NATIVE_SERVICE_NOT_AVAILABLE;
    return StatusCode::NATIVE_SERVICE_NOT_AVAILABLE;
  }
  }


  if (pimpl_->current_wakelock) {
  if (pimpl_->current_wakelock) {
    LOG_INFO("wakelock is already acquired");
    log::info("wakelock is already acquired");
    return StatusCode::SUCCESS;
    return StatusCode::SUCCESS;
  }
  }


  auto status = pimpl_->suspend_service->acquireWakeLock(
  auto status = pimpl_->suspend_service->acquireWakeLock(
      WakeLockType::PARTIAL, lock_name, &pimpl_->current_wakelock);
      WakeLockType::PARTIAL, lock_name, &pimpl_->current_wakelock);
  if (!pimpl_->current_wakelock) {
  if (!pimpl_->current_wakelock) {
    LOG_ERROR("wake lock not acquired: %s", status.getDescription().c_str());
    log::error("wake lock not acquired: {}", status.getDescription());
    return StatusCode::NATIVE_API_ERROR;
    return StatusCode::NATIVE_API_ERROR;
  }
  }


@@ -110,7 +111,7 @@ WakelockNative::StatusCode WakelockNative::Acquire(const std::string& lock_name)


WakelockNative::StatusCode WakelockNative::Release(const std::string& /* lock_name */) {
WakelockNative::StatusCode WakelockNative::Release(const std::string& /* lock_name */) {
  if (!pimpl_->current_wakelock) {
  if (!pimpl_->current_wakelock) {
    LOG_WARN("no lock is currently acquired");
    log::warn("no lock is currently acquired");
    return StatusCode::SUCCESS;
    return StatusCode::SUCCESS;
  }
  }
  pimpl_->current_wakelock->release();
  pimpl_->current_wakelock->release();
@@ -119,14 +120,14 @@ WakelockNative::StatusCode WakelockNative::Release(const std::string& /* lock_na
}
}


void WakelockNative::CleanUp() {
void WakelockNative::CleanUp() {
  LOG_INFO("Cleaning up native wake locks");
  log::info("Cleaning up native wake locks");
  if (pimpl_->current_wakelock) {
  if (pimpl_->current_wakelock) {
    LOG_INFO("releasing current wakelock during clean up");
    log::info("releasing current wakelock during clean up");
    pimpl_->current_wakelock->release();
    pimpl_->current_wakelock->release();
    pimpl_->current_wakelock = nullptr;
    pimpl_->current_wakelock = nullptr;
  }
  }
  if (pimpl_->suspend_service) {
  if (pimpl_->suspend_service) {
    LOG_INFO("Unlink death recipient");
    log::info("Unlink death recipient");
    AIBinder_unlinkToDeath(
    AIBinder_unlinkToDeath(
        pimpl_->suspend_service->asBinder().get(),
        pimpl_->suspend_service->asBinder().get(),
        pimpl_->suspend_death_recipient.get(),
        pimpl_->suspend_death_recipient.get(),
+16 −15
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@


#include "os/metrics.h"
#include "os/metrics.h"


#include <bluetooth/log.h>
#include <metrics/structured_events.h>
#include <metrics/structured_events.h>


#include "metrics/utils.h"
#include "metrics/utils.h"
@@ -66,10 +67,10 @@ void LogMetricA2dpAudioOverrunEvent(


  addr_string = address.ToString();
  addr_string = address.ToString();


  LOG_DEBUG(
  log::debug(
      "A2dpAudioOverrun: %s, %s, %llu, %d, %d, %d",
      "A2dpAudioOverrun: {}, {}, {}, {}, {}, {}",
      boot_id.c_str(),
      boot_id,
      addr_string.c_str(),
      addr_string,
      (long long unsigned)encoding_interval_millis,
      (long long unsigned)encoding_interval_millis,
      num_dropped_buffers,
      num_dropped_buffers,
      num_dropped_encoded_bytes,
      num_dropped_encoded_bytes,
@@ -94,10 +95,10 @@ void LogMetricHfpPacketLossStats(


  addr_string = address.ToString();
  addr_string = address.ToString();


  LOG_DEBUG(
  log::debug(
      "HfpPacketLoss: %s, %s, %d, %f, %u",
      "HfpPacketLoss: {}, {}, {}, {:f}, {}",
      boot_id.c_str(),
      boot_id,
      addr_string.c_str(),
      addr_string,
      num_decoded_frames,
      num_decoded_frames,
      packet_loss_ratio,
      packet_loss_ratio,
      codec_type);
      codec_type);
@@ -117,9 +118,9 @@ void LogMetricMmcTranscodeRttStats(


  if (!metrics::GetBootId(&boot_id)) return;
  if (!metrics::GetBootId(&boot_id)) return;


  LOG_DEBUG(
  log::debug(
      "MmcTranscodeRttStats: %s, %d, %f, %d, %d",
      "MmcTranscodeRttStats: {}, {}, {:f}, {}, {}",
      boot_id.c_str(),
      boot_id,
      maximum_rtt,
      maximum_rtt,
      mean_rtt,
      mean_rtt,
      num_requests,
      num_requests,
@@ -207,10 +208,10 @@ void LogMetricA2dpSessionMetricsEvent(


  addr_string = address.ToString();
  addr_string = address.ToString();


  LOG_DEBUG(
  log::debug(
      "A2dpSessionMetrics: %s, %s, %lld, %d, %d, %d, %d, %d, %d, %f, %d, %lld, %d",
      "A2dpSessionMetrics: {}, {}, {}, {}, {}, {}, {}, {}, {}, {:f}, {}, {}, {}",
      boot_id.c_str(),
      boot_id,
      addr_string.c_str(),
      addr_string,
      (long long int)audio_duration_ms,
      (long long int)audio_duration_ms,
      media_timer_min_ms,
      media_timer_min_ms,
      media_timer_max_ms,
      media_timer_max_ms,
Loading