• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, QosBandwidth downlink, QosBandwidth uplink)51     Qos(int type, QosBandwidth downlink, QosBandwidth uplink) {
52         this.type = type;
53         this.downlink = downlink;
54         this.uplink = uplink;
55     }
56 
getDownlinkBandwidth()57     public QosBandwidth getDownlinkBandwidth() {
58         return downlink;
59     }
60 
getUplinkBandwidth()61     public QosBandwidth getUplinkBandwidth() {
62         return uplink;
63     }
64 
65     public static class QosBandwidth implements Parcelable {
66         int maxBitrateKbps;
67         int guaranteedBitrateKbps;
68 
QosBandwidth(int maxBitrateKbps, int guaranteedBitrateKbps)69         public QosBandwidth(int maxBitrateKbps, int guaranteedBitrateKbps) {
70             this.maxBitrateKbps = maxBitrateKbps;
71             this.guaranteedBitrateKbps = guaranteedBitrateKbps;
72         }
73 
QosBandwidth(Parcel source)74         private QosBandwidth(Parcel source) {
75             maxBitrateKbps = source.readInt();
76             guaranteedBitrateKbps = source.readInt();
77         }
78 
getMaxBitrateKbps()79         public int getMaxBitrateKbps() {
80             return maxBitrateKbps;
81         }
82 
getGuaranteedBitrateKbps()83         public int getGuaranteedBitrateKbps() {
84             return guaranteedBitrateKbps;
85         }
86 
87         @Override
writeToParcel(Parcel dest, int flags)88         public void writeToParcel(Parcel dest, int flags) {
89             dest.writeInt(maxBitrateKbps);
90             dest.writeInt(guaranteedBitrateKbps);
91         }
92 
93         @Override
describeContents()94         public int describeContents() {
95             return 0;
96         }
97 
98         @Override
hashCode()99         public int hashCode() {
100             return Objects.hash(maxBitrateKbps, guaranteedBitrateKbps);
101         }
102 
103         @Override
equals(Object o)104         public boolean equals(Object o) {
105             if (this == o) return true;
106 
107             if (o == null || !(o instanceof QosBandwidth)) {
108                 return false;
109             }
110 
111             QosBandwidth other = (QosBandwidth) o;
112             return maxBitrateKbps == other.maxBitrateKbps
113                     && guaranteedBitrateKbps == other.guaranteedBitrateKbps;
114         }
115 
116         @Override
toString()117         public String toString() {
118             return "Bandwidth {"
119                     + " maxBitrateKbps=" + maxBitrateKbps
120                     + " guaranteedBitrateKbps=" + guaranteedBitrateKbps + "}";
121         }
122 
123         public static final @NonNull Parcelable.Creator<QosBandwidth> CREATOR =
124                 new Parcelable.Creator<QosBandwidth>() {
125                     @Override
126                     public QosBandwidth createFromParcel(Parcel source) {
127                         return new QosBandwidth(source);
128                     }
129 
130                     @Override
131                     public QosBandwidth[] newArray(int size) {
132                         return new QosBandwidth[size];
133                     }
134                 };
135     };
136 
Qos(@onNull Parcel source)137     protected Qos(@NonNull Parcel source) {
138         type = source.readInt();
139         downlink = source.readParcelable(QosBandwidth.class.getClassLoader(), android.telephony.data.Qos.QosBandwidth.class);
140         uplink = source.readParcelable(QosBandwidth.class.getClassLoader(), android.telephony.data.Qos.QosBandwidth.class);
141     }
142 
143     /**
144      * Used by child classes for parceling.
145      *
146      * @hide
147      */
148     @CallSuper
writeToParcel(@osType int type, Parcel dest, int flags)149     public void writeToParcel(@QosType int type, Parcel dest, int flags) {
150         dest.writeInt(type);
151         dest.writeParcelable(downlink, flags);
152         dest.writeParcelable(uplink, flags);
153     }
154 
155     /** @hide */
getType()156     public @QosType int getType() {
157         return type;
158     }
159 
160     @Override
hashCode()161     public int hashCode() {
162         return Objects.hash(downlink, uplink);
163     }
164 
165     @Override
equals(Object o)166     public boolean equals(Object o) {
167         if (this == o) return true;
168 
169         Qos other = (Qos) o;
170         return type == other.type
171                 && downlink.equals(other.downlink)
172                 && uplink.equals(other.uplink);
173     }
174 }
175