Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +3 −2 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +1 −2 Original line number Diff line number Diff line Loading @@ -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); } } android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +3 −2 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +1 −2 Original line number Diff line number Diff line Loading @@ -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); } }
android/app/tests/unit/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -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. Loading