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

Commit 3aecac67 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
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1831254
Merged-In: Ibd6dc8d61f3f52abed7afbeac3f027a0630ea40a
Change-Id: Ibd6dc8d61f3f52abed7afbeac3f027a0630ea40a
(cherry picked from commit 4ab9aeeea5b79194c78c944c631f8a21c8105cbb)
parent e68a810b
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
@@ -497,7 +497,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);
@@ -1152,7 +1152,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
@@ -22,6 +22,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;

@@ -35,7 +36,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;
@@ -257,6 +260,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<>();