0
点赞
收藏
分享

微信扫一扫

Android11 蓝牙设备连接和断开连接流程分析

源码分析

蓝牙连接状态定义位于

packages/modules/Bluetooth/framework/java/android/bluetooth/BluetoothProfile.java

共有四个状态如下

/** The profile is in disconnected state */
int STATE_DISCONNECTED = 0;
/** The profile is in connecting state */
int STATE_CONNECTING = 1;
/** The profile is in connected state */
int STATE_CONNECTED = 2;
/** The profile is in disconnecting state */
int STATE_DISCONNECTING = 3;

状态变更回调源码

packages/services/Telecomm/src/com/android/server/telecom/bluetooth/BluetoothStateReceiver.java

Android11 蓝牙设备连接和断开连接流程分析_java

当主板主动连接蓝牙设备时会,经历状态1 2 的过程

当主板主动断开蓝牙设备时,会经历状态3 0 的过程

如果是蓝牙设备主动断开,则直接从2变为0,不会经过状态3

日志分析

以下就是蓝牙设备主动断开,抓状态日志

$ logcat | grep "changed state"
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 1: BSR.oR@ACM
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 2: BSR.oR@ACU
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 0: BSR.oR@ADc

如果是主板端主动断开,抓日志如下

$ logcat | grep "changed state"
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 1: BSR.oR@ACM
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 2: BSR.oR@ACU
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 3: BSR.oR@ACE
Telecom : BluetoothStateReceiver: Device 70:56:BA:0B:E0:AA changed state to 0: BSR.oR@ADc

举报

相关推荐

0 条评论