Android 8.1 Bluedroid init

JNI
packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp

static bool initNative(JNIEnv* env, jobject obj)

int ret = sBluetoothInterface-> init(& sBluetoothCallbacks);

sBluetoothSocketInterface =

    (btsock_interface_t*)sBluetoothInterface->get_profile_interface(

        BT_PROFILE_SOCKETS_ID);

________________________________________________________

static bt_callbacks_t sBluetoothCallbacks = {
    sizeof(sBluetoothCallbacks), adapter_state_change_callback,
    adapter_properties_callback, remote_device_properties_callback,
    device_found_callback,       discovery_state_changed_callback,
    pin_request_callback,        ssp_request_callback,
    bond_state_changed_callback, acl_state_changed_callback,
    callback_thread_event,       dut_mode_recv_callback,
    le_test_mode_recv_callback,  energy_info_recv_callback};


HAL

hardware/libhardware/include/hardware/bluetooth.h

int (*init)(bt_callbacks_t* callbacks );


BLUEDROID

/system/bt/btif/src/bluetooth.cc

static int init(bt_callbacks_t* callbacks)

if (interface_ready()) return BT_STATUS_DONE;

bt_hal_cbacks = callbacks;

stack_manager_get_interface()->init_stack();

btif_debug_init();

_______________________________________________________

static const bt_interface_t bluetoothInterface = {
    sizeof(bluetoothInterface),
    init,
    enable,
    disable,
    cleanup,
    get_adapter_properties,
    get_adapter_property,
    set_adapter_property,
    get_remote_device_properties,
    get_remote_device_property,
    set_remote_device_property,
    get_remote_service_record,
    get_remote_services,
    start_discovery,
    cancel_discovery,
    create_bond,
    create_bond_out_of_band,
    remove_bond,
    cancel_bond,
    get_connection_state,
    pin_reply,
    ssp_reply,
    get_profile_interface,
    dut_mode_configure,
    dut_mode_send,
    le_test_mode,
    set_os_callouts,
    read_energy_info,
    dump,
    config_clear,
    interop_database_clear,
    interop_database_add,
};

const bt_interface_t* bluetooth__get_bluetooth_interface() {
  return &bluetoothInterface;

}

system/bt/btif/src/stack_manager.cc

static void init_stack(void)

thread_post(management_thread, event_init_stack, semaphore);

static void event_init_stack(void* context)

    module_management_start();
    start_bt_logger();

    module_init(get_module(OSI_MODULE));
    module_init(get_module(BT_UTILS_MODULE));
    module_init(get_module(BTIF_CONFIG_MODULE));

    future_t* local_hack_future = future_new();

    hack_future = local_hack_future;  

   btif_init_bluetooth();

    future_await(local_hack_future);
    stack_is_initialized = true;

static const stack_manager_t interface = {init_stack, start_up_stack_async,
                                          shut_down_stack_async, clean_up_stack,

                                          get_stack_is_running};

_______________________________________________________

system/bt/btif/include/stack_manager.h
typedef struct {
  void (* init_stack)(void);
  void (*start_up_stack_async)(void);
  void (*shut_down_stack_async)(void);
  void (*clean_up_stack)(void);

  bool (*get_stack_is_running)(void);
} stack_manager_t;

const stack_manager_t* stack_manager_get_interface();
const stack_manager_t* stack_manager_get_interface() {
  ensure_manager_initialized();
  return &interface;

}

system/bt/btif/src/btif_core.cc

bt_status_t btif_init_bluetooth()

bte_main_boot_entry();

bt_jni_workqueue_thread = thread_new_sized(BT_JNI_WORKQUEUE_NAME, MAX_JNI_WORKQUEUE_COUNT);

thread_post(bt_jni_workqueue_thread, run_message_loop, nullptr);

system/bt/main/bte_main.cc

void bte_main_boot_entry(void)

module_init(get_module(INTEROP_MODULE));

module_init(get_module(PROFILE_CONFIG_MODULE));

hci = hci_layer_get_interface();

hci->set_data_cb(base::Bind(&post_to_hci_message_loop));

module_init(get_module(STACK_CONFIG_MODULE));

system/bt/hci/src/hci_layer.cc

const hci_t* hci_layer_get_interface()

init_layer_interface();

static void init_layer_interface()







 

猜你喜欢

转载自blog.csdn.net/kikyo_yu/article/details/79994992
8.1