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

Commit 99321739 authored by Jakub Rotkiewicz's avatar Jakub Rotkiewicz Committed by Jakub Rotkiewicz (xWF)
Browse files

TbsGatt: test null URI for incoming call

Test if provided nulled URI doesn't cause crash

Bug: 358527937
Test: atest TbsGenericTest
Flag: EXEMPT, test only
Change-Id: I2ccceb3e1d5a6a17f52c00447557be58134863c0
parent d26f2419
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -127,8 +127,11 @@ public class TbsCall {
    }

    public String getSafeUri() {
        if (mUri != null) {
            return Uri.parse(mUri).toSafeString();
        }
        return null;
    }

    public int getFlags() {
        return mFlags;
+32 −0
Original line number Diff line number Diff line
@@ -222,6 +222,38 @@ public class TbsGenericTest {
        assertThat(capturedTbsCall.getFriendlyName()).isEqualTo("aFriendlyCaller");
    }

    @Test
    public void testCallAddedWithNullUri() {
        Integer ccid = prepareTestBearer();
        reset(mTbsGatt);

        BluetoothLeCall tbsCall =
                new BluetoothLeCall(
                        UUID.randomUUID(),
                        null,
                        "aFriendlyCaller",
                        BluetoothLeCall.STATE_INCOMING,
                        0);
        mTbsGeneric.callAdded(ccid, tbsCall);

        ArgumentCaptor<Integer> callIndexCaptor = ArgumentCaptor.forClass(Integer.class);
        verify(mTbsGatt).setIncomingCall(callIndexCaptor.capture(), eq(null));
        Integer capturedCallIndex = callIndexCaptor.getValue();
        verify(mTbsGatt).setCallFriendlyName(eq(capturedCallIndex), eq("aFriendlyCaller"));
        ArgumentCaptor<Map> currentCallsCaptor = ArgumentCaptor.forClass(Map.class);
        verify(mTbsGatt).setCallState(currentCallsCaptor.capture());
        Map<Integer, TbsCall> capturedCurrentCalls = currentCallsCaptor.getValue();
        assertThat(capturedCurrentCalls.size()).isEqualTo(1);
        TbsCall capturedTbsCall = capturedCurrentCalls.get(capturedCallIndex);
        assertThat(capturedTbsCall).isNotNull();
        assertThat(capturedTbsCall.getState()).isEqualTo(BluetoothLeCall.STATE_INCOMING);
        assertThat(capturedTbsCall.getUri()).isEqualTo(null);
        assertThat(capturedTbsCall.getSafeUri()).isEqualTo(null);
        assertThat(capturedTbsCall.getFlags()).isEqualTo(0);
        assertThat(capturedTbsCall.isIncoming()).isTrue();
        assertThat(capturedTbsCall.getFriendlyName()).isEqualTo("aFriendlyCaller");
    }

    @Test
    public void testCallRemoved() {
        Integer ccid = prepareTestBearer();