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

Commit a9d39ace authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

mcp: Fix null pointer exception

Sponsor: jpawlowski@
Bug: 203499147
Bug: 150670922
Test: atest MediaControlGattServiceTest
Change-Id: Ica269bd8f90f318a77b8598cc5b59436d7db2789
parent d8365b3d
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);
    }
}