• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.Objects;
29 
30 /**
31  * Link Capacity Estimate from the modem
32  * @hide
33  */
34 @SystemApi
35 public final class LinkCapacityEstimate implements Parcelable {
36     /** A value indicates that the capacity estimate is not available */
37     public static final int INVALID = -1;
38 
39     /**
40      * LCE for the primary network
41      */
42     public static final int LCE_TYPE_PRIMARY = 0;
43 
44     /**
45      * LCE for the secondary network
46      */
47     public static final int LCE_TYPE_SECONDARY = 1;
48 
49     /**
50      * Combined LCE for primary network and secondary network reported by the legacy modem
51      */
52     public static final int LCE_TYPE_COMBINED = 2;
53 
54     /** @hide */
55     @IntDef(prefix = { "LCE_TYPE_" }, value = {
56             LCE_TYPE_PRIMARY,
57             LCE_TYPE_SECONDARY,
58             LCE_TYPE_COMBINED,
59     })
60     @Retention(RetentionPolicy.SOURCE)
61     public @interface LceType {}
62 
63     private final @LceType int mType;
64 
65     /** Downlink capacity estimate in kbps */
66     private final int mDownlinkCapacityKbps;
67 
68     /** Uplink capacity estimate in kbps */
69     private final int mUplinkCapacityKbps;
70 
71     /**
72      * Constructor for link capacity estimate
73      */
LinkCapacityEstimate(@ceType int type, int downlinkCapacityKbps, int uplinkCapacityKbps)74     public LinkCapacityEstimate(@LceType int type,
75             int downlinkCapacityKbps, int uplinkCapacityKbps) {
76         mDownlinkCapacityKbps = downlinkCapacityKbps;
77         mUplinkCapacityKbps = uplinkCapacityKbps;
78         mType = type;
79     }
80 
81     /**
82      * @hide
83      */
LinkCapacityEstimate(Parcel in)84     public LinkCapacityEstimate(Parcel in) {
85         mDownlinkCapacityKbps = in.readInt();
86         mUplinkCapacityKbps = in.readInt();
87         mType = in.readInt();
88     }
89 
90     /**
91      * Retrieves the type of LCE
92      * @return The type of link capacity estimate
93      */
getType()94     public @LceType int getType() {
95         return mType;
96     }
97 
98     /**
99      * Retrieves the downlink bandwidth in Kbps.
100      * This will be {@link #INVALID} if the network is not connected
101      * @return The estimated first hop downstream (network to device) bandwidth.
102      */
getDownlinkCapacityKbps()103     public int getDownlinkCapacityKbps() {
104         return mDownlinkCapacityKbps;
105     }
106 
107     /**
108      * Retrieves the uplink bandwidth in Kbps.
109      * This will be {@link #INVALID} if the network is not connected
110      *
111      * @return The estimated first hop upstream (device to network) bandwidth.
112      */
getUplinkCapacityKbps()113     public int getUplinkCapacityKbps() {
114         return mUplinkCapacityKbps;
115     }
116 
117     @Override
toString()118     public String toString() {
119         return new StringBuilder()
120                 .append("{mType=")
121                 .append(mType)
122                 .append(", mDownlinkCapacityKbps=")
123                 .append(mDownlinkCapacityKbps)
124                 .append(", mUplinkCapacityKbps=")
125                 .append(mUplinkCapacityKbps)
126                 .append("}")
127                 .toString();
128     }
129 
130     /**
131      * {@link Parcelable#describeContents}
132      */
describeContents()133     public int describeContents() {
134         return 0;
135     }
136 
137     /**
138      * {@link Parcelable#writeToParcel}
139      * @hide
140      */
writeToParcel(@onNull Parcel dest, int flags)141     public void writeToParcel(@NonNull Parcel dest, int flags) {
142         dest.writeInt(mDownlinkCapacityKbps);
143         dest.writeInt(mUplinkCapacityKbps);
144         dest.writeInt(mType);
145     }
146 
147     @Override
equals(@ullable Object o)148     public boolean equals(@Nullable Object o) {
149         if (o == null || !(o instanceof LinkCapacityEstimate) || hashCode() != o.hashCode())  {
150             return false;
151         }
152 
153         if (this == o) {
154             return true;
155         }
156 
157         LinkCapacityEstimate that = (LinkCapacityEstimate) o;
158         return mDownlinkCapacityKbps == that.mDownlinkCapacityKbps
159                 && mUplinkCapacityKbps == that.mUplinkCapacityKbps
160                 && mType == that.mType;
161     }
162 
163     @Override
hashCode()164     public int hashCode() {
165         return Objects.hash(mDownlinkCapacityKbps, mUplinkCapacityKbps, mType);
166     }
167 
168     public static final
169             @android.annotation.NonNull Parcelable.Creator<LinkCapacityEstimate> CREATOR =
170             new Parcelable.Creator() {
171         public LinkCapacityEstimate createFromParcel(Parcel in) {
172             return new LinkCapacityEstimate(in);
173         }
174 
175         public LinkCapacityEstimate[] newArray(int size) {
176             return new LinkCapacityEstimate[size];
177         }
178     };
179 }
180