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

Commit d243d11a authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issue with sending BluetoothCallQualityReport to Telecom.

The negative ack count would always be zero due to the fact that both
packetsNotReceivedCount and negativeAcknowledgementCount were assigned to
the packetsNotReceivedCount property of the builder.

Modified isNullCall to call BluetoothCall#isCallNull so that the result
can be mocked out to facilitate the unit test (otherwise we'd need to be
able to return a mock android.telecom.Call which is not possible due to
the fact it is a final class).

Tag: #stability
Test: atest BluetoothInCallServiceTest
Bug: 200389658
Change-Id: I5af150fda830b036f278552782f394989586acb9
parent dd070462
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ public class BluetoothCall {
        return mCall;
    }

    public boolean isCallNull() {
        return mCall == null;
    }

    public void setCall(Call call) {
        mCall = call;
    }
+2 −2
Original line number Diff line number Diff line
@@ -492,7 +492,7 @@ public class BluetoothInCallService extends InCallService {
                        .setSnrDb(snr)
                        .setRetransmittedPacketsCount(retransmissionCount)
                        .setPacketsNotReceivedCount(packetsNotReceiveCount)
                        .setPacketsNotReceivedCount(negativeAcknowledgementCount)
                        .setNegativeAcknowledgementCount(negativeAcknowledgementCount)
                        .build());
        call.sendCallEvent(
                BluetoothCallQualityReport.EVENT_BLUETOOTH_CALL_QUALITY_REPORT, b);
@@ -1145,7 +1145,7 @@ public class BluetoothInCallService extends InCallService {
        }

        public boolean isNullCall(BluetoothCall call) {
            return call == null || call.getCall() == null;
            return call == null || call.isCallNull();
        }
    };
};
+37 −0
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.telecom.BluetoothCallQualityReport;
import android.telecom.Call;
import android.telecom.Connection;
import android.telecom.GatewayInfo;
@@ -49,6 +51,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -256,6 +259,40 @@ public class BluetoothInCallServiceTest {
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

    /**
     * Verifies bluetooth call quality reports are properly parceled and set as a call event to
     * Telecom.
     */
    @Test
    public void testBluetoothCallQualityReport() {
        BluetoothCall activeCall = createForegroundCall();
        when(activeCall.isCallNull()).thenReturn(false);
        mBluetoothInCallService.onCallAdded(activeCall);

        mBluetoothInCallService.sendBluetoothCallQualityReport(
                10, // long timestamp
                20, // int rssi
                30, // int snr
                40, // int retransmissionCount
                50, // int packetsNotReceiveCount
                60 // int negativeAcknowledgementCount
        );

        ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
        verify(activeCall).sendCallEvent(
                eq(BluetoothCallQualityReport.EVENT_BLUETOOTH_CALL_QUALITY_REPORT),
                bundleCaptor.capture());
        Bundle bundle = bundleCaptor.getValue();
        BluetoothCallQualityReport report = (BluetoothCallQualityReport) bundle.get(
                BluetoothCallQualityReport.EXTRA_BLUETOOTH_CALL_QUALITY_REPORT);
        Assert.assertEquals(10, report.getSentTimestampMillis());
        Assert.assertEquals(20, report.getRssiDbm());
        Assert.assertEquals(30, report.getSnrDb());
        Assert.assertEquals(40, report.getRetransmittedPacketsCount());
        Assert.assertEquals(50, report.getPacketsNotReceivedCount());
        Assert.assertEquals(60, report.getNegativeAcknowledgementCount());
    }

    @Test
    public void testListCurrentCallsSilentRinging() throws Exception {
        ArrayList<BluetoothCall> calls = new ArrayList<>();