Loading android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -750,7 +750,11 @@ public class AvrcpControllerService extends ProfileService { protected AvrcpControllerStateMachine getOrCreateStateMachine(BluetoothDevice device) { AvrcpControllerStateMachine newStateMachine = new AvrcpControllerStateMachine(device, this, mNativeInterface); new AvrcpControllerStateMachine( device, this, mNativeInterface, Utils.isAutomotive(getApplicationContext())); AvrcpControllerStateMachine existingStateMachine = mDeviceStateMap.putIfAbsent(device, newStateMachine); // Given null is not a valid value in our map, ConcurrentHashMap will return null if the Loading android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +12 −4 Original line number Diff line number Diff line Loading @@ -147,7 +147,8 @@ class AvrcpControllerStateMachine extends StateMachine { AvrcpControllerStateMachine( BluetoothDevice device, AvrcpControllerService service, AvrcpControllerNativeInterface nativeInterface) { AvrcpControllerNativeInterface nativeInterface, boolean isControllerAbsoluteVolumeEnabled) { super(TAG); mDevice = device; mDeviceAddress = Utils.getByteAddress(mDevice); Loading Loading @@ -184,7 +185,7 @@ class AvrcpControllerStateMachine extends StateMachine { mGetFolderList = new GetFolderList(); addState(mGetFolderList, mConnected); mAudioManager = service.getSystemService(AudioManager.class); mIsVolumeFixed = mAudioManager.isVolumeFixed(); mIsVolumeFixed = mAudioManager.isVolumeFixed() || isControllerAbsoluteVolumeEnabled; setInitialState(mDisconnected); Loading Loading @@ -1171,8 +1172,15 @@ class AvrcpControllerStateMachine extends StateMachine { int maxLocalVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int curLocalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int reqLocalVolume = (maxLocalVolume * absVol) / ABS_VOL_BASE; debug("setAbsVolme: absVol = " + absVol + ", reqLocal = " + reqLocalVolume + ", curLocal = " + curLocalVolume + ", maxLocal = " + maxLocalVolume); debug( "setAbsVolume: absVol = " + absVol + ", reqLocal = " + reqLocalVolume + ", curLocal = " + curLocalVolume + ", maxLocal = " + maxLocalVolume); /* * In some cases change in percentage is not sufficient enough to warrant Loading android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java +51 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,8 @@ public class AvrcpControllerStateMachineTest { */ private AvrcpControllerStateMachine makeStateMachine(BluetoothDevice device) { AvrcpControllerStateMachine sm = new AvrcpControllerStateMachine(device, mAvrcpControllerService, mNativeInterface); new AvrcpControllerStateMachine( device, mAvrcpControllerService, mNativeInterface, false); sm.start(); return sm; } Loading Loading @@ -1119,6 +1120,55 @@ public class AvrcpControllerStateMachineTest { .sendRegisterAbsVolRsp(any(), anyByte(), eq(127), eq((int) label)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsFixed_setsAbsVolumeBase() { byte label = 42; setUpConnectedState(true, true); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(127), eq((int) label)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsNotFixed_setsAbsVolumeBase() { doReturn(false).when(mAudioManager).isVolumeFixed(); mAvrcpStateMachine = new AvrcpControllerStateMachine( mTestDevice, mAvrcpControllerService, mNativeInterface, false); mAvrcpStateMachine.start(); byte label = 42; setUpConnectedState(true, true); doReturn(100).when(mAudioManager).getStreamMaxVolume(eq(AudioManager.STREAM_MUSIC)); doReturn(25).when(mAudioManager).getStreamVolume(eq(AudioManager.STREAM_MUSIC)); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(20), eq((int) label)); verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .setStreamVolume( eq(AudioManager.STREAM_MUSIC), eq(15), eq(AudioManager.FLAG_SHOW_UI)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsNotFixedSinkAbsoluteVolumeEnabled_setsAbsVolumeBase() { doReturn(false).when(mAudioManager).isVolumeFixed(); mAvrcpStateMachine = new AvrcpControllerStateMachine( mTestDevice, mAvrcpControllerService, mNativeInterface, true); mAvrcpStateMachine.start(); byte label = 42; setUpConnectedState(true, true); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(127), eq((int) label)); } /** * Test playback does not request focus when another app is playing music. */ Loading Loading
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerService.java +5 −1 Original line number Diff line number Diff line Loading @@ -750,7 +750,11 @@ public class AvrcpControllerService extends ProfileService { protected AvrcpControllerStateMachine getOrCreateStateMachine(BluetoothDevice device) { AvrcpControllerStateMachine newStateMachine = new AvrcpControllerStateMachine(device, this, mNativeInterface); new AvrcpControllerStateMachine( device, this, mNativeInterface, Utils.isAutomotive(getApplicationContext())); AvrcpControllerStateMachine existingStateMachine = mDeviceStateMap.putIfAbsent(device, newStateMachine); // Given null is not a valid value in our map, ConcurrentHashMap will return null if the Loading
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +12 −4 Original line number Diff line number Diff line Loading @@ -147,7 +147,8 @@ class AvrcpControllerStateMachine extends StateMachine { AvrcpControllerStateMachine( BluetoothDevice device, AvrcpControllerService service, AvrcpControllerNativeInterface nativeInterface) { AvrcpControllerNativeInterface nativeInterface, boolean isControllerAbsoluteVolumeEnabled) { super(TAG); mDevice = device; mDeviceAddress = Utils.getByteAddress(mDevice); Loading Loading @@ -184,7 +185,7 @@ class AvrcpControllerStateMachine extends StateMachine { mGetFolderList = new GetFolderList(); addState(mGetFolderList, mConnected); mAudioManager = service.getSystemService(AudioManager.class); mIsVolumeFixed = mAudioManager.isVolumeFixed(); mIsVolumeFixed = mAudioManager.isVolumeFixed() || isControllerAbsoluteVolumeEnabled; setInitialState(mDisconnected); Loading Loading @@ -1171,8 +1172,15 @@ class AvrcpControllerStateMachine extends StateMachine { int maxLocalVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int curLocalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int reqLocalVolume = (maxLocalVolume * absVol) / ABS_VOL_BASE; debug("setAbsVolme: absVol = " + absVol + ", reqLocal = " + reqLocalVolume + ", curLocal = " + curLocalVolume + ", maxLocal = " + maxLocalVolume); debug( "setAbsVolume: absVol = " + absVol + ", reqLocal = " + reqLocalVolume + ", curLocal = " + curLocalVolume + ", maxLocal = " + maxLocalVolume); /* * In some cases change in percentage is not sufficient enough to warrant Loading
android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java +51 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,8 @@ public class AvrcpControllerStateMachineTest { */ private AvrcpControllerStateMachine makeStateMachine(BluetoothDevice device) { AvrcpControllerStateMachine sm = new AvrcpControllerStateMachine(device, mAvrcpControllerService, mNativeInterface); new AvrcpControllerStateMachine( device, mAvrcpControllerService, mNativeInterface, false); sm.start(); return sm; } Loading Loading @@ -1119,6 +1120,55 @@ public class AvrcpControllerStateMachineTest { .sendRegisterAbsVolRsp(any(), anyByte(), eq(127), eq((int) label)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsFixed_setsAbsVolumeBase() { byte label = 42; setUpConnectedState(true, true); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(127), eq((int) label)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsNotFixed_setsAbsVolumeBase() { doReturn(false).when(mAudioManager).isVolumeFixed(); mAvrcpStateMachine = new AvrcpControllerStateMachine( mTestDevice, mAvrcpControllerService, mNativeInterface, false); mAvrcpStateMachine.start(); byte label = 42; setUpConnectedState(true, true); doReturn(100).when(mAudioManager).getStreamMaxVolume(eq(AudioManager.STREAM_MUSIC)); doReturn(25).when(mAudioManager).getStreamVolume(eq(AudioManager.STREAM_MUSIC)); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(20), eq((int) label)); verify(mAudioManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .setStreamVolume( eq(AudioManager.STREAM_MUSIC), eq(15), eq(AudioManager.FLAG_SHOW_UI)); } /** Test that set absolute volume is working */ @Test public void testSetAbsoluteVolume_volumeIsNotFixedSinkAbsoluteVolumeEnabled_setsAbsVolumeBase() { doReturn(false).when(mAudioManager).isVolumeFixed(); mAvrcpStateMachine = new AvrcpControllerStateMachine( mTestDevice, mAvrcpControllerService, mNativeInterface, true); mAvrcpStateMachine.start(); byte label = 42; setUpConnectedState(true, true); mAvrcpStateMachine.sendMessage( AvrcpControllerStateMachine.MESSAGE_PROCESS_SET_ABS_VOL_CMD, 20, label); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)) .sendAbsVolRsp(any(), eq(127), eq((int) label)); } /** * Test playback does not request focus when another app is playing music. */ Loading