Loading system/gd/metrics/BUILD.gn +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ source_set("BluetoothMetricsSources_chromeos") { "chromeos/metrics.cc", "chromeos/metrics_event.cc", ] deps = [ "//bt/system/gd:gd_default_deps" ] configs += [ "//bt/system/gd:gd_defaults" ] } Loading system/gd/metrics/chromeos/metrics.cc +68 −4 Original line number Diff line number Diff line Loading @@ -22,26 +22,90 @@ #include "common/time_util.h" #include "gd/metrics/chromeos/metrics_event.h" #include "gd/metrics/utils.h" #include "gd/os/log.h" namespace bluetooth { namespace metrics { void LogMetricsAdapterStateChanged(uint32_t state) { int64_t adapter_state; int64_t boot_time; std::string boot_id; if (!GetBootId(&boot_id)) return; adapter_state = (int64_t)ToAdapterState(state); boot_time = bluetooth::common::time_get_os_boottime_us(); LOG_DEBUG("AdapterStateChanged: %s, %d, %d", boot_id.c_str(), boot_time, adapter_state); ::metrics::structured::events::bluetooth::BluetoothAdapterStateChanged() .SetBootId(boot_id) .SetSystemTime(bluetooth::common::time_get_os_boottime_us()) .SetSystemTime(boot_time) .SetIsFloss(true) .SetAdapterState((int64_t)ToAdapterState(state)) .SetAdapterState(adapter_state) .Record(); } void LogMetricsBondCreateAttempt(RawAddress* addr, uint32_t device_type) {} void LogMetricsBondCreateAttempt(RawAddress* addr, uint32_t device_type) { int64_t boot_time; std::string addr_string; std::string boot_id; if (!GetBootId(&boot_id)) return; addr_string = addr->ToString(); boot_time = bluetooth::common::time_get_os_boottime_us(); LOG_DEBUG( "PairingStateChanged: %s, %d, %s, %d, %d", boot_id.c_str(), boot_time, addr_string.c_str(), device_type, PairingState::PAIR_STARTING); ::metrics::structured::events::bluetooth::BluetoothPairingStateChanged() .SetBootId(boot_id) .SetSystemTime(boot_time) .SetDeviceId(addr_string) .SetDeviceType(device_type) .SetPairingState((int64_t)PairingState::PAIR_STARTING) .Record(); } void LogMetricsBondStateChanged( RawAddress* addr, uint32_t device_type, uint32_t status, uint32_t bond_state, int32_t fail_reason) {} RawAddress* addr, uint32_t device_type, uint32_t status, uint32_t bond_state, int32_t fail_reason) { int64_t boot_time; PairingState pairing_state; std::string addr_string; std::string boot_id; if (!GetBootId(&boot_id)) return; addr_string = addr->ToString(); boot_time = bluetooth::common::time_get_os_boottime_us(); pairing_state = ToPairingState(status, bond_state, fail_reason); // Ignore the start of pairing event as its logged separated above. if (pairing_state == PairingState::PAIR_STARTING) return; LOG_DEBUG( "PairingStateChanged: %s, %d, %s, %d, %d", boot_id.c_str(), boot_time, addr_string.c_str(), device_type, pairing_state); ::metrics::structured::events::bluetooth::BluetoothPairingStateChanged() .SetBootId(boot_id) .SetSystemTime(boot_time) .SetDeviceId(addr_string) .SetDeviceType(device_type) .SetPairingState((int64_t)pairing_state) .Record(); } } // namespace metrics } // namespace bluetooth system/gd/metrics/chromeos/metrics_event.cc +168 −0 Original line number Diff line number Diff line Loading @@ -15,12 +15,180 @@ */ #include "gd/metrics/chromeos/metrics_event.h" #include "hci/hci_packets.h" namespace bluetooth { namespace metrics { // ENUM definitaion for Bluetooth Bond State in sync with topshim::btif::BtBondState enum class BtBondState { NotBonded = 0, Bonding, Bonded, }; // ENUM definitaion for Bluetooth action status in sync with topshim::btif::BtStatus enum class BtStatus { Success = 0, Fail, NotReady, NoMemory, Busy, Done, Unsupported, InvalidParam, Unhandled, AuthFailure, RemoteDeviceDown, AuthRejected, JniEnvironmentError, JniThreadAttachError, WakeLockError, // Any statuses that couldn't be cleanly converted Unknown = 0xff, }; static PairingState StatusToPairingState(uint32_t status) { switch ((BtStatus)status) { case BtStatus::Success: return PairingState::PAIR_SUCCEED; case BtStatus::Fail: return PairingState::PAIR_FAIL_FAILED; case BtStatus::NoMemory: return PairingState::PAIR_FAIL_NO_RESOURCES; case BtStatus::Busy: return PairingState::PAIR_FAIL_BUSY; case BtStatus::Unsupported: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case BtStatus::InvalidParam: return PairingState::PAIR_FAIL_INVALID_PARAMS; case BtStatus::AuthFailure: return PairingState::PAIR_FAIL_AUTH_FAILED; case BtStatus::RemoteDeviceDown: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case BtStatus::AuthRejected: return PairingState::PAIR_FAIL_AUTH_FAILED; case BtStatus::NotReady: case BtStatus::Done: case BtStatus::Unhandled: default: return PairingState::PAIR_FAIL_UNKNOWN; } } static PairingState FailReasonToPairingState(int32_t fail_reason) { switch ((hci::ErrorCode)fail_reason) { case hci::ErrorCode::SUCCESS: return PairingState::PAIR_SUCCEED; case hci::ErrorCode::UNKNOWN_HCI_COMMAND: return PairingState::PAIR_FAIL_UNKNOWN_COMMAND; case hci::ErrorCode::UNKNOWN_CONNECTION: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::HARDWARE_FAILURE: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::PAGE_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::AUTHENTICATION_FAILURE: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::PIN_OR_KEY_MISSING: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::CONNECTION_LIMIT_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_ALREADY_EXISTS: return PairingState::PAIR_FAIL_ALREADY_PAIRED; case hci::ErrorCode::COMMAND_DISALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::CONNECTION_REJECTED_LIMITED_RESOURCES: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_REJECTED_SECURITY_REASONS: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::CONNECTION_ACCEPT_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::INVALID_HCI_COMMAND_PARAMETERS: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REPEATED_ATTEMPTS: return PairingState::PAIR_FAIL_BUSY; case hci::ErrorCode::PAIRING_NOT_ALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::UNKNOWN_LMP_PDU: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::UNSPECIFIED_ERROR: return PairingState::PAIR_FAIL_UNKNOWN; case hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::TRANSACTION_RESPONSE_TIMEOUT: return PairingState::PAIR_FAIL_TIMEOUT; case hci::ErrorCode::LINK_LAYER_COLLISION: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::ENCRYPTION_MODE_NOT_ACCEPTABLE: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::ROLE_SWITCH_FAILED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::CONTROLLER_BUSY: return PairingState::PAIR_FAIL_BUSY; case hci::ErrorCode::CONNECTION_FAILED_ESTABLISHMENT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::LIMIT_REACHED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::SCO_OFFSET_REJECTED: case hci::ErrorCode::SCO_INTERVAL_REJECTED: case hci::ErrorCode::SCO_AIR_MODE_REJECTED: case hci::ErrorCode::ADVERTISING_TIMEOUT: case hci::ErrorCode::STATUS_UNKNOWN: return PairingState::PAIR_FAIL_UNKNOWN; } } AdapterState ToAdapterState(uint32_t state) { return state == 1 ? AdapterState::ON : AdapterState::OFF; } PairingState ToPairingState(uint32_t status, uint32_t bond_state, int32_t fail_reason) { PairingState pairing_state = PairingState::PAIR_FAIL_UNKNOWN; // The Bonding is a transitional state during the pairing process. Ignore it by returning the starting again. if ((BtBondState)bond_state == BtBondState::Bonding) return PairingState::PAIR_STARTING; if ((BtStatus)status == BtStatus::Success && (hci::ErrorCode)fail_reason == hci::ErrorCode::SUCCESS) { if ((BtBondState)bond_state == BtBondState::Bonded) { return PairingState::PAIR_SUCCEED; } else { return PairingState::PAIR_FAIL_CANCELLED; } } // When both status and fail reason are provided and disagree with each other, overwrite status with the fail reason // as fail reason is generated closer to the HCI and provides a more accurate description. if (status) pairing_state = StatusToPairingState(status); if (fail_reason) pairing_state = FailReasonToPairingState(status); return pairing_state; } } // namespace metrics } // namespace bluetooth No newline at end of file system/gd/metrics/chromeos/metrics_event.h +47 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,55 @@ namespace metrics { // BluetoothAdapterStateChanged/AdapterState. enum class AdapterState : int64_t { OFF = 0, ON = 1 }; // ENUM definitaion for pairing state that in sync with ChromeOS strcutured metrics // BluetoothPairingStateChanged/PairingState and BlueZ metrics_pair_result. enum class PairingState : int64_t { PAIR_STARTING = 0, PAIR_SUCCEED = 1, // The controller is not powered. PAIR_FAIL_NONPOWERED = 2, // The remote device has been paired with the local host. PAIR_FAIL_ALREADY_PAIRED = 3, // This can be invalid address type, invalid IO capability. PAIR_FAIL_INVALID_PARAMS = 4, // The pairing is in progress or being canceled. PAIR_FAIL_BUSY = 5, // Simple pairing or pairing is not supported on the remote device. PAIR_FAIL_NOT_SUPPORTED = 6, // Fail to set up connection with the remote device. PAIR_FAIL_ESTABLISH_CONN = 7, // The authentication failure can be caused by incorrect PIN/link key or // missing PIN/link key during pairing or authentication procedure. // This can also be a failure during message integrity check. PAIR_FAIL_AUTH_FAILED = 8, // The pairing request is rejected by the remote device. PAIR_FAIL_REJECTED = 9, // The pairing was cancelled. PAIR_FAIL_CANCELLED = 10, // The connection was timeout. PAIR_FAIL_TIMEOUT = 11, PAIR_FAIL_UNKNOWN = 12, // BT IO connection error PAIR_FAIL_BT_IO_CONNECT_ERROR = 13, // Unknown command. PAIR_FAIL_UNKNOWN_COMMAND = 14, // The peer was not connected. PAIR_FAIL_NOT_CONNECTED = 15, // Exceeded the limit of resource such as memory, connections. PAIR_FAIL_NO_RESOURCES = 16, // Disconnected due to power, user termination or other reasons. PAIR_FAIL_DISCONNECTED = 17, // Failed due to all the other reasons such as hardware, invalid LMP // PDU, transaction collision, role change, slot violation etc. PAIR_FAIL_FAILED = 18, PAIR_FAIL_END = 19, }; // Convert topshim::btif::BtState to AdapterState. AdapterState ToAdapterState(uint32_t state); // Convert topshim::btif::bond_state info (status, addr, bond_state, and fail_reason) to PairingState PairingState ToPairingState(uint32_t status, uint32_t bond_state, int32_t fail_reason); } // namespace metrics } // namespace bluetooth No newline at end of file Loading
system/gd/metrics/BUILD.gn +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ source_set("BluetoothMetricsSources_chromeos") { "chromeos/metrics.cc", "chromeos/metrics_event.cc", ] deps = [ "//bt/system/gd:gd_default_deps" ] configs += [ "//bt/system/gd:gd_defaults" ] } Loading
system/gd/metrics/chromeos/metrics.cc +68 −4 Original line number Diff line number Diff line Loading @@ -22,26 +22,90 @@ #include "common/time_util.h" #include "gd/metrics/chromeos/metrics_event.h" #include "gd/metrics/utils.h" #include "gd/os/log.h" namespace bluetooth { namespace metrics { void LogMetricsAdapterStateChanged(uint32_t state) { int64_t adapter_state; int64_t boot_time; std::string boot_id; if (!GetBootId(&boot_id)) return; adapter_state = (int64_t)ToAdapterState(state); boot_time = bluetooth::common::time_get_os_boottime_us(); LOG_DEBUG("AdapterStateChanged: %s, %d, %d", boot_id.c_str(), boot_time, adapter_state); ::metrics::structured::events::bluetooth::BluetoothAdapterStateChanged() .SetBootId(boot_id) .SetSystemTime(bluetooth::common::time_get_os_boottime_us()) .SetSystemTime(boot_time) .SetIsFloss(true) .SetAdapterState((int64_t)ToAdapterState(state)) .SetAdapterState(adapter_state) .Record(); } void LogMetricsBondCreateAttempt(RawAddress* addr, uint32_t device_type) {} void LogMetricsBondCreateAttempt(RawAddress* addr, uint32_t device_type) { int64_t boot_time; std::string addr_string; std::string boot_id; if (!GetBootId(&boot_id)) return; addr_string = addr->ToString(); boot_time = bluetooth::common::time_get_os_boottime_us(); LOG_DEBUG( "PairingStateChanged: %s, %d, %s, %d, %d", boot_id.c_str(), boot_time, addr_string.c_str(), device_type, PairingState::PAIR_STARTING); ::metrics::structured::events::bluetooth::BluetoothPairingStateChanged() .SetBootId(boot_id) .SetSystemTime(boot_time) .SetDeviceId(addr_string) .SetDeviceType(device_type) .SetPairingState((int64_t)PairingState::PAIR_STARTING) .Record(); } void LogMetricsBondStateChanged( RawAddress* addr, uint32_t device_type, uint32_t status, uint32_t bond_state, int32_t fail_reason) {} RawAddress* addr, uint32_t device_type, uint32_t status, uint32_t bond_state, int32_t fail_reason) { int64_t boot_time; PairingState pairing_state; std::string addr_string; std::string boot_id; if (!GetBootId(&boot_id)) return; addr_string = addr->ToString(); boot_time = bluetooth::common::time_get_os_boottime_us(); pairing_state = ToPairingState(status, bond_state, fail_reason); // Ignore the start of pairing event as its logged separated above. if (pairing_state == PairingState::PAIR_STARTING) return; LOG_DEBUG( "PairingStateChanged: %s, %d, %s, %d, %d", boot_id.c_str(), boot_time, addr_string.c_str(), device_type, pairing_state); ::metrics::structured::events::bluetooth::BluetoothPairingStateChanged() .SetBootId(boot_id) .SetSystemTime(boot_time) .SetDeviceId(addr_string) .SetDeviceType(device_type) .SetPairingState((int64_t)pairing_state) .Record(); } } // namespace metrics } // namespace bluetooth
system/gd/metrics/chromeos/metrics_event.cc +168 −0 Original line number Diff line number Diff line Loading @@ -15,12 +15,180 @@ */ #include "gd/metrics/chromeos/metrics_event.h" #include "hci/hci_packets.h" namespace bluetooth { namespace metrics { // ENUM definitaion for Bluetooth Bond State in sync with topshim::btif::BtBondState enum class BtBondState { NotBonded = 0, Bonding, Bonded, }; // ENUM definitaion for Bluetooth action status in sync with topshim::btif::BtStatus enum class BtStatus { Success = 0, Fail, NotReady, NoMemory, Busy, Done, Unsupported, InvalidParam, Unhandled, AuthFailure, RemoteDeviceDown, AuthRejected, JniEnvironmentError, JniThreadAttachError, WakeLockError, // Any statuses that couldn't be cleanly converted Unknown = 0xff, }; static PairingState StatusToPairingState(uint32_t status) { switch ((BtStatus)status) { case BtStatus::Success: return PairingState::PAIR_SUCCEED; case BtStatus::Fail: return PairingState::PAIR_FAIL_FAILED; case BtStatus::NoMemory: return PairingState::PAIR_FAIL_NO_RESOURCES; case BtStatus::Busy: return PairingState::PAIR_FAIL_BUSY; case BtStatus::Unsupported: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case BtStatus::InvalidParam: return PairingState::PAIR_FAIL_INVALID_PARAMS; case BtStatus::AuthFailure: return PairingState::PAIR_FAIL_AUTH_FAILED; case BtStatus::RemoteDeviceDown: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case BtStatus::AuthRejected: return PairingState::PAIR_FAIL_AUTH_FAILED; case BtStatus::NotReady: case BtStatus::Done: case BtStatus::Unhandled: default: return PairingState::PAIR_FAIL_UNKNOWN; } } static PairingState FailReasonToPairingState(int32_t fail_reason) { switch ((hci::ErrorCode)fail_reason) { case hci::ErrorCode::SUCCESS: return PairingState::PAIR_SUCCEED; case hci::ErrorCode::UNKNOWN_HCI_COMMAND: return PairingState::PAIR_FAIL_UNKNOWN_COMMAND; case hci::ErrorCode::UNKNOWN_CONNECTION: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::HARDWARE_FAILURE: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::PAGE_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::AUTHENTICATION_FAILURE: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::PIN_OR_KEY_MISSING: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::CONNECTION_LIMIT_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_ALREADY_EXISTS: return PairingState::PAIR_FAIL_ALREADY_PAIRED; case hci::ErrorCode::COMMAND_DISALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::CONNECTION_REJECTED_LIMITED_RESOURCES: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::CONNECTION_REJECTED_SECURITY_REASONS: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::CONNECTION_ACCEPT_TIMEOUT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::INVALID_HCI_COMMAND_PARAMETERS: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST: return PairingState::PAIR_FAIL_DISCONNECTED; case hci::ErrorCode::REPEATED_ATTEMPTS: return PairingState::PAIR_FAIL_BUSY; case hci::ErrorCode::PAIRING_NOT_ALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::UNKNOWN_LMP_PDU: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS: return PairingState::PAIR_FAIL_INVALID_PARAMS; case hci::ErrorCode::UNSPECIFIED_ERROR: return PairingState::PAIR_FAIL_UNKNOWN; case hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER: return PairingState::PAIR_FAIL_NOT_SUPPORTED; case hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::TRANSACTION_RESPONSE_TIMEOUT: return PairingState::PAIR_FAIL_TIMEOUT; case hci::ErrorCode::LINK_LAYER_COLLISION: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::ENCRYPTION_MODE_NOT_ACCEPTABLE: return PairingState::PAIR_FAIL_AUTH_FAILED; case hci::ErrorCode::ROLE_SWITCH_FAILED: return PairingState::PAIR_FAIL_FAILED; case hci::ErrorCode::CONTROLLER_BUSY: return PairingState::PAIR_FAIL_BUSY; case hci::ErrorCode::CONNECTION_FAILED_ESTABLISHMENT: return PairingState::PAIR_FAIL_ESTABLISH_CONN; case hci::ErrorCode::LIMIT_REACHED: return PairingState::PAIR_FAIL_NO_RESOURCES; case hci::ErrorCode::SCO_OFFSET_REJECTED: case hci::ErrorCode::SCO_INTERVAL_REJECTED: case hci::ErrorCode::SCO_AIR_MODE_REJECTED: case hci::ErrorCode::ADVERTISING_TIMEOUT: case hci::ErrorCode::STATUS_UNKNOWN: return PairingState::PAIR_FAIL_UNKNOWN; } } AdapterState ToAdapterState(uint32_t state) { return state == 1 ? AdapterState::ON : AdapterState::OFF; } PairingState ToPairingState(uint32_t status, uint32_t bond_state, int32_t fail_reason) { PairingState pairing_state = PairingState::PAIR_FAIL_UNKNOWN; // The Bonding is a transitional state during the pairing process. Ignore it by returning the starting again. if ((BtBondState)bond_state == BtBondState::Bonding) return PairingState::PAIR_STARTING; if ((BtStatus)status == BtStatus::Success && (hci::ErrorCode)fail_reason == hci::ErrorCode::SUCCESS) { if ((BtBondState)bond_state == BtBondState::Bonded) { return PairingState::PAIR_SUCCEED; } else { return PairingState::PAIR_FAIL_CANCELLED; } } // When both status and fail reason are provided and disagree with each other, overwrite status with the fail reason // as fail reason is generated closer to the HCI and provides a more accurate description. if (status) pairing_state = StatusToPairingState(status); if (fail_reason) pairing_state = FailReasonToPairingState(status); return pairing_state; } } // namespace metrics } // namespace bluetooth No newline at end of file
system/gd/metrics/chromeos/metrics_event.h +47 −0 Original line number Diff line number Diff line Loading @@ -24,8 +24,55 @@ namespace metrics { // BluetoothAdapterStateChanged/AdapterState. enum class AdapterState : int64_t { OFF = 0, ON = 1 }; // ENUM definitaion for pairing state that in sync with ChromeOS strcutured metrics // BluetoothPairingStateChanged/PairingState and BlueZ metrics_pair_result. enum class PairingState : int64_t { PAIR_STARTING = 0, PAIR_SUCCEED = 1, // The controller is not powered. PAIR_FAIL_NONPOWERED = 2, // The remote device has been paired with the local host. PAIR_FAIL_ALREADY_PAIRED = 3, // This can be invalid address type, invalid IO capability. PAIR_FAIL_INVALID_PARAMS = 4, // The pairing is in progress or being canceled. PAIR_FAIL_BUSY = 5, // Simple pairing or pairing is not supported on the remote device. PAIR_FAIL_NOT_SUPPORTED = 6, // Fail to set up connection with the remote device. PAIR_FAIL_ESTABLISH_CONN = 7, // The authentication failure can be caused by incorrect PIN/link key or // missing PIN/link key during pairing or authentication procedure. // This can also be a failure during message integrity check. PAIR_FAIL_AUTH_FAILED = 8, // The pairing request is rejected by the remote device. PAIR_FAIL_REJECTED = 9, // The pairing was cancelled. PAIR_FAIL_CANCELLED = 10, // The connection was timeout. PAIR_FAIL_TIMEOUT = 11, PAIR_FAIL_UNKNOWN = 12, // BT IO connection error PAIR_FAIL_BT_IO_CONNECT_ERROR = 13, // Unknown command. PAIR_FAIL_UNKNOWN_COMMAND = 14, // The peer was not connected. PAIR_FAIL_NOT_CONNECTED = 15, // Exceeded the limit of resource such as memory, connections. PAIR_FAIL_NO_RESOURCES = 16, // Disconnected due to power, user termination or other reasons. PAIR_FAIL_DISCONNECTED = 17, // Failed due to all the other reasons such as hardware, invalid LMP // PDU, transaction collision, role change, slot violation etc. PAIR_FAIL_FAILED = 18, PAIR_FAIL_END = 19, }; // Convert topshim::btif::BtState to AdapterState. AdapterState ToAdapterState(uint32_t state); // Convert topshim::btif::bond_state info (status, addr, bond_state, and fail_reason) to PairingState PairingState ToPairingState(uint32_t status, uint32_t bond_state, int32_t fail_reason); } // namespace metrics } // namespace bluetooth No newline at end of file