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

Commit e1810e60 authored by Kyunglyul Hyun's avatar Kyunglyul Hyun Committed by Automerger Merge Worker
Browse files

Merge "mcp: Fix NPE from getMediaStateChar" am: 2ecced65

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1932799

Change-Id: I0eae7c5e866c0593f16713179f2ba2438a650aaa
parents 95b6829a 2ecced65
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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) {
+21 −0
Original line number Diff line number Diff line
@@ -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);
    }
}