Loading android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java +8 −2 Original line number Diff line number Diff line Loading @@ -995,14 +995,20 @@ public class MediaControlGattService implements MediaControlGattServiceInterface } } private int getMediaStateChar() { @VisibleForTesting int getMediaStateChar() { if (!isFeatureSupported(ServiceFeature.MEDIA_STATE)) return MediaState.INACTIVE.getValue(); BluetoothGattCharacteristic stateChar = mCharacteristics.get(CharId.MEDIA_STATE); if (stateChar.getValue() != null) { return stateChar.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); } return MediaState.INACTIVE.getValue(); } @VisibleForTesting void updateMediaStateChar(int state) { if (DBG) { Loading android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -1158,4 +1158,25 @@ public class MediaControlGattServiceTest { state_map.put(PlayerStateField.PLAYER_NAME, player_name); mMcpService.updatePlayerState(state_map); } @Test public void testUpdatePlayerStateFromNullStateChar() { BluetoothGattService service = initAllFeaturesGattService(); BluetoothGattCharacteristic characteristic = service.getCharacteristic(MediaControlGattService.UUID_MEDIA_STATE); Assert.assertNotNull(characteristic); byte[] nullBytes = null; characteristic.setValue(nullBytes); prepareConnectedDevice(); doReturn(BluetoothDevice.ACCESS_ALLOWED) .when(mMockMcpService) .getDeviceAuthorization(any(BluetoothDevice.class)); Map<PlayerStateField, Object> state_map = new HashMap<>(); MediaState playback_state = MediaState.SEEKING; state_map.put(PlayerStateField.PLAYBACK_STATE, playback_state); mMcpService.updatePlayerState(state_map); } } Loading
android/app/src/com/android/bluetooth/mcp/MediaControlGattService.java +8 −2 Original line number Diff line number Diff line Loading @@ -995,14 +995,20 @@ public class MediaControlGattService implements MediaControlGattServiceInterface } } private int getMediaStateChar() { @VisibleForTesting int getMediaStateChar() { if (!isFeatureSupported(ServiceFeature.MEDIA_STATE)) return MediaState.INACTIVE.getValue(); BluetoothGattCharacteristic stateChar = mCharacteristics.get(CharId.MEDIA_STATE); if (stateChar.getValue() != null) { return stateChar.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); } return MediaState.INACTIVE.getValue(); } @VisibleForTesting void updateMediaStateChar(int state) { if (DBG) { Loading
android/app/tests/unit/src/com/android/bluetooth/mcp/MediaControlGattServiceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -1158,4 +1158,25 @@ public class MediaControlGattServiceTest { state_map.put(PlayerStateField.PLAYER_NAME, player_name); mMcpService.updatePlayerState(state_map); } @Test public void testUpdatePlayerStateFromNullStateChar() { BluetoothGattService service = initAllFeaturesGattService(); BluetoothGattCharacteristic characteristic = service.getCharacteristic(MediaControlGattService.UUID_MEDIA_STATE); Assert.assertNotNull(characteristic); byte[] nullBytes = null; characteristic.setValue(nullBytes); prepareConnectedDevice(); doReturn(BluetoothDevice.ACCESS_ALLOWED) .when(mMockMcpService) .getDeviceAuthorization(any(BluetoothDevice.class)); Map<PlayerStateField, Object> state_map = new HashMap<>(); MediaState playback_state = MediaState.SEEKING; state_map.put(PlayerStateField.PLAYBACK_STATE, playback_state); mMcpService.updatePlayerState(state_map); } }