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