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