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

Commit 24982535 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge "mcp: Fix null pointer exception"

parents 8fb64ca9 a9d39ace
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1119,7 +1119,7 @@ public class MediaControlGattService implements MediaControlGattServiceInterface

        if (stateFields.containsKey(PlayerStateField.PLAYER_NAME)) {
            String name = (String) stateFields.get(PlayerStateField.PLAYER_NAME);
            if (name.compareTo(getPlayerNameChar()) != 0) {
            if ((getPlayerNameChar() != null) && (name.compareTo(getPlayerNameChar()) != 0)) {
                updatePlayerNameChar(name, doNotifyValueChange);

                // Most likely the player has changed - request critical info fields
+21 −0
Original line number Diff line number Diff line
@@ -1137,4 +1137,25 @@ public class MediaControlGattServiceTest {
                .sendResponse(eq(mCurrentDevice), eq(1),
                        eq(BluetoothGatt.GATT_INSUFFICIENT_AUTHORIZATION), eq(0), any());
    }

    @Test
    public void testUpdatePlayerNameFromNull() {
        BluetoothGattService service = initAllFeaturesGattService();

        BluetoothGattCharacteristic characteristic =
                service.getCharacteristic(MediaControlGattService.UUID_PLAYER_NAME);
        Assert.assertNotNull(characteristic);
        byte[] nullname = null;
        characteristic.setValue(nullname);

        prepareConnectedDevice();
        doReturn(BluetoothDevice.ACCESS_ALLOWED)
                .when(mMockMcpService)
                .getDeviceAuthorization(any(BluetoothDevice.class));

        Map<PlayerStateField, Object> state_map = new HashMap<>();
        String player_name = "TestPlayerName";
        state_map.put(PlayerStateField.PLAYER_NAME, player_name);
        mMcpService.updatePlayerState(state_map);
    }
}