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 */ 33 public final class TelephonyDisplayInfo implements Parcelable { 34 /** 35 * No override. {@link #getNetworkType()} should be used for display network 36 * type. 37 */ 38 public static final int OVERRIDE_NETWORK_TYPE_NONE = 0; 39 40 /** 41 * Override network type when the device is connected to 42 * {@link TelephonyManager#NETWORK_TYPE_LTE} cellular network and is using carrier aggregation. 43 */ 44 public static final int OVERRIDE_NETWORK_TYPE_LTE_CA = 1; 45 46 /** 47 * Override network type when the device is connected to advanced pro 48 * {@link TelephonyManager#NETWORK_TYPE_LTE} cellular network. 49 */ 50 public static final int OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO = 2; 51 52 /** 53 * Override network type when the device is connected to 54 * {@link TelephonyManager#NETWORK_TYPE_LTE} network and has E-UTRA-NR Dual Connectivity(EN-DC) 55 * capability or is currently connected to the secondary 56 * {@link TelephonyManager#NETWORK_TYPE_NR} cellular network. 57 */ 58 public static final int OVERRIDE_NETWORK_TYPE_NR_NSA = 3; 59 60 /** 61 * Override network type when the device is connected to 62 * {@link TelephonyManager#NETWORK_TYPE_LTE} network and has E-UTRA-NR Dual Connectivity(EN-DC) 63 * capability or is currently connected to the secondary 64 * {@link TelephonyManager#NETWORK_TYPE_NR} cellular network on millimeter wave bands. 65 */ 66 public static final int OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE = 4; 67 68 @NetworkType 69 private final int mNetworkType; 70 71 @OverrideNetworkType 72 private final int mOverrideNetworkType; 73 74 /** 75 * Constructor 76 * 77 * @param networkType Current packet-switching cellular network type 78 * @param overrideNetworkType The override network type 79 * 80 * @hide 81 */ TelephonyDisplayInfo(@etworkType int networkType, @OverrideNetworkType int overrideNetworkType)82 public TelephonyDisplayInfo(@NetworkType int networkType, 83 @OverrideNetworkType int overrideNetworkType) { 84 mNetworkType = networkType; 85 mOverrideNetworkType = overrideNetworkType; 86 } 87 88 /** @hide */ TelephonyDisplayInfo(Parcel p)89 public TelephonyDisplayInfo(Parcel p) { 90 mNetworkType = p.readInt(); 91 mOverrideNetworkType = p.readInt(); 92 } 93 94 /** 95 * Get current packet-switching cellular network type. This is the actual network type the 96 * device is camped on. 97 * 98 * @return The network type. 99 */ 100 @NetworkType getNetworkType()101 public int getNetworkType() { 102 return mNetworkType; 103 } 104 105 /** 106 * Get the override network type. Note the override network type is for market branding 107 * or visualization purposes only. It cannot be treated as the actual network type device is 108 * camped on. 109 * 110 * @return The override network type. 111 */ 112 @OverrideNetworkType getOverrideNetworkType()113 public int getOverrideNetworkType() { 114 return mOverrideNetworkType; 115 } 116 117 @Override writeToParcel(@onNull Parcel dest, int flags)118 public void writeToParcel(@NonNull Parcel dest, int flags) { 119 dest.writeInt(mNetworkType); 120 dest.writeInt(mOverrideNetworkType); 121 } 122 123 public static final @NonNull Parcelable.Creator<TelephonyDisplayInfo> CREATOR = 124 new Parcelable.Creator<TelephonyDisplayInfo>() { 125 @Override 126 public TelephonyDisplayInfo createFromParcel(Parcel source) { 127 return new TelephonyDisplayInfo(source); 128 } 129 130 @Override 131 public TelephonyDisplayInfo[] newArray(int size) { 132 return new TelephonyDisplayInfo[size]; 133 } 134 }; 135 136 @Override describeContents()137 public int describeContents() { 138 return 0; 139 } 140 141 @Override equals(Object o)142 public boolean equals(Object o) { 143 if (this == o) return true; 144 if (o == null || getClass() != o.getClass()) return false; 145 TelephonyDisplayInfo that = (TelephonyDisplayInfo) o; 146 return mNetworkType == that.mNetworkType 147 && mOverrideNetworkType == that.mOverrideNetworkType; 148 } 149 150 @Override hashCode()151 public int hashCode() { 152 return Objects.hash(mNetworkType, mOverrideNetworkType); 153 } 154 155 /** 156 * Convert override network type to string. 157 * 158 * @param type Override network type 159 * @return Override network type in string format 160 * @hide 161 */ overrideNetworkTypeToString(@verrideNetworkType int type)162 public static String overrideNetworkTypeToString(@OverrideNetworkType int type) { 163 switch (type) { 164 case OVERRIDE_NETWORK_TYPE_NONE: return "NONE"; 165 case OVERRIDE_NETWORK_TYPE_LTE_CA: return "LTE_CA"; 166 case OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO: return "LTE_ADV_PRO"; 167 case OVERRIDE_NETWORK_TYPE_NR_NSA: return "NR_NSA"; 168 case OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE: return "NR_NSA_MMWAVE"; 169 default: return "UNKNOWN"; 170 } 171 } 172 173 @Override toString()174 public String toString() { 175 return "TelephonyDisplayInfo {network=" + TelephonyManager.getNetworkTypeName(mNetworkType) 176 + ", override=" + overrideNetworkTypeToString(mOverrideNetworkType) + "}"; 177 } 178 } 179