Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec6a8de1 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioService: new SCO audio connection management

The SCO audio link activation is not controlled by
audio service but similarly to A2DP or LE Audio by the
activation of the audio stream between the audio HAL and the
BT stack when a SCO audio device is selected.

Audio service still listens to the SCO audio link activation
to control the A2DP and LE audio suspend status.

Test: make
Bug: 265057196
Flag: android.media.audio.sco_managed_by_audio
Change-Id: I52f85c3f0aca23f15f9eaa8ccc83ca4bf0b00a2b
parent d12e2e01
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -413,7 +413,7 @@ public class AudioDeviceBroker {
        if (client == null) {
            return;
        }

        if (!mScoManagedByAudio) {
            boolean isBtScoRequested = isBluetoothScoRequested();
            if (isBtScoRequested && (!wasBtScoRequested || !isBluetoothScoActive())) {
                if (!mBtHelper.startBluetoothSco(scoAudioMode, eventSource)) {
@@ -430,7 +430,7 @@ public class AudioDeviceBroker {
            } else if (!isBtScoRequested && wasBtScoRequested) {
                mBtHelper.stopBluetoothSco(eventSource);
            }

        }
        // In BT classic for communication, the device changes from a2dp to sco device, but for
        // LE Audio it stays the same and we must trigger the proper stream volume alignment, if
        // LE Audio communication device is activated after the audio system has already switched to
@@ -2526,7 +2526,7 @@ public class AudioDeviceBroker {
            setCommunicationRouteForClient(crc.getBinder(), crc.getUid(), crc.getDevice(),
                    BtHelper.SCO_MODE_UNDEFINED, crc.isPrivileged(), eventSource);
        } else {
            if (!isBluetoothScoRequested() && wasBtScoRequested) {
            if (!mScoManagedByAudio && !isBluetoothScoRequested() && wasBtScoRequested) {
                mBtHelper.stopBluetoothSco(eventSource);
            }
            updateCommunicationRoute(eventSource);
+58 −42
Original line number Diff line number Diff line
@@ -401,6 +401,22 @@ public class BtHelper {
    private void onScoAudioStateChanged(int state) {
        boolean broadcast = false;
        int scoAudioState = AudioManager.SCO_AUDIO_STATE_ERROR;
        if (mDeviceBroker.isScoManagedByAudio()) {
            switch (state) {
                case BluetoothHeadset.STATE_AUDIO_CONNECTED:
                    mDeviceBroker.setBluetoothScoOn(true, "BtHelper.onScoAudioStateChanged");
                    scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTED;
                    broadcast = true;
                    break;
                case BluetoothHeadset.STATE_AUDIO_DISCONNECTED:
                    mDeviceBroker.setBluetoothScoOn(false, "BtHelper.onScoAudioStateChanged");
                    scoAudioState = AudioManager.SCO_AUDIO_STATE_DISCONNECTED;
                    broadcast = true;
                    break;
                default:
                    break;
            }
        } else {
            switch (state) {
                case BluetoothHeadset.STATE_AUDIO_CONNECTED:
                    scoAudioState = AudioManager.SCO_AUDIO_STATE_CONNECTED;
@@ -446,6 +462,7 @@ public class BtHelper {
                default:
                    break;
            }
        }
        if (broadcast) {
            broadcastScoConnectionState(scoAudioState);
            //FIXME: this is to maintain compatibility with deprecated intent
@@ -454,7 +471,6 @@ public class BtHelper {
            newIntent.putExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, scoAudioState);
            sendStickyBroadcastToAll(newIntent);
        }

    }
    /**
     *