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 android.telephony.ims;
18 
19 import android.annotation.IntDef;
20 import android.annotation.IntRange;
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.telephony.AccessNetworkConstants.TransportType;
26 
27 import java.util.Objects;
28 
29 /**
30  * A representation of Media quality status.
31  *
32  * @hide
33  */
34 @SystemApi
35 public final class MediaQualityStatus implements Parcelable {
36     public static final int MEDIA_SESSION_TYPE_AUDIO =  1;
37     public static final int MEDIA_SESSION_TYPE_VIDEO =  2;
38 
39     private final String mImsCallSessionId;
40     private final int mMediaSessionType;
41     private final int mTransportType;
42     private final int mRtpPacketLossRate;
43     private final int mRtpJitterMillis;
44     private final long mRtpInactivityTimeMillis;
45 
46     /** @hide */
47     @IntDef(
48             value = {
49                     MEDIA_SESSION_TYPE_AUDIO,
50                     MEDIA_SESSION_TYPE_VIDEO,
51             })
52     public @interface MediaSessionType {}
53 
54     /**
55      * The constructor for MediaQualityStatus, which represents the media quality for each session
56      * type ({@link #MEDIA_SESSION_TYPE_AUDIO} or {@link #MEDIA_SESSION_TYPE_VIDEO}) of the IMS call
57      *
58      * @param imsCallSessionId IMS call session id of this quality status
59      * @param mediaSessionType media session type of this quality status
60      * @param transportType transport type of this quality status
61      * @param rtpPacketLossRate measured RTP packet loss rate in percentage
62      * @param rtpJitterMillis measured RTP jitter(RFC3550) in milliseconds
63      * @param rptInactivityTimeMillis measured RTP inactivity time in milliseconds
64      */
MediaQualityStatus(@onNull String imsCallSessionId, @MediaSessionType int mediaSessionType, @TransportType int transportType, @IntRange(from = 0, to = 100) int rtpPacketLossRate, @IntRange(from = 0) int rtpJitterMillis, @IntRange(from = 0) long rptInactivityTimeMillis)65     public MediaQualityStatus(@NonNull String imsCallSessionId,
66             @MediaSessionType int mediaSessionType, @TransportType int transportType,
67             @IntRange(from = 0, to = 100) int rtpPacketLossRate,
68             @IntRange(from = 0) int rtpJitterMillis,
69             @IntRange(from = 0) long rptInactivityTimeMillis) {
70         mImsCallSessionId = imsCallSessionId;
71         mMediaSessionType = mediaSessionType;
72         mTransportType = transportType;
73         mRtpPacketLossRate = rtpPacketLossRate;
74         mRtpJitterMillis = rtpJitterMillis;
75         mRtpInactivityTimeMillis = rptInactivityTimeMillis;
76     }
77 
78     /**
79      * Retrieves call session ID for this quality status
80      */
81     @NonNull
getCallSessionId()82     public String getCallSessionId() {
83         return mImsCallSessionId;
84     }
85 
86     /**
87      * Retrieves media session type of this quality status
88      */
getMediaSessionType()89     public @MediaSessionType int getMediaSessionType() {
90         return mMediaSessionType;
91     }
92 
93 
94     /**
95      * Retrieves Transport type for which this media quality was measured.
96      */
getTransportType()97     public @TransportType int getTransportType() {
98         return mTransportType;
99     }
100 
101     /**
102      * Retrieves measured RTP packet loss rate in percentage.
103      */
104     @IntRange(from = 0, to = 100)
getRtpPacketLossRate()105     public int getRtpPacketLossRate() {
106         return mRtpPacketLossRate;
107     }
108 
109     /**
110      * Retrieves measured RTP jitter(RFC3550) value in milliseconds
111      */
112     @IntRange(from = 0)
getRtpJitterMillis()113     public int getRtpJitterMillis() {
114         return mRtpJitterMillis;
115     }
116 
117     /**
118      * Retrieves measured RTP inactivity time in milliseconds
119      */
120     @IntRange(from = 0)
getRtpInactivityMillis()121     public long getRtpInactivityMillis() {
122         return mRtpInactivityTimeMillis;
123     }
124 
125     /**
126      * Creates a new instance of {@link MediaQualityStatus} from a parcel.
127      * @param in The parceled data to read.
128      */
MediaQualityStatus(@onNull Parcel in)129     private MediaQualityStatus(@NonNull Parcel in) {
130         mImsCallSessionId = in.readString();
131         mMediaSessionType = in.readInt();
132         mTransportType = in.readInt();
133         mRtpPacketLossRate = in.readInt();
134         mRtpJitterMillis = in.readInt();
135         mRtpInactivityTimeMillis = in.readLong();
136     }
137 
138     @Override
writeToParcel(@onNull Parcel dest, int flags)139     public void writeToParcel(@NonNull Parcel dest, int flags) {
140         dest.writeString(mImsCallSessionId);
141         dest.writeInt(mMediaSessionType);
142         dest.writeInt(mTransportType);
143         dest.writeInt(mRtpPacketLossRate);
144         dest.writeInt(mRtpJitterMillis);
145         dest.writeLong(mRtpInactivityTimeMillis);
146     }
147 
148     public static final @NonNull Creator<MediaQualityStatus> CREATOR =
149             new Creator<MediaQualityStatus>() {
150                 @Override
151                 public MediaQualityStatus createFromParcel(@NonNull Parcel in) {
152                     return new MediaQualityStatus(in);
153                 }
154 
155                 @Override
156                 public MediaQualityStatus[] newArray(int size) {
157                     return new MediaQualityStatus[size];
158                 }
159             };
160 
161     @Override
describeContents()162     public int describeContents() {
163         return 0;
164     }
165 
166     @Override
equals(Object o)167     public boolean equals(Object o) {
168         if (this == o) return true;
169         if (o == null || getClass() != o.getClass()) return false;
170         MediaQualityStatus that = (MediaQualityStatus) o;
171         return mImsCallSessionId != null && mImsCallSessionId.equals(that.mImsCallSessionId)
172                 && mMediaSessionType == that.mMediaSessionType
173                 && mTransportType == that.mTransportType
174                 && mRtpPacketLossRate == that.mRtpPacketLossRate
175                 && mRtpJitterMillis == that.mRtpJitterMillis
176                 && mRtpInactivityTimeMillis == that.mRtpInactivityTimeMillis;
177     }
178 
179     @Override
hashCode()180     public int hashCode() {
181         return Objects.hash(mImsCallSessionId, mMediaSessionType, mTransportType,
182                 mRtpPacketLossRate, mRtpJitterMillis, mRtpInactivityTimeMillis);
183     }
184 
185     @Override
toString()186     public String toString() {
187         StringBuilder sb = new StringBuilder();
188         sb.append("MediaThreshold{mImsCallSessionId=");
189         sb.append(mImsCallSessionId);
190         sb.append(", mMediaSessionType=");
191         sb.append(mMediaSessionType);
192         sb.append(", mTransportType=");
193         sb.append(mTransportType);
194         sb.append(", mRtpPacketLossRate=");
195         sb.append(mRtpPacketLossRate);
196         sb.append(", mRtpJitterMillis=");
197         sb.append(mRtpJitterMillis);
198         sb.append(", mRtpInactivityTimeMillis=");
199         sb.append(mRtpInactivityTimeMillis);
200         sb.append("}");
201         return sb.toString();
202     }
203 }
204