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

Commit 156bb5fd authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Gerrit Code Review
Browse files

Merge "AudioDeviceBroker: reapply BT HAL state on native AS restart" into main

parents a54facd2 9aa3a169
Loading
Loading
Loading
Loading
+32 −3
Original line number Diff line number Diff line
@@ -1024,11 +1024,9 @@ public class AudioDeviceBroker {
    private void initAudioHalBluetoothState() {
        synchronized (mBluetoothAudioStateLock) {
            mBluetoothScoOnApplied = false;
            AudioSystem.setParameters("BT_SCO=off");
            mBluetoothA2dpSuspendedApplied = false;
            AudioSystem.setParameters("A2dpSuspended=false");
            mBluetoothLeSuspendedApplied = false;
            AudioSystem.setParameters("LeAudioSuspended=false");
            reapplyAudioHalBluetoothState();
        }
    }

@@ -1091,6 +1089,34 @@ public class AudioDeviceBroker {
        }
    }

    @GuardedBy("mBluetoothAudioStateLock")
    private void reapplyAudioHalBluetoothState() {
        if (AudioService.DEBUG_COMM_RTE) {
            Log.v(TAG, "reapplyAudioHalBluetoothState() mBluetoothScoOnApplied: "
                    + mBluetoothScoOnApplied + ", mBluetoothA2dpSuspendedApplied: "
                    + mBluetoothA2dpSuspendedApplied + ", mBluetoothLeSuspendedApplied: "
                    + mBluetoothLeSuspendedApplied);
        }
        // Note: the order of parameters is important.
        if (mBluetoothScoOnApplied) {
            AudioSystem.setParameters("A2dpSuspended=true");
            AudioSystem.setParameters("LeAudioSuspended=true");
            AudioSystem.setParameters("BT_SCO=on");
        } else {
            AudioSystem.setParameters("BT_SCO=off");
            if (mBluetoothA2dpSuspendedApplied) {
                AudioSystem.setParameters("A2dpSuspended=true");
            } else {
                AudioSystem.setParameters("A2dpSuspended=false");
            }
            if (mBluetoothLeSuspendedApplied) {
                AudioSystem.setParameters("LeAudioSuspended=true");
            } else {
                AudioSystem.setParameters("LeAudioSuspended=false");
            }
        }
    }

    /*package*/ void setBluetoothScoOn(boolean on, String eventSource) {
        if (AudioService.DEBUG_COMM_RTE) {
            Log.v(TAG, "setBluetoothScoOn: " + on + " " + eventSource);
@@ -1727,6 +1753,9 @@ public class AudioDeviceBroker {
                            initRoutingStrategyIds();
                            updateActiveCommunicationDevice();
                            mDeviceInventory.onRestoreDevices();
                            synchronized (mBluetoothAudioStateLock) {
                                reapplyAudioHalBluetoothState();
                            }
                            mBtHelper.onAudioServerDiedRestoreA2dp();
                            updateCommunicationRoute("MSG_RESTORE_DEVICES");
                        }