1 /** 2 * Copyright 2020 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.data; 18 19 import android.annotation.CallSuper; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 import java.util.Objects; 28 29 /** 30 * Class that stores information specific to QOS. 31 * 32 * @hide 33 */ 34 public abstract class Qos { 35 36 /** @hide */ 37 @Retention(RetentionPolicy.SOURCE) 38 @IntDef(prefix = "QOS_TYPE_", 39 value = {QOS_TYPE_EPS, QOS_TYPE_NR}) 40 public @interface QosType {} 41 42 @QosType 43 final int type; 44 45 static final int QOS_TYPE_EPS = 1; 46 static final int QOS_TYPE_NR = 2; 47 48 final QosBandwidth downlink; 49 final QosBandwidth uplink; 50 Qos(int type, @NonNull android.hardware.radio.V1_6.QosBandwidth downlink, @NonNull android.hardware.radio.V1_6.QosBandwidth uplink)51 Qos(int type, 52 @NonNull android.hardware.radio.V1_6.QosBandwidth downlink, 53 @NonNull android.hardware.radio.V1_6.QosBandwidth uplink) { 54 this.type = type; 55 this.downlink = new QosBandwidth(downlink.maxBitrateKbps, downlink.guaranteedBitrateKbps); 56 this.uplink = new QosBandwidth(uplink.maxBitrateKbps, uplink.guaranteedBitrateKbps); 57 } 58 getDownlinkBandwidth()59 public QosBandwidth getDownlinkBandwidth() { 60 return downlink; 61 } 62 getUplinkBandwidth()63 public QosBandwidth getUplinkBandwidth() { 64 return uplink; 65 } 66 67 public static class QosBandwidth implements Parcelable { 68 int maxBitrateKbps; 69 int guaranteedBitrateKbps; 70 QosBandwidth()71 QosBandwidth() { 72 } 73 QosBandwidth(int maxBitrateKbps, int guaranteedBitrateKbps)74 QosBandwidth(int maxBitrateKbps, int guaranteedBitrateKbps) { 75 this.maxBitrateKbps = maxBitrateKbps; 76 this.guaranteedBitrateKbps = guaranteedBitrateKbps; 77 } 78 QosBandwidth(Parcel source)79 private QosBandwidth(Parcel source) { 80 maxBitrateKbps = source.readInt(); 81 guaranteedBitrateKbps = source.readInt(); 82 } 83 getMaxBitrateKbps()84 public int getMaxBitrateKbps() { 85 return maxBitrateKbps; 86 } 87 getGuaranteedBitrateKbps()88 public int getGuaranteedBitrateKbps() { 89 return guaranteedBitrateKbps; 90 } 91 92 @Override writeToParcel(Parcel dest, int flags)93 public void writeToParcel(Parcel dest, int flags) { 94 dest.writeInt(maxBitrateKbps); 95 dest.writeInt(guaranteedBitrateKbps); 96 } 97 98 @Override describeContents()99 public int describeContents() { 100 return 0; 101 } 102 103 @Override hashCode()104 public int hashCode() { 105 return Objects.hash(maxBitrateKbps, guaranteedBitrateKbps); 106 } 107 108 @Override equals(Object o)109 public boolean equals(Object o) { 110 if (this == o) return true; 111 112 if (o == null || !(o instanceof QosBandwidth)) { 113 return false; 114 } 115 116 QosBandwidth other = (QosBandwidth) o; 117 return maxBitrateKbps == other.maxBitrateKbps 118 && guaranteedBitrateKbps == other.guaranteedBitrateKbps; 119 } 120 121 @Override toString()122 public String toString() { 123 return "Bandwidth {" 124 + " maxBitrateKbps=" + maxBitrateKbps 125 + " guaranteedBitrateKbps=" + guaranteedBitrateKbps + "}"; 126 } 127 128 public static final @NonNull Parcelable.Creator<QosBandwidth> CREATOR = 129 new Parcelable.Creator<QosBandwidth>() { 130 @Override 131 public QosBandwidth createFromParcel(Parcel source) { 132 return new QosBandwidth(source); 133 } 134 135 @Override 136 public QosBandwidth[] newArray(int size) { 137 return new QosBandwidth[size]; 138 } 139 }; 140 }; 141 Qos(@onNull Parcel source)142 protected Qos(@NonNull Parcel source) { 143 type = source.readInt(); 144 downlink = source.readParcelable(QosBandwidth.class.getClassLoader()); 145 uplink = source.readParcelable(QosBandwidth.class.getClassLoader()); 146 } 147 148 /** 149 * Used by child classes for parceling. 150 * 151 * @hide 152 */ 153 @CallSuper writeToParcel(@osType int type, Parcel dest, int flags)154 public void writeToParcel(@QosType int type, Parcel dest, int flags) { 155 dest.writeInt(type); 156 dest.writeParcelable(downlink, flags); 157 dest.writeParcelable(uplink, flags); 158 } 159 160 /** @hide */ create(@onNull android.hardware.radio.V1_6.Qos qos)161 public static @NonNull Qos create(@NonNull android.hardware.radio.V1_6.Qos qos) { 162 switch (qos.getDiscriminator()) { 163 case android.hardware.radio.V1_6.Qos.hidl_discriminator.eps: 164 return new EpsQos(qos.eps()); 165 case android.hardware.radio.V1_6.Qos.hidl_discriminator.nr: 166 return new NrQos(qos.nr()); 167 default: 168 return null; 169 } 170 } 171 172 /** @hide */ getType()173 public @QosType int getType() { 174 return type; 175 } 176 177 @Override hashCode()178 public int hashCode() { 179 return Objects.hash(downlink, uplink); 180 } 181 182 @Override equals(Object o)183 public boolean equals(Object o) { 184 if (this == o) return true; 185 186 Qos other = (Qos) o; 187 return type == other.type 188 && downlink.equals(other.downlink) 189 && uplink.equals(other.uplink); 190 } 191 } 192