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

Commit 3db7dff6 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by android-build-merger
Browse files

Merge changes I547d1950,I7b958a9f

am: 957d43a9

Change-Id: I5107aab77c5599ef3d7a0c5566d666d751b78849
parents 0a754eeb 957d43a9
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -183,8 +183,9 @@ public class A2dpSinkStreamHandler extends Handler {
                break;

            case AUDIO_FOCUS_CHANGE:
                mAudioFocus = (int) message.obj;
                // message.obj is the newly granted audio focus.
                switch ((int) message.obj) {
                switch (mAudioFocus) {
                    case AudioManager.AUDIOFOCUS_GAIN:
                        removeMessages(DELAYED_PAUSE);
                        // Begin playing audio, if we paused the remote, send a play now.
@@ -245,7 +246,7 @@ public class A2dpSinkStreamHandler extends Handler {
     */
    private void requestAudioFocusIfNone() {
        if (DBG) Log.d(TAG, "requestAudioFocusIfNone()");
        if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
        if (mAudioFocus != AudioManager.AUDIOFOCUS_GAIN) {
            requestAudioFocus();
        }
        // On the off change mMediaPlayer errors out and dies, we want to make sure we retry this.
+1 −2
Original line number Diff line number Diff line
@@ -881,7 +881,6 @@ class AvrcpControllerStateMachine extends StateMachine {

    private boolean shouldRequestFocus() {
        return mService.getResources()
                .getBoolean(R.bool.a2dp_sink_automatically_request_audio_focus)
                || !mAudioManager.isMusicActive();
                .getBoolean(R.bool.a2dp_sink_automatically_request_audio_focus);
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -194,6 +194,21 @@ public class A2dpSinkStreamHandlerTest {
        verify(mMockA2dpSink, times(1)).informAudioTrackGainNative(0);
    }

    @Test
    public void testFocusRerequest() {
        // Focus was lost transiently, expect streaming to stop.
        testSnkPlay();
        mStreamHandler.handleMessage(
                mStreamHandler.obtainMessage(A2dpSinkStreamHandler.AUDIO_FOCUS_CHANGE,
                        AudioManager.AUDIOFOCUS_LOSS_TRANSIENT));
        verify(mMockAudioManager, times(0)).abandonAudioFocus(any());
        verify(mMockA2dpSink, times(0)).informAudioFocusStateNative(0);
        verify(mMockA2dpSink, times(1)).informAudioTrackGainNative(0);
        mStreamHandler.handleMessage(
                mStreamHandler.obtainMessage(A2dpSinkStreamHandler.REQUEST_FOCUS, true));
        verify(mMockAudioManager, times(2)).requestAudioFocus(any());
    }

    @Test
    public void testFocusGainTransient() {
        // Focus was lost then regained.