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

Commit 91d259ed authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9414670 from ae874fb7 to tm-qpr2-release

Change-Id: Ic28969bc57fff8eb82fa3d613a4a2e09e9bc0fb9
parents df31f030 ae874fb7
Loading
Loading
Loading
Loading
+26 −18
Original line number Diff line number Diff line
@@ -494,13 +494,32 @@ public class A2dpService extends ProfileService {
                previousActiveDevice = mActiveDevice;
            }

            int prevActiveConnectionState = getConnectionState(previousActiveDevice);

            // As per b/202602952, if we remove the active device due to a disconnection,
            // we need to check if another device is connected and set it active instead.
            // Calling this before any other active related calls has the same effect as
            // a classic active device switch.
            BluetoothDevice fallbackdevice = getFallbackDevice();
            if (fallbackdevice != null && prevActiveConnectionState
                    != BluetoothProfile.STATE_CONNECTED) {
                setActiveDevice(fallbackdevice);
                return;
            }

            // This needs to happen before we inform the audio manager that the device
            // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why.
            updateAndBroadcastActiveDevice(null);

            // Make sure the Audio Manager knows the previous Active device is removed.
            // Make sure the Audio Manager knows the previous Active device is disconnected.
            // However, if A2DP is still connected and not forcing stop audio for that remote
            // device, the user has explicitly switched the output to the local device and music
            // should continue playing. Otherwise, the remote device has been indeed disconnected
            // and audio should be suspended before switching the output to the local device.
            boolean stopAudio = forceStopPlayingAudio || (prevActiveConnectionState
                        != BluetoothProfile.STATE_CONNECTED);
            mAudioManager.handleBluetoothActiveDeviceChanged(null, previousActiveDevice,
                    BluetoothProfileConnectionInfo.createA2dpInfo(!forceStopPlayingAudio, -1));
                    BluetoothProfileConnectionInfo.createA2dpInfo(!stopAudio, -1));

            synchronized (mStateMachines) {
                // Make sure the Active device in native layer is set to null and audio is off
@@ -544,22 +563,10 @@ public class A2dpService extends ProfileService {
     * @return true on success, otherwise false
     */
    public boolean setActiveDevice(BluetoothDevice device) {
        return setActiveDevice(device, false);
    }

    /**
     * Set the active device.
     *
     * @param device the active device
     * @param hasFallbackDevice whether it has fallback device when the {@code device}
     *                          is {@code null}.
     * @return true on success, otherwise false
     */
    public boolean setActiveDevice(BluetoothDevice device, boolean hasFallbackDevice) {
        synchronized (mActiveSwitchingGuard) {
            if (device == null) {
                // Remove active device and continue playing audio only if necessary.
                removeActiveDevice(!hasFallbackDevice);
                removeActiveDevice(false);
                return true;
            }

@@ -1246,9 +1253,10 @@ public class A2dpService extends ProfileService {
        if (toState == BluetoothProfile.STATE_CONNECTED && (mMaxConnectedAudioDevices == 1)) {
            setActiveDevice(device);
        }

        // When disconnected, ActiveDeviceManager will call setActiveDevice(null)

        // Check if the active device is not connected anymore
        if (isActiveDevice(device) && (fromState == BluetoothProfile.STATE_CONNECTED)) {
            setActiveDevice(null);
        }
        // Check if the device is disconnected - if unbond, remove the state machine
        if (toState == BluetoothProfile.STATE_DISCONNECTED) {
            if (mAdapterService.getBondState(device) == BluetoothDevice.BOND_NONE) {
Loading