[置顶] android4.2 bluetooth蓝牙HFP/HSP/A2DP

HFP/HSP:

JniCallbacks 回调AdapterState.stateChangeCallback,当状态时BT_STATE_ON,则自动连接Headset A2dp

if (status == AbstractionLayer.BT_STATE_ON) {

            // We should have got the property change for adapter and remote devices.

            sendMessage(ENABLED_READY);

继而transitionTo(mOnState),在OnState enter 里连接HeadsetA2DP,

      public void enter() {

            infoLog("Entering On State");

            mAdapterService.autoConnect();

        }

AdapterState:

public void autoConnect(){

      …

         if (isQuietModeEnabled() == false) {

            if (DBG) debugLog( "Initiate auto connection on BT on...");

             autoConnectHeadset();

             autoConnectA2dp();

         }

      …

    }

 

 

切换蓝牙通道:

电话接听时,如果是从其他方式切换到蓝牙,则需要重新连接HFP/A2DP,

直接调用函数connectBluetoothAudio()/disconnectBluetoothAudio()来实现切换蓝牙通道,

如果蓝牙已经连接上了,则不做任何操作。

case BLUETOOTH:

                // If already connected to BT, there's nothing to do here.

                if (isBluetoothAvailable() && !isBluetoothAudioConnected()) {

                    if (PhoneUtils.isSpeakerOn(this)) {

                        PhoneUtils.turnOnSpeaker(this, false, true);

                    }

                    connectBluetoothAudio();

                }

                break;

函数调用:

|――connectBluetoothAudio

       |――mBluetoothHeadset.connectAudio()

              |――mService.connectAudio()

                     |――HeadsetService.connectAudio()

                     |――mStateMachine.sendMessage(HeadsetStateMachine

                            .CONNECT_AUDIO);

                            |――connectHfpNative(getByteAddress(device))

                            |――HeadsetStateMachine.connectAudioNative

                                   (getByteAddress(mCurrentDevice))

A2DP:

在设置界面进行A2DP业务的连接时,函数调用流程如下:

BluetoothDevicePreference(    onClick() / connect()   )配对

CachedBluetoothDevice.connect()---->

CachedBluetoothDevice. connectWithoutResettingTimer()---->

connectInt()---->

profile.connect(mDevice)

这时的profileLocalBluetoothProfile,由其子类A2DProfile实现connect方法

A2dpProfile(   connect()   ) ---->

BluetoothA2DP(   connect()   ) ---->

AdapterService$BluetoothA2dpBinder (  connect()  ) ---->

A2dpStateMachine  ( connectA2dpNative() )

 

你可能感兴趣的:([置顶] android4.2 bluetooth蓝牙HFP/HSP/A2DP)