1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.telephony.data; 18 19 import static android.telephony.data.ApnSetting.ProtocolType; 20 21 import android.annotation.ElapsedRealtimeLong; 22 import android.annotation.IntDef; 23 import android.annotation.NonNull; 24 import android.annotation.Nullable; 25 import android.annotation.SystemApi; 26 import android.net.NetworkCapabilities; 27 import android.os.Parcel; 28 import android.os.Parcelable; 29 import android.telephony.Annotation.NetCapability; 30 import android.telephony.TelephonyManager; 31 import android.telephony.TelephonyManager.NetworkTypeBitMask; 32 import android.telephony.data.ApnSetting.ApnType; 33 import android.telephony.data.ApnSetting.AuthType; 34 import android.text.TextUtils; 35 36 import java.lang.annotation.Retention; 37 import java.lang.annotation.RetentionPolicy; 38 import java.util.Objects; 39 40 /** 41 * Description of a mobile data profile used for establishing data networks. The data profile 42 * consist an {@link ApnSetting} which is needed for 2G/3G/4G networks bring up, and a 43 * {@link TrafficDescriptor} contains additional information that can be used for 5G standalone 44 * network bring up. 45 * 46 * @hide 47 */ 48 @SystemApi 49 public final class DataProfile implements Parcelable { 50 /** @hide */ 51 @Retention(RetentionPolicy.SOURCE) 52 @IntDef(prefix = {"TYPE_"}, 53 value = { 54 TYPE_COMMON, 55 TYPE_3GPP, 56 TYPE_3GPP2}) 57 public @interface Type {} 58 59 /** Common data profile */ 60 public static final int TYPE_COMMON = 0; 61 62 /** 3GPP type data profile */ 63 public static final int TYPE_3GPP = 1; 64 65 /** 3GPP2 type data profile */ 66 public static final int TYPE_3GPP2 = 2; 67 68 private final @Type int mType; 69 70 private final @Nullable ApnSetting mApnSetting; 71 72 private final @Nullable TrafficDescriptor mTrafficDescriptor; 73 74 private boolean mPreferred; 75 76 /** 77 * The last timestamp of this data profile being used for data network setup. Never add this 78 * to {@link #equals(Object)} and {@link #hashCode()}. 79 */ 80 private @ElapsedRealtimeLong long mSetupTimestamp; 81 DataProfile(@onNull Builder builder)82 private DataProfile(@NonNull Builder builder) { 83 mApnSetting = builder.mApnSetting; 84 mTrafficDescriptor = builder.mTrafficDescriptor; 85 mPreferred = builder.mPreferred; 86 87 if (builder.mType != -1) { 88 mType = builder.mType; 89 } else if (mApnSetting != null) { 90 int networkTypes = mApnSetting.getNetworkTypeBitmask(); 91 92 if (networkTypes == 0) { 93 mType = DataProfile.TYPE_COMMON; 94 } else if ((networkTypes & TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2) 95 == networkTypes) { 96 mType = DataProfile.TYPE_3GPP2; 97 } else if ((networkTypes & TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP) 98 == networkTypes) { 99 mType = DataProfile.TYPE_3GPP; 100 } else { 101 mType = DataProfile.TYPE_COMMON; 102 } 103 } else { 104 mType = DataProfile.TYPE_COMMON; 105 } 106 } 107 DataProfile(Parcel source)108 private DataProfile(Parcel source) { 109 mType = source.readInt(); 110 mApnSetting = source.readParcelable(ApnSetting.class.getClassLoader(), android.telephony.data.ApnSetting.class); 111 mTrafficDescriptor = source.readParcelable(TrafficDescriptor.class.getClassLoader(), android.telephony.data.TrafficDescriptor.class); 112 mPreferred = source.readBoolean(); 113 mSetupTimestamp = source.readLong(); 114 } 115 116 /** 117 * @return Id of the data profile. 118 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getProfileId()} instead. 119 */ 120 @Deprecated getProfileId()121 public int getProfileId() { 122 if (mApnSetting != null) { 123 return mApnSetting.getProfileId(); 124 } 125 return 0; 126 } 127 128 /** 129 * @return The APN (Access Point Name) to establish data connection. This is a string 130 * specifically defined by the carrier. 131 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getApnName()} instead. 132 */ 133 @Deprecated getApn()134 public @NonNull String getApn() { 135 if (mApnSetting != null) { 136 return TextUtils.emptyIfNull(mApnSetting.getApnName()); 137 } 138 return ""; 139 } 140 141 /** 142 * @return The connection protocol defined in 3GPP TS 27.007 section 10.1.1. 143 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getProtocol()} instead. 144 */ 145 @Deprecated getProtocolType()146 public @ProtocolType int getProtocolType() { 147 if (mApnSetting != null) { 148 return mApnSetting.getProtocol(); 149 } 150 return ApnSetting.PROTOCOL_IPV4V6; 151 } 152 153 /** 154 * @return The authentication protocol used for this PDP context. 155 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getAuthType()} instead. 156 */ 157 @Deprecated getAuthType()158 public @AuthType int getAuthType() { 159 if (mApnSetting != null) { 160 return mApnSetting.getAuthType(); 161 } 162 return ApnSetting.AUTH_TYPE_NONE; 163 } 164 165 /** 166 * @return The username for APN. 167 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getUser()} instead. 168 */ 169 @Deprecated getUserName()170 public @Nullable String getUserName() { 171 if (mApnSetting != null) { 172 return mApnSetting.getUser(); 173 } 174 return null; 175 } 176 177 /** 178 * @return The password for APN. 179 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getPassword()} instead. 180 */ 181 @Deprecated getPassword()182 public @Nullable String getPassword() { 183 if (mApnSetting != null) { 184 return mApnSetting.getPassword(); 185 } 186 return null; 187 } 188 189 /** 190 * @return The profile type. 191 */ getType()192 public @Type int getType() { 193 return mType; 194 } 195 196 /** 197 * @return The period in seconds to limit the maximum connections. 198 * 199 * @hide 200 */ getMaxConnectionsTime()201 public int getMaxConnectionsTime() { 202 if (mApnSetting != null) { 203 return mApnSetting.getMaxConnsTime(); 204 } 205 return 0; 206 } 207 208 /** 209 * @return The maximum connections allowed. 210 * 211 * @hide 212 */ getMaxConnections()213 public int getMaxConnections() { 214 if (mApnSetting != null) { 215 return mApnSetting.getMaxConns(); 216 } 217 return 0; 218 } 219 220 /** 221 * @return The required wait time in seconds after a successful UE initiated disconnect of a 222 * given PDN connection before the device can send a new PDN connection request for that given 223 * PDN. 224 * 225 * @hide 226 */ getWaitTime()227 public int getWaitTime() { 228 if (mApnSetting != null) { 229 return mApnSetting.getWaitTime(); 230 } 231 return 0; 232 } 233 234 /** 235 * @return {@code true} if the profile is enabled. If the profile only has a 236 * {@link TrafficDescriptor}, but no {@link ApnSetting}, then this profile is always enabled. 237 */ isEnabled()238 public boolean isEnabled() { 239 if (mApnSetting != null) { 240 return mApnSetting.isEnabled(); 241 } 242 return true; 243 } 244 245 /** 246 * @return The supported APN types bitmask. 247 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getApnTypeBitmask()} instead. 248 */ getSupportedApnTypesBitmask()249 @Deprecated public @ApnType int getSupportedApnTypesBitmask() { 250 if (mApnSetting != null) { 251 return mApnSetting.getApnTypeBitmask(); 252 } 253 return ApnSetting.TYPE_NONE; 254 } 255 256 /** 257 * @return The connection protocol on roaming network defined in 3GPP TS 27.007 section 10.1.1. 258 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#getRoamingProtocol()} instead. 259 */ 260 @Deprecated getRoamingProtocolType()261 public @ProtocolType int getRoamingProtocolType() { 262 if (mApnSetting != null) { 263 return mApnSetting.getRoamingProtocol(); 264 } 265 return ApnSetting.PROTOCOL_IP; 266 } 267 268 /** 269 * @return The bearer bitmask indicating the applicable networks for this data profile. 270 * @deprecated use {@link #getApnSetting()} and {@link ApnSetting#getNetworkTypeBitmask()} 271 * instead. 272 */ 273 @Deprecated getBearerBitmask()274 public @NetworkTypeBitMask int getBearerBitmask() { 275 if (mApnSetting != null) { 276 return mApnSetting.getNetworkTypeBitmask(); 277 } 278 return (int) TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN; 279 } 280 281 /** 282 * @return The maximum transmission unit (MTU) size in bytes. 283 * @deprecated use {@link #getApnSetting()} and {@link ApnSetting#getMtuV4()}/ 284 * {@link ApnSetting#getMtuV6()} instead. 285 */ 286 @Deprecated getMtu()287 public int getMtu() { 288 return getMtuV4(); 289 } 290 291 /** 292 * This replaces the deprecated method getMtu. 293 * @return The maximum transmission unit (MTU) size in bytes, for IPv4. 294 * @deprecated use {@link #getApnSetting()} and {@link ApnSetting#getMtuV4()} instead. 295 */ 296 @Deprecated getMtuV4()297 public int getMtuV4() { 298 if (mApnSetting != null) { 299 return mApnSetting.getMtuV4(); 300 } 301 return 0; 302 } 303 304 /** 305 * @return The maximum transmission unit (MTU) size in bytes, for IPv6. 306 * @deprecated use {@link #getApnSetting()} and {@link ApnSetting#getMtuV6()} instead. 307 */ 308 @Deprecated getMtuV6()309 public int getMtuV6() { 310 if (mApnSetting != null) { 311 return mApnSetting.getMtuV6(); 312 } 313 return 0; 314 } 315 316 /** 317 * @return {@code true} if modem must persist this data profile. 318 * @deprecated Use {@link #getApnSetting()} and {@link ApnSetting#isPersistent()} instead. 319 */ 320 @Deprecated isPersistent()321 public boolean isPersistent() { 322 if (mApnSetting != null) { 323 return mApnSetting.isPersistent(); 324 } 325 return false; 326 } 327 328 /** 329 * Set the preferred flag for the data profile. 330 * 331 * @param preferred {@code true} if this data profile is preferred for internet. 332 * @hide 333 */ setPreferred(boolean preferred)334 public void setPreferred(boolean preferred) { 335 mPreferred = preferred; 336 } 337 338 /** 339 * @return {@code true} if this data profile was used to bring up the last default 340 * (i.e internet) data connection successfully, or the one chosen by the user in Settings' 341 * APN editor. For one carrier there can be only one profiled preferred. 342 */ isPreferred()343 public boolean isPreferred() { 344 return mPreferred; 345 } 346 347 /** 348 * @return The APN setting {@link ApnSetting}, which is used to establish data network on 349 * 2G/3G/4G. 350 */ getApnSetting()351 public @Nullable ApnSetting getApnSetting() { 352 return mApnSetting; 353 } 354 355 /** 356 * @return The traffic descriptor {@link TrafficDescriptor}, which can be used to establish 357 * data network on 5G. 358 */ getTrafficDescriptor()359 public @Nullable TrafficDescriptor getTrafficDescriptor() { 360 return mTrafficDescriptor; 361 } 362 363 /** 364 * Check if this data profile can satisfy certain network capabilities 365 * 366 * @param networkCapabilities The network capabilities. Note that the non-APN-type capabilities 367 * will be ignored. 368 * 369 * @return {@code true} if this data profile can satisfy the given network capabilities. 370 * @hide 371 */ canSatisfy(@onNull @etCapability int[] networkCapabilities)372 public boolean canSatisfy(@NonNull @NetCapability int[] networkCapabilities) { 373 if (mApnSetting != null) { 374 for (int netCap : networkCapabilities) { 375 if (!canSatisfy(netCap)) { 376 return false; 377 } 378 } 379 return true; 380 } 381 return false; 382 } 383 384 /** 385 * Check if this data profile can satisfy a certain network capability. 386 * 387 * @param networkCapability The network capability. Note that the non-APN-type capability 388 * will always be satisfied. 389 * @return {@code true} if this data profile can satisfy the given network capability. 390 * @hide 391 */ canSatisfy(@etCapability int networkCapability)392 public boolean canSatisfy(@NetCapability int networkCapability) { 393 return mApnSetting != null && mApnSetting.canHandleType( 394 networkCapabilityToApnType(networkCapability)); 395 } 396 397 /** 398 * Convert network capability into APN type. 399 * 400 * @param networkCapability Network capability. 401 * @return APN type. 402 * @hide 403 */ networkCapabilityToApnType(@etCapability int networkCapability)404 private static @ApnType int networkCapabilityToApnType(@NetCapability int networkCapability) { 405 switch (networkCapability) { 406 case NetworkCapabilities.NET_CAPABILITY_MMS: 407 return ApnSetting.TYPE_MMS; 408 case NetworkCapabilities.NET_CAPABILITY_SUPL: 409 return ApnSetting.TYPE_SUPL; 410 case NetworkCapabilities.NET_CAPABILITY_DUN: 411 return ApnSetting.TYPE_DUN; 412 case NetworkCapabilities.NET_CAPABILITY_FOTA: 413 return ApnSetting.TYPE_FOTA; 414 case NetworkCapabilities.NET_CAPABILITY_IMS: 415 return ApnSetting.TYPE_IMS; 416 case NetworkCapabilities.NET_CAPABILITY_CBS: 417 return ApnSetting.TYPE_CBS; 418 case NetworkCapabilities.NET_CAPABILITY_XCAP: 419 return ApnSetting.TYPE_XCAP; 420 case NetworkCapabilities.NET_CAPABILITY_EIMS: 421 return ApnSetting.TYPE_EMERGENCY; 422 case NetworkCapabilities.NET_CAPABILITY_INTERNET: 423 return ApnSetting.TYPE_DEFAULT; 424 case NetworkCapabilities.NET_CAPABILITY_MCX: 425 return ApnSetting.TYPE_MCX; 426 case NetworkCapabilities.NET_CAPABILITY_IA: 427 return ApnSetting.TYPE_IA; 428 case NetworkCapabilities.NET_CAPABILITY_BIP: 429 return ApnSetting.TYPE_BIP; 430 case NetworkCapabilities.NET_CAPABILITY_VSIM: 431 return ApnSetting.TYPE_VSIM; 432 case NetworkCapabilities.NET_CAPABILITY_ENTERPRISE: 433 return ApnSetting.TYPE_ENTERPRISE; 434 case NetworkCapabilities.NET_CAPABILITY_RCS: 435 return ApnSetting.TYPE_RCS; 436 default: 437 return ApnSetting.TYPE_NONE; 438 } 439 } 440 441 /** 442 * Set the timestamp of this data profile being used for data network setup. 443 * 444 * @hide 445 */ setLastSetupTimestamp(@lapsedRealtimeLong long timestamp)446 public void setLastSetupTimestamp(@ElapsedRealtimeLong long timestamp) { 447 mSetupTimestamp = timestamp; 448 } 449 450 /** 451 * @return the timestamp of this data profile being used for data network setup. 452 * 453 * @hide 454 */ getLastSetupTimestamp()455 public @ElapsedRealtimeLong long getLastSetupTimestamp() { 456 return mSetupTimestamp; 457 } 458 459 @Override describeContents()460 public int describeContents() { 461 return 0; 462 } 463 464 @NonNull 465 @Override toString()466 public String toString() { 467 return "[DataProfile=" + mApnSetting + ", " + mTrafficDescriptor + ", preferred=" 468 + mPreferred + "]"; 469 } 470 471 @Override writeToParcel(Parcel dest, int flags)472 public void writeToParcel(Parcel dest, int flags) { 473 dest.writeInt(mType); 474 dest.writeParcelable(mApnSetting, flags); 475 dest.writeParcelable(mTrafficDescriptor, flags); 476 dest.writeBoolean(mPreferred); 477 dest.writeLong(mSetupTimestamp); 478 } 479 480 public static final @android.annotation.NonNull Parcelable.Creator<DataProfile> CREATOR = 481 new Parcelable.Creator<DataProfile>() { 482 @Override 483 public DataProfile createFromParcel(Parcel source) { 484 return new DataProfile(source); 485 } 486 487 @Override 488 public DataProfile[] newArray(int size) { 489 return new DataProfile[size]; 490 } 491 }; 492 493 @Override equals(Object o)494 public boolean equals(Object o) { 495 if (this == o) return true; 496 if (o == null || getClass() != o.getClass()) return false; 497 DataProfile that = (DataProfile) o; 498 return mType == that.mType 499 && Objects.equals(mApnSetting, that.mApnSetting) 500 && Objects.equals(mTrafficDescriptor, that.mTrafficDescriptor); 501 } 502 503 @Override hashCode()504 public int hashCode() { 505 return Objects.hash(mType, mApnSetting, mTrafficDescriptor); 506 } 507 508 /** 509 * Provides a convenient way to set the fields of a {@link DataProfile} when creating a new 510 * instance. 511 * 512 * <p>The example below shows how you might create a new {@code DataProfile}: 513 * 514 * <pre><code> 515 * 516 * DataProfile dp = new DataProfile.Builder() 517 * .setApn("apn.xyz.com") 518 * .setProtocol(ApnSetting.PROTOCOL_IPV4V6) 519 * .build(); 520 * </code></pre> 521 */ 522 public static final class Builder { 523 private int mProfileId; 524 525 private String mApn; 526 527 @ProtocolType 528 private int mProtocolType; 529 530 @AuthType 531 private int mAuthType; 532 533 private String mUserName; 534 535 private String mPassword; 536 537 @Type 538 private int mType = -1; 539 540 private boolean mEnabled = true; 541 542 @ApnType 543 private int mSupportedApnTypesBitmask; 544 545 @ProtocolType 546 private int mRoamingProtocolType; 547 548 @NetworkTypeBitMask 549 private int mBearerBitmask; 550 551 private int mMtuV4; 552 553 private int mMtuV6; 554 555 private boolean mPersistent; 556 557 private boolean mPreferred; 558 559 private ApnSetting mApnSetting; 560 561 private TrafficDescriptor mTrafficDescriptor; 562 563 /** 564 * Default constructor for Builder. 565 */ Builder()566 public Builder() { 567 } 568 569 /** 570 * Set profile id. Note that this is not a global unique id of the data profile. This id 571 * is only used by certain CDMA carriers to identify the type of data profile. 572 * 573 * @param profileId Network domain. 574 * @return The same instance of the builder. 575 * @deprecated use {@link #setApnSetting(ApnSetting)} and 576 * {@link ApnSetting.Builder#setProfileId(int)} instead. 577 */ 578 @Deprecated setProfileId(int profileId)579 public @NonNull Builder setProfileId(int profileId) { 580 mProfileId = profileId; 581 return this; 582 } 583 584 /** 585 * Set the APN (Access Point Name) to establish data connection. This is a string 586 * specifically defined by the carrier. 587 * 588 * @param apn Access point name 589 * @return The same instance of the builder. 590 * @deprecated use {@link #setApnSetting(ApnSetting)} and 591 * {@link ApnSetting.Builder#setApnName(String)} instead. 592 */ 593 @Deprecated setApn(@onNull String apn)594 public @NonNull Builder setApn(@NonNull String apn) { 595 mApn = apn; 596 return this; 597 } 598 599 /** 600 * Set the connection protocol type. 601 * 602 * @param protocolType The connection protocol defined in 3GPP TS 27.007 section 10.1.1. 603 * @return The same instance of the builder. 604 * @deprecated use {@link #setApnSetting(ApnSetting)} and 605 * {@link ApnSetting.Builder#setProtocol(int)} instead. 606 */ 607 @Deprecated setProtocolType(@rotocolType int protocolType)608 public @NonNull Builder setProtocolType(@ProtocolType int protocolType) { 609 mProtocolType = protocolType; 610 return this; 611 } 612 613 /** 614 * Set the authentication type. 615 * 616 * @param authType The authentication type 617 * @return The same instance of the builder. 618 * @deprecated use {@link #setApnSetting(ApnSetting)} and 619 * {@link ApnSetting.Builder#setAuthType(int)} instead. 620 */ 621 @Deprecated setAuthType(@uthType int authType)622 public @NonNull Builder setAuthType(@AuthType int authType) { 623 mAuthType = authType; 624 return this; 625 } 626 627 /** 628 * Set the user name 629 * 630 * @param userName The user name 631 * @return The same instance of the builder. 632 * @deprecated use {@link #setApnSetting(ApnSetting)} and 633 * {@link ApnSetting.Builder#setUser(String)} instead. 634 */ 635 @Deprecated setUserName(@onNull String userName)636 public @NonNull Builder setUserName(@NonNull String userName) { 637 mUserName = userName; 638 return this; 639 } 640 641 /** 642 * Set the password 643 * 644 * @param password The password 645 * @return The same instance of the builder. 646 * @deprecated use {@link #setApnSetting(ApnSetting)} and 647 * {@link ApnSetting.Builder#setPassword(String)} (int)} instead. 648 */ 649 @Deprecated setPassword(@onNull String password)650 public @NonNull Builder setPassword(@NonNull String password) { 651 mPassword = password; 652 return this; 653 } 654 655 /** 656 * Set the type 657 * 658 * @param type The profile type 659 * @return The same instance of the builder. 660 */ setType(@ype int type)661 public @NonNull Builder setType(@Type int type) { 662 mType = type; 663 return this; 664 } 665 666 /** 667 * Enable the data profile 668 * 669 * @param isEnabled {@code true} to enable the data profile, otherwise disable. 670 * @return The same instance of the builder. 671 */ enable(boolean isEnabled)672 public @NonNull Builder enable(boolean isEnabled) { 673 mEnabled = isEnabled; 674 return this; 675 } 676 677 /** 678 * Set the supported APN types bitmask. 679 * 680 * @param supportedApnTypesBitmask The supported APN types bitmask. 681 * @return The same instance of the builder. 682 * @deprecated use {@link #setApnSetting(ApnSetting)} and 683 * {@link ApnSetting.Builder#setApnTypeBitmask(int)} instead. 684 */ 685 @Deprecated setSupportedApnTypesBitmask(@pnType int supportedApnTypesBitmask)686 public @NonNull Builder setSupportedApnTypesBitmask(@ApnType int supportedApnTypesBitmask) { 687 mSupportedApnTypesBitmask = supportedApnTypesBitmask; 688 return this; 689 } 690 691 /** 692 * Set the connection protocol type for roaming. 693 * 694 * @param protocolType The connection protocol defined in 3GPP TS 27.007 section 10.1.1. 695 * @return The same instance of the builder. 696 * @deprecated use {@link #setApnSetting(ApnSetting)} and 697 * {@link ApnSetting.Builder#setRoamingProtocol(int)} instead. 698 */ 699 @Deprecated setRoamingProtocolType(@rotocolType int protocolType)700 public @NonNull Builder setRoamingProtocolType(@ProtocolType int protocolType) { 701 mRoamingProtocolType = protocolType; 702 return this; 703 } 704 705 /** 706 * Set the bearer bitmask indicating the applicable networks for this data profile. 707 * 708 * @param bearerBitmask The bearer bitmask indicating the applicable networks for this data 709 * profile. 710 * @return The same instance of the builder. 711 * @deprecated use {@link #setApnSetting(ApnSetting)} and 712 * {@link ApnSetting.Builder#setNetworkTypeBitmask(int)} instead. 713 */ 714 @Deprecated setBearerBitmask(@etworkTypeBitMask int bearerBitmask)715 public @NonNull Builder setBearerBitmask(@NetworkTypeBitMask int bearerBitmask) { 716 mBearerBitmask = bearerBitmask; 717 return this; 718 } 719 720 /** 721 * Set the maximum transmission unit (MTU) size in bytes. 722 * 723 * @param mtu The maximum transmission unit (MTU) size in bytes. 724 * @return The same instance of the builder. 725 * @deprecated use {@link #setApnSetting(ApnSetting)} and 726 * {@link ApnSetting.Builder#setMtuV4(int)}/{@link ApnSetting.Builder#setMtuV6(int)} 727 * instead. 728 */ 729 @Deprecated setMtu(int mtu)730 public @NonNull Builder setMtu(int mtu) { 731 mMtuV4 = mMtuV6 = mtu; 732 return this; 733 } 734 735 /** 736 * Set the maximum transmission unit (MTU) size in bytes, for IPv4. 737 * 738 * @param mtu The maximum transmission unit (MTU) size in bytes. 739 * @return The same instance of the builder. 740 * @deprecated Use {{@link #setApnSetting(ApnSetting)}} and 741 * {@link ApnSetting.Builder#setMtuV4(int)} instead. 742 */ 743 @Deprecated setMtuV4(int mtu)744 public @NonNull Builder setMtuV4(int mtu) { 745 mMtuV4 = mtu; 746 return this; 747 } 748 749 /** 750 * Set the maximum transmission unit (MTU) size in bytes, for IPv6. 751 * 752 * @param mtu The maximum transmission unit (MTU) size in bytes. 753 * @return The same instance of the builder. 754 * @deprecated Use {{@link #setApnSetting(ApnSetting)}} and 755 * {@link ApnSetting.Builder#setMtuV6(int)} instead. 756 */ 757 @Deprecated setMtuV6(int mtu)758 public @NonNull Builder setMtuV6(int mtu) { 759 mMtuV6 = mtu; 760 return this; 761 } 762 763 /** 764 * Set data profile as preferred/non-preferred. 765 * 766 * @param isPreferred {@code true} if this data profile was used to bring up the last 767 * default (i.e internet) data connection successfully, or the one chosen by the user in 768 * Settings' APN editor. For one carrier there can be only one profiled preferred. 769 * @return The same instance of the builder. 770 */ setPreferred(boolean isPreferred)771 public @NonNull Builder setPreferred(boolean isPreferred) { 772 mPreferred = isPreferred; 773 return this; 774 } 775 776 /** 777 * Set data profile as persistent/non-persistent. 778 * 779 * @param isPersistent {@code true} if this data profile was used to bring up the last 780 * default (i.e internet) data connection successfully. 781 * @return The same instance of the builder. 782 * @deprecated Use {{@link #setApnSetting(ApnSetting)}} and 783 * {@link ApnSetting.Builder#setPersistent(boolean)} instead. 784 */ 785 @Deprecated setPersistent(boolean isPersistent)786 public @NonNull Builder setPersistent(boolean isPersistent) { 787 mPersistent = isPersistent; 788 return this; 789 } 790 791 /** 792 * Set the APN setting. Note that if an APN setting is not set here, then either 793 * {@link #setApn(String)} or {@link #setTrafficDescriptor(TrafficDescriptor)} must be 794 * called. Otherwise {@link IllegalArgumentException} will be thrown when {@link #build()} 795 * the data profile. 796 * 797 * @param apnSetting The APN setting. 798 * @return The same instance of the builder. 799 */ setApnSetting(@onNull ApnSetting apnSetting)800 public @NonNull Builder setApnSetting(@NonNull ApnSetting apnSetting) { 801 mApnSetting = apnSetting; 802 return this; 803 } 804 805 /** 806 * Set the traffic descriptor. Note that if a traffic descriptor is not set here, then 807 * either {@link #setApnSetting(ApnSetting)} or {@link #setApn(String)} must be called. 808 * Otherwise {@link IllegalArgumentException} will be thrown when {@link #build()} the data 809 * profile. 810 * 811 * @param trafficDescriptor The traffic descriptor. 812 * @return The same instance of the builder. 813 */ setTrafficDescriptor(@onNull TrafficDescriptor trafficDescriptor)814 public @NonNull Builder setTrafficDescriptor(@NonNull TrafficDescriptor trafficDescriptor) { 815 mTrafficDescriptor = trafficDescriptor; 816 return this; 817 } 818 819 /** 820 * Build the DataProfile object. 821 * 822 * @return The data profile object. 823 */ build()824 public @NonNull DataProfile build() { 825 if (mApnSetting == null && mApn != null) { 826 // This is for backwards compatibility. 827 mApnSetting = new ApnSetting.Builder() 828 .setEntryName(mApn) 829 .setApnName(mApn) 830 .setApnTypeBitmask(mSupportedApnTypesBitmask) 831 .setAuthType(mAuthType) 832 .setCarrierEnabled(mEnabled) 833 .setModemCognitive(mPersistent) 834 .setMtuV4(mMtuV4) 835 .setMtuV6(mMtuV6) 836 .setNetworkTypeBitmask(mBearerBitmask) 837 .setProfileId(mProfileId) 838 .setPassword(mPassword) 839 .setProtocol(mProtocolType) 840 .setRoamingProtocol(mRoamingProtocolType) 841 .setUser(mUserName) 842 .build(); 843 } 844 845 if (mApnSetting == null && mTrafficDescriptor == null) { 846 throw new IllegalArgumentException("APN setting and traffic descriptor can't be " 847 + "both null."); 848 } 849 850 return new DataProfile(this); 851 } 852 } 853 } 854