1 /*
2  * Copyright (C) 2018 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 android.telephony;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.Objects;
29 
30 /**
31  * Parcelable object to handle call quality.
32  * <p>
33  * Currently this supports IMS calls.
34  * <p>
35  * It provides the call quality level, duration, and additional information related to RTP packets,
36  * jitter and delay.
37  * <p>
38  * If there are multiple active calls, the CallQuality will pertain to the call in the foreground.
39  *
40  * @hide
41  */
42 @SystemApi
43 public final class CallQuality implements Parcelable {
44 
45     // Constants representing the call quality level (see #CallQuality);
46     public static final int CALL_QUALITY_EXCELLENT = 0;
47     public static final int CALL_QUALITY_GOOD = 1;
48     public static final int CALL_QUALITY_FAIR = 2;
49     public static final int CALL_QUALITY_POOR = 3;
50     public static final int CALL_QUALITY_BAD = 4;
51     public static final int CALL_QUALITY_NOT_AVAILABLE = 5;
52 
53     /**
54      * Call quality
55      * @hide
56      */
57     @IntDef(prefix = { "CALL_QUALITY_" }, value = {
58             CALL_QUALITY_EXCELLENT,
59             CALL_QUALITY_GOOD,
60             CALL_QUALITY_FAIR,
61             CALL_QUALITY_POOR,
62             CALL_QUALITY_BAD,
63             CALL_QUALITY_NOT_AVAILABLE,
64     })
65     @Retention(RetentionPolicy.SOURCE)
66     public @interface CallQualityLevel {}
67 
68     @CallQualityLevel
69     private int mDownlinkCallQualityLevel;
70     @CallQualityLevel
71     private int mUplinkCallQualityLevel;
72     private int mCallDuration;
73     private int mNumRtpPacketsTransmitted;
74     private int mNumRtpPacketsReceived;
75     private int mNumRtpPacketsTransmittedLost;
76     private int mNumRtpPacketsNotReceived;
77     private int mAverageRelativeJitter;
78     private int mMaxRelativeJitter;
79     private int mAverageRoundTripTime;
80     private int mCodecType;
81     private boolean mRtpInactivityDetected;
82     private boolean mRxSilenceDetected;
83     private boolean mTxSilenceDetected;
84     private int mNumVoiceFrames;
85     private int mNumNoDataFrames;
86     private int mNumDroppedRtpPackets;
87     private long mMinPlayoutDelayMillis;
88     private long mMaxPlayoutDelayMillis;
89     private int mNumRtpSidPacketsReceived;
90     private int mNumRtpDuplicatePackets;
91 
92     /** @hide **/
CallQuality(Parcel in)93     public CallQuality(Parcel in) {
94         mDownlinkCallQualityLevel = in.readInt();
95         mUplinkCallQualityLevel = in.readInt();
96         mCallDuration = in.readInt();
97         mNumRtpPacketsTransmitted = in.readInt();
98         mNumRtpPacketsReceived = in.readInt();
99         mNumRtpPacketsTransmittedLost = in.readInt();
100         mNumRtpPacketsNotReceived = in.readInt();
101         mAverageRelativeJitter = in.readInt();
102         mMaxRelativeJitter = in.readInt();
103         mAverageRoundTripTime = in.readInt();
104         mCodecType = in.readInt();
105         mRtpInactivityDetected = in.readBoolean();
106         mRxSilenceDetected = in.readBoolean();
107         mTxSilenceDetected = in.readBoolean();
108         mNumVoiceFrames = in.readInt();
109         mNumNoDataFrames = in.readInt();
110         mNumDroppedRtpPackets = in.readInt();
111         mMinPlayoutDelayMillis = in.readLong();
112         mMaxPlayoutDelayMillis = in.readLong();
113         mNumRtpSidPacketsReceived = in.readInt();
114         mNumRtpDuplicatePackets = in.readInt();
115     }
116 
117     /** @hide **/
CallQuality()118     public CallQuality() {
119     }
120 
121     /**
122      * Constructor.
123      *
124      * @param callQualityLevel the call quality level (see #CallQualityLevel)
125      * @param callDuration the call duration in milliseconds
126      * @param numRtpPacketsTransmitted RTP packets sent to network
127      * @param numRtpPacketsReceived RTP packets received from network
128      * @param numRtpPacketsTransmittedLost RTP packets which were lost in network and never
129      * transmitted
130      * @param numRtpPacketsNotReceived RTP packets which were lost in network and never received
131      * @param averageRelativeJitter average relative jitter in milliseconds
132      * @param maxRelativeJitter maximum relative jitter in milliseconds
133      * @param averageRoundTripTime average round trip delay in milliseconds
134      * @param codecType the codec type
135      */
CallQuality( @allQualityLevel int downlinkCallQualityLevel, @CallQualityLevel int uplinkCallQualityLevel, int callDuration, int numRtpPacketsTransmitted, int numRtpPacketsReceived, int numRtpPacketsTransmittedLost, int numRtpPacketsNotReceived, int averageRelativeJitter, int maxRelativeJitter, int averageRoundTripTime, int codecType)136     public CallQuality(
137             @CallQualityLevel int downlinkCallQualityLevel,
138             @CallQualityLevel int uplinkCallQualityLevel,
139             int callDuration,
140             int numRtpPacketsTransmitted,
141             int numRtpPacketsReceived,
142             int numRtpPacketsTransmittedLost,
143             int numRtpPacketsNotReceived,
144             int averageRelativeJitter,
145             int maxRelativeJitter,
146             int averageRoundTripTime,
147             int codecType) {
148         this(downlinkCallQualityLevel, uplinkCallQualityLevel, callDuration,
149             numRtpPacketsTransmitted, numRtpPacketsReceived, numRtpPacketsTransmittedLost,
150             numRtpPacketsNotReceived, averageRelativeJitter, maxRelativeJitter,
151             averageRoundTripTime, codecType, false, false, false);
152     }
153 
154     /**
155      * Constructor.
156      *
157      * @param callQualityLevel the call quality level (see #CallQualityLevel)
158      * @param callDuration the call duration in milliseconds
159      * @param numRtpPacketsTransmitted RTP packets sent to network
160      * @param numRtpPacketsReceived RTP packets received from network
161      * @param numRtpPacketsTransmittedLost RTP packets which were lost in network and never
162      * transmitted
163      * @param numRtpPacketsNotReceived RTP packets which were lost in network and never received
164      * @param averageRelativeJitter average relative jitter in milliseconds
165      * @param maxRelativeJitter maximum relative jitter in milliseconds
166      * @param averageRoundTripTime average round trip delay in milliseconds
167      * @param codecType the codec type
168      * @param rtpInactivityDetected True if no incoming RTP is received for a continuous duration of
169      * 4 seconds
170      * @param rxSilenceDetected True if only silence RTP packets are received for 20 seconds
171      * immediately after call is connected
172      * @param txSilenceDetected True if only silence RTP packets are sent for 20 seconds immediately
173      * after call is connected
174      */
CallQuality( @allQualityLevel int downlinkCallQualityLevel, @CallQualityLevel int uplinkCallQualityLevel, int callDuration, int numRtpPacketsTransmitted, int numRtpPacketsReceived, int numRtpPacketsTransmittedLost, int numRtpPacketsNotReceived, int averageRelativeJitter, int maxRelativeJitter, int averageRoundTripTime, int codecType, boolean rtpInactivityDetected, boolean rxSilenceDetected, boolean txSilenceDetected)175     public CallQuality(
176             @CallQualityLevel int downlinkCallQualityLevel,
177             @CallQualityLevel int uplinkCallQualityLevel,
178             int callDuration,
179             int numRtpPacketsTransmitted,
180             int numRtpPacketsReceived,
181             int numRtpPacketsTransmittedLost,
182             int numRtpPacketsNotReceived,
183             int averageRelativeJitter,
184             int maxRelativeJitter,
185             int averageRoundTripTime,
186             int codecType,
187             boolean rtpInactivityDetected,
188             boolean rxSilenceDetected,
189             boolean txSilenceDetected) {
190         this.mDownlinkCallQualityLevel = downlinkCallQualityLevel;
191         this.mUplinkCallQualityLevel = uplinkCallQualityLevel;
192         this.mCallDuration = callDuration;
193         this.mNumRtpPacketsTransmitted = numRtpPacketsTransmitted;
194         this.mNumRtpPacketsReceived = numRtpPacketsReceived;
195         this.mNumRtpPacketsTransmittedLost = numRtpPacketsTransmittedLost;
196         this.mNumRtpPacketsNotReceived = numRtpPacketsNotReceived;
197         this.mAverageRelativeJitter = averageRelativeJitter;
198         this.mMaxRelativeJitter = maxRelativeJitter;
199         this.mAverageRoundTripTime = averageRoundTripTime;
200         this.mCodecType = codecType;
201         this.mRtpInactivityDetected = rtpInactivityDetected;
202         this.mRxSilenceDetected = rxSilenceDetected;
203         this.mTxSilenceDetected = txSilenceDetected;
204     }
205 
206     // getters
207     /**
208      * Returns the downlink CallQualityLevel for a given ongoing call.
209      */
210     @CallQualityLevel
getDownlinkCallQualityLevel()211     public int getDownlinkCallQualityLevel() {
212         return mDownlinkCallQualityLevel;
213     }
214 
215     /**
216      * Returns the uplink CallQualityLevel for a given ongoing call.
217      */
218     @CallQualityLevel
getUplinkCallQualityLevel()219     public int getUplinkCallQualityLevel() {
220         return mUplinkCallQualityLevel;
221     }
222 
223     /**
224      * Returns the duration of the call, in milliseconds.
225      */
getCallDuration()226     public int getCallDuration() {
227         return mCallDuration;
228     }
229 
230     /**
231      * Returns the total number of RTP packets transmitted by this device for a given ongoing call.
232      */
getNumRtpPacketsTransmitted()233     public int getNumRtpPacketsTransmitted() {
234         return mNumRtpPacketsTransmitted;
235     }
236 
237     /**
238      * Returns the total number of RTP packets received by this device for a given ongoing call.
239      */
getNumRtpPacketsReceived()240     public int getNumRtpPacketsReceived() {
241         return mNumRtpPacketsReceived;
242     }
243 
244     /**
245      * Returns the number of RTP packets which were sent by this device but were lost in the
246      * network before reaching the other party.
247      */
getNumRtpPacketsTransmittedLost()248     public int getNumRtpPacketsTransmittedLost() {
249         return mNumRtpPacketsTransmittedLost;
250     }
251 
252     /**
253      * Returns the number of RTP packets which were sent by the other party but were lost in the
254      * network before reaching this device.
255      */
getNumRtpPacketsNotReceived()256     public int getNumRtpPacketsNotReceived() {
257         return mNumRtpPacketsNotReceived;
258     }
259 
260     /**
261      * Returns the average relative jitter in milliseconds. Jitter represents the amount of variance
262      * in interarrival time of packets, for example, if two packets are sent 2 milliseconds apart
263      * but received 3 milliseconds apart, the relative jitter between those packets is 1
264      * millisecond.
265      *
266      * <p>See RFC 3550 for more information on jitter calculations.
267      */
getAverageRelativeJitter()268     public int getAverageRelativeJitter() {
269         return mAverageRelativeJitter;
270     }
271 
272     /**
273      * Returns the maximum relative jitter for a given ongoing call. Jitter represents the amount of
274      * variance in interarrival time of packets, for example, if two packets are sent 2 milliseconds
275      * apart but received 3 milliseconds apart, the relative jitter between those packets is 1
276      * millisecond.
277      *
278      * <p>See RFC 3550 for more information on jitter calculations.
279      */
getMaxRelativeJitter()280     public int getMaxRelativeJitter() {
281         return mMaxRelativeJitter;
282     }
283 
284     /**
285      * Returns the average round trip time in milliseconds.
286      */
getAverageRoundTripTime()287     public int getAverageRoundTripTime() {
288         return mAverageRoundTripTime;
289     }
290 
291     /**
292      * Returns true if no rtp packets are received continuously for the last 4 seconds
293      */
isRtpInactivityDetected()294     public boolean isRtpInactivityDetected() {
295         return mRtpInactivityDetected;
296     }
297 
298     /**
299      * Returns true if only silence rtp packets are received for a duration of 20 seconds starting
300      * at call setup
301      */
isIncomingSilenceDetectedAtCallSetup()302     public boolean isIncomingSilenceDetectedAtCallSetup() {
303         return mRxSilenceDetected;
304     }
305 
306     /**
307       * Returns true if only silence rtp packets are sent for a duration of 20 seconds starting at
308       * call setup
309       */
isOutgoingSilenceDetectedAtCallSetup()310     public boolean isOutgoingSilenceDetectedAtCallSetup() {
311         return mTxSilenceDetected;
312     }
313 
314     /**
315      * Returns the number of Voice frames sent by jitter buffer to audio
316      */
getNumVoiceFrames()317     public int getNumVoiceFrames() {
318         return mNumVoiceFrames;
319     }
320 
321     /**
322      * Returns the number of no-data frames sent by jitter buffer to audio
323      */
getNumNoDataFrames()324     public int getNumNoDataFrames() {
325         return mNumNoDataFrames;
326     }
327 
328     /**
329      * Returns the number of RTP voice packets dropped by jitter buffer
330      */
getNumDroppedRtpPackets()331     public int getNumDroppedRtpPackets() {
332         return mNumDroppedRtpPackets;
333     }
334 
335     /**
336      * Returns the minimum playout delay in the reporting interval
337      * in milliseconds.
338      */
getMinPlayoutDelayMillis()339     public long getMinPlayoutDelayMillis() {
340         return mMinPlayoutDelayMillis;
341     }
342 
343     /**
344      * Returns the maximum playout delay in the reporting interval
345      * in milliseconds.
346      */
getMaxPlayoutDelayMillis()347     public long getMaxPlayoutDelayMillis() {
348         return mMaxPlayoutDelayMillis;
349     }
350 
351     /**
352      * Returns the total number of RTP SID (Silence Insertion Descriptor) packets
353      * received by this device for an ongoing call
354      */
getNumRtpSidPacketsReceived()355     public int getNumRtpSidPacketsReceived() {
356         return mNumRtpSidPacketsReceived;
357     }
358 
359     /**
360      * Returns the total number of RTP duplicate packets received by this device
361      * for an ongoing call
362      */
getNumRtpDuplicatePackets()363     public int getNumRtpDuplicatePackets() {
364         return mNumRtpDuplicatePackets;
365     }
366 
367     /**
368      * Returns the codec type. This value corresponds to the AUDIO_QUALITY_* constants in
369      * {@link ImsStreamMediaProfile}.
370      *
371      * @see ImsStreamMediaProfile#AUDIO_QUALITY_NONE
372      * @see ImsStreamMediaProfile#AUDIO_QUALITY_AMR
373      * @see ImsStreamMediaProfile#AUDIO_QUALITY_AMR_WB
374      * @see ImsStreamMediaProfile#AUDIO_QUALITY_QCELP13K
375      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVRC
376      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVRC_B
377      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVRC_WB
378      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVRC_NW
379      * @see ImsStreamMediaProfile#AUDIO_QUALITY_GSM_EFR
380      * @see ImsStreamMediaProfile#AUDIO_QUALITY_GSM_FR
381      * @see ImsStreamMediaProfile#AUDIO_QUALITY_GSM_HR
382      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G711U
383      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G723
384      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G711A
385      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G722
386      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G711AB
387      * @see ImsStreamMediaProfile#AUDIO_QUALITY_G729
388      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVS_NB
389      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVS_WB
390      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVS_SWB
391      * @see ImsStreamMediaProfile#AUDIO_QUALITY_EVS_FB
392      */
getCodecType()393     public int getCodecType() {
394         return mCodecType;
395     }
396 
397     // Parcelable things
398     @NonNull
399     @Override
toString()400     public String toString() {
401         return "CallQuality: {downlinkCallQualityLevel=" + mDownlinkCallQualityLevel
402                 + " uplinkCallQualityLevel=" + mUplinkCallQualityLevel
403                 + " callDuration=" + mCallDuration
404                 + " numRtpPacketsTransmitted=" + mNumRtpPacketsTransmitted
405                 + " numRtpPacketsReceived=" + mNumRtpPacketsReceived
406                 + " numRtpPacketsTransmittedLost=" + mNumRtpPacketsTransmittedLost
407                 + " numRtpPacketsNotReceived=" + mNumRtpPacketsNotReceived
408                 + " averageRelativeJitter=" + mAverageRelativeJitter
409                 + " maxRelativeJitter=" + mMaxRelativeJitter
410                 + " averageRoundTripTime=" + mAverageRoundTripTime
411                 + " codecType=" + mCodecType
412                 + " rtpInactivityDetected=" + mRtpInactivityDetected
413                 + " txSilenceDetected=" + mTxSilenceDetected
414                 + " rxSilenceDetected=" + mRxSilenceDetected
415                 + " numVoiceFrames=" + mNumVoiceFrames
416                 + " numNoDataFrames=" + mNumNoDataFrames
417                 + " numDroppedRtpPackets=" + mNumDroppedRtpPackets
418                 + " minPlayoutDelayMillis=" + mMinPlayoutDelayMillis
419                 + " maxPlayoutDelayMillis=" + mMaxPlayoutDelayMillis
420                 + " numRtpSidPacketsReceived=" + mNumRtpSidPacketsReceived
421                 + " numRtpDuplicatePackets=" + mNumRtpDuplicatePackets
422                 + "}";
423     }
424 
425     @Override
hashCode()426     public int hashCode() {
427         return Objects.hash(
428                 mDownlinkCallQualityLevel,
429                 mUplinkCallQualityLevel,
430                 mCallDuration,
431                 mNumRtpPacketsTransmitted,
432                 mNumRtpPacketsReceived,
433                 mNumRtpPacketsTransmittedLost,
434                 mNumRtpPacketsNotReceived,
435                 mAverageRelativeJitter,
436                 mMaxRelativeJitter,
437                 mAverageRoundTripTime,
438                 mCodecType,
439                 mRtpInactivityDetected,
440                 mRxSilenceDetected,
441                 mTxSilenceDetected,
442                 mNumVoiceFrames,
443                 mNumNoDataFrames,
444                 mNumDroppedRtpPackets,
445                 mMinPlayoutDelayMillis,
446                 mMaxPlayoutDelayMillis,
447                 mNumRtpSidPacketsReceived,
448                 mNumRtpDuplicatePackets);
449     }
450 
451     @Override
equals(@ullable Object o)452     public boolean equals(@Nullable Object o) {
453         if (o == null || !(o instanceof CallQuality) || hashCode() != o.hashCode()) {
454             return false;
455         }
456 
457         if (this == o) {
458             return true;
459         }
460 
461         CallQuality s = (CallQuality) o;
462 
463         return (mDownlinkCallQualityLevel == s.mDownlinkCallQualityLevel
464                 && mUplinkCallQualityLevel == s.mUplinkCallQualityLevel
465                 && mCallDuration == s.mCallDuration
466                 && mNumRtpPacketsTransmitted == s.mNumRtpPacketsTransmitted
467                 && mNumRtpPacketsReceived == s.mNumRtpPacketsReceived
468                 && mNumRtpPacketsTransmittedLost == s.mNumRtpPacketsTransmittedLost
469                 && mNumRtpPacketsNotReceived == s.mNumRtpPacketsNotReceived
470                 && mAverageRelativeJitter == s.mAverageRelativeJitter
471                 && mMaxRelativeJitter == s.mMaxRelativeJitter
472                 && mAverageRoundTripTime == s.mAverageRoundTripTime
473                 && mCodecType == s.mCodecType
474                 && mRtpInactivityDetected == s.mRtpInactivityDetected
475                 && mRxSilenceDetected == s.mRxSilenceDetected
476                 && mTxSilenceDetected == s.mTxSilenceDetected
477                 && mNumVoiceFrames == s.mNumVoiceFrames
478                 && mNumNoDataFrames == s.mNumNoDataFrames
479                 && mNumDroppedRtpPackets == s.mNumDroppedRtpPackets
480                 && mMinPlayoutDelayMillis == s.mMinPlayoutDelayMillis
481                 && mMaxPlayoutDelayMillis == s.mMaxPlayoutDelayMillis
482                 && mNumRtpSidPacketsReceived == s.mNumRtpSidPacketsReceived
483                 && mNumRtpDuplicatePackets == s.mNumRtpDuplicatePackets);
484     }
485 
486     /**
487      * {@link Parcelable#describeContents}
488      */
describeContents()489     public int describeContents() {
490         return 0;
491     }
492 
493     /**
494      * {@link Parcelable#writeToParcel}
495      */
writeToParcel(Parcel dest, int flags)496     public void writeToParcel(Parcel dest, int flags) {
497         dest.writeInt(mDownlinkCallQualityLevel);
498         dest.writeInt(mUplinkCallQualityLevel);
499         dest.writeInt(mCallDuration);
500         dest.writeInt(mNumRtpPacketsTransmitted);
501         dest.writeInt(mNumRtpPacketsReceived);
502         dest.writeInt(mNumRtpPacketsTransmittedLost);
503         dest.writeInt(mNumRtpPacketsNotReceived);
504         dest.writeInt(mAverageRelativeJitter);
505         dest.writeInt(mMaxRelativeJitter);
506         dest.writeInt(mAverageRoundTripTime);
507         dest.writeInt(mCodecType);
508         dest.writeBoolean(mRtpInactivityDetected);
509         dest.writeBoolean(mRxSilenceDetected);
510         dest.writeBoolean(mTxSilenceDetected);
511         dest.writeInt(mNumVoiceFrames);
512         dest.writeInt(mNumNoDataFrames);
513         dest.writeInt(mNumDroppedRtpPackets);
514         dest.writeLong(mMinPlayoutDelayMillis);
515         dest.writeLong(mMaxPlayoutDelayMillis);
516         dest.writeInt(mNumRtpSidPacketsReceived);
517         dest.writeInt(mNumRtpDuplicatePackets);
518     }
519 
520     public static final @android.annotation.NonNull Parcelable.Creator<CallQuality> CREATOR = new Parcelable.Creator() {
521         public CallQuality createFromParcel(Parcel in) {
522             return new CallQuality(in);
523         }
524 
525         public CallQuality[] newArray(int size) {
526             return new CallQuality[size];
527         }
528     };
529 
530     /**
531      * Provides a convenient way to set the fields of a {@link CallQuality} when creating a new
532      * instance.
533      *
534      * <p>The example below shows how you might create a new {@code CallQuality}:
535      *
536      * <pre><code>
537      *
538      * CallQuality callQuality = new CallQuality.Builder()
539      *     .setNumRtpPacketsTransmitted(150)
540      *     .setNumRtpPacketsReceived(200)
541      *     .build();
542      * </code></pre>
543      */
544     public static final class Builder {
545 
546         private int mDownlinkCallQualityLevel;
547         private int mUplinkCallQualityLevel;
548         private int mCallDuration;
549         private int mNumRtpPacketsTransmitted;
550         private int mNumRtpPacketsReceived;
551         private int mNumRtpPacketsTransmittedLost;
552         private int mNumRtpPacketsNotReceived;
553         private int mAverageRelativeJitter;
554         private int mMaxRelativeJitter;
555         private int mAverageRoundTripTime;
556         private int mCodecType;
557         private boolean mRtpInactivityDetected;
558         private boolean mRxSilenceDetected;
559         private boolean mTxSilenceDetected;
560         private int mNumVoiceFrames;
561         private int mNumNoDataFrames;
562         private int mNumDroppedRtpPackets;
563         private long mMinPlayoutDelayMillis;
564         private long mMaxPlayoutDelayMillis;
565         private int mNumRtpSidPacketsReceived;
566         private int mNumRtpDuplicatePackets;
567 
568         /**
569          * Set the downlink call quality level for ongoing call.
570          *
571          * @param downlinkCallQualityLevel the Downlink call quality level
572          * @return The same instance of the builder.
573          */
setDownlinkCallQualityLevel( @allQualityLevel int downlinkCallQualityLevel)574         public @NonNull Builder setDownlinkCallQualityLevel(
575                 @CallQualityLevel int downlinkCallQualityLevel) {
576             mDownlinkCallQualityLevel = downlinkCallQualityLevel;
577             return this;
578         }
579 
580         /**
581          * Set the uplink call quality level for ongoing call.
582          *
583          * @param uplinkCallQualityLevel the Uplink call quality level
584          * @return The same instance of the builder.
585          */
setUplinkCallQualityLevel( @allQualityLevel int uplinkCallQualityLevel)586         public @NonNull Builder setUplinkCallQualityLevel(
587                 @CallQualityLevel int uplinkCallQualityLevel) {
588             mUplinkCallQualityLevel = uplinkCallQualityLevel;
589             return this;
590         }
591 
592         /**
593          * Set the call duration in milliseconds.
594          *
595          * @param callDuration the call duration in milliseconds
596          * @return The same instance of the builder.
597          */
598         // Newer builder includes guidelines compliant units; existing method does not.
599         @NonNull
600         @SuppressWarnings("MissingGetterMatchingBuilder")
setCallDurationMillis(int callDurationMillis)601         public Builder setCallDurationMillis(int callDurationMillis) {
602             mCallDuration = callDurationMillis;
603             return this;
604         }
605 
606         /**
607          * Set the number of RTP packets sent for ongoing call.
608          *
609          * @param numRtpPacketsTransmitted RTP packets sent to network
610          * @return The same instance of the builder.
611          */
setNumRtpPacketsTransmitted(int numRtpPacketsTransmitted)612         public @NonNull Builder setNumRtpPacketsTransmitted(int numRtpPacketsTransmitted) {
613             mNumRtpPacketsTransmitted = numRtpPacketsTransmitted;
614             return this;
615         }
616 
617         /**
618          * Set the number of RTP packets received for ongoing call.
619          *
620          * @param numRtpPacketsReceived RTP packets received from network
621          * @return The same instance of the builder.
622          */
setNumRtpPacketsReceived(int numRtpPacketsReceived)623         public @NonNull Builder setNumRtpPacketsReceived(int numRtpPacketsReceived) {
624             mNumRtpPacketsReceived = numRtpPacketsReceived;
625             return this;
626         }
627 
628         /**
629          * Set the number of RTP packets which were lost in network and never
630          * transmitted.
631          *
632          * @param numRtpPacketsTransmittedLost RTP packets which were lost in network and never
633          * transmitted
634          * @return The same instance of the builder.
635          */
setNumRtpPacketsTransmittedLost(int numRtpPacketsTransmittedLost)636         public @NonNull Builder setNumRtpPacketsTransmittedLost(int numRtpPacketsTransmittedLost) {
637             mNumRtpPacketsTransmittedLost = numRtpPacketsTransmittedLost;
638             return this;
639         }
640 
641         /**
642          * Set the number of RTP packets which were lost in network and never received.
643          *
644          * @param numRtpPacketsNotReceived RTP packets which were lost in network and
645          * never received
646          * @return The same instance of the builder.
647          */
setNumRtpPacketsNotReceived(int numRtpPacketsNotReceived)648         public @NonNull Builder setNumRtpPacketsNotReceived(int numRtpPacketsNotReceived) {
649             mNumRtpPacketsNotReceived = numRtpPacketsNotReceived;
650             return this;
651         }
652 
653         /**
654          * Set the average relative jitter in milliseconds.
655          *
656          * @param averageRelativeJitter average relative jitter in milliseconds
657          * @return The same instance of the builder.
658          */
setAverageRelativeJitter(int averageRelativeJitter)659         public @NonNull Builder setAverageRelativeJitter(int averageRelativeJitter) {
660             mAverageRelativeJitter = averageRelativeJitter;
661             return this;
662         }
663 
664         /**
665          * Set the maximum relative jitter in milliseconds.
666          *
667          * @param maxRelativeJitter maximum relative jitter in milliseconds
668          * @return The same instance of the builder.
669          */
setMaxRelativeJitter(int maxRelativeJitter)670         public @NonNull Builder setMaxRelativeJitter(int maxRelativeJitter) {
671             mMaxRelativeJitter = maxRelativeJitter;
672             return this;
673         }
674 
675         /**
676          * Set the average round trip delay in milliseconds.
677          *
678          * @param averageRoundTripTime average round trip delay in milliseconds
679          * @return The same instance of the builder.
680          */
681         // Newer builder includes guidelines compliant units; existing method does not.
682         @NonNull
683         @SuppressWarnings("MissingGetterMatchingBuilder")
setAverageRoundTripTimeMillis(int averageRoundTripTimeMillis)684         public Builder setAverageRoundTripTimeMillis(int averageRoundTripTimeMillis) {
685             mAverageRoundTripTime = averageRoundTripTimeMillis;
686             return this;
687         }
688 
689         /**
690          * Set the codec type used in the ongoing call.
691          *
692          * @param codecType the codec type.
693          * @return The same instance of the builder.
694          */
setCodecType(int codecType)695         public @NonNull Builder setCodecType(int codecType) {
696             mCodecType = codecType;
697             return this;
698         }
699 
700         /**
701          * Set to be True if no incoming RTP is received for a continuous
702          * duration of 4 seconds.
703          *
704          * @param rtpInactivityDetected True if no incoming RTP is received for
705          * a continuous duration of 4 seconds
706          * @return The same instance of the builder.
707          */
setRtpInactivityDetected(boolean rtpInactivityDetected)708         public @NonNull Builder setRtpInactivityDetected(boolean rtpInactivityDetected) {
709             mRtpInactivityDetected = rtpInactivityDetected;
710             return this;
711         }
712 
713         /**
714          * Set to be True if only silence RTP packets are received for 20 seconds
715          * immediately after call is connected.
716          *
717          * @param rxSilenceDetected True if only silence RTP packets are received for 20 seconds
718          * immediately after call is connected
719          * @return The same instance of the builder.
720          */
setIncomingSilenceDetectedAtCallSetup(boolean rxSilenceDetected)721         public @NonNull Builder setIncomingSilenceDetectedAtCallSetup(boolean rxSilenceDetected) {
722             mRxSilenceDetected = rxSilenceDetected;
723             return this;
724         }
725 
726         /**
727          * Set to be True if only silence RTP packets are sent for 20 seconds immediately
728          * after call is connected.
729          *
730          * @param txSilenceDetected True if only silence RTP packets are sent for
731          * 20 seconds immediately after call is connected.
732          * @return The same instance of the builder.
733          */
setOutgoingSilenceDetectedAtCallSetup(boolean txSilenceDetected)734         public @NonNull Builder setOutgoingSilenceDetectedAtCallSetup(boolean txSilenceDetected) {
735             mTxSilenceDetected = txSilenceDetected;
736             return this;
737         }
738 
739         /**
740          * Set the number of voice frames sent by jitter buffer to audio.
741          *
742          * @param numVoiceFrames Voice frames sent by jitter buffer to audio.
743          * @return The same instance of the builder.
744          */
setNumVoiceFrames(int numVoiceFrames)745         public @NonNull Builder setNumVoiceFrames(int numVoiceFrames) {
746             mNumVoiceFrames = numVoiceFrames;
747             return this;
748         }
749 
750         /**
751          * Set the number of no-data frames sent by jitter buffer to audio.
752          *
753          * @param numNoDataFrames no-data frames sent by jitter buffer to audio
754          * @return The same instance of the builder.
755          */
setNumNoDataFrames(int numNoDataFrames)756         public @NonNull Builder setNumNoDataFrames(int numNoDataFrames) {
757             mNumNoDataFrames = numNoDataFrames;
758             return this;
759         }
760 
761         /**
762          * Set the number of RTP Voice packets dropped by jitter buffer.
763          *
764          * @param numDroppedRtpPackets number of RTP Voice packets dropped by jitter buffer
765          * @return The same instance of the builder.
766          */
setNumDroppedRtpPackets(int numDroppedRtpPackets)767         public @NonNull Builder setNumDroppedRtpPackets(int numDroppedRtpPackets) {
768             mNumDroppedRtpPackets = numDroppedRtpPackets;
769             return this;
770         }
771 
772         /**
773          * Set the minimum playout delay in the reporting interval in milliseconds.
774          *
775          * @param minPlayoutDelayMillis minimum playout delay in the reporting interval
776          * @return The same instance of the builder.
777          */
setMinPlayoutDelayMillis(long minPlayoutDelayMillis)778         public @NonNull Builder setMinPlayoutDelayMillis(long minPlayoutDelayMillis) {
779             mMinPlayoutDelayMillis = minPlayoutDelayMillis;
780             return this;
781         }
782 
783         /**
784          * Set the maximum Playout delay in the reporting interval in milliseconds.
785          *
786          * @param maxPlayoutDelayMillis maximum Playout delay in the reporting interval
787          * @return The same instance of the builder.
788          */
setMaxPlayoutDelayMillis(long maxPlayoutDelayMillis)789         public @NonNull Builder setMaxPlayoutDelayMillis(long maxPlayoutDelayMillis) {
790             mMaxPlayoutDelayMillis = maxPlayoutDelayMillis;
791             return this;
792         }
793 
794         /**
795          * Set the total number of RTP SID (Silence Insertion Descriptor)
796          * packets received by this device for an ongoing call.
797          *
798          * @param numRtpSidPacketsReceived the total number of RTP SID packets received
799          * by this device for an ongoing call.
800          * @return The same instance of the builder.
801          */
setNumRtpSidPacketsReceived(int numRtpSidPacketsReceived)802         public @NonNull Builder setNumRtpSidPacketsReceived(int numRtpSidPacketsReceived) {
803             mNumRtpSidPacketsReceived = numRtpSidPacketsReceived;
804             return this;
805         }
806 
807         /**
808          * Set the total number of RTP duplicate packets received by this device
809          * for an ongoing call.
810          *
811          * @param numRtpDuplicatePackets the total number of RTP duplicate packets
812          * received by this device for an ongoing call
813          * @return The same instance of the builder.
814          */
setNumRtpDuplicatePackets(int numRtpDuplicatePackets)815         public @NonNull Builder setNumRtpDuplicatePackets(int numRtpDuplicatePackets) {
816             mNumRtpDuplicatePackets = numRtpDuplicatePackets;
817             return this;
818         }
819 
820         /**
821          * Build the CallQuality.
822          *
823          * @return the CallQuality object.
824          */
build()825         public @NonNull CallQuality build() {
826 
827             CallQuality callQuality = new CallQuality();
828             callQuality.mDownlinkCallQualityLevel = mDownlinkCallQualityLevel;
829             callQuality.mUplinkCallQualityLevel = mUplinkCallQualityLevel;
830             callQuality.mCallDuration = mCallDuration;
831             callQuality.mNumRtpPacketsTransmitted = mNumRtpPacketsTransmitted;
832             callQuality.mNumRtpPacketsReceived = mNumRtpPacketsReceived;
833             callQuality.mNumRtpPacketsTransmittedLost = mNumRtpPacketsTransmittedLost;
834             callQuality.mNumRtpPacketsNotReceived = mNumRtpPacketsNotReceived;
835             callQuality.mAverageRelativeJitter = mAverageRelativeJitter;
836             callQuality.mMaxRelativeJitter = mMaxRelativeJitter;
837             callQuality.mAverageRoundTripTime = mAverageRoundTripTime;
838             callQuality.mCodecType = mCodecType;
839             callQuality.mRtpInactivityDetected = mRtpInactivityDetected;
840             callQuality.mTxSilenceDetected = mTxSilenceDetected;
841             callQuality.mRxSilenceDetected = mRxSilenceDetected;
842             callQuality.mNumVoiceFrames = mNumVoiceFrames;
843             callQuality.mNumNoDataFrames = mNumNoDataFrames;
844             callQuality.mNumDroppedRtpPackets = mNumDroppedRtpPackets;
845             callQuality.mMinPlayoutDelayMillis = mMinPlayoutDelayMillis;
846             callQuality.mMaxPlayoutDelayMillis = mMaxPlayoutDelayMillis;
847             callQuality.mNumRtpSidPacketsReceived = mNumRtpSidPacketsReceived;
848             callQuality.mNumRtpDuplicatePackets = mNumRtpDuplicatePackets;
849 
850             return callQuality;
851         }
852     }
853 }
854