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