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; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.telephony.Annotation.NetworkType; 23 import android.telephony.Annotation.OverrideNetworkType; 24 25 import java.util.Objects; 26 27 /** 28 * TelephonyDisplayInfo contains telephony-related information used for display purposes only. This 29 * information is provided in accordance with carrier policy and branding preferences; it is not 30 * necessarily a precise or accurate representation of the current state and should be treated 31 * accordingly. 32 * To be notified of changes in TelephonyDisplayInfo, use 33 * {@link TelephonyManager#registerTelephonyCallback} with a {@link TelephonyCallback} 34 * that implements {@link TelephonyCallback.DisplayInfoListener}. 35 * Override the onDisplayInfoChanged() method to handle the broadcast. 36 */ 37 public final class TelephonyDisplayInfo implements Parcelable { 38 /** 39 * No override. {@link #getNetworkType()} should be used for display network 40 * type. 41 */ 42 public static final int OVERRIDE_NETWORK_TYPE_NONE = 0; 43 44 /** 45 * Override network type when the device is connected to 46 * {@link TelephonyManager#NETWORK_TYPE_LTE} cellular network and is using carrier aggregation. 47 */ 48 public static final int OVERRIDE_NETWORK_TYPE_LTE_CA = 1; 49 50 /** 51 * Override network type when the device is connected to advanced pro 52 * {@link TelephonyManager#NETWORK_TYPE_LTE} cellular network. 53 */ 54 public static final int OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO = 2; 55 56 /** 57 * Override network type when the device is connected to 58 * {@link TelephonyManager#NETWORK_TYPE_LTE} network and has E-UTRA-NR Dual Connectivity(EN-DC) 59 * capability or is currently connected to the secondary 60 * {@link TelephonyManager#NETWORK_TYPE_NR} cellular network. 61 */ 62 public static final int OVERRIDE_NETWORK_TYPE_NR_NSA = 3; 63 64 /** 65 * Override network type when the device is connected to 66 * {@link TelephonyManager#NETWORK_TYPE_LTE} network and has E-UTRA-NR Dual Connectivity(EN-DC) 67 * capability or is currently connected to the secondary 68 * {@link TelephonyManager#NETWORK_TYPE_NR} cellular network on millimeter wave bands. 69 * @deprecated Use{@link #OVERRIDE_NETWORK_TYPE_NR_ADVANCED} instead. 70 */ 71 @Deprecated 72 public static final int OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE = 4; 73 74 /** 75 * Override network type when the device is connected NR cellular network and the data rate is 76 * higher than the generic 5G date rate. 77 * Including but not limited to 78 * <ul> 79 * <li>The device is connected to the NR cellular network on millimeter wave bands. </li> 80 * <li>The device is connected to the specific network which the carrier is using 81 * proprietary means to provide a faster overall data connection than would be otherwise 82 * possible. This may include using other bands unique to the carrier, or carrier 83 * aggregation, for example.</li> 84 * </ul> 85 * One of the use case is that UX can show a different icon, for example, "5G+" 86 */ 87 public static final int OVERRIDE_NETWORK_TYPE_NR_ADVANCED = 5; 88 89 @NetworkType 90 private final int mNetworkType; 91 92 @OverrideNetworkType 93 private final int mOverrideNetworkType; 94 95 private final boolean mIsRoaming; 96 97 private final boolean mIsNtn; 98 99 private final boolean mIsSatelliteConstrainedData; 100 101 /** 102 * Constructor 103 * 104 * @param networkType Current packet-switching cellular network type 105 * @param overrideNetworkType The override network type 106 * 107 * @deprecated will not use this constructor anymore. 108 * @hide 109 */ 110 @Deprecated TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType)111 public TelephonyDisplayInfo(@NetworkType int networkType, 112 @OverrideNetworkType int overrideNetworkType) { 113 this(networkType, overrideNetworkType, false, false, false); 114 } 115 116 /** 117 * Constructor 118 * 119 * @param networkType Current packet-switching cellular network type 120 * @param overrideNetworkType The override network type 121 * @param isRoaming True if the device is roaming after override. 122 * 123 * @hide 124 */ 125 @Deprecated TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType, boolean isRoaming)126 public TelephonyDisplayInfo(@NetworkType int networkType, 127 @OverrideNetworkType int overrideNetworkType, 128 boolean isRoaming) { 129 mNetworkType = networkType; 130 mOverrideNetworkType = overrideNetworkType; 131 mIsRoaming = isRoaming; 132 mIsNtn = false; 133 mIsSatelliteConstrainedData = false; 134 } 135 136 /** 137 * Constructor 138 * 139 * @param networkType Current packet-switching cellular network type 140 * @param overrideNetworkType The override network type 141 * @param isRoaming True if the device is roaming after override. 142 * @param isNtn True if the device is camped to non-terrestrial network. 143 * @param isSatelliteConstrainedData True if the device satellite internet is bandwidth 144 * constrained. 145 * 146 * @hide 147 */ TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType, boolean isRoaming, boolean isNtn, boolean isSatelliteConstrainedData)148 public TelephonyDisplayInfo(@NetworkType int networkType, 149 @OverrideNetworkType int overrideNetworkType, 150 boolean isRoaming, boolean isNtn, boolean isSatelliteConstrainedData) { 151 mNetworkType = networkType; 152 mOverrideNetworkType = overrideNetworkType; 153 mIsRoaming = isRoaming; 154 mIsNtn = isNtn; 155 mIsSatelliteConstrainedData = isSatelliteConstrainedData; 156 } 157 158 /** @hide */ TelephonyDisplayInfo(Parcel p)159 public TelephonyDisplayInfo(Parcel p) { 160 mNetworkType = p.readInt(); 161 mOverrideNetworkType = p.readInt(); 162 mIsRoaming = p.readBoolean(); 163 mIsNtn = p.readBoolean(); 164 mIsSatelliteConstrainedData = p.readBoolean(); 165 } 166 167 /** 168 * Get current packet-switching cellular network type. This is the actual network type the 169 * device is camped on. 170 * 171 * @return The network type. 172 */ 173 @NetworkType getNetworkType()174 public int getNetworkType() { 175 return mNetworkType; 176 } 177 178 /** 179 * Get the override network type. Note the override network type is for market branding 180 * or visualization purposes only. It cannot be treated as the actual network type device is 181 * camped on. 182 * 183 * @return The override network type. 184 */ 185 @OverrideNetworkType getOverrideNetworkType()186 public int getOverrideNetworkType() { 187 return mOverrideNetworkType; 188 } 189 190 /** 191 * Get device is roaming or not. Note the isRoaming is for market branding or visualization 192 * purposes only. It cannot be treated as the actual roaming device is camped on. 193 * 194 * @return True if the device is registered on roaming network overridden by config. 195 * @see CarrierConfigManager#KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY 196 * @see CarrierConfigManager#KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY 197 * @see CarrierConfigManager#KEY_CDMA_ROAMING_NETWORKS_STRING_ARRAY 198 * @see CarrierConfigManager#KEY_CDMA_NONROAMING_NETWORKS_STRING_ARRAY 199 */ isRoaming()200 public boolean isRoaming() { 201 return mIsRoaming; 202 } 203 204 /** 205 * Get whether the satellite internet is with bandwidth constrained capability set. 206 * 207 * @return {@code true} if satellite internet is connected with bandwidth constrained 208 * capability else {@code false}. 209 * @hide 210 */ isSatelliteConstrainedData()211 public boolean isSatelliteConstrainedData() { 212 return mIsSatelliteConstrainedData; 213 } 214 215 /** 216 * Get whether the network is a non-terrestrial network. 217 * 218 * @return {@code true} if network is a non-terrestrial network else {@code false}. 219 * @hide 220 */ isNtn()221 public boolean isNtn() { 222 return mIsNtn; 223 } 224 225 @Override writeToParcel(@onNull Parcel dest, int flags)226 public void writeToParcel(@NonNull Parcel dest, int flags) { 227 dest.writeInt(mNetworkType); 228 dest.writeInt(mOverrideNetworkType); 229 dest.writeBoolean(mIsRoaming); 230 dest.writeBoolean(mIsNtn); 231 dest.writeBoolean(mIsSatelliteConstrainedData); 232 } 233 234 public static final @NonNull Parcelable.Creator<TelephonyDisplayInfo> CREATOR = 235 new Parcelable.Creator<TelephonyDisplayInfo>() { 236 @Override 237 public TelephonyDisplayInfo createFromParcel(Parcel source) { 238 return new TelephonyDisplayInfo(source); 239 } 240 241 @Override 242 public TelephonyDisplayInfo[] newArray(int size) { 243 return new TelephonyDisplayInfo[size]; 244 } 245 }; 246 247 @Override describeContents()248 public int describeContents() { 249 return 0; 250 } 251 252 @Override equals(Object o)253 public boolean equals(Object o) { 254 if (this == o) return true; 255 if (o == null || getClass() != o.getClass()) return false; 256 TelephonyDisplayInfo that = (TelephonyDisplayInfo) o; 257 return mNetworkType == that.mNetworkType 258 && mOverrideNetworkType == that.mOverrideNetworkType 259 && mIsRoaming == that.mIsRoaming 260 && mIsNtn == that.mIsNtn 261 && mIsSatelliteConstrainedData == that.mIsSatelliteConstrainedData; 262 } 263 264 @Override hashCode()265 public int hashCode() { 266 return Objects.hash(mNetworkType, mOverrideNetworkType, mIsRoaming, mIsNtn, 267 mIsSatelliteConstrainedData); 268 } 269 270 /** 271 * Convert override network type to string. 272 * 273 * @param type Override network type 274 * @return Override network type in string format 275 * @hide 276 */ overrideNetworkTypeToString(@verrideNetworkType int type)277 public static String overrideNetworkTypeToString(@OverrideNetworkType int type) { 278 switch (type) { 279 case OVERRIDE_NETWORK_TYPE_NONE: return "NONE"; 280 case OVERRIDE_NETWORK_TYPE_LTE_CA: return "LTE_CA"; 281 case OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO: return "LTE_ADV_PRO"; 282 case OVERRIDE_NETWORK_TYPE_NR_NSA: return "NR_NSA"; 283 case OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE: return "NR_NSA_MMWAVE"; 284 case OVERRIDE_NETWORK_TYPE_NR_ADVANCED: return "NR_ADVANCED"; 285 default: return "UNKNOWN"; 286 } 287 } 288 289 @Override toString()290 public String toString() { 291 return "TelephonyDisplayInfo {network=" + TelephonyManager.getNetworkTypeName(mNetworkType) 292 + ", overrideNetwork=" + overrideNetworkTypeToString(mOverrideNetworkType) 293 + ", isRoaming=" + mIsRoaming 294 + ", isNtn=" + mIsNtn 295 + ", isSatelliteConstrainedData=" + mIsSatelliteConstrainedData + "}"; 296 } 297 } 298