我是靠谱客的博主 不安鞋垫,最近开发中收集的这篇文章主要介绍蓝牙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                                         <
<Bluedroid>
    <N1 Tag="Local">
        <N1 Tag="Adapter">
    [  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
        <N1 Tag="BluezMigrationDone" Type="int">1</N1>
            <N2 Tag="Address" Type="string">22:22:be:e3:0b:b1</N2>
            <N3 Tag="LE_LOCAL_KEY_IR" Type="binary">8539be4988f0ebfb4dccdd3ea4772006</N3>
            <N4 Tag="LE_LOCAL_KEY_IRK" Type="binary">5d696d1fefdcae55a7d0cb3cbc085c18</N4>
            <N5 Tag="LE_LOCAL_KEY_DHK" Type="binary">e825f9c5519b2843037ecbae6fab536a</N5>
            <N6 Tag="ScanMode" Type="int">1</N6>
            <N7 Tag="DiscoveryTimeout" Type="int">120</N7>
            <N8 Tag="LE_LOCAL_KEY_ER" Type="binary">70abd7c3fbbbd50fefcd1a6c5bfbb121</N8>
        </N1>
        <N2 Tag="AutoPairBlacklist">
            <N1 Tag="AddressBlacklist" Type="string">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</N1>
            <N2 Tag="ExactNameBlacklist" Type="string">Motorola IHF1000,i.TechBlueBAND,X5 Stereo v1.3,KML_CAN</N2>
            <N3 Tag="FixedPinZerosKeyboardBlacklist" Type="string">00:0F:F6</N3>
            <N4 Tag="PartialNameBlacklist" Type="string">BMW,Audi,Parrot,Car</N4>
        </N2>
    </N1>
    <N2 Tag="Remote">
        <N1 Tag="00:0c:bf:18:ac:07">
            <N1 Tag="Name" Type="string">Haier-V3-15EJ</N1>
            <N2 Tag="DevClass" Type="int">7936</N2>
            <N3 Tag="DevType" Type="int">3</N3>
            <N4 Tag="AddrType" Type="int">0</N4>
            <N5 Tag="Manufacturer" Type="int">57</N5>
            <N6 Tag="LmpVer" Type="int">6</N6>
            <N7 Tag="LmpSubVer" Type="int">256</N7>
            <N8 Tag="Timestamp" Type="int">1533260847</N8>
            <N9 Tag="LinkKeyType" Type="int">0</N9>
            <N10 Tag="PinLength" Type="int">4</N10>
            <N11 Tag="LinkKey" Type="binary">43ac65f2968ed22332e3b35e11053e68</N11>
            <N12 Tag="Service" Type="string">00001101-0000-1000-8000-00805f9b34fb </N12>
        </N1>
        <N2 Tag="1e:3f:2b:d7:df:ba">
            <N1 Tag="DevType" Type="int">2</N1>
        </N2>
        <N3 Tag="19:2f:6d:16:e1:9a">
            <N1 Tag="DevType" Type="int">2</N1>
        </N3>
        <N4 Tag="00:cf:86:87:dd:fe">
            <N1 Tag="DevType" Type="int">2</N1>
        </N4>
        <N5 Tag="04:ba:fa:4a:43:47">
            <N1 Tag="DevType" Type="int">2</N1>
        </N5>
        <N6 Tag="f3:fc:89:2a:78:65">
            <N1 Tag="Name" Type="string">MI Band 2</N1>
            <N2 Tag="DevClass" Type="int">7936</N2>
            <N3 Tag="DevType" Type="int">2</N3>
            <N4 Tag="AddrType" Type="int">1</N4>
        </N6>
        <N7 Tag="24:e9:87:6b:46:c0">
            <N1 Tag="DevType" Type="int">2</N1>
        </N7>
        <N8 Tag="df:8d:b0:fe:ed:b3">
            <N1 Tag="Name" Type="string">MI Band 2</N1>
            <N2 Tag="DevClass" Type="int">7936</N2>
            <N3 Tag="DevType" Type="int">2</N3>
            <N4 Tag="AddrType" Type="int">1</N4>
        </N8>
        <N9 Tag="1f:19:c0:57:1f:30">
            <N1 Tag="DevType" Type="int">2</N1>
        </N9>
        <N10 Tag="74:23:44:d1:33:73">
            <N1 Tag="Timestamp" Type="int">1533259246</N1>
            <N2 Tag="Name" Type="string">QCOM-BTD</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N10>
        <N11 Tag="94:87:e0:81:4b:7b">
            <N1 Tag="Timestamp" Type="int">1533260859</N1>
            <N2 Tag="Name" Type="string">MI8</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N11>
        <N12 Tag="b4:0b:44:d7:ad:f9">
            <N1 Tag="Timestamp" Type="int">1531747811</N1>
            <N2 Tag="Name" Type="string">坚果 Pro</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N12>
        <N13 Tag="e4:46:da:7b:1d:29">
            <N1 Tag="Timestamp" Type="int">1533260103</N1>
            <N2 Tag="Name" Type="string">小米手机</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N13>
        <N14 Tag="23:19:24:5e:1a:d4">
            <N1 Tag="DevType" Type="int">2</N1>
        </N14>
        <N15 Tag="17:2a:3f:73:87:bc">
            <N1 Tag="DevType" Type="int">2</N1>
        </N15>
        <N16 Tag="12:9c:bb:ae:1c:c6">
            <N1 Tag="DevType" Type="int">2</N1>
        </N16>
        <N17 Tag="3a:88:0c:5e:85:b5">
            <N1 Tag="DevType" Type="int">2</N1>
        </N17>
        <N18 Tag="d8:63:75:a7:0d:b0">
            <N1 Tag="Timestamp" Type="int">1533259264</N1>
            <N2 Tag="DevClass" Type="int">5898764</N2>
            <N3 Tag="DevType" Type="int">1</N3>
            <N4 Tag="AddrType" Type="int">0</N4>
            <N5 Tag="Name" Type="string">小米手机</N5>
        </N18>
        <N19 Tag="20:82:c0:63:d0:c3">
            <N1 Tag="Timestamp" Type="int">1533260691</N1>
            <N2 Tag="Name" Type="string">小米手机</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N19>
        <N20 Tag="fc:3d:93:77:16:2c">
            <N1 Tag="Timestamp" Type="int">1533259263</N1>
            <N2 Tag="DevClass" Type="int">2491420</N2>
            <N3 Tag="DevType" Type="int">1</N3>
            <N4 Tag="AddrType" Type="int">0</N4>
            <N5 Tag="Manufacturer" Type="int">10</N5>
            <N6 Tag="LmpVer" Type="int">4</N6>
            <N7 Tag="LmpSubVer" Type="int">4192</N7>
            <N8 Tag="Name" Type="string">小钢炮蓝牙音箱青春版</N8>
        </N20>
        <N21 Tag="a4:93:3f:ae:72:f7">
            <N1 Tag="Timestamp" Type="int">1533259385</N1>
            <N2 Tag="Name" Type="string">honor Band 3-2f7</N2>
            <N3 Tag="DevClass" Type="int">7936</N3>
            <N4 Tag="DevType" Type="int">2</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N21>
        <N22 Tag="3b:8c:47:7e:22:1d">
            <N1 Tag="DevType" Type="int">2</N1>
        </N22>
        <N23 Tag="14:3b:2d:e1:5b:28">
            <N1 Tag="DevType" Type="int">2</N1>
        </N23>
        <N24 Tag="0e:e2:21:17:b0:5c">
            <N1 Tag="DevType" Type="int">2</N1>
        </N24>
        <N25 Tag="10:9e:ce:2b:bd:b0">
            <N1 Tag="DevType" Type="int">2</N1>
        </N25>
        <N26 Tag="08:e3:16:3a:2e:fb">
            <N1 Tag="DevType" Type="int">2</N1>
        </N26>
        <N27 Tag="15:cb:96:47:01:c4">
            <N1 Tag="DevType" Type="int">2</N1>
        </N27>
        <N28 Tag="2a:a3:46:00:de:5d">
            <N1 Tag="DevType" Type="int">2</N1>
        </N28>
        <N29 Tag="2b:ca:84:8b:bc:22">
            <N1 Tag="DevType" Type="int">2</N1>
        </N29>
        <N30 Tag="2e:f4:0e:38:71:5a">
            <N1 Tag="DevType" Type="int">2</N1>
        </N30>
        <N31 Tag="30:1c:10:14:43:f0">
            <N1 Tag="DevType" Type="int">2</N1>
        </N31>
        <N32 Tag="74:d2:1d:0f:48:8d">
            <N1 Tag="Timestamp" Type="int">1533260489</N1>
            <N2 Tag="DevClass" Type="int">5898764</N2>
            <N3 Tag="DevType" Type="int">1</N3>
            <N4 Tag="AddrType" Type="int">0</N4>
            <N5 Tag="Name" Type="string">Honor V10</N5>
        </N32>
        <N33 Tag="01:9e:97:fc:4c:d6">
            <N1 Tag="DevType" Type="int">2</N1>
        </N33>
        <N34 Tag="33:49:3a:7d:03:0b">
            <N1 Tag="DevType" Type="int">2</N1>
        </N34>
        <N35 Tag="29:25:36:91:e3:3b">
            <N1 Tag="DevType" Type="int">2</N1>
        </N35>
        <N36 Tag="1d:76:c3:1b:e4:cc">
            <N1 Tag="DevType" Type="int">2</N1>
        </N36>
        <N37 Tag="b8:98:f7:2c:ac:3d">
            <N1 Tag="Timestamp" Type="int">1533260848</N1>
            <N2 Tag="Name" Type="string">GIONEE GN8003L</N2>
            <N3 Tag="DevClass" Type="int">5898764</N3>
            <N4 Tag="DevType" Type="int">1</N4>
            <N5 Tag="AddrType" Type="int">0</N5>
        </N37>
    </N2>
</Bluedroid>

从出错代码来看:

        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的设备的处理存在问题。

最后

以上就是不安鞋垫为你收集整理的蓝牙BLE连接设备报错onClientConnectionState() - status=133解决方法的全部内容,希望文章能够帮你解决蓝牙BLE连接设备报错onClientConnectionState() - status=133解决方法所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部