2. 蓝牙耳机主动跟Android 连首先BluetoothAudioGateway 会在一个线程中收到来自蓝牙耳机的RFCOMM 连接,然后发送消息给BluetoothHeadsetService。
mConnectingHeadsetRfcommChannel = -1;
mConnectingHandsfreeRfcommChannel = -1;
if(waitForHandsfreeConnectNative(SELECT_WAIT_TIMEOUT) == false) {
if (mTimeoutRemainingMs > 0) {
try {
Log.i(tag, "select thread timed out, but " +
mTimeoutRemainingMs + "ms of
waiting remain.");
Thread.sleep(mTimeoutRemainingMs);
} catch (InterruptedException e) {
Log.i(tag, "select thread was interrupted (2),
exiting");
mInterrupted = true;
}
}
}
BluetoothHeadsetService 会根据当前的状态来处理消息,分3 种情况,第一是当前状态是非连接状态,会发送RFCOMM_CONNECTED 消息,后续处理请参见前面的分析。
case BluetoothHeadset.STATE_DISCONNECTED:
// h