public void onAudioPortListUpdate(AudioPort[] portList) { synchronized (mLockForPatch) { log("onAudioPortListUpdate"); mOutPortSpeaker = null; mInPortA2dpSink = null; for (int i = 0; i < portList.length; i++) { AudioPort port = portList[i]; if (port instanceof AudioDevicePort) { AudioDevicePort devicePort = (AudioDevicePort) port; if (devicePort.type() == AudioSystem.DEVICE_OUT_SPEAKER) { log("Updating Speaker Port"); mOutPortSpeaker = devicePort; } else if (devicePort.type() == AudioSystem.DEVICE_IN_BLUETOOTH_A2DP) { log("Updating In Port A2DP Sink"); mInPortA2dpSink = devicePort; /* Check if we still have focus */ if ((mAudioFocusAcquired == AUDIO_FOCUS_GAIN) && (mInPortA2dpSink != null) && (mA2dpSinkAudioPatch == null)) { /* This is the case of Port available * later than focus acquired. Try patching ports now */ log(" Sink Port updated, but patch not made"); patchPorts(); } } } } } }