建立通话,如何连接蓝牙耳机SCO

时间:2022-02-25 09:25:20

1)通话之前,ACL是连接好的。在PoneApp里用了bluetoothhandfree这个类.在onCreate方法中,定义了bluetoothhandfree的对象,并把CM的信息传给了bluetoothhandfree类里。
if (BluetoothAdapter.getDefaultAdapter() != null) {
                // Start BluetoothHandsree even if device is not voice capable.
                // The device can still support VOIP.
                mBtHandsfree = BluetoothHandsfree.init(this, mCM);
                startService(new Intent(this, BluetoothHeadsetService.class));
            } else {
                // Device is not bluetooth capable
                mBtHandsfree = null;
            }
2)有电话被激活时,PhoneApp收到由PhoneProxy发送的intent ACTION_RADIO_TECHNOLOGY_CHANGED.
else if (action.equals(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED)) {
                String newPhone = intent.getStringExtra(Phone.PHONE_NAME_KEY);
                Log.d(LOG_TAG, "Radio technology switched. Now " + newPhone + " is active.");
                initForNewRadioTechnology();
            }
3)在initForNewRadioTechnology私有方法中
if (mBtHandsfree != null) {
            mBtHandsfree.updateBtHandsfreeAfterRadioTechnologyChange();
        }当RadioTechnology有变化时,交由bluetoothhandfree处理;
4)BluetoothHandfree处理:
void updateBtHandsfreeAfterRadioTechnologyChange() {
        if (VDBG) Log.d(TAG, "updateBtHandsfreeAfterRadioTechnologyChange...");

        mBluetoothPhoneState.updateBtPhoneStateAfterRadioTechnologyChange();
}
mBluetoothPhoneState.updateBtPhoneStateAfterRadioTechnologyChange()的处理:
//Register all events new to the new active phone
mCM.getDefaultPhone().registerForServiceStateChanged(mStateChangeHandler,SERVICE_STATE_CHANGED, null);
mCM.registerForPreciseCallStateChanged(mStateChangeHandler,PRECISE_CALL_STATE_CHANGED, null);
mCM.registerForCallWaiting(mStateChangeHandler,PHONE_CDMA_CALL_WAITING, null);
5)BluetoothHandfree处理注册的消息,在有变化时;
handlePreciseCallStateChange,这个方法将处理响铃和通话和蓝牙相关的东西,包括连接SCO,用AudioManager设置声音通道等。