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 /** 98 * Constructor 99 * 100 * @param networkType Current packet-switching cellular network type 101 * @param overrideNetworkType The override network type 102 * 103 * @deprecated will not use this constructor anymore. 104 * @hide 105 */ 106 @Deprecated TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType)107 public TelephonyDisplayInfo(@NetworkType int networkType, 108 @OverrideNetworkType int overrideNetworkType) { 109 this(networkType, overrideNetworkType, false); 110 } 111 112 /** 113 * Constructor 114 * 115 * @param networkType Current packet-switching cellular network type 116 * @param overrideNetworkType The override network type 117 * @param isRoaming True if the device is roaming after override. 118 * 119 * @hide 120 */ TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType, boolean isRoaming)121 public TelephonyDisplayInfo(@NetworkType int networkType, 122 @OverrideNetworkType int overrideNetworkType, 123 boolean isRoaming) { 124 mNetworkType = networkType; 125 mOverrideNetworkType = overrideNetworkType; 126 mIsRoaming = isRoaming; 127 } 128 129 /** @hide */ TelephonyDisplayInfo(Parcel p)130 public TelephonyDisplayInfo(Parcel p) { 131 mNetworkType = p.readInt(); 132 mOverrideNetworkType = p.readInt(); 133 mIsRoaming = p.readBoolean(); 134 } 135 136 /** 137 * Get current packet-switching cellular network type. This is the actual network type the 138 * device is camped on. 139 * 140 * @return The network type. 141 */ 142 @NetworkType getNetworkType()143 public int getNetworkType() { 144 return mNetworkType; 145 } 146 147 /** 148 * Get the override network type. Note the override network type is for market branding 149 * or visualization purposes only. It cannot be treated as the actual network type device is 150 * camped on. 151 * 152 * @return The override network type. 153 */ 154 @OverrideNetworkType getOverrideNetworkType()155 public int getOverrideNetworkType() { 156 return mOverrideNetworkType; 157 } 158 159 /** 160 * Get device is roaming or not. Note the isRoaming is for market branding or visualization 161 * purposes only. It cannot be treated as the actual roaming device is camped on. 162 * 163 * @return True if the device is registered on roaming network overridden by config. 164 * @see CarrierConfigManager#KEY_GSM_ROAMING_NETWORKS_STRING_ARRAY 165 * @see CarrierConfigManager#KEY_GSM_NONROAMING_NETWORKS_STRING_ARRAY 166 * @see CarrierConfigManager#KEY_CDMA_ROAMING_NETWORKS_STRING_ARRAY 167 * @see CarrierConfigManager#KEY_CDMA_NONROAMING_NETWORKS_STRING_ARRAY 168 */ isRoaming()169 public boolean isRoaming() { 170 return mIsRoaming; 171 } 172 173 @Override writeToParcel(@onNull Parcel dest, int flags)174 public void writeToParcel(@NonNull Parcel dest, int flags) { 175 dest.writeInt(mNetworkType); 176 dest.writeInt(mOverrideNetworkType); 177 dest.writeBoolean(mIsRoaming); 178 } 179 180 public static final @NonNull Parcelable.Creator<TelephonyDisplayInfo> CREATOR = 181 new Parcelable.Creator<TelephonyDisplayInfo>() { 182 @Override 183 public TelephonyDisplayInfo createFromParcel(Parcel source) { 184 return new TelephonyDisplayInfo(source); 185 } 186 187 @Override 188 public TelephonyDisplayInfo[] newArray(int size) { 189 return new TelephonyDisplayInfo[size]; 190 } 191 }; 192 193 @Override describeContents()194 public int describeContents() { 195 return 0; 196 } 197 198 @Override equals(Object o)199 public boolean equals(Object o) { 200 if (this == o) return true; 201 if (o == null || getClass() != o.getClass()) return false; 202 TelephonyDisplayInfo that = (TelephonyDisplayInfo) o; 203 return mNetworkType == that.mNetworkType 204 && mOverrideNetworkType == that.mOverrideNetworkType 205 && mIsRoaming == that.mIsRoaming; 206 } 207 208 @Override hashCode()209 public int hashCode() { 210 return Objects.hash(mNetworkType, mOverrideNetworkType, mIsRoaming); 211 } 212 213 /** 214 * Convert override network type to string. 215 * 216 * @param type Override network type 217 * @return Override network type in string format 218 * @hide 219 */ overrideNetworkTypeToString(@verrideNetworkType int type)220 public static String overrideNetworkTypeToString(@OverrideNetworkType int type) { 221 switch (type) { 222 case OVERRIDE_NETWORK_TYPE_NONE: return "NONE"; 223 case OVERRIDE_NETWORK_TYPE_LTE_CA: return "LTE_CA"; 224 case OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO: return "LTE_ADV_PRO"; 225 case OVERRIDE_NETWORK_TYPE_NR_NSA: return "NR_NSA"; 226 case OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE: return "NR_NSA_MMWAVE"; 227 case OVERRIDE_NETWORK_TYPE_NR_ADVANCED: return "NR_ADVANCED"; 228 default: return "UNKNOWN"; 229 } 230 } 231 232 @Override toString()233 public String toString() { 234 return "TelephonyDisplayInfo {network=" + TelephonyManager.getNetworkTypeName(mNetworkType) 235 + ", overrideNetwork=" + overrideNetworkTypeToString(mOverrideNetworkType) 236 + ", isRoaming=" + mIsRoaming + "}"; 237 } 238 } 239