连接关闭和应用程序终止后,BLE堆栈会重复连接到外围设备

时间:2018-05-15 10:57:11

标签: android bluetooth bluetooth-lowenergy

我有一个应用程序打开与BLE设备的短暂连接,进行一些特征性的读写操作,然后断开连接并关闭连接。该应用使用autoReconnect = false,设备未配对或绑定。

我看到Android的一些非常奇怪的行为,即使在连接关闭()d,应用程序被杀或甚至卸载后,它似乎反复且意外地重新连接到外围设备。

此问题之前已与Spotify触发重新连接相关联(请参阅:Android BLE unexpectedly and repeatedly reconnects to peripheral),但就我而言,即使未安装Spotify ,也会发生这种情况。

可以可靠再现的设备是:

  • Google Pixel,Android 8.1
  • LG Nexus 5X,Android 7.1.2
  • 三星Galaxy S7,Android 7.0
  • 三星Galaxy S6,Andorid 6.0

连接是短暂的,持续约3秒。我可以验证是否建立了连接,因为外围设备提供了其连接的可视指示和日志输出。

我对于可能导致重复重新连接的原因感到非常难过,因为BLE堆栈的logcat没有提供关于导致连接的人或者是什么的提示。运行7.1.2的Nexus 5X上的一个连接/断开循环的蓝牙服务(com.android.bluetooth)的logcat输出如下所示:

05-15 10:36:55.428  6397  7029 W bt_smp  : smp_br_connect_callback is called on unexpected transport 2
05-15 10:36:55.428  6397  7029 W bt_btif : bta_dm_acl_change info: 0x0
05-15 10:36:55.428  6397  7029 E bt_btif : bta_gattc_cache_load: can't open GATT cache file /data/misc/bluetooth/gatt_cache_c4be844851e9 for reading, error: No such file or directory
05-15 10:36:55.428  6397  6526 D bt_btif_dm: remote version info [c4:be:84:48:51:e9]: 0, 0, 0
05-15 10:36:55.432  6397  6526 E BluetoothRemoteDevices: state12newState0
05-15 10:36:56.141  6397  7029 W bt_bta_gattc: bta_gattc_explore_srvc no more services found
05-15 10:36:56.141  6397  7029 I bt_bta_dm: bta_dm_gatt_disc_result service_id_uuid_len=2 
05-15 10:36:56.141  6397  7029 I bt_bta_dm: bta_dm_gatt_disc_result service_id_uuid_len=2 
05-15 10:36:56.142  6397  7029 I bt_bta_dm: bta_dm_gatt_disc_result service_id_uuid_len=2 
05-15 10:36:58.185  6397  7029 W bt_btif : bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
05-15 10:36:58.185  6397  7029 W bt_btif : bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
05-15 10:36:58.185  6397  7029 W bt_btif : bta_gattc_conn_cback() - cif=5 connected=0 conn_id=5 reason=0x0016
05-15 10:36:58.185  6397  7029 W bt_btif : bta_gattc_conn_cback() - cif=6 connected=0 conn_id=6 reason=0x0016
05-15 10:36:58.185  6397  7029 I bt_btm_sec: btm_sec_disconnected clearing pending flag handle:5 reason:22
05-15 10:36:58.187  6397  6526 E BluetoothRemoteDevices: state12newState1
05-15 10:36:58.199  6397  6397 D BluetoothMapService: onReceive
05-15 10:36:58.200  6397  6397 D BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED

我目前调试的主要途径是在Pixel上闪烁AOSP并向BT堆栈添加额外的日志语句。到目前为止,问题还没有出现在AOSP上(当然),这让我相信某些第三方或Google服务可能会负责。

知道怎么追查这个吗?目前只有骑车蓝牙有帮助。

0 个答案:

没有答案