You are on page 1of 25

AndroidBluetoothIntroduction

ErinYueh 2009/06/26

Agenda

AndroidBluetootharchitecture Relatedsourcecode InitBluetooth ConnectwithotherBTdevices(dbus) RFCOMM OBEX(socket)

Androidarchitecture

The diagram above offers a library-oriented view of the Bluetooth stack.

Relatedsourcecode

Bluez3.36(userspaceandkernel)
/mydroid/externel/bluez /mydroid/kernel/drivers/bluetooth /mydroid/kernel/net/bluetooth

Androidappframework(java&c++)
/mydroid/frameworks/base/core/jni/android_bluetooth_*.cpp /mydroid/frameworks/base/core/java/android/bluetooth/*.java /mydroid/frameworks/base/services/java/com/android/server/(SystemServer)

AndroidUIapplication
/mydroid/packages/apps/Phone/src/com/android/phone/(PhoneApp) /mydroid/packages/apps/Settings/src/com/android/settings/bluetooth/(SettingsApp)

InitBluetooth

/root/init.rc mkdir/data/misc/hcid(storedeviceinfo) servicedbus/system/bin/dbusdaemon servicehcid/system/bin/hcid(disabled) servicehfag/system/bin/sdptooladdchannel=10HFAG(handsfree,disabled,oneshot) servicehsag/system/bin/sdptooladdchannel=11HSAG(headset,disabled,oneshot)

/root/init.trout.rc servicehciattach(disabled)

systemserver deciceBTpowerOnorOfffromsettingsvalue startrelatedservices

ddms:dalvikdebugmonitorI.

ddms:dalvikdebugmonitorII.

Bluetoothheadset

Musicplayer+Dialer

ConnectwithotherBTdevices

Bluez: hcid daemon dbus-daemon: connections between hcid and system server D-Bus is a simple inter-process communication (IPC) system for software applications to communicate with one another. dbus-daemon is the D-Bus message bus daemon. D-Bus is first a library that provides one-to-one communication between any two applications; dbus-daemon is an application that uses this library to implement a message bus daemon. Multiple programs connect to the message bus daemon and can exchange messages with one another. debug utility: d-feet, dbus-monitor, dbus-send

BlueZDBusArchitecture

DFeet:DBusvieweranddebugger

Dbussend:sendamessagetoamessage bus

ScannearbyBTdevicesinAndroid

Bluezutility:hcitoolscan DiscoverDevices:bluez/util/hcid/dbusapi.txt Thismethodstartsthedevicediscoveryprocedure.Thisincludesaninquiry procedureandremotedevicenameresolving.Onstartupthisprocesswill generateaDiscoveryStartedsignalandthenreturnDeviceFoundsingals.Ifthe procedurehasbeenfinishedanDiscoveryCompletedsignalwillbesent.

Sourcecode:android_server_BluetoothDeviceService.cpp /*Composethecommand*/ msg=dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC,nat>adapter, DBUS_CLASS_NAME,"DiscoverDevices"); /*Sendthecommand.*/ reply=dbus_connection_send_with_reply_and_block(nat>conn,msg,1,&err);

Signals

HowtopairwithaBTdevice?I.Register PasskeyAgent

II.RequestPINcode

RFCOMM(RadioFrequency Communication)

TheBluetoothprotocolRFCOMMisasimplesetof transportprotocols. RFCOMMissometimescalledSerialPortEmulation. TheBluetoothSerialPortProfileisbasedonthisprotocol. Intheprotocolstack,RFCOMMisboundtoL2CAP RFCOMMprovidesasimplereliabledatastreamtothe user,similartoTCP.Itisuseddirectlybymanytelephony relatedprofilesasacarrierforATcommands

SendATcommandsviabluetooth

ConnectwithNokiaN73phone >sdptoolbrowse00:18:C5:42:18:78 >sudorfcommconnect000:18:C5:42:18:782 minicom >AT >AT+CGMR >AT+CGMI

OBEX(ObjectEXchange)

acommunications protocolthat facilitatesthe exchangeofbinary objectsbetween devices. intheprotocolstack, OBEXisboundto RFCOMM

SOCKET

UNIXsocket (AF_BLUETOOTH) interprocess communication likeInternetsocket clientserver


recv() send()

ReceivefilesviaBTinAndroid

openobex+obexpushd RunanOBEXdataserverinAndroid >obexpushd listenRFCOMMconnections Filepermission

SendfilesviaBTinAndroid

Openobex+obexftp ConnecttoaRFCOMMconnection >obex_testbBTADDRCHANNEL >obexftpbBTADDRBCHANNELlist

ThankYou!

You might also like