1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.telephony.imsmedia; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.os.Parcel; 22 import android.telephony.CallQuality; 23 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(AndroidJUnit4.class) 30 public class CallQualityTest { 31 private static final int DOWNLINKCALLQUALITYLEVEL = 1; 32 private static final int UPLINKCALLQUALITYLEVEL = 2; 33 private static final int CALLDURATION = 40000; 34 private static final int NUMRTPPACKETSTRANSMITTED = 1600; 35 private static final int NUMRTPPACKETSRECEIVED = 1700; 36 private static final int NUMRTPPACKETSTRANSMITTEDLOST = 400; 37 private static final int NUMRTPPACKETSNOTRECEIVED = 42; 38 private static final int AVERAGERELATIVEJITTER = 30; 39 private static final int MAXRELATIVEJITTER = 40; 40 private static final int AVERAGEROUNDTRIPTIME = 100; 41 private static final int CODECTYPE = 1; 42 private static final boolean RTPINACTIVITYDETECTED = true; 43 private static final boolean RXSILENCEDETECTED = false; 44 private static final boolean TXSILENCEDETECTED = false; 45 private static final int NUMVOICEFRAMES = 100; 46 private static final int NUMNODATAFRAMES = 20; 47 private static final int NUMDROPPEDRTPPACKETS = 40; 48 private static final long MINPLAYOUTDELAYMILLIS = 200; 49 private static final long MAXPLAYOUTDELAYMILLIS = 1000; 50 private static final int NUMRTPSIDPACKETSRECEIVED = 20; 51 private static final int NUMRTPDUPLICATEPACKETS = 50; 52 createCallQuality()53 static CallQuality createCallQuality() { 54 return new CallQuality.Builder() 55 .setDownlinkCallQualityLevel(DOWNLINKCALLQUALITYLEVEL) 56 .setUplinkCallQualityLevel(UPLINKCALLQUALITYLEVEL) 57 .setCallDurationMillis(CALLDURATION) 58 .setNumRtpPacketsTransmitted(NUMRTPPACKETSTRANSMITTED) 59 .setNumRtpPacketsReceived(NUMRTPPACKETSRECEIVED) 60 .setNumRtpPacketsTransmittedLost(NUMRTPPACKETSTRANSMITTEDLOST) 61 .setNumRtpPacketsNotReceived(NUMRTPPACKETSNOTRECEIVED) 62 .setAverageRelativeJitter(AVERAGERELATIVEJITTER) 63 .setMaxRelativeJitter(MAXRELATIVEJITTER) 64 .setAverageRoundTripTimeMillis(AVERAGEROUNDTRIPTIME) 65 .setCodecType(CODECTYPE) 66 .setRtpInactivityDetected(RTPINACTIVITYDETECTED) 67 .setIncomingSilenceDetectedAtCallSetup(RXSILENCEDETECTED) 68 .setOutgoingSilenceDetectedAtCallSetup(TXSILENCEDETECTED) 69 .setNumVoiceFrames(NUMVOICEFRAMES) 70 .setNumNoDataFrames(NUMNODATAFRAMES) 71 .setNumDroppedRtpPackets(NUMDROPPEDRTPPACKETS) 72 .setMinPlayoutDelayMillis(MINPLAYOUTDELAYMILLIS) 73 .setMaxPlayoutDelayMillis(MAXPLAYOUTDELAYMILLIS) 74 .setNumRtpSidPacketsReceived(NUMRTPSIDPACKETSRECEIVED) 75 .setNumRtpDuplicatePackets(NUMRTPDUPLICATEPACKETS) 76 .build(); 77 } 78 createHalCallQuality()79 static android.hardware.radio.ims.media.CallQuality createHalCallQuality() { 80 final android.hardware.radio.ims.media.CallQuality callQuality = 81 new android.hardware.radio.ims.media.CallQuality(); 82 callQuality.downlinkCallQualityLevel = DOWNLINKCALLQUALITYLEVEL; 83 callQuality.uplinkCallQualityLevel = UPLINKCALLQUALITYLEVEL; 84 callQuality.callDuration = CALLDURATION; 85 callQuality.numRtpPacketsTransmitted = NUMRTPPACKETSTRANSMITTED; 86 callQuality.numRtpPacketsReceived = NUMRTPPACKETSRECEIVED; 87 callQuality.numRtpPacketsTransmittedLost = NUMRTPPACKETSTRANSMITTEDLOST; 88 callQuality.numRtpPacketsNotReceived = NUMRTPPACKETSNOTRECEIVED; 89 callQuality.averageRelativeJitter = AVERAGERELATIVEJITTER; 90 callQuality.maxRelativeJitter = MAXRELATIVEJITTER; 91 callQuality.averageRoundTripTime = AVERAGEROUNDTRIPTIME; 92 callQuality.codecType = CODECTYPE; 93 callQuality.rtpInactivityDetected = RTPINACTIVITYDETECTED; 94 callQuality.rxSilenceDetected = RXSILENCEDETECTED; 95 callQuality.txSilenceDetected = TXSILENCEDETECTED; 96 callQuality.numVoiceFrames = NUMVOICEFRAMES; 97 callQuality.numNoDataFrames = NUMNODATAFRAMES; 98 callQuality.numDroppedRtpPackets = NUMDROPPEDRTPPACKETS; 99 callQuality.minPlayoutDelayMillis = MINPLAYOUTDELAYMILLIS; 100 callQuality.maxPlayoutDelayMillis = MAXPLAYOUTDELAYMILLIS; 101 callQuality.numRtpSidPacketsReceived = NUMRTPSIDPACKETSRECEIVED; 102 callQuality.numRtpDuplicatePackets = NUMRTPDUPLICATEPACKETS; 103 return callQuality; 104 } 105 106 @Test testConstructorAndGetters()107 public void testConstructorAndGetters() { 108 CallQuality callQuality = createCallQuality(); 109 110 assertThat(callQuality.getDownlinkCallQualityLevel()).isEqualTo(DOWNLINKCALLQUALITYLEVEL); 111 assertThat(callQuality.getUplinkCallQualityLevel()).isEqualTo(UPLINKCALLQUALITYLEVEL); 112 assertThat(callQuality.getCallDuration()).isEqualTo(CALLDURATION); 113 assertThat(callQuality.getNumRtpPacketsTransmitted()).isEqualTo(NUMRTPPACKETSTRANSMITTED); 114 assertThat(callQuality.getNumRtpPacketsReceived()).isEqualTo(NUMRTPPACKETSRECEIVED); 115 assertThat(callQuality.getNumRtpPacketsTransmittedLost()) 116 .isEqualTo(NUMRTPPACKETSTRANSMITTEDLOST); 117 assertThat(callQuality.getNumRtpPacketsNotReceived()).isEqualTo(NUMRTPPACKETSNOTRECEIVED); 118 assertThat(callQuality.getAverageRelativeJitter()).isEqualTo(AVERAGERELATIVEJITTER); 119 assertThat(callQuality.getMaxRelativeJitter()).isEqualTo(MAXRELATIVEJITTER); 120 assertThat(callQuality.getAverageRoundTripTime()).isEqualTo(AVERAGEROUNDTRIPTIME); 121 assertThat(callQuality.getCodecType()).isEqualTo(CODECTYPE); 122 assertThat(callQuality.isRtpInactivityDetected()).isEqualTo(RTPINACTIVITYDETECTED); 123 assertThat(callQuality.isIncomingSilenceDetectedAtCallSetup()).isEqualTo(RXSILENCEDETECTED); 124 assertThat(callQuality.isOutgoingSilenceDetectedAtCallSetup()).isEqualTo(TXSILENCEDETECTED); 125 assertThat(callQuality.getNumVoiceFrames()).isEqualTo(NUMVOICEFRAMES); 126 assertThat(callQuality.getNumNoDataFrames()).isEqualTo(NUMNODATAFRAMES); 127 assertThat(callQuality.getNumDroppedRtpPackets()).isEqualTo(NUMDROPPEDRTPPACKETS); 128 assertThat(callQuality.getMinPlayoutDelayMillis()).isEqualTo(MINPLAYOUTDELAYMILLIS); 129 assertThat(callQuality.getMaxPlayoutDelayMillis()).isEqualTo(MAXPLAYOUTDELAYMILLIS); 130 assertThat(callQuality.getNumRtpSidPacketsReceived()).isEqualTo(NUMRTPSIDPACKETSRECEIVED); 131 assertThat(callQuality.getNumRtpDuplicatePackets()).isEqualTo(NUMRTPDUPLICATEPACKETS); 132 } 133 134 @Test testParcel()135 public void testParcel() { 136 CallQuality callQuality = createCallQuality(); 137 138 Parcel parcel = Parcel.obtain(); 139 callQuality.writeToParcel(parcel, 0); 140 parcel.setDataPosition(0); 141 142 CallQuality parcelConfig = CallQuality.CREATOR.createFromParcel(parcel); 143 assertThat(callQuality).isEqualTo(parcelConfig); 144 } 145 146 @Test testEqual()147 public void testEqual() { 148 CallQuality callQuality1 = createCallQuality(); 149 CallQuality callQuality2 = createCallQuality(); 150 151 assertThat(callQuality1).isEqualTo(callQuality2); 152 } 153 154 @Test testNotEqual()155 public void testNotEqual() { 156 CallQuality callQuality1 = createCallQuality(); 157 CallQuality callQuality2 = new CallQuality.Builder() 158 .setDownlinkCallQualityLevel(DOWNLINKCALLQUALITYLEVEL) 159 .setUplinkCallQualityLevel(UPLINKCALLQUALITYLEVEL) 160 .setCallDurationMillis(CALLDURATION) 161 .setNumRtpPacketsTransmitted(NUMRTPPACKETSTRANSMITTED) 162 .setNumRtpPacketsReceived(NUMRTPPACKETSRECEIVED) 163 .setNumRtpPacketsTransmittedLost(NUMRTPPACKETSTRANSMITTEDLOST) 164 .setNumRtpPacketsNotReceived((NUMRTPPACKETSNOTRECEIVED + 1)) 165 .setAverageRelativeJitter(AVERAGERELATIVEJITTER) 166 .setMaxRelativeJitter(MAXRELATIVEJITTER) 167 .setAverageRoundTripTimeMillis(AVERAGEROUNDTRIPTIME) 168 .setCodecType(CODECTYPE) 169 .setRtpInactivityDetected(RTPINACTIVITYDETECTED) 170 .setIncomingSilenceDetectedAtCallSetup(RXSILENCEDETECTED) 171 .setOutgoingSilenceDetectedAtCallSetup(TXSILENCEDETECTED) 172 .setNumVoiceFrames(NUMVOICEFRAMES) 173 .setNumNoDataFrames(NUMNODATAFRAMES) 174 .setNumDroppedRtpPackets(NUMDROPPEDRTPPACKETS) 175 .setMinPlayoutDelayMillis(MINPLAYOUTDELAYMILLIS) 176 .setMaxPlayoutDelayMillis(MAXPLAYOUTDELAYMILLIS) 177 .setNumRtpSidPacketsReceived(NUMRTPSIDPACKETSRECEIVED) 178 .setNumRtpDuplicatePackets(NUMRTPDUPLICATEPACKETS) 179 .build(); 180 assertThat(callQuality1).isNotEqualTo(callQuality2); 181 } 182 } 183