我有一个应用程序,它打开与 BLE 设备的短暂连接,执行一些特征读取和写入,然后断开并关闭连接。应用程序使用 autoReconnect=false,并且设备未配对或绑定。
我看到 Android 的一些非常奇怪的行为,它似乎反复且意外地重新连接到外围设备,即使在连接 close()d 之后,应用程序被杀死甚至卸载。
此问题之前已与 Spotify 触发重新连接相关(请参阅:Android BLE 意外且反复重新连接到外设 https://stackoverflow.com/questions/43160195/android-ble-unexpectedly-and-repeatedly-reconnects-to-peripheral),但就我而言,这种情况甚至会发生未安装 Spotify.
可以可靠地重现这一点的设备是:
- 谷歌像素,安卓 8.1
- LG Nexus 5X,安卓 7.1.2
- 三星盖乐世 S7,安卓 7.0
- 三星盖乐世 S6,安卓 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 上(当然),这让我相信某些 3rd 方或 Google 服务可能要对此负责。
知道如何追踪这一点吗?目前只有骑行蓝牙有帮助。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)