1 /** 2 * Copyright (C) 2023 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.imsmedia; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 25 import java.util.Objects; 26 27 /** 28 * Class to set the media quality status for notifications 29 * 30 * @hide 31 */ 32 33 public final class MediaQualityStatus implements Parcelable { 34 private final int mRtpInactivityTimeMillis; 35 private final int mRtcpInactivityTimeMillis; 36 private final int mRtpPacketLossRate; 37 private final int mRtpJitterMillis; 38 39 /** @hide **/ MediaQualityStatus(Parcel in)40 public MediaQualityStatus(Parcel in) { 41 mRtpInactivityTimeMillis = in.readInt(); 42 mRtcpInactivityTimeMillis = in.readInt(); 43 mRtpPacketLossRate = in.readInt(); 44 mRtpJitterMillis = in.readInt(); 45 } 46 47 /** @hide **/ MediaQualityStatus(Builder builder)48 public MediaQualityStatus(Builder builder) { 49 mRtpInactivityTimeMillis = builder.mRtpInactivityTimeMillis; 50 mRtcpInactivityTimeMillis = builder.mRtcpInactivityTimeMillis; 51 mRtpPacketLossRate = builder.mRtpPacketLossRate; 52 mRtpJitterMillis = builder.mRtpJitterMillis; 53 } 54 55 /** @hide **/ getRtpInactivityTimeMillis()56 public int getRtpInactivityTimeMillis() { 57 return mRtpInactivityTimeMillis; 58 } 59 60 /** @hide **/ getRtcpInactivityTimeMillis()61 public int getRtcpInactivityTimeMillis() { 62 return mRtcpInactivityTimeMillis; 63 } 64 65 /** @hide **/ getRtpPacketLossRate()66 public int getRtpPacketLossRate() { 67 return mRtpPacketLossRate; 68 } 69 70 /** @hide **/ getRtpJitterMillis()71 public int getRtpJitterMillis() { 72 return mRtpJitterMillis; 73 } 74 75 @NonNull 76 @Override toString()77 public String toString() { 78 return "MediaQualityStatus: {mRtpInactivityTimeMillis=" + mRtpInactivityTimeMillis 79 + ", mRtcpInactivityTimeMillis=" + mRtcpInactivityTimeMillis 80 + ", mRtpPacketLossRate=" + mRtpPacketLossRate 81 + ", mRtpJitterMillis=" + mRtpJitterMillis 82 + " }"; 83 } 84 85 @Override hashCode()86 public int hashCode() { 87 return Objects.hash( 88 mRtpInactivityTimeMillis, mRtcpInactivityTimeMillis, mRtpPacketLossRate, 89 mRtpJitterMillis); 90 } 91 92 @Override equals(@ullable Object o)93 public boolean equals(@Nullable Object o) { 94 if (o == null || !(o instanceof MediaQualityStatus) || hashCode() != o.hashCode()) { 95 return false; 96 } 97 98 if (this == o) { 99 return true; 100 } 101 102 MediaQualityStatus s = (MediaQualityStatus) o; 103 104 return (mRtpInactivityTimeMillis == s.mRtpInactivityTimeMillis 105 && mRtcpInactivityTimeMillis == s.mRtcpInactivityTimeMillis 106 && mRtpPacketLossRate == s.mRtpPacketLossRate 107 && mRtpJitterMillis == s.mRtpJitterMillis); 108 } 109 110 /** 111 * {@link Parcelable#describeContents} 112 */ describeContents()113 public int describeContents() { 114 return 0; 115 } 116 117 /** 118 * {@link Parcelable#writeToParcel} 119 */ writeToParcel(Parcel dest, int flags)120 public void writeToParcel(Parcel dest, int flags) { 121 dest.writeInt(mRtpInactivityTimeMillis); 122 dest.writeInt(mRtcpInactivityTimeMillis); 123 dest.writeInt(mRtpPacketLossRate); 124 dest.writeInt(mRtpJitterMillis); 125 } 126 127 public static final @NonNull Parcelable.Creator<MediaQualityStatus> 128 CREATOR = new Parcelable.Creator() { 129 public MediaQualityStatus createFromParcel(Parcel in) { 130 // TODO use builder class so it will validate 131 return new MediaQualityStatus(in); 132 } 133 134 public MediaQualityStatus[] newArray(int size) { 135 return new MediaQualityStatus[size]; 136 } 137 }; 138 139 /** 140 * Provides a convenient way to set the fields of a {@link MediaQualityStatus} 141 * when creating a new instance. 142 */ 143 public static final class Builder { 144 private int mRtpInactivityTimeMillis; 145 private int mRtcpInactivityTimeMillis; 146 private int mRtpPacketLossRate; 147 private int mRtpJitterMillis; 148 149 /** 150 * Set the rtp inactivity observed as per thresholds set by the MediaQualityThreshold API 151 * @param value The receiving rtp inacitivity time observed in milliseconds unit 152 */ setRtpInactivityTimeMillis(int value)153 public @NonNull Builder setRtpInactivityTimeMillis(int value) { 154 this.mRtpInactivityTimeMillis = value; 155 return this; 156 } 157 158 /** 159 * Set the rtcp inactivity observed as per thresholds set by the MediaQualityThreshold API 160 * @param value The receiving rtcp inacitivity time observed in milliseconds unit 161 */ setRtcpInactivityTimeMillis(int value)162 public @NonNull Builder setRtcpInactivityTimeMillis(int value) { 163 this.mRtcpInactivityTimeMillis = value; 164 return this; 165 } 166 167 /** 168 * Set the rtp packet loss rate observed as per thresholds set by the MediaQualityThreshold 169 * API 170 * @param value The receiving rtp packet loss rate calculated in percentage unit 171 */ setRtpPacketLossRate(int value)172 public @NonNull Builder setRtpPacketLossRate(int value) { 173 this.mRtpPacketLossRate = value; 174 return this; 175 } 176 177 /** 178 * Set the rtp jitter observed as per thresholds set by MediaQualityThreshold API 179 * @param value The receiving rtp jitter calculated in milliseconds unit 180 */ setRtpJitterMillis(int value)181 public @NonNull Builder setRtpJitterMillis(int value) { 182 this.mRtpJitterMillis = value; 183 return this; 184 } 185 186 /** 187 * Build the MediaQualityStatus. 188 * 189 * @return the MediaQualityStatus object. 190 */ build()191 public @NonNull MediaQualityStatus build() { 192 // TODO validation 193 return new MediaQualityStatus(this); 194 } 195 } 196 } 197