蓝牙BLE连接设备报错onClientConnectionState() - status=133解决方法

S905平台,Android 5.1.1,WIFI+蓝牙芯片AP6255,客户某蓝牙设备使用他们专用的APK连接不上,查logcat信息如下:

D/BluetoothAdapter( 5097): stopLeScan()
D/BluetoothAdapter( 5097): scan not started yet
D/BluetoothLeService( 5097): Trying to use an existing mBluetoothGatt for connection.
D/BtGatt.GattService( 5132): clientConnect() - address=00:0C:BF:18:AC:07, isDirect=false
D/btif_config( 5132): btif_get_address_type: Device [00:0c:bf:18:ac:07] address type 0
D/btif_config( 5132): btif_get_device_type: Device [00:0c:bf:18:ac:07] type 3
E/bt-att  ( 5132): Unsupported transport for background connection
E/bt-btif ( 5132): bta_gattc_init_bk_conn failed
D/BtGatt.GattService( 5132): onConnected() - clientIf=5, connId=65535, address=00:0C:BF:18:AC:07
D/BluetoothGatt( 5097): onClientConnectionState() - status=133 clientIf=5 device=00:0C:BF:18:AC:07
I/BluetoothLeService( 5097): 您的手机无法连接该设备...

网上的解决是在APK里面做一些close操作释放资源再重新连接设备,所以先让他们尝试修改APK发现无果。

后来分析了一下蓝牙Bluedroid协议栈,找到报错的位置:

BOOLEAN GATT_Connect (tGATT_IF gatt_if, BD_ADDR bd_addr, BOOLEAN is_direct, tBT_TRANSPORT transport)
{
    tGATT_REG    *p_reg;
    BOOLEAN status = FALSE;

    GATT_TRACE_API ("GATT_Connect gatt_if=%d", gatt_if);

    /* Make sure app is registered */
    if ((p_reg = gatt_get_regcb(gatt_if)) == NULL)
    {
        GATT_TRACE_ERROR("GATT_Connect - gatt_if =%d is not registered", gatt_if);
        return(FALSE);
    }

    if (is_direct)
        status = gatt_act_connect (p_reg, bd_addr, transport);
    else
    {
        if (transport == BT_TRANSPORT_LE)
        status = gatt_update_auto_connect_dev(gatt_if,TRUE, bd_addr, TRUE);
        else
        {
            GATT_TRACE_ERROR("Unsupported transport for background connection");
        }
    }

    return status;

}

再结合/data/misc/bluedroid/bt_config.xml里面扫描到的设备信息,发现DevType是3

130|root@p201:/ # cat /data/misc/bluedroid/                                    
bt_config.old   bt_config.xml   
130|root@p201:/ # cat /data[  872.319441@0] type=1400 audit(1533261021.174:28): avc: denied { read } for pid=2796 comm="sh" name="bluedroid" dev="mmcblk0p14" ino=144867 scontext=u:r:shell:s0 tcontext=u:object_r:bluetooth_data_file:s0 tclass=dir permissive=1
/misc/bluedroid/bt_config.      [  872.343311@0] type=1400 audit(1533261021.174:29): avc: denied { open } for pid=2796 comm="sh" path="/data/misc/bluedroid" dev="mmcblk0p14" ino=144867 scontext=u:r:shell:s0 tcontext=u:object_r:bluetooth_data_file:s0 tclass=dir permissive=1
        [  872.367313@1] type=1400 audit(1533261021.174:30): avc: denied { getattr } for pid=2796 comm="sh" path="/data/misc/bluedroid/bt_config.xml" dev="mmcblk0p14" ino=144907 scontext=u:r:shell:s0 tcontext=u:object_r:bluetooth_data_file:s0 tclass=file permissive=1

bt_config.old   bt_config.xml   
at /data/misc/bluedroid/bt_config.xml                                         <

    
        
    [  876.213669@0] type=1400 audit(1533261025.074:31): avc: denied { read } for pid=2796 comm="sh" name="bt_config.xml" dev="mmcblk0p14" ino=144907 scontext=u:r:shell:s0 tcontext=u:object_r:bluetooth_data_file:s0 tclass=file permissive=1
[  876.236668@1] type=1400 audit(1533261025.074:32): avc: denied { open } for pid=2796 comm="sh" path="/data/misc/bluedroid/bt_config.xml" dev="mmcblk0p14" ino=144907 scontext=u:r:shell:s0 tcontext=u:object_r:bluetooth_data_file:s0 tclass=file permissive=1
        1
            22:22:be:e3:0b:b1
            8539be4988f0ebfb4dccdd3ea4772006
            5d696d1fefdcae55a7d0cb3cbc085c18
            e825f9c5519b2843037ecbae6fab536a
            1
            120
            70abd7c3fbbbd50fefcd1a6c5bfbb121
        
        
            00:02:C7,00:16:FE,00:19:C1,00:1B:FB,00:1E:3D,00:21:4F,00:23:06,00:24:33,00:A0:79,00:0E:6D,00:13:E0,00:21:E8,00:60:57,00:0E:9F,00:12:1C,00:18:91,00:18:96,00:13:04,00:16:FD,00:22:A0,00:0B:4C,00:60:6F,00:23:3D,00:C0:59,00:0A:30,00:1E:AE,00:1C:D7,00:80:F0,00:12:8A,00:09:93,00:80:37,00:26:7E,00:26:e8
            Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN
            00:0F:F6
            BMW,Audi,Parrot,Car
        
    
    
        
            Haier-V3-15EJ
            7936
            3
            0
            57
            6
            256
            1533260847
            0
            4
            43ac65f2968ed22332e3b35e11053e68
            00001101-0000-1000-8000-00805f9b34fb 
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            MI Band 2
            7936
            2
            1
        
        
            2
        
        
            MI Band 2
            7936
            2
            1
        
        
            2
        
        
            1533259246
            QCOM-BTD
            5898764
            1
            0
        
        
            1533260859
            MI8
            5898764
            1
            0
        
        
            1531747811
            坚果 Pro
            5898764
            1
            0
        
        
            1533260103
            小米手机
            5898764
            1
            0
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            1533259264
            5898764
            1
            0
            小米手机
        
        
            1533260691
            小米手机
            5898764
            1
            0
        
        
            1533259263
            2491420
            1
            0
            10
            4
            4192
            小钢炮蓝牙音箱青春版
        
        
            1533259385
            honor Band 3-2f7
            7936
            2
            0
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            1533260489
            5898764
            1
            0
            Honor V10
        
        
            2
        
        
            2
        
        
            2
        
        
            2
        
        
            1533260848
            GIONEE GN8003L
            5898764
            1
            0
        
    

从出错代码来看:

        if (transport == BT_TRANSPORT_LE)
        status = gatt_update_auto_connect_dev(gatt_if,TRUE, bd_addr, TRUE);
        else
        {
            GATT_TRACE_ERROR("Unsupported transport for background connection");
        }

BT_TRANSPORT_LE定义为2

应该是由于设备上报了3,导致这里的gatt_update_auto_connect_dev没有跑进去,所以对代码做了修改:

        if ((transport & BT_TRANSPORT_LE) == BT_TRANSPORT_LE)
        status = gatt_update_auto_connect_dev(gatt_if,TRUE, bd_addr, TRUE);
        else
        {
            GATT_TRACE_ERROR("Unsupported transport for background connection");
        }

修改后该设备正常连接S905。

究其原因,应该是旧版本的bluedroid协议栈对DevType为3的设备的处理存在问题。

你可能感兴趣的:(Android)