Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +15 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.bluetooth.a2dpsink; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.pm.PackageManager; import android.media.AudioAttributes; import android.media.AudioFocusRequest; import android.media.AudioManager; Loading Loading @@ -135,7 +136,16 @@ public class A2dpSinkStreamHandler extends Handler { break; case SRC_PLAY: // Remote play command, if we have audio focus update avrcp, otherwise send pause. // Remote play command. // If is an iot device gain focus and start avrcp updates. if (isIotDevice()) { if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) { requestAudioFocus(); } startAvrcpUpdates(); break; } // Otherwise, pause if we don't have focus if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) { sendAvrcpPause(); } else { Loading Loading @@ -337,4 +347,8 @@ public class A2dpSinkStreamHandler extends Handler { Log.e(TAG, "Passthrough not sent, connection un-available."); } } private boolean isIotDevice() { return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_EMBEDDED); } } android/app/tests/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; Loading Loading @@ -58,6 +59,8 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { @Mock Resources mockResources; @Mock PackageManager mockPackageManager; @Before public void setUp() { // Mock the looper Loading @@ -79,6 +82,8 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { when(mockAudioManager.abandonAudioFocus(any())).thenReturn(AudioManager.AUDIOFOCUS_GAIN); doNothing().when(mockA2dpSink).informAudioTrackGainNative(anyFloat()); when(mockContext.getMainLooper()).thenReturn(mHandlerThread.getLooper()); when(mockContext.getPackageManager()).thenReturn(mockPackageManager); when(mockPackageManager.hasSystemFeature(any())).thenReturn(false); streamHandler = spy(new A2dpSinkStreamHandler(mockA2dpSink, mockContext)); } Loading Loading @@ -139,6 +144,16 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { verify(mockA2dpSink, times(0)).informAudioTrackGainNative(1.0f); } @Test public void testSrcPlayIot() { // Play was pressed remotely for an iot device, expect streaming to start. when(mockPackageManager.hasSystemFeature(any())).thenReturn(true); streamHandler.handleMessage(streamHandler.obtainMessage(A2dpSinkStreamHandler.SRC_PLAY)); verify(mockAudioManager, times(1)).requestAudioFocus(any(), anyInt(), anyInt()); verify(mockA2dpSink, times(1)).informAudioFocusStateNative(1); verify(mockA2dpSink, times(1)).informAudioTrackGainNative(1.0f); } @Test public void testSrcPause() { // Play was pressed locally, expect streaming to start. Loading Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +15 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.bluetooth.a2dpsink; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.pm.PackageManager; import android.media.AudioAttributes; import android.media.AudioFocusRequest; import android.media.AudioManager; Loading Loading @@ -135,7 +136,16 @@ public class A2dpSinkStreamHandler extends Handler { break; case SRC_PLAY: // Remote play command, if we have audio focus update avrcp, otherwise send pause. // Remote play command. // If is an iot device gain focus and start avrcp updates. if (isIotDevice()) { if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) { requestAudioFocus(); } startAvrcpUpdates(); break; } // Otherwise, pause if we don't have focus if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) { sendAvrcpPause(); } else { Loading Loading @@ -337,4 +347,8 @@ public class A2dpSinkStreamHandler extends Handler { Log.e(TAG, "Passthrough not sent, connection un-available."); } } private boolean isIotDevice() { return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_EMBEDDED); } }
android/app/tests/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandlerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; Loading Loading @@ -58,6 +59,8 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { @Mock Resources mockResources; @Mock PackageManager mockPackageManager; @Before public void setUp() { // Mock the looper Loading @@ -79,6 +82,8 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { when(mockAudioManager.abandonAudioFocus(any())).thenReturn(AudioManager.AUDIOFOCUS_GAIN); doNothing().when(mockA2dpSink).informAudioTrackGainNative(anyFloat()); when(mockContext.getMainLooper()).thenReturn(mHandlerThread.getLooper()); when(mockContext.getPackageManager()).thenReturn(mockPackageManager); when(mockPackageManager.hasSystemFeature(any())).thenReturn(false); streamHandler = spy(new A2dpSinkStreamHandler(mockA2dpSink, mockContext)); } Loading Loading @@ -139,6 +144,16 @@ public class A2dpSinkStreamHandlerTest extends AndroidTestCase { verify(mockA2dpSink, times(0)).informAudioTrackGainNative(1.0f); } @Test public void testSrcPlayIot() { // Play was pressed remotely for an iot device, expect streaming to start. when(mockPackageManager.hasSystemFeature(any())).thenReturn(true); streamHandler.handleMessage(streamHandler.obtainMessage(A2dpSinkStreamHandler.SRC_PLAY)); verify(mockAudioManager, times(1)).requestAudioFocus(any(), anyInt(), anyInt()); verify(mockA2dpSink, times(1)).informAudioFocusStateNative(1); verify(mockA2dpSink, times(1)).informAudioTrackGainNative(1.0f); } @Test public void testSrcPause() { // Play was pressed locally, expect streaming to start. Loading