Loading system/btif/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -428,6 +428,7 @@ cc_test { ":LibBluetoothSources", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestCommonCoreInterface", ":TestMockAndroidHardware", ":BtaDmSources", ":TestMockBtaAg", Loading Loading @@ -547,6 +548,7 @@ cc_test { ":LibBluetoothSources", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestCommonCoreInterface", ":TestMockAndroidHardware", ":BtaDmSources", ":TestMockBtaAg", Loading system/btif/include/core_callbacks.h +53 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,64 @@ #pragma once #include "include/hardware/bluetooth.h" #include "stack/include/btm_ble_api_types.h" #include "types/raw_address.h" namespace bluetooth { namespace core { // These callbacks are not profile specific (e.g. connection complete, bond // complete, etc) and are what go to the Java layer. struct EventCallbacks { void (*invoke_adapter_state_changed_cb)(bt_state_t state); void (*invoke_adapter_properties_cb)(bt_status_t status, int num_properties, bt_property_t* properties); void (*invoke_remote_device_properties_cb)(bt_status_t status, RawAddress bd_addr, int num_properties, bt_property_t* properties); void (*invoke_device_found_cb)(int num_properties, bt_property_t* properties); void (*invoke_discovery_state_changed_cb)(bt_discovery_state_t state); void (*invoke_pin_request_cb)(RawAddress bd_addr, bt_bdname_t bd_name, uint32_t cod, bool min_16_digit); void (*invoke_ssp_request_cb)(RawAddress bd_addr, bt_bdname_t bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key); void (*invoke_oob_data_request_cb)(tBT_TRANSPORT t, bool valid, Octet16 c, Octet16 r, RawAddress raw_address, uint8_t address_type); void (*invoke_bond_state_changed_cb)(bt_status_t status, RawAddress bd_addr, bt_bond_state_t state, int fail_reason); void (*invoke_address_consolidate_cb)(RawAddress main_bd_addr, RawAddress secondary_bd_addr); void (*invoke_le_address_associate_cb)(RawAddress main_bd_addr, RawAddress secondary_bd_addr); void (*invoke_acl_state_changed_cb)(bt_status_t status, RawAddress bd_addr, bt_acl_state_t state, int transport_link_type, bt_hci_error_code_t hci_reason, bt_conn_direction_t direction); void (*invoke_thread_evt_cb)(bt_cb_thread_evt event); void (*invoke_le_test_mode_cb)(bt_status_t status, uint16_t count); void (*invoke_energy_info_cb)(bt_activity_energy_info energy_info, bt_uid_traffic_t* uid_data); void (*invoke_link_quality_report_cb)(uint64_t timestamp, int report_id, int rssi, int snr, int retransmission_count, int packets_not_receive_count, int negative_acknowledgement_count); EventCallbacks(const EventCallbacks&) = delete; EventCallbacks& operator=(const EventCallbacks&) = delete; }; // This class defines the overall interface expected by bluetooth::core. struct CoreInterface { CoreInterface(){}; // generic interface EventCallbacks* events; CoreInterface(EventCallbacks* eventCallbacks) : events{eventCallbacks} {}; CoreInterface(const CoreInterface&) = delete; CoreInterface& operator=(const CoreInterface&) = delete; Loading system/btif/src/bluetooth.cc +18 −1 Original line number Diff line number Diff line Loading @@ -172,7 +172,24 @@ struct CoreInterfaceImpl : bluetooth::core::CoreInterface { }; static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() { static auto interfaceForCore = CoreInterfaceImpl(); static auto eventCallbacks = bluetooth::core::EventCallbacks{ .invoke_adapter_state_changed_cb = invoke_adapter_state_changed_cb, .invoke_adapter_properties_cb = invoke_adapter_properties_cb, .invoke_remote_device_properties_cb = invoke_remote_device_properties_cb, .invoke_device_found_cb = invoke_device_found_cb, .invoke_discovery_state_changed_cb = invoke_discovery_state_changed_cb, .invoke_pin_request_cb = invoke_pin_request_cb, .invoke_ssp_request_cb = invoke_ssp_request_cb, .invoke_oob_data_request_cb = invoke_oob_data_request_cb, .invoke_bond_state_changed_cb = invoke_bond_state_changed_cb, .invoke_address_consolidate_cb = invoke_address_consolidate_cb, .invoke_le_address_associate_cb = invoke_le_address_associate_cb, .invoke_acl_state_changed_cb = invoke_acl_state_changed_cb, .invoke_thread_evt_cb = invoke_thread_evt_cb, .invoke_le_test_mode_cb = invoke_le_test_mode_cb, .invoke_energy_info_cb = invoke_energy_info_cb, .invoke_link_quality_report_cb = invoke_link_quality_report_cb}; static auto interfaceForCore = CoreInterfaceImpl(&eventCallbacks); return &interfaceForCore; } Loading system/btif/src/btif_bqr.cc +3 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,9 @@ #include "btm_ble_api.h" #include "common/leaky_bonded_queue.h" #include "common/time_util.h" #include "core_callbacks.h" #include "osi/include/properties.h" #include "stack_manager.h" namespace bluetooth { namespace bqr { Loading Loading @@ -429,7 +431,7 @@ void AddLinkQualityEventToQueue(uint8_t length, p_bqr_event->ParseBqrLinkQualityEvt(length, p_link_quality_event); LOG(WARNING) << *p_bqr_event; invoke_link_quality_report_cb( GetInterfaceToProfiles()->events->invoke_link_quality_report_cb( bluetooth::common::time_get_os_boottime_ms(), p_bqr_event->bqr_link_quality_event_.quality_report_id, p_bqr_event->bqr_link_quality_event_.rssi, Loading system/btif/src/btif_core.cc +20 −12 Original line number Diff line number Diff line Loading @@ -248,7 +248,7 @@ bt_status_t btif_init_bluetooth() { LOG_INFO("%s entered", __func__); exit_manager = new base::AtExitManager(); jni_thread.StartUp(); invoke_thread_evt_cb(ASSOCIATE_JVM); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(ASSOCIATE_JVM); LOG_INFO("%s finished", __func__); return BT_STATUS_SUCCESS; } Loading Loading @@ -300,7 +300,8 @@ void btif_enable_bluetooth_evt() { prop.type = BT_PROPERTY_BDADDR; prop.val = (void*)&local_bd_addr; prop.len = sizeof(RawAddress); invoke_adapter_properties_cb(BT_STATUS_SUCCESS, 1, &prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, 1, &prop); } /* callback to HAL */ Loading Loading @@ -338,7 +339,7 @@ void btif_enable_bluetooth_evt() { bt_status_t btif_cleanup_bluetooth() { LOG_INFO("%s entered", __func__); btif_dm_cleanup(); invoke_thread_evt_cb(DISASSOCIATE_JVM); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(DISASSOCIATE_JVM); btif_queue_release(); jni_thread.ShutDown(); delete exit_manager; Loading Loading @@ -470,7 +471,8 @@ static bt_status_t btif_in_get_adapter_properties(void) { btif_storage_get_adapter_property(&properties[num_props]); num_props++; invoke_adapter_properties_cb(BT_STATUS_SUCCESS, num_props, properties); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, num_props, properties); return BT_STATUS_SUCCESS; } Loading Loading @@ -515,29 +517,33 @@ static bt_status_t btif_in_get_remote_device_properties(RawAddress* bd_addr) { &remote_properties[num_props]); num_props++; invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, *bd_addr, num_props, remote_properties); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( BT_STATUS_SUCCESS, *bd_addr, num_props, remote_properties); return BT_STATUS_SUCCESS; } static void btif_core_storage_adapter_notify_empty_success() { invoke_adapter_properties_cb(BT_STATUS_SUCCESS, 0, NULL); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, 0, NULL); } static void btif_core_storage_adapter_write(bt_property_t* prop) { BTIF_TRACE_EVENT("type: %d, len %d, 0x%x", prop->type, prop->len, prop->val); bt_status_t status = btif_storage_set_adapter_property(prop); invoke_adapter_properties_cb(status, 1, prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1, prop); } void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t* p_props) { invoke_adapter_properties_cb(status, num_props, p_props); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( status, num_props, p_props); } void btif_remote_properties_evt(bt_status_t status, RawAddress* remote_addr, uint32_t num_props, bt_property_t* p_props) { invoke_remote_device_properties_cb(status, *remote_addr, num_props, p_props); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( status, *remote_addr, num_props, p_props); } /******************************************************************************* Loading Loading @@ -670,7 +676,8 @@ void btif_get_adapter_property(bt_property_type_t type) { } else { status = btif_storage_get_adapter_property(&prop); } invoke_adapter_properties_cb(status, 1, &prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1, &prop); } bt_property_t* property_deep_copy(const bt_property_t* prop) { Loading Loading @@ -767,7 +774,8 @@ void btif_get_remote_device_property(RawAddress remote_addr, bt_status_t status = btif_storage_get_remote_device_property(&remote_addr, &prop); invoke_remote_device_properties_cb(status, remote_addr, 1, &prop); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( status, remote_addr, 1, &prop); } /******************************************************************************* Loading Loading
system/btif/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -428,6 +428,7 @@ cc_test { ":LibBluetoothSources", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestCommonCoreInterface", ":TestMockAndroidHardware", ":BtaDmSources", ":TestMockBtaAg", Loading Loading @@ -547,6 +548,7 @@ cc_test { ":LibBluetoothSources", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestCommonCoreInterface", ":TestMockAndroidHardware", ":BtaDmSources", ":TestMockBtaAg", Loading
system/btif/include/core_callbacks.h +53 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,64 @@ #pragma once #include "include/hardware/bluetooth.h" #include "stack/include/btm_ble_api_types.h" #include "types/raw_address.h" namespace bluetooth { namespace core { // These callbacks are not profile specific (e.g. connection complete, bond // complete, etc) and are what go to the Java layer. struct EventCallbacks { void (*invoke_adapter_state_changed_cb)(bt_state_t state); void (*invoke_adapter_properties_cb)(bt_status_t status, int num_properties, bt_property_t* properties); void (*invoke_remote_device_properties_cb)(bt_status_t status, RawAddress bd_addr, int num_properties, bt_property_t* properties); void (*invoke_device_found_cb)(int num_properties, bt_property_t* properties); void (*invoke_discovery_state_changed_cb)(bt_discovery_state_t state); void (*invoke_pin_request_cb)(RawAddress bd_addr, bt_bdname_t bd_name, uint32_t cod, bool min_16_digit); void (*invoke_ssp_request_cb)(RawAddress bd_addr, bt_bdname_t bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key); void (*invoke_oob_data_request_cb)(tBT_TRANSPORT t, bool valid, Octet16 c, Octet16 r, RawAddress raw_address, uint8_t address_type); void (*invoke_bond_state_changed_cb)(bt_status_t status, RawAddress bd_addr, bt_bond_state_t state, int fail_reason); void (*invoke_address_consolidate_cb)(RawAddress main_bd_addr, RawAddress secondary_bd_addr); void (*invoke_le_address_associate_cb)(RawAddress main_bd_addr, RawAddress secondary_bd_addr); void (*invoke_acl_state_changed_cb)(bt_status_t status, RawAddress bd_addr, bt_acl_state_t state, int transport_link_type, bt_hci_error_code_t hci_reason, bt_conn_direction_t direction); void (*invoke_thread_evt_cb)(bt_cb_thread_evt event); void (*invoke_le_test_mode_cb)(bt_status_t status, uint16_t count); void (*invoke_energy_info_cb)(bt_activity_energy_info energy_info, bt_uid_traffic_t* uid_data); void (*invoke_link_quality_report_cb)(uint64_t timestamp, int report_id, int rssi, int snr, int retransmission_count, int packets_not_receive_count, int negative_acknowledgement_count); EventCallbacks(const EventCallbacks&) = delete; EventCallbacks& operator=(const EventCallbacks&) = delete; }; // This class defines the overall interface expected by bluetooth::core. struct CoreInterface { CoreInterface(){}; // generic interface EventCallbacks* events; CoreInterface(EventCallbacks* eventCallbacks) : events{eventCallbacks} {}; CoreInterface(const CoreInterface&) = delete; CoreInterface& operator=(const CoreInterface&) = delete; Loading
system/btif/src/bluetooth.cc +18 −1 Original line number Diff line number Diff line Loading @@ -172,7 +172,24 @@ struct CoreInterfaceImpl : bluetooth::core::CoreInterface { }; static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() { static auto interfaceForCore = CoreInterfaceImpl(); static auto eventCallbacks = bluetooth::core::EventCallbacks{ .invoke_adapter_state_changed_cb = invoke_adapter_state_changed_cb, .invoke_adapter_properties_cb = invoke_adapter_properties_cb, .invoke_remote_device_properties_cb = invoke_remote_device_properties_cb, .invoke_device_found_cb = invoke_device_found_cb, .invoke_discovery_state_changed_cb = invoke_discovery_state_changed_cb, .invoke_pin_request_cb = invoke_pin_request_cb, .invoke_ssp_request_cb = invoke_ssp_request_cb, .invoke_oob_data_request_cb = invoke_oob_data_request_cb, .invoke_bond_state_changed_cb = invoke_bond_state_changed_cb, .invoke_address_consolidate_cb = invoke_address_consolidate_cb, .invoke_le_address_associate_cb = invoke_le_address_associate_cb, .invoke_acl_state_changed_cb = invoke_acl_state_changed_cb, .invoke_thread_evt_cb = invoke_thread_evt_cb, .invoke_le_test_mode_cb = invoke_le_test_mode_cb, .invoke_energy_info_cb = invoke_energy_info_cb, .invoke_link_quality_report_cb = invoke_link_quality_report_cb}; static auto interfaceForCore = CoreInterfaceImpl(&eventCallbacks); return &interfaceForCore; } Loading
system/btif/src/btif_bqr.cc +3 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,9 @@ #include "btm_ble_api.h" #include "common/leaky_bonded_queue.h" #include "common/time_util.h" #include "core_callbacks.h" #include "osi/include/properties.h" #include "stack_manager.h" namespace bluetooth { namespace bqr { Loading Loading @@ -429,7 +431,7 @@ void AddLinkQualityEventToQueue(uint8_t length, p_bqr_event->ParseBqrLinkQualityEvt(length, p_link_quality_event); LOG(WARNING) << *p_bqr_event; invoke_link_quality_report_cb( GetInterfaceToProfiles()->events->invoke_link_quality_report_cb( bluetooth::common::time_get_os_boottime_ms(), p_bqr_event->bqr_link_quality_event_.quality_report_id, p_bqr_event->bqr_link_quality_event_.rssi, Loading
system/btif/src/btif_core.cc +20 −12 Original line number Diff line number Diff line Loading @@ -248,7 +248,7 @@ bt_status_t btif_init_bluetooth() { LOG_INFO("%s entered", __func__); exit_manager = new base::AtExitManager(); jni_thread.StartUp(); invoke_thread_evt_cb(ASSOCIATE_JVM); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(ASSOCIATE_JVM); LOG_INFO("%s finished", __func__); return BT_STATUS_SUCCESS; } Loading Loading @@ -300,7 +300,8 @@ void btif_enable_bluetooth_evt() { prop.type = BT_PROPERTY_BDADDR; prop.val = (void*)&local_bd_addr; prop.len = sizeof(RawAddress); invoke_adapter_properties_cb(BT_STATUS_SUCCESS, 1, &prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, 1, &prop); } /* callback to HAL */ Loading Loading @@ -338,7 +339,7 @@ void btif_enable_bluetooth_evt() { bt_status_t btif_cleanup_bluetooth() { LOG_INFO("%s entered", __func__); btif_dm_cleanup(); invoke_thread_evt_cb(DISASSOCIATE_JVM); GetInterfaceToProfiles()->events->invoke_thread_evt_cb(DISASSOCIATE_JVM); btif_queue_release(); jni_thread.ShutDown(); delete exit_manager; Loading Loading @@ -470,7 +471,8 @@ static bt_status_t btif_in_get_adapter_properties(void) { btif_storage_get_adapter_property(&properties[num_props]); num_props++; invoke_adapter_properties_cb(BT_STATUS_SUCCESS, num_props, properties); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, num_props, properties); return BT_STATUS_SUCCESS; } Loading Loading @@ -515,29 +517,33 @@ static bt_status_t btif_in_get_remote_device_properties(RawAddress* bd_addr) { &remote_properties[num_props]); num_props++; invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, *bd_addr, num_props, remote_properties); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( BT_STATUS_SUCCESS, *bd_addr, num_props, remote_properties); return BT_STATUS_SUCCESS; } static void btif_core_storage_adapter_notify_empty_success() { invoke_adapter_properties_cb(BT_STATUS_SUCCESS, 0, NULL); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( BT_STATUS_SUCCESS, 0, NULL); } static void btif_core_storage_adapter_write(bt_property_t* prop) { BTIF_TRACE_EVENT("type: %d, len %d, 0x%x", prop->type, prop->len, prop->val); bt_status_t status = btif_storage_set_adapter_property(prop); invoke_adapter_properties_cb(status, 1, prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1, prop); } void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t* p_props) { invoke_adapter_properties_cb(status, num_props, p_props); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb( status, num_props, p_props); } void btif_remote_properties_evt(bt_status_t status, RawAddress* remote_addr, uint32_t num_props, bt_property_t* p_props) { invoke_remote_device_properties_cb(status, *remote_addr, num_props, p_props); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( status, *remote_addr, num_props, p_props); } /******************************************************************************* Loading Loading @@ -670,7 +676,8 @@ void btif_get_adapter_property(bt_property_type_t type) { } else { status = btif_storage_get_adapter_property(&prop); } invoke_adapter_properties_cb(status, 1, &prop); GetInterfaceToProfiles()->events->invoke_adapter_properties_cb(status, 1, &prop); } bt_property_t* property_deep_copy(const bt_property_t* prop) { Loading Loading @@ -767,7 +774,8 @@ void btif_get_remote_device_property(RawAddress remote_addr, bt_status_t status = btif_storage_get_remote_device_property(&remote_addr, &prop); invoke_remote_device_properties_cb(status, remote_addr, 1, &prop); GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb( status, remote_addr, 1, &prop); } /******************************************************************************* Loading