前一段时间我们分析了kernel中bluetooth的初始化操作,从这一章起,晓东将会和大家一起正式进入到Android中bluetooth的分析。毫无疑问,我们依然需要知道在Android启动的时候,蓝牙究竟有做些什么。
首先我们来回顾一下Android启动的一般流程,有人把它归结为4个步骤,分别为1)init进程启动;2)Native服务启动;3)System server,Android服务启动;4)Home启动。那么,我们来一个个看在这几个步骤中,都有哪些是和蓝牙有关的。
1、init中的bluetooth
#首先是创建了两个文件夹和bluetooth相关
mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
mkdir /data/misc/bluetooth 0770 system system
#新建了一个dbus的service,dbus是用于bluez和jni层交互的
#细心的同学已经发了,他是没有disabled的,所以,会直接启动哦
#不过dbus只是一个通路而已,我们暂时并不准备去详细地分析
service dbus /system/bin/dbus-daemon --system --nofork
class main
socket dbus stream 660 bluetooth bluetooth
user bluetooth
group bluetooth net_bt_admin
#新建了bluetoothd的service,这个就是bluez了
service bluetoothd /system/bin/bluetoothd -n
class main
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root and
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled
#这里就是各个文件的权限配置了
chmod 666 /dev/ttyS0
chmod 666 /proc/bluetooth/sleep/proto
chmod 666 /sys/class/rfkill/rfkill0/state
chmod 666 /sys/class/rfkill/rfkill0/type
chown bluetooth bluetooth /sys/class/rfkill/rfkill0/state
chown bluetooth bluetooth /sys/class/rfkill/rfkill0/type
#一个hciattach的service,hciattach是bluetooth的一个工具,这里可以用来启动蓝牙
#涉及到一些vendor的信息后面就写成***了
service hciattach /system/bin/logwrapper /system/bin/hciattach -n /dev/ttyS0 ***
class main
user bluetooth
group bluetooth net_bt_admin
disabled
oneshot
</