BluetoothSettings.java
BluetoothEnabler.java
public void onCheckedChanged(CompoundButtonbuttonView, boolean isChecked)
->mLocalAdapter.setBluetoothEnabled(isChecked);
LocalBluetoothAdapter.java
public void setBluetoothEnabled(booleanenabled)
->mAdapter.enable()
AdapterService.java
public boolean enable()
->service.enable()
->booleanenable()
->public synchronized boolean enable(booleanquietMode)
->mAdapterStateMachine.obtainMessage(AdapterState.USER_TURN_ON);
AdapterState.java
private AdapterState(AdapterService service,AdapterProperties adapterProperties)
->private class OffState extends State
->publicboolean processMessage(Message msg)
->switch(msg.what) case USER_TURN_ON:
->adapterService.processStart();
AdapterService.java
void processStart()
->setProfileServiceState(supportedProfileServices,BluetoothAdapter.STATE_ON);
->private void setProfileServiceState(Class[]services, int state)
AdapterState.java
private class PendingCommandState extendsState
->public boolean processMessage(Message msg)
->switch(msg.what) case STARTED:
->boolean ret =adapterService.enableNative();
AdapterService.java
/*package*/ native boolean enableNative();
com_android_bluetooth_btservice_AdapterService.cpp
const bt_interface_t* getBluetoothInterface(){
return sBluetoothInterface;
}
staticconst bt_interface_t *sBluetoothInterface = NULL;
static jboolean enableNative(JNIEnv* env,jobject obj)
-> sBluetoothInterface->enable();
{"enableNative","()Z", (void*) enableNative},
Bluetooth.h(hardware/libhardware/include/hardware/)
bt_interface_t struct
Bluetooth.c
const bt_interface_t*bluetooth__get_bluetooth_interface ()
{
return &bluetoothInterface;
}
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,
remove_bond,
cancel_bond,
pin_reply,
ssp_reply,
get_profile_interface,
dut_mode_configure,
dut_mode_send,
#if BLE_INCLUDED == TRUE
le_test_mode,
#else
NULL,
#endif
config_hci_snoop_log
};
static int enable( void )
->btif_enable_bluetooth()
btif_api.h
bt_status_t btif_enable_bluetooth(void);
btif_core.c
bt_status_t btif_enable_bluetooth(void)
->bte_main_enable()
bte_main.c
void bte_main_enable()
->bte_hci_enable()
->staticvoid bte_hci_enable(void)
->bt_hc_if->set_power(BT_HC_CHIP_PWR_ON)
备注:static bt_hc_interface_t*bt_hc_if=NULL;
bt_hci_lib.h
bt_hc_interface_t struct
bt_hci_bdroid.c
const bt_hc_interface_t*bt_hc_get_interface(void)
{
return &bluetoothHCLibInterface;
}
static const bt_hc_interface_tbluetoothHCLibInterface = {
sizeof(bt_hc_interface_t),
init,
set_power,
lpm,
preload,
postload,
transmit_buf,
set_rxflow,
logging,
cleanup
};
static void set_power(bt_hc_chip_power_state_tstate)
->bt_vnd_if->op(BT_VND_OP_POWER_CTRL, &pwr_state);
备注:externbt_vendor_interface_t *bt_vnd_if;
Bt_vendor_lib.h
bt_vendor_interface_t struct
Bt_vendor_brcm.c
const bt_vendor_interface_tBLUETOOTH_VENDOR_LIB_INTERFACE = {
sizeof(bt_vendor_interface_t),
init,
op,
cleanup
};
static int op(bt_vendor_opcode_t opcode, void*param)
->case BT_VND_OP_POWER_CTRL:
->upio_set_bluetooth_power(UPIO_BT_POWER_ON);
upio.h
int upio_set_bluetooth_power(int on);
upio.c
int upio_set_bluetooth_power(int on)
->/sys/class/rfkill/rfkill%d/type