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 /** 96 * Constructor 97 * 98 * @param networkType Current packet-switching cellular network type 99 * @param overrideNetworkType The override network type 100 * 101 * @hide 102 */ TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType)103 public TelephonyDisplayInfo(@NetworkType int networkType, 104 @OverrideNetworkType int overrideNetworkType) { 105 mNetworkType = networkType; 106 mOverrideNetworkType = overrideNetworkType; 107 } 108 109 /** @hide */ TelephonyDisplayInfo(Parcel p)110 public TelephonyDisplayInfo(Parcel p) { 111 mNetworkType = p.readInt(); 112 mOverrideNetworkType = p.readInt(); 113 } 114 115 /** 116 * Get current packet-switching cellular network type. This is the actual network type the 117 * device is camped on. 118 * 119 * @return The network type. 120 */ 121 @NetworkType getNetworkType()122 public int getNetworkType() { 123 return mNetworkType; 124 } 125 126 /** 127 * Get the override network type. Note the override network type is for market branding 128 * or visualization purposes only. It cannot be treated as the actual network type device is 129 * camped on. 130 * 131 * @return The override network type. 132 */ 133 @OverrideNetworkType getOverrideNetworkType()134 public int getOverrideNetworkType() { 135 return mOverrideNetworkType; 136 } 137 138 @Override writeToParcel(@onNull Parcel dest, int flags)139 public void writeToParcel(@NonNull Parcel dest, int flags) { 140 dest.writeInt(mNetworkType); 141 dest.writeInt(mOverrideNetworkType); 142 } 143 144 public static final @NonNull Parcelable.Creator<TelephonyDisplayInfo> CREATOR = 145 new Parcelable.Creator<TelephonyDisplayInfo>() { 146 @Override 147 public TelephonyDisplayInfo createFromParcel(Parcel source) { 148 return new TelephonyDisplayInfo(source); 149 } 150 151 @Override 152 public TelephonyDisplayInfo[] newArray(int size) { 153 return new TelephonyDisplayInfo[size]; 154 } 155 }; 156 157 @Override describeContents()158 public int describeContents() { 159 return 0; 160 } 161 162 @Override equals(Object o)163 public boolean equals(Object o) { 164 if (this == o) return true; 165 if (o == null || getClass() != o.getClass()) return false; 166 TelephonyDisplayInfo that = (TelephonyDisplayInfo) o; 167 return mNetworkType == that.mNetworkType 168 && mOverrideNetworkType == that.mOverrideNetworkType; 169 } 170 171 @Override hashCode()172 public int hashCode() { 173 return Objects.hash(mNetworkType, mOverrideNetworkType); 174 } 175 176 /** 177 * Convert override network type to string. 178 * 179 * @param type Override network type 180 * @return Override network type in string format 181 * @hide 182 */ overrideNetworkTypeToString(@verrideNetworkType int type)183 public static String overrideNetworkTypeToString(@OverrideNetworkType int type) { 184 switch (type) { 185 case OVERRIDE_NETWORK_TYPE_NONE: return "NONE"; 186 case OVERRIDE_NETWORK_TYPE_LTE_CA: return "LTE_CA"; 187 case OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO: return "LTE_ADV_PRO"; 188 case OVERRIDE_NETWORK_TYPE_NR_NSA: return "NR_NSA"; 189 case OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE: return "NR_NSA_MMWAVE"; 190 case OVERRIDE_NETWORK_TYPE_NR_ADVANCED: return "NR_ADVANCED"; 191 default: return "UNKNOWN"; 192 } 193 } 194 195 @Override toString()196 public String toString() { 197 return "TelephonyDisplayInfo {network=" + TelephonyManager.getNetworkTypeName(mNetworkType) 198 + ", override=" + overrideNetworkTypeToString(mOverrideNetworkType) + "}"; 199 } 200 } 201