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

Commit b61b321f authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP Controller transient loss while idle

While gaining and losing focus due to transient focus requests ensure
Bluetooth restores to the correct playback state.  This corrects issues
that could arise during non media sonification durring a transient
focus loss.

Bug: 136092891
Test: atest com.android.bluetooth.a2dpsink.A2dpSinkStreamHandlerTest
Change-Id: I58997b3b8b96da309ff4c31a2b3039dccf9b3578
parent b8fc769e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Message;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;

import com.android.bluetooth.R;
@@ -225,7 +226,8 @@ public class A2dpSinkStreamHandler extends Handler {
                break;

            case DELAYED_PAUSE:
                if (mStreamAvailable && !inCallFromStreamingDevice()) {
                if (BluetoothMediaBrowserService.getPlaybackState()
                            == PlaybackStateCompat.STATE_PLAYING && !inCallFromStreamingDevice()) {
                    sendAvrcpPause();
                    mSentPause = true;
                    mStreamAvailable = false;
+14 −0
Original line number Diff line number Diff line
@@ -184,6 +184,20 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        }
    }

    /**
     * Get playback state
     */
    public static synchronized int getPlaybackState() {
        if (sBluetoothMediaBrowserService != null) {
            PlaybackStateCompat currentPlaybackState =
                    sBluetoothMediaBrowserService.mSession.getController().getPlaybackState();
            if (currentPlaybackState != null) {
                return currentPlaybackState.getState();
            }
        }
        return PlaybackStateCompat.STATE_ERROR;
    }

    /**
     * Get object for controlling playback
     */
+18 −0
Original line number Diff line number Diff line
@@ -194,6 +194,24 @@ public class A2dpSinkStreamHandlerTest {
        verify(mMockA2dpSink, times(1)).informAudioTrackGainNative(0);
    }

    @Test
    public void testFocusGainTransient() {
        // Focus was lost then regained.
        testSnkPlay();
        mStreamHandler.handleMessage(
                mStreamHandler.obtainMessage(A2dpSinkStreamHandler.AUDIO_FOCUS_CHANGE,
                        AudioManager.AUDIOFOCUS_LOSS_TRANSIENT));
        mStreamHandler.handleMessage(
                mStreamHandler.obtainMessage(A2dpSinkStreamHandler.DELAYED_PAUSE));
        mStreamHandler.handleMessage(
                mStreamHandler.obtainMessage(A2dpSinkStreamHandler.AUDIO_FOCUS_CHANGE,
                        AudioManager.AUDIOFOCUS_GAIN));
        verify(mMockAudioManager, times(0)).abandonAudioFocus(any());
        verify(mMockA2dpSink, times(0)).informAudioFocusStateNative(0);
        verify(mMockA2dpSink, times(1)).informAudioTrackGainNative(0);
        verify(mMockA2dpSink, times(2)).informAudioTrackGainNative(1.0f);
    }

    @Test
    public void testFocusLost() {
        // Focus was lost permanently, expect streaming to stop.