1 /* 2 * Copyright (C) 2018 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 package android.telephony.data; 17 18 import android.annotation.IntDef; 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.StringDef; 22 import android.annotation.SystemApi; 23 import android.content.ContentValues; 24 import android.database.Cursor; 25 import android.hardware.radio.V1_5.ApnTypes; 26 import android.net.Uri; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 import android.provider.Telephony; 30 import android.provider.Telephony.Carriers; 31 import android.telephony.Annotation.NetworkType; 32 import android.telephony.ServiceState; 33 import android.telephony.TelephonyManager; 34 import android.text.TextUtils; 35 import android.util.ArrayMap; 36 import android.util.Log; 37 38 import com.android.telephony.Rlog; 39 40 import java.lang.annotation.Retention; 41 import java.lang.annotation.RetentionPolicy; 42 import java.net.InetAddress; 43 import java.net.UnknownHostException; 44 import java.util.ArrayList; 45 import java.util.List; 46 import java.util.Locale; 47 import java.util.Map; 48 import java.util.Objects; 49 50 /** 51 * An Access Point Name (APN) configuration for a carrier data connection. 52 * 53 * <p>The APN provides configuration to connect a cellular network device to an IP data network. A 54 * carrier uses the name, type and other configuration in an {@code APNSetting} to decide which IP 55 * address to assign, any security methods to apply, and how the device might be connected to 56 * private networks. 57 * 58 * <p>Use {@link ApnSetting.Builder} to create new instances. 59 */ 60 public class ApnSetting implements Parcelable { 61 62 private static final String LOG_TAG = "ApnSetting"; 63 private static final boolean VDBG = false; 64 65 private static final String V2_FORMAT_REGEX = "^\\[ApnSettingV2\\]\\s*"; 66 private static final String V3_FORMAT_REGEX = "^\\[ApnSettingV3\\]\\s*"; 67 private static final String V4_FORMAT_REGEX = "^\\[ApnSettingV4\\]\\s*"; 68 private static final String V5_FORMAT_REGEX = "^\\[ApnSettingV5\\]\\s*"; 69 private static final String V6_FORMAT_REGEX = "^\\[ApnSettingV6\\]\\s*"; 70 private static final String V7_FORMAT_REGEX = "^\\[ApnSettingV7\\]\\s*"; 71 72 /** 73 * Default value for mtu if it's not set. Moved from PhoneConstants. 74 * @hide 75 */ 76 public static final int UNSET_MTU = 0; 77 private static final int UNSPECIFIED_INT = -1; 78 private static final String UNSPECIFIED_STRING = ""; 79 80 /** 81 * APN type for none. Should only be used for initialization. 82 * @hide 83 */ 84 public static final int TYPE_NONE = ApnTypes.NONE; 85 /** 86 * APN type for all APNs (except wild-cardable types). 87 * @hide 88 */ 89 public static final int TYPE_ALL = ApnTypes.DEFAULT | ApnTypes.HIPRI | ApnTypes.MMS 90 | ApnTypes.SUPL | ApnTypes.DUN | ApnTypes.FOTA | ApnTypes.IMS | ApnTypes.CBS; 91 /** APN type for default data traffic. */ 92 public static final int TYPE_DEFAULT = ApnTypes.DEFAULT | ApnTypes.HIPRI; 93 /** APN type for MMS traffic. */ 94 public static final int TYPE_MMS = ApnTypes.MMS; 95 /** APN type for SUPL assisted GPS. */ 96 public static final int TYPE_SUPL = ApnTypes.SUPL; 97 /** APN type for DUN traffic. */ 98 public static final int TYPE_DUN = ApnTypes.DUN; 99 /** APN type for HiPri traffic. */ 100 public static final int TYPE_HIPRI = ApnTypes.HIPRI; 101 /** APN type for accessing the carrier's FOTA portal, used for over the air updates. */ 102 public static final int TYPE_FOTA = ApnTypes.FOTA; 103 /** APN type for IMS. */ 104 public static final int TYPE_IMS = ApnTypes.IMS; 105 /** APN type for CBS. */ 106 public static final int TYPE_CBS = ApnTypes.CBS; 107 /** APN type for IA Initial Attach APN. */ 108 public static final int TYPE_IA = ApnTypes.IA; 109 /** 110 * APN type for Emergency PDN. This is not an IA apn, but is used 111 * for access to carrier services in an emergency call situation. 112 */ 113 public static final int TYPE_EMERGENCY = ApnTypes.EMERGENCY; 114 /** APN type for MCX (Mission Critical Service) where X can be PTT/Video/Data */ 115 public static final int TYPE_MCX = ApnTypes.MCX; 116 /** APN type for XCAP. */ 117 public static final int TYPE_XCAP = ApnTypes.XCAP; 118 /** APN type for VSIM. */ 119 public static final int TYPE_VSIM = 1 << 12; // TODO: Refer to ApnTypes.VSIM 120 /** APN type for BIP. */ 121 public static final int TYPE_BIP = 1 << 13; // TODO: Refer to ApnTypes.BIP 122 /** APN type for ENTERPRISE. */ 123 public static final int TYPE_ENTERPRISE = 1 << 14; //TODO: In future should be referenced from 124 // hardware.interfaces.radio.data.ApnTypes 125 126 /** @hide */ 127 @IntDef(flag = true, prefix = {"TYPE_"}, value = { 128 TYPE_DEFAULT, 129 TYPE_MMS, 130 TYPE_SUPL, 131 TYPE_DUN, 132 TYPE_HIPRI, 133 TYPE_FOTA, 134 TYPE_IMS, 135 TYPE_CBS, 136 TYPE_IA, 137 TYPE_EMERGENCY, 138 TYPE_MCX, 139 TYPE_XCAP, 140 TYPE_BIP, 141 TYPE_VSIM, 142 TYPE_ENTERPRISE, 143 }) 144 @Retention(RetentionPolicy.SOURCE) 145 public @interface ApnType { 146 } 147 148 // Possible values for authentication types. 149 /** 150 * Authentication type is unknown. 151 * @hide 152 */ 153 public static final int AUTH_TYPE_UNKNOWN = -1; 154 /** Authentication is not required. */ 155 public static final int AUTH_TYPE_NONE = 0; 156 /** Authentication type for PAP. */ 157 public static final int AUTH_TYPE_PAP = 1; 158 /** Authentication type for CHAP. */ 159 public static final int AUTH_TYPE_CHAP = 2; 160 /** Authentication type for PAP or CHAP. */ 161 public static final int AUTH_TYPE_PAP_OR_CHAP = 3; 162 163 /** @hide */ 164 @IntDef({ 165 Telephony.Carriers.SKIP_464XLAT_DEFAULT, 166 Telephony.Carriers.SKIP_464XLAT_DISABLE, 167 Telephony.Carriers.SKIP_464XLAT_ENABLE, 168 }) 169 @Retention(RetentionPolicy.SOURCE) 170 public @interface Skip464XlatStatus {} 171 172 /** @hide */ 173 @StringDef(value = { 174 TYPE_ALL_STRING, 175 TYPE_CBS_STRING, 176 TYPE_DEFAULT_STRING, 177 TYPE_DUN_STRING, 178 TYPE_EMERGENCY_STRING, 179 TYPE_FOTA_STRING, 180 TYPE_HIPRI_STRING, 181 TYPE_IA_STRING, 182 TYPE_IMS_STRING, 183 TYPE_MCX_STRING, 184 TYPE_MMS_STRING, 185 TYPE_SUPL_STRING, 186 TYPE_XCAP_STRING, 187 TYPE_VSIM_STRING, 188 TYPE_BIP_STRING, 189 TYPE_ENTERPRISE_STRING, 190 }, prefix = "TYPE_", suffix = "_STRING") 191 @Retention(RetentionPolicy.SOURCE) 192 public @interface ApnTypeString {} 193 194 /** 195 * APN types for data connections. These are usage categories for an APN 196 * entry. One APN entry may support multiple APN types, eg, a single APN 197 * may service regular internet traffic ("default") as well as MMS-specific 198 * connections.<br/> 199 * APN_TYPE_ALL is a special type to indicate that this APN entry can 200 * service all data connections. 201 * 202 * @hide 203 */ 204 @SystemApi 205 public static final String TYPE_ALL_STRING = "*"; 206 207 /** 208 * APN type for default data traffic 209 * 210 * Note: String representations of APN types are intended for system apps to communicate with 211 * modem components or carriers. Non-system apps should use the integer variants instead. 212 * @hide 213 */ 214 @SystemApi 215 public static final String TYPE_DEFAULT_STRING = "default"; 216 217 218 /** 219 * APN type for MMS (Multimedia Messaging Service) traffic. 220 * 221 * Note: String representations of APN types are intended for system apps to communicate with 222 * modem components or carriers. Non-system apps should use the integer variants instead. 223 * @hide 224 */ 225 @SystemApi 226 public static final String TYPE_MMS_STRING = "mms"; 227 228 229 /** 230 * APN type for SUPL (Secure User Plane Location) assisted GPS. 231 * 232 * Note: String representations of APN types are intended for system apps to communicate with 233 * modem components or carriers. Non-system apps should use the integer variants instead. 234 * @hide 235 */ 236 @SystemApi 237 public static final String TYPE_SUPL_STRING = "supl"; 238 239 /** 240 * APN type for DUN (Dial-up networking) traffic 241 * 242 * Note: String representations of APN types are intended for system apps to communicate with 243 * modem components or carriers. Non-system apps should use the integer variants instead. 244 * @hide 245 */ 246 @SystemApi 247 public static final String TYPE_DUN_STRING = "dun"; 248 249 /** 250 * APN type for high-priority traffic 251 * 252 * Note: String representations of APN types are intended for system apps to communicate with 253 * modem components or carriers. Non-system apps should use the integer variants instead. 254 * @hide 255 */ 256 @SystemApi 257 public static final String TYPE_HIPRI_STRING = "hipri"; 258 259 /** 260 * APN type for FOTA (Firmware over-the-air) traffic. 261 * 262 * Note: String representations of APN types are intended for system apps to communicate with 263 * modem components or carriers. Non-system apps should use the integer variants instead. 264 * @hide 265 */ 266 @SystemApi 267 public static final String TYPE_FOTA_STRING = "fota"; 268 269 /** 270 * APN type for IMS (IP Multimedia Subsystem) traffic. 271 * 272 * Note: String representations of APN types are intended for system apps to communicate with 273 * modem components or carriers. Non-system apps should use the integer variants instead. 274 * @hide 275 */ 276 @SystemApi 277 public static final String TYPE_IMS_STRING = "ims"; 278 279 /** 280 * APN type for CBS (Carrier Branded Services) traffic. 281 * 282 * Note: String representations of APN types are intended for system apps to communicate with 283 * modem components or carriers. Non-system apps should use the integer variants instead. 284 * @hide 285 */ 286 @SystemApi 287 public static final String TYPE_CBS_STRING = "cbs"; 288 289 /** 290 * APN type for the IA (Initial Attach) APN 291 * 292 * Note: String representations of APN types are intended for system apps to communicate with 293 * modem components or carriers. Non-system apps should use the integer variants instead. 294 * @hide 295 */ 296 @SystemApi 297 public static final String TYPE_IA_STRING = "ia"; 298 299 /** 300 * APN type for Emergency PDN. This is not an IA apn, but is used 301 * for access to carrier services in an emergency call situation. 302 * 303 * Note: String representations of APN types are intended for system apps to communicate with 304 * modem components or carriers. Non-system apps should use the integer variants instead. 305 * @hide 306 */ 307 @SystemApi 308 public static final String TYPE_EMERGENCY_STRING = "emergency"; 309 310 /** 311 * APN type for Mission Critical Services. 312 * 313 * Note: String representations of APN types are intended for system apps to communicate with 314 * modem components or carriers. Non-system apps should use the integer variants instead. 315 * @hide 316 */ 317 @SystemApi 318 public static final String TYPE_MCX_STRING = "mcx"; 319 320 /** 321 * APN type for XCAP (XML Configuration Access Protocol) traffic. 322 * 323 * Note: String representations of APN types are intended for system apps to communicate with 324 * modem components or carriers. Non-system apps should use the integer variants instead. 325 * @hide 326 */ 327 @SystemApi 328 public static final String TYPE_XCAP_STRING = "xcap"; 329 330 /** 331 * APN type for Virtual SIM service. 332 * 333 * Note: String representations of APN types are intended for system apps to communicate with 334 * modem components or carriers. Non-system apps should use the integer variants instead. 335 * @hide 336 */ 337 @SystemApi 338 public static final String TYPE_VSIM_STRING = "vsim"; 339 340 /** 341 * APN type for Bearer Independent Protocol. 342 * 343 * Note: String representations of APN types are intended for system apps to communicate with 344 * modem components or carriers. Non-system apps should use the integer variants instead. 345 * @hide 346 */ 347 @SystemApi 348 public static final String TYPE_BIP_STRING = "bip"; 349 350 /** 351 * APN type for ENTERPRISE traffic. 352 * 353 * Note: String representations of APN types are intended for system apps to communicate with 354 * modem components or carriers. Non-system apps should use the integer variants instead. 355 * @hide 356 */ 357 @SystemApi 358 public static final String TYPE_ENTERPRISE_STRING = "enterprise"; 359 360 361 /** @hide */ 362 @IntDef(prefix = { "AUTH_TYPE_" }, value = { 363 AUTH_TYPE_UNKNOWN, 364 AUTH_TYPE_NONE, 365 AUTH_TYPE_PAP, 366 AUTH_TYPE_CHAP, 367 AUTH_TYPE_PAP_OR_CHAP, 368 }) 369 @Retention(RetentionPolicy.SOURCE) 370 public @interface AuthType {} 371 372 // Possible values for protocol which is defined in TS 27.007 section 10.1.1. 373 /** Unknown protocol. 374 * @hide 375 */ 376 public static final int PROTOCOL_UNKNOWN = -1; 377 /** Internet protocol. */ 378 public static final int PROTOCOL_IP = 0; 379 /** Internet protocol, version 6. */ 380 public static final int PROTOCOL_IPV6 = 1; 381 /** Virtual PDP type introduced to handle dual IP stack UE capability. */ 382 public static final int PROTOCOL_IPV4V6 = 2; 383 /** Point to point protocol. */ 384 public static final int PROTOCOL_PPP = 3; 385 /** Transfer of Non-IP data to external packet data network. */ 386 public static final int PROTOCOL_NON_IP = 4; 387 /** Transfer of Unstructured data to the Data Network via N6. */ 388 public static final int PROTOCOL_UNSTRUCTURED = 5; 389 390 /** @hide */ 391 @IntDef(prefix = { "PROTOCOL_" }, value = { 392 PROTOCOL_IP, 393 PROTOCOL_IPV6, 394 PROTOCOL_IPV4V6, 395 PROTOCOL_PPP, 396 PROTOCOL_NON_IP, 397 PROTOCOL_UNSTRUCTURED, 398 }) 399 @Retention(RetentionPolicy.SOURCE) 400 public @interface ProtocolType {} 401 402 // Possible values for MVNO type. 403 /** MVNO type for service provider name. */ 404 public static final int MVNO_TYPE_SPN = 0; 405 /** MVNO type for IMSI. */ 406 public static final int MVNO_TYPE_IMSI = 1; 407 /** MVNO type for group identifier level 1. */ 408 public static final int MVNO_TYPE_GID = 2; 409 /** MVNO type for ICCID. */ 410 public static final int MVNO_TYPE_ICCID = 3; 411 412 /** @hide */ 413 @IntDef(prefix = { "MVNO_TYPE_" }, value = { 414 MVNO_TYPE_SPN, 415 MVNO_TYPE_IMSI, 416 MVNO_TYPE_GID, 417 MVNO_TYPE_ICCID, 418 }) 419 @Retention(RetentionPolicy.SOURCE) 420 public @interface MvnoType {} 421 422 private static final Map<String, Integer> APN_TYPE_STRING_MAP; 423 private static final Map<Integer, String> APN_TYPE_INT_MAP; 424 private static final Map<String, Integer> PROTOCOL_STRING_MAP; 425 private static final Map<Integer, String> PROTOCOL_INT_MAP; 426 private static final Map<String, Integer> MVNO_TYPE_STRING_MAP; 427 private static final Map<Integer, String> MVNO_TYPE_INT_MAP; 428 429 static { 430 APN_TYPE_STRING_MAP = new ArrayMap<>(); APN_TYPE_STRING_MAP.put(TYPE_ALL_STRING, TYPE_ALL)431 APN_TYPE_STRING_MAP.put(TYPE_ALL_STRING, TYPE_ALL); APN_TYPE_STRING_MAP.put(TYPE_DEFAULT_STRING, TYPE_DEFAULT)432 APN_TYPE_STRING_MAP.put(TYPE_DEFAULT_STRING, TYPE_DEFAULT); APN_TYPE_STRING_MAP.put(TYPE_MMS_STRING, TYPE_MMS)433 APN_TYPE_STRING_MAP.put(TYPE_MMS_STRING, TYPE_MMS); APN_TYPE_STRING_MAP.put(TYPE_SUPL_STRING, TYPE_SUPL)434 APN_TYPE_STRING_MAP.put(TYPE_SUPL_STRING, TYPE_SUPL); APN_TYPE_STRING_MAP.put(TYPE_DUN_STRING, TYPE_DUN)435 APN_TYPE_STRING_MAP.put(TYPE_DUN_STRING, TYPE_DUN); APN_TYPE_STRING_MAP.put(TYPE_HIPRI_STRING, TYPE_HIPRI)436 APN_TYPE_STRING_MAP.put(TYPE_HIPRI_STRING, TYPE_HIPRI); APN_TYPE_STRING_MAP.put(TYPE_FOTA_STRING, TYPE_FOTA)437 APN_TYPE_STRING_MAP.put(TYPE_FOTA_STRING, TYPE_FOTA); APN_TYPE_STRING_MAP.put(TYPE_IMS_STRING, TYPE_IMS)438 APN_TYPE_STRING_MAP.put(TYPE_IMS_STRING, TYPE_IMS); APN_TYPE_STRING_MAP.put(TYPE_CBS_STRING, TYPE_CBS)439 APN_TYPE_STRING_MAP.put(TYPE_CBS_STRING, TYPE_CBS); APN_TYPE_STRING_MAP.put(TYPE_IA_STRING, TYPE_IA)440 APN_TYPE_STRING_MAP.put(TYPE_IA_STRING, TYPE_IA); APN_TYPE_STRING_MAP.put(TYPE_EMERGENCY_STRING, TYPE_EMERGENCY)441 APN_TYPE_STRING_MAP.put(TYPE_EMERGENCY_STRING, TYPE_EMERGENCY); APN_TYPE_STRING_MAP.put(TYPE_MCX_STRING, TYPE_MCX)442 APN_TYPE_STRING_MAP.put(TYPE_MCX_STRING, TYPE_MCX); APN_TYPE_STRING_MAP.put(TYPE_XCAP_STRING, TYPE_XCAP)443 APN_TYPE_STRING_MAP.put(TYPE_XCAP_STRING, TYPE_XCAP); APN_TYPE_STRING_MAP.put(TYPE_ENTERPRISE_STRING, TYPE_ENTERPRISE)444 APN_TYPE_STRING_MAP.put(TYPE_ENTERPRISE_STRING, TYPE_ENTERPRISE); APN_TYPE_STRING_MAP.put(TYPE_VSIM_STRING, TYPE_VSIM)445 APN_TYPE_STRING_MAP.put(TYPE_VSIM_STRING, TYPE_VSIM); APN_TYPE_STRING_MAP.put(TYPE_BIP_STRING, TYPE_BIP)446 APN_TYPE_STRING_MAP.put(TYPE_BIP_STRING, TYPE_BIP); 447 448 APN_TYPE_INT_MAP = new ArrayMap<>(); APN_TYPE_INT_MAP.put(TYPE_DEFAULT, TYPE_DEFAULT_STRING)449 APN_TYPE_INT_MAP.put(TYPE_DEFAULT, TYPE_DEFAULT_STRING); APN_TYPE_INT_MAP.put(TYPE_MMS, TYPE_MMS_STRING)450 APN_TYPE_INT_MAP.put(TYPE_MMS, TYPE_MMS_STRING); APN_TYPE_INT_MAP.put(TYPE_SUPL, TYPE_SUPL_STRING)451 APN_TYPE_INT_MAP.put(TYPE_SUPL, TYPE_SUPL_STRING); APN_TYPE_INT_MAP.put(TYPE_DUN, TYPE_DUN_STRING)452 APN_TYPE_INT_MAP.put(TYPE_DUN, TYPE_DUN_STRING); APN_TYPE_INT_MAP.put(TYPE_HIPRI, TYPE_HIPRI_STRING)453 APN_TYPE_INT_MAP.put(TYPE_HIPRI, TYPE_HIPRI_STRING); APN_TYPE_INT_MAP.put(TYPE_FOTA, TYPE_FOTA_STRING)454 APN_TYPE_INT_MAP.put(TYPE_FOTA, TYPE_FOTA_STRING); APN_TYPE_INT_MAP.put(TYPE_IMS, TYPE_IMS_STRING)455 APN_TYPE_INT_MAP.put(TYPE_IMS, TYPE_IMS_STRING); APN_TYPE_INT_MAP.put(TYPE_CBS, TYPE_CBS_STRING)456 APN_TYPE_INT_MAP.put(TYPE_CBS, TYPE_CBS_STRING); APN_TYPE_INT_MAP.put(TYPE_IA, TYPE_IA_STRING)457 APN_TYPE_INT_MAP.put(TYPE_IA, TYPE_IA_STRING); APN_TYPE_INT_MAP.put(TYPE_EMERGENCY, TYPE_EMERGENCY_STRING)458 APN_TYPE_INT_MAP.put(TYPE_EMERGENCY, TYPE_EMERGENCY_STRING); APN_TYPE_INT_MAP.put(TYPE_MCX, TYPE_MCX_STRING)459 APN_TYPE_INT_MAP.put(TYPE_MCX, TYPE_MCX_STRING); APN_TYPE_INT_MAP.put(TYPE_XCAP, TYPE_XCAP_STRING)460 APN_TYPE_INT_MAP.put(TYPE_XCAP, TYPE_XCAP_STRING); APN_TYPE_INT_MAP.put(TYPE_ENTERPRISE, TYPE_ENTERPRISE_STRING)461 APN_TYPE_INT_MAP.put(TYPE_ENTERPRISE, TYPE_ENTERPRISE_STRING); APN_TYPE_INT_MAP.put(TYPE_VSIM, TYPE_VSIM_STRING)462 APN_TYPE_INT_MAP.put(TYPE_VSIM, TYPE_VSIM_STRING); APN_TYPE_INT_MAP.put(TYPE_BIP, TYPE_BIP_STRING)463 APN_TYPE_INT_MAP.put(TYPE_BIP, TYPE_BIP_STRING); 464 465 PROTOCOL_STRING_MAP = new ArrayMap<>(); 466 PROTOCOL_STRING_MAP.put("IP", PROTOCOL_IP); 467 PROTOCOL_STRING_MAP.put("IPV6", PROTOCOL_IPV6); 468 PROTOCOL_STRING_MAP.put("IPV4V6", PROTOCOL_IPV4V6); 469 PROTOCOL_STRING_MAP.put("PPP", PROTOCOL_PPP); 470 PROTOCOL_STRING_MAP.put("NON-IP", PROTOCOL_NON_IP); 471 PROTOCOL_STRING_MAP.put("UNSTRUCTURED", PROTOCOL_UNSTRUCTURED); 472 473 PROTOCOL_INT_MAP = new ArrayMap<>(); PROTOCOL_INT_MAP.put(PROTOCOL_IP, R)474 PROTOCOL_INT_MAP.put(PROTOCOL_IP, "IP"); PROTOCOL_INT_MAP.put(PROTOCOL_IPV6, R)475 PROTOCOL_INT_MAP.put(PROTOCOL_IPV6, "IPV6"); PROTOCOL_INT_MAP.put(PROTOCOL_IPV4V6, R)476 PROTOCOL_INT_MAP.put(PROTOCOL_IPV4V6, "IPV4V6"); PROTOCOL_INT_MAP.put(PROTOCOL_PPP, R)477 PROTOCOL_INT_MAP.put(PROTOCOL_PPP, "PPP"); PROTOCOL_INT_MAP.put(PROTOCOL_NON_IP, R)478 PROTOCOL_INT_MAP.put(PROTOCOL_NON_IP, "NON-IP"); PROTOCOL_INT_MAP.put(PROTOCOL_UNSTRUCTURED, R)479 PROTOCOL_INT_MAP.put(PROTOCOL_UNSTRUCTURED, "UNSTRUCTURED"); 480 481 MVNO_TYPE_STRING_MAP = new ArrayMap<>(); 482 MVNO_TYPE_STRING_MAP.put("spn", MVNO_TYPE_SPN); 483 MVNO_TYPE_STRING_MAP.put("imsi", MVNO_TYPE_IMSI); 484 MVNO_TYPE_STRING_MAP.put("gid", MVNO_TYPE_GID); 485 MVNO_TYPE_STRING_MAP.put("iccid", MVNO_TYPE_ICCID); 486 487 MVNO_TYPE_INT_MAP = new ArrayMap<>(); MVNO_TYPE_INT_MAP.put(MVNO_TYPE_SPN, R)488 MVNO_TYPE_INT_MAP.put(MVNO_TYPE_SPN, "spn"); MVNO_TYPE_INT_MAP.put(MVNO_TYPE_IMSI, R)489 MVNO_TYPE_INT_MAP.put(MVNO_TYPE_IMSI, "imsi"); MVNO_TYPE_INT_MAP.put(MVNO_TYPE_GID, R)490 MVNO_TYPE_INT_MAP.put(MVNO_TYPE_GID, "gid"); MVNO_TYPE_INT_MAP.put(MVNO_TYPE_ICCID, R)491 MVNO_TYPE_INT_MAP.put(MVNO_TYPE_ICCID, "iccid"); 492 } 493 494 private final String mEntryName; 495 private final String mApnName; 496 private final String mProxyAddress; 497 private final int mProxyPort; 498 private final Uri mMmsc; 499 private final String mMmsProxyAddress; 500 private final int mMmsProxyPort; 501 private final String mUser; 502 private final String mPassword; 503 private final int mAuthType; 504 private final int mApnTypeBitmask; 505 private final int mId; 506 private final String mOperatorNumeric; 507 private final int mProtocol; 508 private final int mRoamingProtocol; 509 private final int mMtuV4; 510 private final int mMtuV6; 511 private final boolean mCarrierEnabled; 512 private final @TelephonyManager.NetworkTypeBitMask int mNetworkTypeBitmask; 513 private final @TelephonyManager.NetworkTypeBitMask long mLingeringNetworkTypeBitmask; 514 private final int mProfileId; 515 private final boolean mPersistent; 516 private final int mMaxConns; 517 private final int mWaitTime; 518 private final int mMaxConnsTime; 519 private final int mMvnoType; 520 private final String mMvnoMatchData; 521 private final int mApnSetId; 522 private boolean mPermanentFailed = false; 523 private final int mCarrierId; 524 private final int mSkip464Xlat; 525 private final boolean mAlwaysOn; 526 527 /** 528 * Returns the default MTU (Maximum Transmission Unit) size in bytes of the IPv4 routes brought 529 * up by this APN setting. Note this value will only be used when MTU size is not provided 530 * in {@link DataCallResponse#getMtuV4()} during network bring up. 531 * 532 * @return the MTU size in bytes of the route. 533 */ getMtuV4()534 public int getMtuV4() { 535 return mMtuV4; 536 } 537 538 /** 539 * Returns the MTU size of the IPv6 mobile interface to which the APN connected. Note this value 540 * will only be used when MTU size is not provided in {@link DataCallResponse#getMtuV6()} 541 * during network bring up. 542 * 543 * @return the MTU size in bytes of the route. 544 */ getMtuV6()545 public int getMtuV6() { 546 return mMtuV6; 547 } 548 549 /** 550 * Returns the profile id to which the APN saved in modem. 551 * 552 * @return the profile id of the APN 553 */ getProfileId()554 public int getProfileId() { 555 return mProfileId; 556 } 557 558 /** 559 * Returns if the APN setting is persistent on the modem. 560 * 561 * @return {@code true} if the APN setting is persistent on the modem. 562 */ isPersistent()563 public boolean isPersistent() { 564 return mPersistent; 565 } 566 567 /** 568 * Returns the max connections of this APN. 569 * 570 * @return the max connections of this APN 571 * @hide 572 */ getMaxConns()573 public int getMaxConns() { 574 return mMaxConns; 575 } 576 577 /** 578 * Returns the wait time for retry of the APN. 579 * 580 * @return the wait time for retry of the APN 581 * @hide 582 */ getWaitTime()583 public int getWaitTime() { 584 return mWaitTime; 585 } 586 587 /** 588 * Returns the time to limit max connection for the APN. 589 * 590 * @return the time to limit max connection for the APN 591 * @hide 592 */ getMaxConnsTime()593 public int getMaxConnsTime() { 594 return mMaxConnsTime; 595 } 596 597 /** 598 * Returns the MVNO data. Examples: 599 * "spn": A MOBILE, BEN NL 600 * "imsi": 302720x94, 2060188 601 * "gid": 4E, 33 602 * "iccid": 898603 etc.. 603 * 604 * @return the mvno match data 605 * @hide 606 */ getMvnoMatchData()607 public String getMvnoMatchData() { 608 return mMvnoMatchData; 609 } 610 611 /** 612 * Returns the APN set id. 613 * 614 * APNs that are part of the same set should be preferred together, e.g. if the 615 * user selects a default APN with apnSetId=1, then we will prefer all APNs with apnSetId = 1. 616 * 617 * If the apnSetId = Carriers.NO_SET_SET(=0) then the APN is not part of a set. 618 * 619 * @return the APN set id 620 * @hide 621 */ getApnSetId()622 public int getApnSetId() { 623 return mApnSetId; 624 } 625 626 /** 627 * Indicates this APN setting is permanently failed and cannot be 628 * retried by the retry manager anymore. 629 * 630 * @return if this APN setting is permanently failed 631 * @hide 632 */ getPermanentFailed()633 public boolean getPermanentFailed() { 634 return mPermanentFailed; 635 } 636 637 /** 638 * Sets if this APN setting is permanently failed. 639 * 640 * @param permanentFailed if this APN setting is permanently failed 641 * @hide 642 */ setPermanentFailed(boolean permanentFailed)643 public void setPermanentFailed(boolean permanentFailed) { 644 mPermanentFailed = permanentFailed; 645 } 646 647 /** 648 * Gets the human-readable name that describes the APN. 649 * 650 * @return the entry name for the APN 651 */ getEntryName()652 public String getEntryName() { 653 return mEntryName; 654 } 655 656 /** 657 * Returns the name of the APN. 658 * 659 * @return APN name 660 */ getApnName()661 public String getApnName() { 662 return mApnName; 663 } 664 665 /** 666 * Gets the HTTP proxy address configured for the APN. The proxy address might be an IP address 667 * or hostname. This method returns {@code null} if system networking (typically DNS) isn’t 668 * available to resolve a hostname value—values set as IP addresses don’t have this restriction. 669 * This is a known problem and will be addressed in a future release. 670 * 671 * @return the HTTP proxy address or {@code null} if DNS isn’t available to resolve a hostname 672 * @deprecated use {@link #getProxyAddressAsString()} instead. 673 */ 674 @Deprecated getProxyAddress()675 public InetAddress getProxyAddress() { 676 return inetAddressFromString(mProxyAddress); 677 } 678 679 /** 680 * Returns the proxy address of the APN. 681 * 682 * @return proxy address. 683 */ getProxyAddressAsString()684 public String getProxyAddressAsString() { 685 return mProxyAddress; 686 } 687 688 /** 689 * Returns the proxy address of the APN. 690 * 691 * @return proxy address. 692 */ getProxyPort()693 public int getProxyPort() { 694 return mProxyPort; 695 } 696 /** 697 * Returns the MMSC Uri of the APN. 698 * 699 * @return MMSC Uri. 700 */ getMmsc()701 public Uri getMmsc() { 702 return mMmsc; 703 } 704 705 /** 706 * Gets the MMS proxy address configured for the APN. The MMS proxy address might be an IP 707 * address or hostname. This method returns {@code null} if system networking (typically DNS) 708 * isn’t available to resolve a hostname value—values set as IP addresses don’t have this 709 * restriction. This is a known problem and will be addressed in a future release. 710 * 711 * @return the MMS proxy address or {@code null} if DNS isn’t available to resolve a hostname 712 * @deprecated use {@link #getMmsProxyAddressAsString()} instead. 713 */ 714 @Deprecated getMmsProxyAddress()715 public InetAddress getMmsProxyAddress() { 716 return inetAddressFromString(mMmsProxyAddress); 717 } 718 719 /** 720 * Returns the MMS proxy address of the APN. 721 * 722 * @return MMS proxy address. 723 */ getMmsProxyAddressAsString()724 public String getMmsProxyAddressAsString() { 725 return mMmsProxyAddress; 726 } 727 728 /** 729 * Returns the MMS proxy port of the APN. 730 * 731 * @return MMS proxy port 732 */ getMmsProxyPort()733 public int getMmsProxyPort() { 734 return mMmsProxyPort; 735 } 736 737 /** 738 * Returns the APN username of the APN. 739 * 740 * @return APN username 741 */ getUser()742 public String getUser() { 743 return mUser; 744 } 745 746 /** 747 * Returns the APN password of the APN. 748 * 749 * @return APN password 750 */ getPassword()751 public String getPassword() { 752 return mPassword; 753 } 754 755 /** 756 * Returns the authentication type of the APN. 757 * 758 * @return authentication type 759 */ 760 @AuthType getAuthType()761 public int getAuthType() { 762 return mAuthType; 763 } 764 765 /** 766 * Returns the bitmask of APN types. 767 * 768 * <p>Apn types are usage categories for an APN entry. One APN entry may support multiple 769 * APN types, eg, a single APN may service regular internet traffic ("default") as well as 770 * MMS-specific connections. 771 * 772 * <p>The bitmask of APN types is calculated from APN types defined in {@link ApnSetting}. 773 * 774 * @see Builder#setApnTypeBitmask(int) 775 * @return a bitmask describing the types of the APN 776 */ getApnTypeBitmask()777 public @ApnType int getApnTypeBitmask() { 778 return mApnTypeBitmask; 779 } 780 781 /** 782 * Returns the unique database id for this entry. 783 * 784 * @return the unique database id 785 */ getId()786 public int getId() { 787 return mId; 788 } 789 790 /** 791 * Returns the numeric operator ID for the APN. Numeric operator ID is defined as 792 * {@link android.provider.Telephony.Carriers#MCC} + 793 * {@link android.provider.Telephony.Carriers#MNC}. 794 * 795 * @return the numeric operator ID 796 */ getOperatorNumeric()797 public String getOperatorNumeric() { 798 return mOperatorNumeric; 799 } 800 801 /** 802 * Returns the protocol to use to connect to this APN. 803 * 804 * <p>Protocol is one of the {@code PDP_type} values in TS 27.007 section 10.1.1. 805 * 806 * @see Builder#setProtocol(int) 807 * @return the protocol 808 */ 809 @ProtocolType getProtocol()810 public int getProtocol() { 811 return mProtocol; 812 } 813 814 /** 815 * Returns the protocol to use to connect to this APN while the device is roaming. 816 * 817 * <p>Roaming protocol is one of the {@code PDP_type} values in TS 27.007 section 10.1.1. 818 * 819 * @see Builder#setRoamingProtocol(int) 820 * @return the roaming protocol 821 */ 822 @ProtocolType getRoamingProtocol()823 public int getRoamingProtocol() { 824 return mRoamingProtocol; 825 } 826 827 /** 828 * Returns the current status of APN. 829 * 830 * {@code true} : enabled APN. 831 * {@code false} : disabled APN. 832 * 833 * @return the current status 834 */ isEnabled()835 public boolean isEnabled() { 836 return mCarrierEnabled; 837 } 838 839 /** 840 * Returns a bitmask describing the Radio Technologies (Network Types) which this APN may use. 841 * 842 * NetworkType bitmask is calculated from NETWORK_TYPE defined in {@link TelephonyManager}. 843 * 844 * Examples of Network Types include {@link TelephonyManager#NETWORK_TYPE_UNKNOWN}, 845 * {@link TelephonyManager#NETWORK_TYPE_GPRS}, {@link TelephonyManager#NETWORK_TYPE_EDGE}. 846 * 847 * @return a bitmask describing the Radio Technologies (Network Types) or 0 if it is undefined. 848 */ getNetworkTypeBitmask()849 public int getNetworkTypeBitmask() { 850 return mNetworkTypeBitmask; 851 } 852 853 /** 854 * Returns a bitmask describing the Radio Technologies (Network Types) that should not be torn 855 * down if it exists or brought up if it already exists for this APN. 856 * 857 * NetworkType bitmask is calculated from NETWORK_TYPE defined in {@link TelephonyManager}. 858 * 859 * Examples of Network Types include {@link TelephonyManager#NETWORK_TYPE_UNKNOWN}, 860 * {@link TelephonyManager#NETWORK_TYPE_GPRS}, {@link TelephonyManager#NETWORK_TYPE_EDGE}. 861 * 862 * @return a bitmask describing the Radio Technologies (Network Types) that should linger 863 * or 0 if it is undefined. 864 * @hide 865 */ getLingeringNetworkTypeBitmask()866 public @TelephonyManager.NetworkTypeBitMask long getLingeringNetworkTypeBitmask() { 867 return mLingeringNetworkTypeBitmask; 868 } 869 870 /** 871 * Returns the MVNO match type for this APN. 872 * 873 * @see Builder#setMvnoType(int) 874 * @return the MVNO match type 875 */ 876 @MvnoType getMvnoType()877 public int getMvnoType() { 878 return mMvnoType; 879 } 880 881 /** 882 * Returns the carrier id for this APN. 883 * 884 * @see Builder#setCarrierId(int) 885 * @return the carrier id 886 */ getCarrierId()887 public int getCarrierId() { 888 return mCarrierId; 889 } 890 891 /** 892 * Returns the skip464xlat flag for this APN. 893 * 894 * @return SKIP_464XLAT_DEFAULT, SKIP_464XLAT_DISABLE or SKIP_464XLAT_ENABLE 895 * @hide 896 */ 897 @Skip464XlatStatus getSkip464Xlat()898 public int getSkip464Xlat() { 899 return mSkip464Xlat; 900 } 901 902 /** 903 * Returns whether User Plane resources have to be activated during every transition from 904 * CM-IDLE mode to CM-CONNECTED state for this APN 905 * See 3GPP TS 23.501 section 5.6.13 906 * 907 * @return True if the PDU session for this APN should always be on and false otherwise 908 * @hide 909 */ isAlwaysOn()910 public boolean isAlwaysOn() { 911 return mAlwaysOn; 912 } 913 ApnSetting(Builder builder)914 private ApnSetting(Builder builder) { 915 this.mEntryName = builder.mEntryName; 916 this.mApnName = builder.mApnName; 917 this.mProxyAddress = builder.mProxyAddress; 918 this.mProxyPort = builder.mProxyPort; 919 this.mMmsc = builder.mMmsc; 920 this.mMmsProxyAddress = builder.mMmsProxyAddress; 921 this.mMmsProxyPort = builder.mMmsProxyPort; 922 this.mUser = builder.mUser; 923 this.mPassword = builder.mPassword; 924 this.mAuthType = (builder.mAuthType != AUTH_TYPE_UNKNOWN) 925 ? builder.mAuthType 926 : TextUtils.isEmpty(builder.mUser) 927 ? AUTH_TYPE_NONE 928 : AUTH_TYPE_PAP_OR_CHAP; 929 this.mApnTypeBitmask = builder.mApnTypeBitmask; 930 this.mId = builder.mId; 931 this.mOperatorNumeric = builder.mOperatorNumeric; 932 this.mProtocol = builder.mProtocol; 933 this.mRoamingProtocol = builder.mRoamingProtocol; 934 this.mMtuV4 = builder.mMtuV4; 935 this.mMtuV6 = builder.mMtuV6; 936 this.mCarrierEnabled = builder.mCarrierEnabled; 937 this.mNetworkTypeBitmask = builder.mNetworkTypeBitmask; 938 this.mLingeringNetworkTypeBitmask = builder.mLingeringNetworkTypeBitmask; 939 this.mProfileId = builder.mProfileId; 940 this.mPersistent = builder.mModemCognitive; 941 this.mMaxConns = builder.mMaxConns; 942 this.mWaitTime = builder.mWaitTime; 943 this.mMaxConnsTime = builder.mMaxConnsTime; 944 this.mMvnoType = builder.mMvnoType; 945 this.mMvnoMatchData = builder.mMvnoMatchData; 946 this.mApnSetId = builder.mApnSetId; 947 this.mCarrierId = builder.mCarrierId; 948 this.mSkip464Xlat = builder.mSkip464Xlat; 949 this.mAlwaysOn = builder.mAlwaysOn; 950 } 951 952 /** 953 * @hide 954 */ makeApnSetting(Cursor cursor)955 public static ApnSetting makeApnSetting(Cursor cursor) { 956 final int apnTypesBitmask = getApnTypesBitmaskFromString( 957 cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.TYPE))); 958 int networkTypeBitmask = cursor.getInt( 959 cursor.getColumnIndexOrThrow(Telephony.Carriers.NETWORK_TYPE_BITMASK)); 960 if (networkTypeBitmask == 0) { 961 final int bearerBitmask = cursor.getInt(cursor.getColumnIndexOrThrow( 962 Telephony.Carriers.BEARER_BITMASK)); 963 networkTypeBitmask = 964 ServiceState.convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask); 965 } 966 int mtuV4 = cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MTU_V4)); 967 if (mtuV4 == UNSET_MTU) { 968 mtuV4 = cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MTU)); 969 } 970 971 return new Builder() 972 .setId(cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID))) 973 .setOperatorNumeric(cursor.getString( 974 cursor.getColumnIndexOrThrow(Telephony.Carriers.NUMERIC))) 975 .setEntryName(cursor.getString( 976 cursor.getColumnIndexOrThrow(Telephony.Carriers.NAME))) 977 .setApnName(cursor.getString(cursor.getColumnIndexOrThrow(Telephony.Carriers.APN))) 978 .setProxyAddress(cursor.getString( 979 cursor.getColumnIndexOrThrow(Telephony.Carriers.PROXY))) 980 .setProxyPort(portFromString(cursor.getString( 981 cursor.getColumnIndexOrThrow(Telephony.Carriers.PORT)))) 982 .setMmsc(UriFromString(cursor.getString( 983 cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSC)))) 984 .setMmsProxyAddress(cursor.getString( 985 cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPROXY))) 986 .setMmsProxyPort(portFromString(cursor.getString( 987 cursor.getColumnIndexOrThrow(Telephony.Carriers.MMSPORT)))) 988 .setUser(cursor.getString( 989 cursor.getColumnIndexOrThrow(Telephony.Carriers.USER))) 990 .setPassword(cursor.getString( 991 cursor.getColumnIndexOrThrow(Telephony.Carriers.PASSWORD))) 992 .setAuthType(cursor.getInt( 993 cursor.getColumnIndexOrThrow(Telephony.Carriers.AUTH_TYPE))) 994 .setApnTypeBitmask(apnTypesBitmask) 995 .setProtocol(getProtocolIntFromString( 996 cursor.getString( 997 cursor.getColumnIndexOrThrow(Telephony.Carriers.PROTOCOL)))) 998 .setRoamingProtocol(getProtocolIntFromString( 999 cursor.getString(cursor.getColumnIndexOrThrow( 1000 Telephony.Carriers.ROAMING_PROTOCOL)))) 1001 .setCarrierEnabled(cursor.getInt(cursor.getColumnIndexOrThrow( 1002 Telephony.Carriers.CARRIER_ENABLED)) == 1) 1003 .setNetworkTypeBitmask(networkTypeBitmask) 1004 .setLingeringNetworkTypeBitmask(cursor.getInt(cursor.getColumnIndexOrThrow( 1005 Carriers.LINGERING_NETWORK_TYPE_BITMASK))) 1006 .setProfileId(cursor.getInt( 1007 cursor.getColumnIndexOrThrow(Telephony.Carriers.PROFILE_ID))) 1008 .setModemCognitive(cursor.getInt(cursor.getColumnIndexOrThrow( 1009 Telephony.Carriers.MODEM_PERSIST)) == 1) 1010 .setMaxConns(cursor.getInt( 1011 cursor.getColumnIndexOrThrow(Telephony.Carriers.MAX_CONNECTIONS))) 1012 .setWaitTime(cursor.getInt( 1013 cursor.getColumnIndexOrThrow(Telephony.Carriers.WAIT_TIME_RETRY))) 1014 .setMaxConnsTime(cursor.getInt(cursor.getColumnIndexOrThrow( 1015 Telephony.Carriers.TIME_LIMIT_FOR_MAX_CONNECTIONS))) 1016 .setMtuV4(mtuV4) 1017 .setMtuV6(cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers.MTU_V6))) 1018 .setMvnoType(getMvnoTypeIntFromString( 1019 cursor.getString(cursor.getColumnIndexOrThrow( 1020 Telephony.Carriers.MVNO_TYPE)))) 1021 .setMvnoMatchData(cursor.getString(cursor.getColumnIndexOrThrow( 1022 Telephony.Carriers.MVNO_MATCH_DATA))) 1023 .setApnSetId(cursor.getInt( 1024 cursor.getColumnIndexOrThrow(Telephony.Carriers.APN_SET_ID))) 1025 .setCarrierId(cursor.getInt( 1026 cursor.getColumnIndexOrThrow(Telephony.Carriers.CARRIER_ID))) 1027 .setSkip464Xlat(cursor.getInt(cursor.getColumnIndexOrThrow(Carriers.SKIP_464XLAT))) 1028 .setAlwaysOn(cursor.getInt(cursor.getColumnIndexOrThrow(Carriers.ALWAYS_ON)) == 1) 1029 .buildWithoutCheck(); 1030 } 1031 1032 /** 1033 * @hide 1034 */ makeApnSetting(ApnSetting apn)1035 public static ApnSetting makeApnSetting(ApnSetting apn) { 1036 return new Builder() 1037 .setId(apn.mId) 1038 .setOperatorNumeric(apn.mOperatorNumeric) 1039 .setEntryName(apn.mEntryName) 1040 .setApnName(apn.mApnName) 1041 .setProxyAddress(apn.mProxyAddress) 1042 .setProxyPort(apn.mProxyPort) 1043 .setMmsc(apn.mMmsc) 1044 .setMmsProxyAddress(apn.mMmsProxyAddress) 1045 .setMmsProxyPort(apn.mMmsProxyPort) 1046 .setUser(apn.mUser) 1047 .setPassword(apn.mPassword) 1048 .setAuthType(apn.mAuthType) 1049 .setApnTypeBitmask(apn.mApnTypeBitmask) 1050 .setProtocol(apn.mProtocol) 1051 .setRoamingProtocol(apn.mRoamingProtocol) 1052 .setCarrierEnabled(apn.mCarrierEnabled) 1053 .setNetworkTypeBitmask(apn.mNetworkTypeBitmask) 1054 .setLingeringNetworkTypeBitmask(apn.mLingeringNetworkTypeBitmask) 1055 .setProfileId(apn.mProfileId) 1056 .setModemCognitive(apn.mPersistent) 1057 .setMaxConns(apn.mMaxConns) 1058 .setWaitTime(apn.mWaitTime) 1059 .setMaxConnsTime(apn.mMaxConnsTime) 1060 .setMtuV4(apn.mMtuV4) 1061 .setMtuV6(apn.mMtuV6) 1062 .setMvnoType(apn.mMvnoType) 1063 .setMvnoMatchData(apn.mMvnoMatchData) 1064 .setApnSetId(apn.mApnSetId) 1065 .setCarrierId(apn.mCarrierId) 1066 .setSkip464Xlat(apn.mSkip464Xlat) 1067 .setAlwaysOn(apn.mAlwaysOn) 1068 .buildWithoutCheck(); 1069 } 1070 1071 /** 1072 * Returns the string representation of ApnSetting. 1073 * 1074 * This method prints null for unset elements. The output doesn't contain password or user. 1075 * @hide 1076 */ toString()1077 public String toString() { 1078 StringBuilder sb = new StringBuilder(); 1079 sb.append("[ApnSetting] ") 1080 .append(mEntryName) 1081 .append(", ").append(mId) 1082 .append(", ").append(mOperatorNumeric) 1083 .append(", ").append(mApnName) 1084 .append(", ").append(mProxyAddress) 1085 .append(", ").append(UriToString(mMmsc)) 1086 .append(", ").append(mMmsProxyAddress) 1087 .append(", ").append(portToString(mMmsProxyPort)) 1088 .append(", ").append(portToString(mProxyPort)) 1089 .append(", ").append(mAuthType).append(", "); 1090 final String[] types = getApnTypesStringFromBitmask(mApnTypeBitmask).split(","); 1091 sb.append(TextUtils.join(" | ", types)); 1092 sb.append(", ").append(PROTOCOL_INT_MAP.get(mProtocol)); 1093 sb.append(", ").append(PROTOCOL_INT_MAP.get(mRoamingProtocol)); 1094 sb.append(", ").append(mCarrierEnabled); 1095 sb.append(", ").append(mProfileId); 1096 sb.append(", ").append(mPersistent); 1097 sb.append(", ").append(mMaxConns); 1098 sb.append(", ").append(mWaitTime); 1099 sb.append(", ").append(mMaxConnsTime); 1100 sb.append(", ").append(mMtuV4); 1101 sb.append(", ").append(mMtuV6); 1102 sb.append(", ").append(MVNO_TYPE_INT_MAP.get(mMvnoType)); 1103 sb.append(", ").append(mMvnoMatchData); 1104 sb.append(", ").append(mPermanentFailed); 1105 sb.append(", ").append(TelephonyManager.convertNetworkTypeBitmaskToString( 1106 mNetworkTypeBitmask)); 1107 sb.append(", ").append(TelephonyManager.convertNetworkTypeBitmaskToString( 1108 mLingeringNetworkTypeBitmask)); 1109 sb.append(", ").append(mApnSetId); 1110 sb.append(", ").append(mCarrierId); 1111 sb.append(", ").append(mSkip464Xlat); 1112 sb.append(", ").append(mAlwaysOn); 1113 sb.append(", ").append(Objects.hash(mUser, mPassword)); 1114 return sb.toString(); 1115 } 1116 1117 /** 1118 * Returns true if there are MVNO params specified. 1119 * @hide 1120 */ hasMvnoParams()1121 public boolean hasMvnoParams() { 1122 return !TextUtils.isEmpty(getMvnoTypeStringFromInt(mMvnoType)) 1123 && !TextUtils.isEmpty(mMvnoMatchData); 1124 } 1125 hasApnType(int type)1126 private boolean hasApnType(int type) { 1127 return (mApnTypeBitmask & type) == type; 1128 } 1129 1130 /** @hide */ isEmergencyApn()1131 public boolean isEmergencyApn() { 1132 return hasApnType(TYPE_EMERGENCY); 1133 } 1134 1135 /** @hide */ canHandleType(@pnType int type)1136 public boolean canHandleType(@ApnType int type) { 1137 if (!mCarrierEnabled) { 1138 return false; 1139 } 1140 // DEFAULT can handle HIPRI. 1141 return hasApnType(type); 1142 } 1143 1144 // Check whether the types of two APN same (even only one type of each APN is same). typeSameAny(ApnSetting first, ApnSetting second)1145 private boolean typeSameAny(ApnSetting first, ApnSetting second) { 1146 if (VDBG) { 1147 StringBuilder apnType1 = new StringBuilder(first.mApnName + ": "); 1148 apnType1.append(getApnTypesStringFromBitmask(first.mApnTypeBitmask)); 1149 1150 StringBuilder apnType2 = new StringBuilder(second.mApnName + ": "); 1151 apnType2.append(getApnTypesStringFromBitmask(second.mApnTypeBitmask)); 1152 1153 Rlog.d(LOG_TAG, "APN1: is " + apnType1); 1154 Rlog.d(LOG_TAG, "APN2: is " + apnType2); 1155 } 1156 1157 if ((first.mApnTypeBitmask & second.mApnTypeBitmask) != 0) { 1158 if (VDBG) { 1159 Rlog.d(LOG_TAG, "typeSameAny: return true"); 1160 } 1161 return true; 1162 } 1163 1164 if (VDBG) { 1165 Rlog.d(LOG_TAG, "typeSameAny: return false"); 1166 } 1167 return false; 1168 } 1169 1170 @Override hashCode()1171 public int hashCode() { 1172 return Objects.hash(mApnName, mProxyAddress, mProxyPort, mMmsc, mMmsProxyAddress, 1173 mMmsProxyPort, mUser, mPassword, mAuthType, mApnTypeBitmask, mId, mOperatorNumeric, 1174 mProtocol, mRoamingProtocol, mMtuV4, mMtuV6, mCarrierEnabled, mNetworkTypeBitmask, 1175 mLingeringNetworkTypeBitmask, mProfileId, mPersistent, mMaxConns, mWaitTime, 1176 mMaxConnsTime, mMvnoType, mMvnoMatchData, mApnSetId, mCarrierId, mSkip464Xlat, 1177 mAlwaysOn); 1178 } 1179 1180 @Override equals(Object o)1181 public boolean equals(Object o) { 1182 if (o instanceof ApnSetting == false) { 1183 return false; 1184 } 1185 1186 ApnSetting other = (ApnSetting) o; 1187 1188 return mEntryName.equals(other.mEntryName) 1189 && Objects.equals(mId, other.mId) 1190 && Objects.equals(mOperatorNumeric, other.mOperatorNumeric) 1191 && Objects.equals(mApnName, other.mApnName) 1192 && Objects.equals(mProxyAddress, other.mProxyAddress) 1193 && Objects.equals(mMmsc, other.mMmsc) 1194 && Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress) 1195 && Objects.equals(mMmsProxyPort, other.mMmsProxyPort) 1196 && Objects.equals(mProxyPort, other.mProxyPort) 1197 && Objects.equals(mUser, other.mUser) 1198 && Objects.equals(mPassword, other.mPassword) 1199 && Objects.equals(mAuthType, other.mAuthType) 1200 && Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask) 1201 && Objects.equals(mProtocol, other.mProtocol) 1202 && Objects.equals(mRoamingProtocol, other.mRoamingProtocol) 1203 && Objects.equals(mCarrierEnabled, other.mCarrierEnabled) 1204 && Objects.equals(mProfileId, other.mProfileId) 1205 && Objects.equals(mPersistent, other.mPersistent) 1206 && Objects.equals(mMaxConns, other.mMaxConns) 1207 && Objects.equals(mWaitTime, other.mWaitTime) 1208 && Objects.equals(mMaxConnsTime, other.mMaxConnsTime) 1209 && Objects.equals(mMtuV4, other.mMtuV4) 1210 && Objects.equals(mMtuV6, other.mMtuV6) 1211 && Objects.equals(mMvnoType, other.mMvnoType) 1212 && Objects.equals(mMvnoMatchData, other.mMvnoMatchData) 1213 && Objects.equals(mNetworkTypeBitmask, other.mNetworkTypeBitmask) 1214 && Objects.equals(mLingeringNetworkTypeBitmask, other.mLingeringNetworkTypeBitmask) 1215 && Objects.equals(mApnSetId, other.mApnSetId) 1216 && Objects.equals(mCarrierId, other.mCarrierId) 1217 && Objects.equals(mSkip464Xlat, other.mSkip464Xlat) 1218 && Objects.equals(mAlwaysOn, other.mAlwaysOn); 1219 } 1220 1221 /** 1222 * Compare two APN settings 1223 * 1224 * Note: This method does not compare 'mId', 'mNetworkTypeBitmask'. We only use this for 1225 * determining if tearing a data call is needed when conditions change. See 1226 * cleanUpConnectionsOnUpdatedApns in DcTracker. 1227 * 1228 * @param o the other object to compare 1229 * @param isDataRoaming True if the device is on data roaming 1230 * @return True if the two APN settings are same 1231 * @hide 1232 */ equals(Object o, boolean isDataRoaming)1233 public boolean equals(Object o, boolean isDataRoaming) { 1234 if (!(o instanceof ApnSetting)) { 1235 return false; 1236 } 1237 1238 ApnSetting other = (ApnSetting) o; 1239 1240 return mEntryName.equals(other.mEntryName) 1241 && Objects.equals(mOperatorNumeric, other.mOperatorNumeric) 1242 && Objects.equals(mApnName, other.mApnName) 1243 && Objects.equals(mProxyAddress, other.mProxyAddress) 1244 && Objects.equals(mMmsc, other.mMmsc) 1245 && Objects.equals(mMmsProxyAddress, other.mMmsProxyAddress) 1246 && Objects.equals(mMmsProxyPort, other.mMmsProxyPort) 1247 && Objects.equals(mProxyPort, other.mProxyPort) 1248 && Objects.equals(mUser, other.mUser) 1249 && Objects.equals(mPassword, other.mPassword) 1250 && Objects.equals(mAuthType, other.mAuthType) 1251 && Objects.equals(mApnTypeBitmask, other.mApnTypeBitmask) 1252 && Objects.equals(mLingeringNetworkTypeBitmask, other.mLingeringNetworkTypeBitmask) 1253 && (isDataRoaming || Objects.equals(mProtocol, other.mProtocol)) 1254 && (!isDataRoaming || Objects.equals(mRoamingProtocol, other.mRoamingProtocol)) 1255 && Objects.equals(mCarrierEnabled, other.mCarrierEnabled) 1256 && Objects.equals(mProfileId, other.mProfileId) 1257 && Objects.equals(mPersistent, other.mPersistent) 1258 && Objects.equals(mMaxConns, other.mMaxConns) 1259 && Objects.equals(mWaitTime, other.mWaitTime) 1260 && Objects.equals(mMaxConnsTime, other.mMaxConnsTime) 1261 && Objects.equals(mMtuV4, other.mMtuV4) 1262 && Objects.equals(mMtuV6, other.mMtuV6) 1263 && Objects.equals(mMvnoType, other.mMvnoType) 1264 && Objects.equals(mMvnoMatchData, other.mMvnoMatchData) 1265 && Objects.equals(mApnSetId, other.mApnSetId) 1266 && Objects.equals(mCarrierId, other.mCarrierId) 1267 && Objects.equals(mSkip464Xlat, other.mSkip464Xlat) 1268 && Objects.equals(mAlwaysOn, other.mAlwaysOn); 1269 } 1270 1271 /** 1272 * Check if neither mention DUN and are substantially similar 1273 * 1274 * @param other The other APN settings to compare 1275 * @return True if two APN settings are similar 1276 * @hide 1277 */ similar(ApnSetting other)1278 public boolean similar(ApnSetting other) { 1279 return (!this.canHandleType(TYPE_DUN) 1280 && !other.canHandleType(TYPE_DUN) 1281 && Objects.equals(this.mApnName, other.mApnName) 1282 && xorEqualsString(this.mProxyAddress, other.mProxyAddress) 1283 && xorEqualsInt(this.mProxyPort, other.mProxyPort) 1284 && xorEquals(this.mMmsc, other.mMmsc) 1285 && xorEqualsString(this.mMmsProxyAddress, other.mMmsProxyAddress) 1286 && xorEqualsInt(this.mMmsProxyPort, other.mMmsProxyPort)) 1287 && xorEqualsString(this.mUser, other.mUser) 1288 && xorEqualsString(this.mPassword, other.mPassword) 1289 && Objects.equals(this.mAuthType, other.mAuthType) 1290 && !typeSameAny(this, other) 1291 && Objects.equals(this.mOperatorNumeric, other.mOperatorNumeric) 1292 && Objects.equals(this.mProtocol, other.mProtocol) 1293 && Objects.equals(this.mRoamingProtocol, other.mRoamingProtocol) 1294 && mtuUnsetOrEquals(this.mMtuV4, other.mMtuV4) 1295 && mtuUnsetOrEquals(this.mMtuV6, other.mMtuV6) 1296 && Objects.equals(this.mCarrierEnabled, other.mCarrierEnabled) 1297 && Objects.equals(this.mNetworkTypeBitmask, other.mNetworkTypeBitmask) 1298 && Objects.equals(this.mLingeringNetworkTypeBitmask, 1299 other.mLingeringNetworkTypeBitmask) 1300 && Objects.equals(this.mProfileId, other.mProfileId) 1301 && Objects.equals(this.mPersistent, other.mPersistent) 1302 && Objects.equals(this.mApnSetId, other.mApnSetId) 1303 && Objects.equals(this.mCarrierId, other.mCarrierId) 1304 && Objects.equals(this.mSkip464Xlat, other.mSkip464Xlat) 1305 && Objects.equals(this.mAlwaysOn, other.mAlwaysOn); 1306 } 1307 1308 // Equal or one is null. xorEquals(Object first, Object second)1309 private boolean xorEquals(Object first, Object second) { 1310 return first == null || second == null || first.equals(second); 1311 } 1312 1313 // Equal or one is null. xorEqualsString(String first, String second)1314 private boolean xorEqualsString(String first, String second) { 1315 return TextUtils.isEmpty(first) || TextUtils.isEmpty(second) || first.equals(second); 1316 } 1317 1318 // Equal or one is not specified. xorEqualsInt(int first, int second)1319 private boolean xorEqualsInt(int first, int second) { 1320 return first == UNSPECIFIED_INT || second == UNSPECIFIED_INT 1321 || first == second; 1322 } 1323 1324 // Equal or one is not specified. Specific to MTU where <= 0 indicates unset. mtuUnsetOrEquals(int first, int second)1325 private boolean mtuUnsetOrEquals(int first, int second) { 1326 return first <= 0 || second <= 0 || first == second; 1327 } 1328 nullToEmpty(String stringValue)1329 private String nullToEmpty(String stringValue) { 1330 return stringValue == null ? UNSPECIFIED_STRING : stringValue; 1331 } 1332 1333 /** 1334 * @hide 1335 * Called by {@link android.app.admin.DevicePolicyManager} to convert this APN into 1336 * ContentValue. If a field is not specified then we put "" instead of null. 1337 */ toContentValues()1338 public ContentValues toContentValues() { 1339 ContentValues apnValue = new ContentValues(); 1340 apnValue.put(Telephony.Carriers.NUMERIC, nullToEmpty(mOperatorNumeric)); 1341 // If the APN is editable, the user may be able to set an invalid numeric. The numeric must 1342 // always be 5 or 6 characters (depending on the length of the MNC), so skip if it is 1343 // potentially invalid. 1344 if (!TextUtils.isEmpty(mOperatorNumeric) 1345 && (mOperatorNumeric.length() == 5 || mOperatorNumeric.length() == 6)) { 1346 apnValue.put(Telephony.Carriers.MCC, mOperatorNumeric.substring(0, 3)); 1347 apnValue.put(Telephony.Carriers.MNC, mOperatorNumeric.substring(3)); 1348 } 1349 apnValue.put(Telephony.Carriers.NAME, nullToEmpty(mEntryName)); 1350 apnValue.put(Telephony.Carriers.APN, nullToEmpty(mApnName)); 1351 apnValue.put(Telephony.Carriers.PROXY, nullToEmpty(mProxyAddress)); 1352 apnValue.put(Telephony.Carriers.PORT, nullToEmpty(portToString(mProxyPort))); 1353 apnValue.put(Telephony.Carriers.MMSC, nullToEmpty(UriToString(mMmsc))); 1354 apnValue.put(Telephony.Carriers.MMSPORT, nullToEmpty(portToString(mMmsProxyPort))); 1355 apnValue.put(Telephony.Carriers.MMSPROXY, nullToEmpty( 1356 mMmsProxyAddress)); 1357 apnValue.put(Telephony.Carriers.USER, nullToEmpty(mUser)); 1358 apnValue.put(Telephony.Carriers.PASSWORD, nullToEmpty(mPassword)); 1359 apnValue.put(Telephony.Carriers.AUTH_TYPE, mAuthType); 1360 String apnType = getApnTypesStringFromBitmask(mApnTypeBitmask); 1361 apnValue.put(Telephony.Carriers.TYPE, nullToEmpty(apnType)); 1362 apnValue.put(Telephony.Carriers.PROTOCOL, 1363 getProtocolStringFromInt(mProtocol)); 1364 apnValue.put(Telephony.Carriers.ROAMING_PROTOCOL, 1365 getProtocolStringFromInt(mRoamingProtocol)); 1366 apnValue.put(Telephony.Carriers.CARRIER_ENABLED, mCarrierEnabled); 1367 apnValue.put(Telephony.Carriers.MVNO_TYPE, getMvnoTypeStringFromInt(mMvnoType)); 1368 apnValue.put(Telephony.Carriers.MVNO_MATCH_DATA, nullToEmpty(mMvnoMatchData)); 1369 apnValue.put(Telephony.Carriers.NETWORK_TYPE_BITMASK, mNetworkTypeBitmask); 1370 apnValue.put(Telephony.Carriers.LINGERING_NETWORK_TYPE_BITMASK, 1371 mLingeringNetworkTypeBitmask); 1372 apnValue.put(Telephony.Carriers.MTU_V4, mMtuV4); 1373 apnValue.put(Telephony.Carriers.MTU_V6, mMtuV6); 1374 apnValue.put(Telephony.Carriers.CARRIER_ID, mCarrierId); 1375 apnValue.put(Telephony.Carriers.SKIP_464XLAT, mSkip464Xlat); 1376 apnValue.put(Telephony.Carriers.ALWAYS_ON, mAlwaysOn); 1377 return apnValue; 1378 } 1379 1380 /** 1381 * Get supported APN types 1382 * 1383 * @return list of APN types 1384 * @hide 1385 */ 1386 @ApnType getApnTypes()1387 public List<Integer> getApnTypes() { 1388 List<Integer> types = new ArrayList<>(); 1389 for (Integer type : APN_TYPE_INT_MAP.keySet()) { 1390 if ((mApnTypeBitmask & type) == type) { 1391 types.add(type); 1392 } 1393 } 1394 return types; 1395 } 1396 1397 /** 1398 * Converts the integer value of an APN type to the string version. 1399 * @param apnTypeBitmask bitmask of APN types. 1400 * @return comma delimited list of APN types. 1401 * @hide 1402 */ 1403 @NonNull getApnTypesStringFromBitmask(int apnTypeBitmask)1404 public static String getApnTypesStringFromBitmask(int apnTypeBitmask) { 1405 List<String> types = new ArrayList<>(); 1406 for (Integer type : APN_TYPE_INT_MAP.keySet()) { 1407 if ((apnTypeBitmask & type) == type) { 1408 types.add(APN_TYPE_INT_MAP.get(type)); 1409 } 1410 } 1411 return TextUtils.join(",", types); 1412 } 1413 1414 /** 1415 * Converts the APN type bitmask to an array of all APN types 1416 * @param apnTypeBitmask bitmask of APN types. 1417 * @return int array of APN types 1418 * @hide 1419 */ 1420 @NonNull getApnTypesFromBitmask(int apnTypeBitmask)1421 public static int[] getApnTypesFromBitmask(int apnTypeBitmask) { 1422 return APN_TYPE_INT_MAP.keySet().stream() 1423 .filter(type -> ((apnTypeBitmask & type) == type)) 1424 .mapToInt(Integer::intValue) 1425 .toArray(); 1426 } 1427 1428 /** 1429 * Converts the integer representation of APN type to its string representation. 1430 * 1431 * @param apnType APN type as an integer 1432 * @return String representation of the APN type, or an empty string if the provided integer is 1433 * not a valid APN type. 1434 * @hide 1435 */ 1436 @SystemApi getApnTypeString(@pnType int apnType)1437 public static @NonNull @ApnTypeString String getApnTypeString(@ApnType int apnType) { 1438 if (apnType == TYPE_ALL) { 1439 return "*"; 1440 } 1441 String apnTypeString = APN_TYPE_INT_MAP.get(apnType); 1442 return apnTypeString == null ? "" : apnTypeString; 1443 } 1444 1445 /** 1446 * Converts the string representation of an APN type to its integer representation. 1447 * 1448 * @param apnType APN type as a string 1449 * @return Integer representation of the APN type, or 0 if the provided string is not a valid 1450 * APN type. 1451 * @hide 1452 */ 1453 @SystemApi getApnTypeInt(@onNull @pnTypeString String apnType)1454 public static @ApnType int getApnTypeInt(@NonNull @ApnTypeString String apnType) { 1455 return APN_TYPE_STRING_MAP.getOrDefault(apnType.toLowerCase(Locale.ROOT), 0); 1456 } 1457 1458 /** 1459 * @param types comma delimited list of APN types. 1460 * @return bitmask of APN types. 1461 * @hide 1462 */ getApnTypesBitmaskFromString(String types)1463 public static int getApnTypesBitmaskFromString(String types) { 1464 // If unset, set to ALL. 1465 if (TextUtils.isEmpty(types)) { 1466 return TYPE_ALL; 1467 } else { 1468 int result = 0; 1469 for (String str : types.split(",")) { 1470 Integer type = APN_TYPE_STRING_MAP.get(str.toLowerCase(Locale.ROOT)); 1471 if (type != null) { 1472 result |= type; 1473 } 1474 } 1475 return result; 1476 } 1477 } 1478 1479 /** @hide */ getMvnoTypeIntFromString(String mvnoType)1480 public static int getMvnoTypeIntFromString(String mvnoType) { 1481 String mvnoTypeString = TextUtils.isEmpty(mvnoType) 1482 ? mvnoType : mvnoType.toLowerCase(Locale.ROOT); 1483 Integer mvnoTypeInt = MVNO_TYPE_STRING_MAP.get(mvnoTypeString); 1484 return mvnoTypeInt == null ? UNSPECIFIED_INT : mvnoTypeInt; 1485 } 1486 1487 /** @hide */ getMvnoTypeStringFromInt(int mvnoType)1488 public static String getMvnoTypeStringFromInt(int mvnoType) { 1489 String mvnoTypeString = MVNO_TYPE_INT_MAP.get(mvnoType); 1490 return mvnoTypeString == null ? UNSPECIFIED_STRING : mvnoTypeString; 1491 } 1492 1493 /** @hide */ getProtocolIntFromString(String protocol)1494 public static int getProtocolIntFromString(String protocol) { 1495 Integer protocolInt = PROTOCOL_STRING_MAP.get(protocol); 1496 return protocolInt == null ? UNSPECIFIED_INT : protocolInt; 1497 } 1498 1499 /** @hide */ getProtocolStringFromInt(int protocol)1500 public static String getProtocolStringFromInt(int protocol) { 1501 String protocolString = PROTOCOL_INT_MAP.get(protocol); 1502 return protocolString == null ? UNSPECIFIED_STRING : protocolString; 1503 } 1504 UriFromString(String uri)1505 private static Uri UriFromString(String uri) { 1506 return TextUtils.isEmpty(uri) ? null : Uri.parse(uri); 1507 } 1508 UriToString(Uri uri)1509 private static String UriToString(Uri uri) { 1510 return uri == null ? null : uri.toString(); 1511 } 1512 1513 /** @hide */ inetAddressFromString(String inetAddress)1514 public static InetAddress inetAddressFromString(String inetAddress) { 1515 if (TextUtils.isEmpty(inetAddress)) { 1516 return null; 1517 } 1518 try { 1519 return InetAddress.getByName(inetAddress); 1520 } catch (UnknownHostException e) { 1521 Log.e(LOG_TAG, "Can't parse InetAddress from string: unknown host."); 1522 return null; 1523 } 1524 } 1525 1526 /** @hide */ inetAddressToString(InetAddress inetAddress)1527 public static String inetAddressToString(InetAddress inetAddress) { 1528 if (inetAddress == null) { 1529 return null; 1530 } 1531 final String inetAddressString = inetAddress.toString(); 1532 if (TextUtils.isEmpty(inetAddressString)) { 1533 return null; 1534 } 1535 final String hostName = inetAddressString.substring(0, inetAddressString.indexOf("/")); 1536 final String address = inetAddressString.substring(inetAddressString.indexOf("/") + 1); 1537 if (TextUtils.isEmpty(hostName) && TextUtils.isEmpty(address)) { 1538 return null; 1539 } 1540 return TextUtils.isEmpty(hostName) ? address : hostName; 1541 } 1542 portFromString(String strPort)1543 private static int portFromString(String strPort) { 1544 int port = UNSPECIFIED_INT; 1545 if (!TextUtils.isEmpty(strPort)) { 1546 try { 1547 port = Integer.parseInt(strPort); 1548 } catch (NumberFormatException e) { 1549 Log.e(LOG_TAG, "Can't parse port from String"); 1550 } 1551 } 1552 return port; 1553 } 1554 portToString(int port)1555 private static String portToString(int port) { 1556 return port == UNSPECIFIED_INT ? null : Integer.toString(port); 1557 } 1558 1559 /** 1560 * Check if this APN setting can support the given network 1561 * 1562 * @param networkType The network type 1563 * @return {@code true} if this APN setting can support the given network. 1564 * 1565 * @hide 1566 */ canSupportNetworkType(@etworkType int networkType)1567 public boolean canSupportNetworkType(@NetworkType int networkType) { 1568 // Do a special checking for GSM. In reality, GSM is a voice only network type and can never 1569 // be used for data. We allow it here because in some DSDS corner cases, on the non-DDS 1570 // sub, modem reports data rat unknown. In that case if voice is GSM and this APN supports 1571 // GPRS or EDGE, this APN setting should be selected. 1572 if (networkType == TelephonyManager.NETWORK_TYPE_GSM 1573 && (mNetworkTypeBitmask & (TelephonyManager.NETWORK_TYPE_BITMASK_GPRS 1574 | TelephonyManager.NETWORK_TYPE_BITMASK_EDGE)) != 0) { 1575 return true; 1576 } 1577 1578 return ServiceState.bitmaskHasTech(mNetworkTypeBitmask, networkType); 1579 } 1580 1581 /** 1582 * Check if this APN setting can support the given lingering network 1583 * 1584 * @param networkType The lingering network type 1585 * @return {@code true} if this APN setting can support the given lingering network. 1586 * 1587 * @hide 1588 */ canSupportLingeringNetworkType(@etworkType int networkType)1589 public boolean canSupportLingeringNetworkType(@NetworkType int networkType) { 1590 // For backwards compatibility, if this field is not set, we just use the existing 1591 // network type bitmask. 1592 if (mLingeringNetworkTypeBitmask == 0) { 1593 return canSupportNetworkType(networkType); 1594 } 1595 // Do a special checking for GSM. In reality, GSM is a voice only network type and can never 1596 // be used for data. We allow it here because in some DSDS corner cases, on the non-DDS 1597 // sub, modem reports data rat unknown. In that case if voice is GSM and this APN supports 1598 // GPRS or EDGE, this APN setting should be selected. 1599 if (networkType == TelephonyManager.NETWORK_TYPE_GSM 1600 && (mLingeringNetworkTypeBitmask & (TelephonyManager.NETWORK_TYPE_BITMASK_GPRS 1601 | TelephonyManager.NETWORK_TYPE_BITMASK_EDGE)) != 0) { 1602 return true; 1603 } 1604 1605 return ServiceState.bitmaskHasTech((int) mLingeringNetworkTypeBitmask, networkType); 1606 } 1607 1608 // Implement Parcelable. 1609 @Override 1610 /** @hide */ describeContents()1611 public int describeContents() { 1612 return 0; 1613 } 1614 1615 @Override 1616 /** @hide */ writeToParcel(@onNull Parcel dest, int flags)1617 public void writeToParcel(@NonNull Parcel dest, int flags) { 1618 dest.writeInt(mId); 1619 dest.writeString(mOperatorNumeric); 1620 dest.writeString(mEntryName); 1621 dest.writeString(mApnName); 1622 dest.writeString(mProxyAddress); 1623 dest.writeInt(mProxyPort); 1624 dest.writeParcelable(mMmsc, flags); 1625 dest.writeString(mMmsProxyAddress); 1626 dest.writeInt(mMmsProxyPort); 1627 dest.writeString(mUser); 1628 dest.writeString(mPassword); 1629 dest.writeInt(mAuthType); 1630 dest.writeInt(mApnTypeBitmask); 1631 dest.writeInt(mProtocol); 1632 dest.writeInt(mRoamingProtocol); 1633 dest.writeBoolean(mCarrierEnabled); 1634 dest.writeInt(mNetworkTypeBitmask); 1635 dest.writeLong(mLingeringNetworkTypeBitmask); 1636 dest.writeInt(mProfileId); 1637 dest.writeBoolean(mPersistent); 1638 dest.writeInt(mMaxConns); 1639 dest.writeInt(mWaitTime); 1640 dest.writeInt(mMaxConnsTime); 1641 dest.writeInt(mMtuV4); 1642 dest.writeInt(mMtuV6); 1643 dest.writeInt(mMvnoType); 1644 dest.writeString(mMvnoMatchData); 1645 dest.writeInt(mApnSetId); 1646 dest.writeInt(mCarrierId); 1647 dest.writeInt(mSkip464Xlat); 1648 dest.writeBoolean(mAlwaysOn); 1649 } 1650 readFromParcel(Parcel in)1651 private static ApnSetting readFromParcel(Parcel in) { 1652 return new Builder() 1653 .setId(in.readInt()) 1654 .setOperatorNumeric(in.readString()) 1655 .setEntryName(in.readString()) 1656 .setApnName(in.readString()) 1657 .setProxyAddress(in.readString()) 1658 .setProxyPort(in.readInt()) 1659 .setMmsc(in.readParcelable(Uri.class.getClassLoader(), android.net.Uri.class)) 1660 .setMmsProxyAddress(in.readString()) 1661 .setMmsProxyPort(in.readInt()) 1662 .setUser(in.readString()) 1663 .setPassword(in.readString()) 1664 .setAuthType(in.readInt()) 1665 .setApnTypeBitmask(in.readInt()) 1666 .setProtocol(in.readInt()) 1667 .setRoamingProtocol(in.readInt()) 1668 .setCarrierEnabled(in.readBoolean()) 1669 .setNetworkTypeBitmask(in.readInt()) 1670 .setLingeringNetworkTypeBitmask(in.readLong()) 1671 .setProfileId(in.readInt()) 1672 .setModemCognitive(in.readBoolean()) 1673 .setMaxConns(in.readInt()) 1674 .setWaitTime(in.readInt()) 1675 .setMaxConnsTime(in.readInt()) 1676 .setMtuV4(in.readInt()) 1677 .setMtuV6(in.readInt()) 1678 .setMvnoType(in.readInt()) 1679 .setMvnoMatchData(in.readString()) 1680 .setApnSetId(in.readInt()) 1681 .setCarrierId(in.readInt()) 1682 .setSkip464Xlat(in.readInt()) 1683 .setAlwaysOn(in.readBoolean()) 1684 .buildWithoutCheck(); 1685 } 1686 1687 public static final @android.annotation.NonNull Parcelable.Creator<ApnSetting> CREATOR = 1688 new Parcelable.Creator<ApnSetting>() { 1689 @Override 1690 public ApnSetting createFromParcel(Parcel in) { 1691 return readFromParcel(in); 1692 } 1693 1694 @Override 1695 public ApnSetting[] newArray(int size) { 1696 return new ApnSetting[size]; 1697 } 1698 }; 1699 1700 /** 1701 * Provides a convenient way to set the fields of a {@link ApnSetting} when creating a new 1702 * instance. The following settings are required to build an {@code ApnSetting}: 1703 * 1704 * <ul><li>apnTypeBitmask</li> 1705 * <li>apnName</li> 1706 * <li>entryName</li></ul> 1707 * 1708 * <p>The example below shows how you might create a new {@code ApnSetting}: 1709 * 1710 * <pre><code> 1711 * // Create an MMS proxy address with a hostname. A network might not be 1712 * // available, so supply a placeholder (0.0.0.0) IPv4 address to avoid DNS lookup. 1713 * String host = "mms.example.com"; 1714 * byte[] ipAddress = new byte[4]; 1715 * InetAddress mmsProxy; 1716 * try { 1717 * mmsProxy = InetAddress.getByAddress(host, ipAddress); 1718 * } catch (UnknownHostException e) { 1719 * e.printStackTrace(); 1720 * return; 1721 * } 1722 * 1723 * ApnSetting apn = new ApnSetting.Builder() 1724 * .setApnTypeBitmask(ApnSetting.TYPE_DEFAULT | ApnSetting.TYPE_MMS) 1725 * .setApnName("apn.example.com") 1726 * .setEntryName("Example Carrier APN") 1727 * .setMmsc(Uri.parse("http://mms.example.com:8002")) 1728 * .setMmsProxyAddress(mmsProxy) 1729 * .setMmsProxyPort(8799) 1730 * .build(); 1731 * </code></pre> 1732 */ 1733 public static class Builder{ 1734 private String mEntryName; 1735 private String mApnName; 1736 private String mProxyAddress; 1737 private int mProxyPort = UNSPECIFIED_INT; 1738 private Uri mMmsc; 1739 private String mMmsProxyAddress; 1740 private int mMmsProxyPort = UNSPECIFIED_INT; 1741 private String mUser; 1742 private String mPassword; 1743 private int mAuthType = AUTH_TYPE_UNKNOWN; 1744 private int mApnTypeBitmask; 1745 private int mId; 1746 private String mOperatorNumeric; 1747 private int mProtocol = UNSPECIFIED_INT; 1748 private int mRoamingProtocol = UNSPECIFIED_INT; 1749 private int mMtuV4; 1750 private int mMtuV6; 1751 private @TelephonyManager.NetworkTypeBitMask int mNetworkTypeBitmask; 1752 private @TelephonyManager.NetworkTypeBitMask long mLingeringNetworkTypeBitmask; 1753 private boolean mCarrierEnabled; 1754 private int mProfileId; 1755 private boolean mModemCognitive; 1756 private int mMaxConns; 1757 private int mWaitTime; 1758 private int mMaxConnsTime; 1759 private int mMvnoType = UNSPECIFIED_INT; 1760 private String mMvnoMatchData; 1761 private int mApnSetId; 1762 private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; 1763 private int mSkip464Xlat = Carriers.SKIP_464XLAT_DEFAULT; 1764 private boolean mAlwaysOn; 1765 1766 /** 1767 * Default constructor for Builder. 1768 */ Builder()1769 public Builder() {} 1770 1771 /** 1772 * Sets the unique database id for this entry. 1773 * 1774 * @param id the unique database id to set for this entry 1775 * @hide 1776 */ setId(int id)1777 public Builder setId(int id) { 1778 this.mId = id; 1779 return this; 1780 } 1781 1782 /** 1783 * Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv4 routes brought 1784 * up by this APN setting. Note this value will only be used when MTU size is not provided 1785 * in {@link DataCallResponse#getMtuV4()} during network bring up. 1786 * 1787 * @param mtuV4 the MTU size in bytes of the route. 1788 */ setMtuV4(int mtuV4)1789 public @NonNull Builder setMtuV4(int mtuV4) { 1790 this.mMtuV4 = mtuV4; 1791 return this; 1792 } 1793 1794 /** 1795 * Set the default MTU (Maximum Transmission Unit) size in bytes of the IPv6 routes brought 1796 * up by this APN setting. Note this value will only be used when MTU size is not provided 1797 * in {@link DataCallResponse#getMtuV6()} during network bring up. 1798 * 1799 * @param mtuV6 the MTU size in bytes of the route. 1800 */ setMtuV6(int mtuV6)1801 public @NonNull Builder setMtuV6(int mtuV6) { 1802 this.mMtuV6 = mtuV6; 1803 return this; 1804 } 1805 1806 /** 1807 * Sets the profile id to which the APN saved in modem. 1808 * 1809 * @param profileId the profile id to set for the APN. 1810 */ setProfileId(int profileId)1811 public @NonNull Builder setProfileId(int profileId) { 1812 this.mProfileId = profileId; 1813 return this; 1814 } 1815 1816 /** 1817 * Set if the APN setting should be persistent/non-persistent in modem. 1818 * 1819 * @param isPersistent {@code true} if this APN setting should be persistent/non-persistent 1820 * in modem. 1821 * @return The same instance of the builder. 1822 */ setPersistent(boolean isPersistent)1823 public @NonNull Builder setPersistent(boolean isPersistent) { 1824 return setModemCognitive(isPersistent); 1825 } 1826 1827 /** 1828 * Sets if the APN setting is to be set in modem. 1829 * 1830 * @param modemCognitive if the APN setting is to be set in modem 1831 * @hide 1832 */ setModemCognitive(boolean modemCognitive)1833 public Builder setModemCognitive(boolean modemCognitive) { 1834 this.mModemCognitive = modemCognitive; 1835 return this; 1836 } 1837 1838 /** 1839 * Sets the max connections of this APN. 1840 * 1841 * @param maxConns the max connections of this APN 1842 * @hide 1843 */ setMaxConns(int maxConns)1844 public Builder setMaxConns(int maxConns) { 1845 this.mMaxConns = maxConns; 1846 return this; 1847 } 1848 1849 /** 1850 * Sets the wait time for retry of the APN. 1851 * 1852 * @param waitTime the wait time for retry of the APN 1853 * @hide 1854 */ setWaitTime(int waitTime)1855 public Builder setWaitTime(int waitTime) { 1856 this.mWaitTime = waitTime; 1857 return this; 1858 } 1859 1860 /** 1861 * Sets the time to limit max connection for the APN. 1862 * 1863 * @param maxConnsTime the time to limit max connection for the APN 1864 * @hide 1865 */ setMaxConnsTime(int maxConnsTime)1866 public Builder setMaxConnsTime(int maxConnsTime) { 1867 this.mMaxConnsTime = maxConnsTime; 1868 return this; 1869 } 1870 1871 /** 1872 * Sets the MVNO match data for the APN. 1873 * 1874 * @param mvnoMatchData the MVNO match data for the APN 1875 * @hide 1876 */ setMvnoMatchData(@ullable String mvnoMatchData)1877 public Builder setMvnoMatchData(@Nullable String mvnoMatchData) { 1878 this.mMvnoMatchData = mvnoMatchData; 1879 return this; 1880 } 1881 1882 /** 1883 * Sets the APN set id for the APN. 1884 * 1885 * @param apnSetId the set id for the APN 1886 * @hide 1887 */ setApnSetId(int apnSetId)1888 public Builder setApnSetId(int apnSetId) { 1889 this.mApnSetId = apnSetId; 1890 return this; 1891 } 1892 1893 /** 1894 * Sets a human-readable name that describes the APN. 1895 * 1896 * @param entryName the entry name to set for the APN 1897 */ 1898 @NonNull setEntryName(@ullable String entryName)1899 public Builder setEntryName(@Nullable String entryName) { 1900 this.mEntryName = entryName; 1901 return this; 1902 } 1903 1904 /** 1905 * Sets the name of the APN. 1906 * 1907 * @param apnName the name to set for the APN 1908 */ 1909 @NonNull setApnName(@ullable String apnName)1910 public Builder setApnName(@Nullable String apnName) { 1911 this.mApnName = apnName; 1912 return this; 1913 } 1914 1915 /** 1916 * Sets the address of an HTTP proxy for the APN. The proxy address can be an IP address or 1917 * hostname. If {@code proxy} contains both an IP address and hostname, this method ignores 1918 * the IP address. 1919 * 1920 * <p>The {@link java.net.InetAddress} methods 1921 * {@link java.net.InetAddress#getAllByName getAllByName()} require DNS for hostname 1922 * resolution. To avoid this requirement when setting a hostname, call 1923 * {@link java.net.InetAddress#getByAddress(java.lang.String, byte[])} with both the 1924 * hostname and a placeholder IP address. See {@link ApnSetting.Builder above} for an 1925 * example. 1926 * 1927 * @param proxy the proxy address to set for the APN 1928 * @deprecated use {@link #setProxyAddress(String)} instead. 1929 */ 1930 @Deprecated setProxyAddress(InetAddress proxy)1931 public Builder setProxyAddress(InetAddress proxy) { 1932 this.mProxyAddress = inetAddressToString(proxy); 1933 return this; 1934 } 1935 1936 /** 1937 * Sets the proxy address of the APN. 1938 * 1939 * @param proxy the proxy address to set for the APN 1940 */ 1941 @NonNull setProxyAddress(@ullable String proxy)1942 public Builder setProxyAddress(@Nullable String proxy) { 1943 this.mProxyAddress = proxy; 1944 return this; 1945 } 1946 1947 /** 1948 * Sets the proxy port of the APN. 1949 * 1950 * @param port the proxy port to set for the APN 1951 */ 1952 @NonNull setProxyPort(int port)1953 public Builder setProxyPort(int port) { 1954 this.mProxyPort = port; 1955 return this; 1956 } 1957 1958 /** 1959 * Sets the MMSC Uri of the APN. 1960 * 1961 * @param mmsc the MMSC Uri to set for the APN 1962 */ 1963 @NonNull setMmsc(@ullable Uri mmsc)1964 public Builder setMmsc(@Nullable Uri mmsc) { 1965 this.mMmsc = mmsc; 1966 return this; 1967 } 1968 1969 /** 1970 * Sets the address of an MMS proxy for the APN. The MMS proxy address can be an IP address 1971 * or hostname. If {@code mmsProxy} contains both an IP address and hostname, this method 1972 * ignores the IP address. 1973 * 1974 * <p>The {@link java.net.InetAddress} methods 1975 * {@link java.net.InetAddress#getByName getByName()} and 1976 * {@link java.net.InetAddress#getAllByName getAllByName()} require DNS for hostname 1977 * resolution. To avoid this requirement when setting a hostname, call 1978 * {@link java.net.InetAddress#getByAddress(java.lang.String, byte[])} with both the 1979 * hostname and a placeholder IP address. See {@link ApnSetting.Builder above} for an 1980 * example. 1981 * 1982 * @param mmsProxy the MMS proxy address to set for the APN 1983 * @deprecated use {@link #setMmsProxyAddress(String)} instead. 1984 */ 1985 @Deprecated setMmsProxyAddress(InetAddress mmsProxy)1986 public Builder setMmsProxyAddress(InetAddress mmsProxy) { 1987 this.mMmsProxyAddress = inetAddressToString(mmsProxy); 1988 return this; 1989 } 1990 1991 /** 1992 * Sets the MMS proxy address of the APN. 1993 * 1994 * @param mmsProxy the MMS proxy address to set for the APN 1995 */ 1996 @NonNull setMmsProxyAddress(@ullable String mmsProxy)1997 public Builder setMmsProxyAddress(@Nullable String mmsProxy) { 1998 this.mMmsProxyAddress = mmsProxy; 1999 return this; 2000 } 2001 2002 /** 2003 * Sets the MMS proxy port of the APN. 2004 * 2005 * @param mmsPort the MMS proxy port to set for the APN 2006 */ 2007 @NonNull setMmsProxyPort(int mmsPort)2008 public Builder setMmsProxyPort(int mmsPort) { 2009 this.mMmsProxyPort = mmsPort; 2010 return this; 2011 } 2012 2013 /** 2014 * Sets the APN username of the APN. 2015 * 2016 * @param user the APN username to set for the APN 2017 */ 2018 @NonNull setUser(@ullable String user)2019 public Builder setUser(@Nullable String user) { 2020 this.mUser = user; 2021 return this; 2022 } 2023 2024 /** 2025 * Sets the APN password of the APN. 2026 * 2027 * @see android.provider.Telephony.Carriers#PASSWORD 2028 * @param password the APN password to set for the APN 2029 */ 2030 @NonNull setPassword(@ullable String password)2031 public Builder setPassword(@Nullable String password) { 2032 this.mPassword = password; 2033 return this; 2034 } 2035 2036 /** 2037 * Sets the authentication type of the APN. 2038 * 2039 * @param authType the authentication type to set for the APN 2040 */ 2041 @NonNull setAuthType(@uthType int authType)2042 public Builder setAuthType(@AuthType int authType) { 2043 this.mAuthType = authType; 2044 return this; 2045 } 2046 2047 /** 2048 * Sets the bitmask of APN types. 2049 * 2050 * <p>Apn types are usage categories for an APN entry. One APN entry may support multiple 2051 * APN types, eg, a single APN may service regular internet traffic ("default") as well as 2052 * MMS-specific connections. 2053 * 2054 * <p>The bitmask of APN types is calculated from APN types defined in {@link ApnSetting}. 2055 * 2056 * @param apnTypeBitmask a bitmask describing the types of the APN 2057 */ 2058 @NonNull setApnTypeBitmask(@pnType int apnTypeBitmask)2059 public Builder setApnTypeBitmask(@ApnType int apnTypeBitmask) { 2060 this.mApnTypeBitmask = apnTypeBitmask; 2061 return this; 2062 } 2063 2064 /** 2065 * Sets the numeric operator ID for the APN. Numeric operator ID is defined as 2066 * {@link android.provider.Telephony.Carriers#MCC} + 2067 * {@link android.provider.Telephony.Carriers#MNC}. 2068 * 2069 * @param operatorNumeric the numeric operator ID to set for this entry 2070 */ 2071 @NonNull setOperatorNumeric(@ullable String operatorNumeric)2072 public Builder setOperatorNumeric(@Nullable String operatorNumeric) { 2073 this.mOperatorNumeric = operatorNumeric; 2074 return this; 2075 } 2076 2077 /** 2078 * Sets the protocol to use to connect to this APN. 2079 * 2080 * <p>Protocol is one of the {@code PDP_type} values in TS 27.007 section 10.1.1. 2081 * 2082 * @param protocol the protocol to set to use to connect to this APN 2083 */ 2084 @NonNull setProtocol(@rotocolType int protocol)2085 public Builder setProtocol(@ProtocolType int protocol) { 2086 this.mProtocol = protocol; 2087 return this; 2088 } 2089 2090 /** 2091 * Sets the protocol to use to connect to this APN when the device is roaming. 2092 * 2093 * <p>Roaming protocol is one of the {@code PDP_type} values in TS 27.007 section 10.1.1. 2094 * 2095 * @param roamingProtocol the protocol to set to use to connect to this APN when roaming 2096 */ 2097 @NonNull setRoamingProtocol(@rotocolType int roamingProtocol)2098 public Builder setRoamingProtocol(@ProtocolType int roamingProtocol) { 2099 this.mRoamingProtocol = roamingProtocol; 2100 return this; 2101 } 2102 2103 /** 2104 * Sets the current status for this APN. 2105 * 2106 * @param carrierEnabled the current status to set for this APN 2107 */ 2108 @NonNull setCarrierEnabled(boolean carrierEnabled)2109 public Builder setCarrierEnabled(boolean carrierEnabled) { 2110 this.mCarrierEnabled = carrierEnabled; 2111 return this; 2112 } 2113 2114 /** 2115 * Sets Radio Technology (Network Type) info for this APN. 2116 * 2117 * @param networkTypeBitmask the Radio Technology (Network Type) info 2118 */ 2119 @NonNull setNetworkTypeBitmask(int networkTypeBitmask)2120 public Builder setNetworkTypeBitmask(int networkTypeBitmask) { 2121 this.mNetworkTypeBitmask = networkTypeBitmask; 2122 return this; 2123 } 2124 2125 /** 2126 * Sets lingering Radio Technology (Network Type) for this APN. 2127 * 2128 * @param lingeringNetworkTypeBitmask the Radio Technology (Network Type) that should linger 2129 * @hide 2130 */ 2131 @NonNull setLingeringNetworkTypeBitmask(@elephonyManager.NetworkTypeBitMask long lingeringNetworkTypeBitmask)2132 public Builder setLingeringNetworkTypeBitmask(@TelephonyManager.NetworkTypeBitMask 2133 long lingeringNetworkTypeBitmask) { 2134 this.mLingeringNetworkTypeBitmask = lingeringNetworkTypeBitmask; 2135 return this; 2136 } 2137 2138 /** 2139 * Sets the MVNO match type for this APN. 2140 * 2141 * @param mvnoType the MVNO match type to set for this APN 2142 */ 2143 @NonNull setMvnoType(@vnoType int mvnoType)2144 public Builder setMvnoType(@MvnoType int mvnoType) { 2145 this.mMvnoType = mvnoType; 2146 return this; 2147 } 2148 2149 /** 2150 * Sets the carrier id for this APN. 2151 * 2152 * See {@link TelephonyManager#getSimCarrierId()} which provides more background for what a 2153 * carrier ID is. 2154 * 2155 * @param carrierId the carrier id to set for this APN 2156 */ 2157 @NonNull setCarrierId(int carrierId)2158 public Builder setCarrierId(int carrierId) { 2159 this.mCarrierId = carrierId; 2160 return this; 2161 } 2162 2163 /** 2164 * Sets skip464xlat flag for this APN. 2165 * 2166 * @param skip464xlat skip464xlat for this APN. 2167 * @hide 2168 */ setSkip464Xlat(@kip464XlatStatus int skip464xlat)2169 public Builder setSkip464Xlat(@Skip464XlatStatus int skip464xlat) { 2170 this.mSkip464Xlat = skip464xlat; 2171 return this; 2172 } 2173 2174 /** 2175 * Sets whether the PDU session brought up by this APN should always be on. 2176 * See 3GPP TS 23.501 section 5.6.13 2177 * 2178 * @param alwaysOn the always on status to set for this APN 2179 * @hide 2180 */ setAlwaysOn(boolean alwaysOn)2181 public Builder setAlwaysOn(boolean alwaysOn) { 2182 this.mAlwaysOn = alwaysOn; 2183 return this; 2184 } 2185 2186 /** 2187 * Builds {@link ApnSetting} from this builder. 2188 * 2189 * @return {@code null} if {@link #setApnName(String)} or {@link #setEntryName(String)} 2190 * is empty, or {@link #setApnTypeBitmask(int)} doesn't contain a valid bit, 2191 * {@link ApnSetting} built from this builder otherwise. 2192 */ build()2193 public ApnSetting build() { 2194 if ((mApnTypeBitmask & (TYPE_DEFAULT | TYPE_MMS | TYPE_SUPL | TYPE_DUN | TYPE_HIPRI 2195 | TYPE_FOTA | TYPE_IMS | TYPE_CBS | TYPE_IA | TYPE_EMERGENCY | TYPE_MCX 2196 | TYPE_XCAP | TYPE_VSIM | TYPE_BIP | TYPE_ENTERPRISE)) == 0 2197 || TextUtils.isEmpty(mApnName) || TextUtils.isEmpty(mEntryName)) { 2198 return null; 2199 } 2200 if ((mApnTypeBitmask & TYPE_MMS) != 0 && !TextUtils.isEmpty(mMmsProxyAddress) 2201 && mMmsProxyAddress.startsWith("http")) { 2202 Log.wtf(LOG_TAG,"mms proxy(" + mMmsProxyAddress 2203 + ") should be a hostname, not a url"); 2204 Uri mMmsProxyAddressUri = Uri.parse(mMmsProxyAddress); 2205 mMmsProxyAddress = mMmsProxyAddressUri.getHost(); 2206 } 2207 return new ApnSetting(this); 2208 } 2209 2210 /** 2211 * Builds {@link ApnSetting} from this builder. This function doesn't check if 2212 * {@link #setApnName(String)} or {@link #setEntryName(String)}, or 2213 * {@link #setApnTypeBitmask(int)} is empty. 2214 * @hide 2215 */ buildWithoutCheck()2216 public ApnSetting buildWithoutCheck() { 2217 return new ApnSetting(this); 2218 } 2219 } 2220 } 2221