Android bluetooth

在SystemServer启动的时候,会生成一个BluetoothDeviceService的实例

 

//skip bluetooth if we have an emulator kernel

//TODO:Use a more reliable check to see if this product should
// support Bluetooth
if(SystemProperties.get("ro.kernel.qemu").equals("1")){
    Log.i(TAG, "Registering null Bluetooth Service(Emulator)");
    ServiceManager.addService(Context.BLUETOOTH_SERVICE,null);
} else if(factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
    Log.i(TAG, "Registering null Bluetooth Service(factory test)");
    ServiceManager.addService(Context.BLUETOOTH_SERVICE,null);
} else {
    Log.i(TAG, "Starting Bluetooth Service");
    bluetooth = new BluetoothDeviceService(context);
    bluetooth.init();
    ServiceManager.addService(Context.BLUETOOTH_SERVICE,bluetooth);
    
    int bluetoothOn = Settings.System.getInt(mContentResolver,Settings.System.BLUETOOTH_ON, 0);
    if( bluetoothOn > 0){
        bluetooth.enable(null);
    }
}

 

BluetoothDeviceService会生成一个BluetoothEventLoop的实例,它们两者均通过DBUS来和
BlusZ通信。BluetoothDeviceService是通过DBUS向BlueZ发送命令,儿命令的返回结果则是
由BlueZ通过DBUS传回给BluetoothEventLoop的(具体交互请参加BlueZ的dbus_api.txt),
BlueZ也会通过DBUS向BluetoothEventLoop发送一些事件通知。BluetoothEventLoop和外部
的接口是通过预先定义的Intent,
初始的时候蓝牙是没有使能的,是通过BluetoothSettings或者WirelessSettings来打开蓝牙设备
,然后通过BluetoothSettings去查找附近的其他蓝牙设备,找到后可以建立RFCOMM连接和配对。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值