1 /* 2 * Copyright (C) 2009 Qualcomm Innovation Center, Inc. All Rights Reserved. 3 * Copyright (C) 2009 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package android.telephony.data; 19 20 import android.annotation.IntDef; 21 import android.annotation.IntRange; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.SystemApi; 25 import android.net.LinkAddress; 26 import android.os.Parcel; 27 import android.os.Parcelable; 28 import android.telephony.Annotation.DataFailureCause; 29 import android.telephony.DataFailCause; 30 import android.telephony.PreciseDataConnectionState; 31 import android.telephony.data.ApnSetting.ProtocolType; 32 33 import com.android.internal.annotations.VisibleForTesting; 34 import com.android.internal.util.Preconditions; 35 36 import java.lang.annotation.Retention; 37 import java.lang.annotation.RetentionPolicy; 38 import java.net.InetAddress; 39 import java.util.ArrayList; 40 import java.util.Collections; 41 import java.util.List; 42 import java.util.Objects; 43 import java.util.Set; 44 45 /** 46 * Description of the response of a setup data call connection request. 47 * 48 * @hide 49 */ 50 @SystemApi 51 public final class DataCallResponse implements Parcelable { 52 53 /** {@hide} */ 54 @IntDef(prefix = "LINK_STATUS_", value = { 55 LINK_STATUS_UNKNOWN, 56 LINK_STATUS_INACTIVE, 57 LINK_STATUS_DORMANT, 58 LINK_STATUS_ACTIVE 59 }) 60 @Retention(RetentionPolicy.SOURCE) 61 public @interface LinkStatus {} 62 63 /** Unknown status */ 64 public static final int LINK_STATUS_UNKNOWN = -1; 65 66 /** Indicates the data connection is inactive. */ 67 public static final int LINK_STATUS_INACTIVE = 0; 68 69 /** Indicates the data connection is active with physical link dormant. */ 70 public static final int LINK_STATUS_DORMANT = 1; 71 72 /** Indicates the data connection is active with physical link up. */ 73 public static final int LINK_STATUS_ACTIVE = 2; 74 75 /** {@hide} */ 76 @IntDef(prefix = "HANDOVER_FAILURE_MODE_", value = { 77 HANDOVER_FAILURE_MODE_UNKNOWN, 78 HANDOVER_FAILURE_MODE_LEGACY, 79 HANDOVER_FAILURE_MODE_DO_FALLBACK, 80 HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_HANDOVER, 81 HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_SETUP_NORMAL 82 }) 83 @Retention(RetentionPolicy.SOURCE) 84 public @interface HandoverFailureMode {} 85 86 /** 87 * Data handover failure mode is unknown. 88 */ 89 public static final int HANDOVER_FAILURE_MODE_UNKNOWN = -1; 90 91 /** 92 * Perform fallback to the source data transport on data handover failure using 93 * the legacy logic, which is fallback if the fail cause is 94 * {@link DataFailCause#HANDOFF_PREFERENCE_CHANGED}. 95 */ 96 public static final int HANDOVER_FAILURE_MODE_LEGACY = 0; 97 98 /** 99 * Perform fallback to the source data transport on data handover failure. 100 */ 101 public static final int HANDOVER_FAILURE_MODE_DO_FALLBACK = 1; 102 103 /** 104 * Do not perform fallback to the source data transport on data handover failure. 105 * Framework will retry setting up a new data connection by sending 106 * {@link DataService#REQUEST_REASON_HANDOVER} request to the underlying {@link DataService}. 107 */ 108 public static final int HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_HANDOVER = 2; 109 110 /** 111 * Do not perform fallback to the source transport on data handover failure. 112 * Framework will retry setting up a new data connection by sending 113 * {@link DataService#REQUEST_REASON_NORMAL} request to the underlying {@link DataService}. 114 */ 115 public static final int HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_SETUP_NORMAL = 3; 116 117 /** 118 * Indicates that data retry duration is not specified. Platform can determine when to 119 * perform data setup appropriately. 120 */ 121 public static final int RETRY_DURATION_UNDEFINED = -1; 122 123 /** 124 * Indicates that the pdu session id is not set. 125 */ 126 public static final int PDU_SESSION_ID_NOT_SET = 0; 127 private final @DataFailureCause int mCause; 128 private final long mSuggestedRetryTime; 129 private final int mId; 130 private final @LinkStatus int mLinkStatus; 131 private final @ProtocolType int mProtocolType; 132 private final String mInterfaceName; 133 private final List<LinkAddress> mAddresses; 134 private final List<InetAddress> mDnsAddresses; 135 private final List<InetAddress> mGatewayAddresses; 136 private final List<InetAddress> mPcscfAddresses; 137 private final int mMtu; 138 private final int mMtuV4; 139 private final int mMtuV6; 140 private final @HandoverFailureMode int mHandoverFailureMode; 141 private final int mPduSessionId; 142 private final Qos mDefaultQos; 143 private final List<QosBearerSession> mQosBearerSessions; 144 private final NetworkSliceInfo mSliceInfo; 145 private final List<TrafficDescriptor> mTrafficDescriptors; 146 private final @PreciseDataConnectionState.NetworkValidationStatus int mNetworkValidationStatus; 147 148 /** 149 * @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error. 150 * @param suggestedRetryTime The suggested data retry time in milliseconds. 151 * @param id The unique id of the data connection. 152 * @param linkStatus Data connection link status. 153 * @param protocolType The connection protocol, should be one of the PDP_type values in 3GPP 154 * TS 27.007 section 10.1.1. For example, "IP", "IPV6", "IPV4V6", or "PPP". 155 * @param interfaceName The network interface name. 156 * @param addresses A list of addresses with optional "/" prefix length, e.g., 157 * "192.0.1.3" or "192.0.1.11/16 2001:db8::1/64". Typically 1 IPv4 or 1 IPv6 or 158 * one of each. If the prefix length is absent the addresses are assumed to be 159 * point to point with IPv4 having a prefix length of 32 and IPv6 128. 160 * @param dnsAddresses A list of DNS server addresses, e.g., "192.0.1.3" or 161 * "192.0.1.11 2001:db8::1". Null if no dns server addresses returned. 162 * @param gatewayAddresses A list of default gateway addresses, e.g., "192.0.1.3" or 163 * "192.0.1.11 2001:db8::1". When null, the addresses represent point to point connections. 164 * @param pcscfAddresses A list of Proxy Call State Control Function address via PCO (Protocol 165 * Configuration Option) for IMS client. 166 * @param mtu MTU (maximum transmission unit) in bytes received from network. 167 * Zero or negative values means network has either not sent a value or sent an invalid value. 168 * 169 * @removed Use the {@link Builder()} instead. 170 */ DataCallResponse(@ataFailureCause int cause, int suggestedRetryTime, int id, @LinkStatus int linkStatus, @ProtocolType int protocolType, @Nullable String interfaceName, @Nullable List<LinkAddress> addresses, @Nullable List<InetAddress> dnsAddresses, @Nullable List<InetAddress> gatewayAddresses, @Nullable List<InetAddress> pcscfAddresses, int mtu)171 public DataCallResponse(@DataFailureCause int cause, int suggestedRetryTime, int id, 172 @LinkStatus int linkStatus, 173 @ProtocolType int protocolType, @Nullable String interfaceName, 174 @Nullable List<LinkAddress> addresses, 175 @Nullable List<InetAddress> dnsAddresses, 176 @Nullable List<InetAddress> gatewayAddresses, 177 @Nullable List<InetAddress> pcscfAddresses, int mtu) { 178 this(cause, suggestedRetryTime, id, 179 linkStatus, protocolType, 180 interfaceName == null ? "" : interfaceName, 181 addresses == null ? Collections.emptyList() : addresses, 182 dnsAddresses == null ? Collections.emptyList() : dnsAddresses, 183 gatewayAddresses == null ? Collections.emptyList() : gatewayAddresses, 184 pcscfAddresses == null ? Collections.emptyList() : pcscfAddresses, 185 mtu, mtu /* mtuV4 */, mtu /* mtuV6 */, 186 HANDOVER_FAILURE_MODE_LEGACY, PDU_SESSION_ID_NOT_SET, 187 null /* defaultQos */, Collections.emptyList() /* qosBearerSessions */, 188 null /* sliceInfo */, 189 Collections.emptyList(), /* trafficDescriptors */ 190 PreciseDataConnectionState.NETWORK_VALIDATION_UNSUPPORTED); 191 } 192 DataCallResponse(@ataFailureCause int cause, long suggestedRetryTime, int id, @LinkStatus int linkStatus, @ProtocolType int protocolType, @NonNull String interfaceName, @NonNull List<LinkAddress> addresses, @NonNull List<InetAddress> dnsAddresses, @NonNull List<InetAddress> gatewayAddresses, @NonNull List<InetAddress> pcscfAddresses, int mtu, int mtuV4, int mtuV6, @HandoverFailureMode int handoverFailureMode, int pduSessionId, @Nullable Qos defaultQos, @NonNull List<QosBearerSession> qosBearerSessions, @Nullable NetworkSliceInfo sliceInfo, @NonNull List<TrafficDescriptor> trafficDescriptors, @PreciseDataConnectionState.NetworkValidationStatus int networkValidationStatus)193 private DataCallResponse(@DataFailureCause int cause, long suggestedRetryTime, int id, 194 @LinkStatus int linkStatus, @ProtocolType int protocolType, 195 @NonNull String interfaceName, @NonNull List<LinkAddress> addresses, 196 @NonNull List<InetAddress> dnsAddresses, @NonNull List<InetAddress> gatewayAddresses, 197 @NonNull List<InetAddress> pcscfAddresses, int mtu, int mtuV4, int mtuV6, 198 @HandoverFailureMode int handoverFailureMode, int pduSessionId, 199 @Nullable Qos defaultQos, @NonNull List<QosBearerSession> qosBearerSessions, 200 @Nullable NetworkSliceInfo sliceInfo, 201 @NonNull List<TrafficDescriptor> trafficDescriptors, 202 @PreciseDataConnectionState.NetworkValidationStatus int networkValidationStatus) { 203 mCause = cause; 204 mSuggestedRetryTime = suggestedRetryTime; 205 mId = id; 206 mLinkStatus = linkStatus; 207 mProtocolType = protocolType; 208 mInterfaceName = interfaceName; 209 mAddresses = new ArrayList<>(addresses); 210 mDnsAddresses = new ArrayList<>(dnsAddresses); 211 mGatewayAddresses = new ArrayList<>(gatewayAddresses); 212 mPcscfAddresses = new ArrayList<>(pcscfAddresses); 213 mMtu = mtu; 214 mMtuV4 = mtuV4; 215 mMtuV6 = mtuV6; 216 mHandoverFailureMode = handoverFailureMode; 217 mPduSessionId = pduSessionId; 218 mDefaultQos = defaultQos; 219 mQosBearerSessions = new ArrayList<>(qosBearerSessions); 220 mSliceInfo = sliceInfo; 221 mTrafficDescriptors = new ArrayList<>(trafficDescriptors); 222 mNetworkValidationStatus = networkValidationStatus; 223 224 if (mLinkStatus == LINK_STATUS_ACTIVE 225 || mLinkStatus == LINK_STATUS_DORMANT) { 226 Objects.requireNonNull( 227 mInterfaceName, "Active data calls must be on a valid interface!"); 228 if (mCause != DataFailCause.NONE) { 229 throw new IllegalStateException("Active data call must not have a failure!"); 230 } 231 } 232 } 233 234 /** @hide */ 235 @VisibleForTesting DataCallResponse(Parcel source)236 public DataCallResponse(Parcel source) { 237 mCause = source.readInt(); 238 mSuggestedRetryTime = source.readLong(); 239 mId = source.readInt(); 240 mLinkStatus = source.readInt(); 241 mProtocolType = source.readInt(); 242 mInterfaceName = source.readString(); 243 mAddresses = new ArrayList<>(); 244 source.readList(mAddresses, 245 LinkAddress.class.getClassLoader(), 246 android.net.LinkAddress.class); 247 mDnsAddresses = new ArrayList<>(); 248 source.readList(mDnsAddresses, 249 InetAddress.class.getClassLoader(), 250 java.net.InetAddress.class); 251 mGatewayAddresses = new ArrayList<>(); 252 source.readList(mGatewayAddresses, 253 InetAddress.class.getClassLoader(), 254 java.net.InetAddress.class); 255 mPcscfAddresses = new ArrayList<>(); 256 source.readList(mPcscfAddresses, 257 InetAddress.class.getClassLoader(), 258 java.net.InetAddress.class); 259 mMtu = source.readInt(); 260 mMtuV4 = source.readInt(); 261 mMtuV6 = source.readInt(); 262 mHandoverFailureMode = source.readInt(); 263 mPduSessionId = source.readInt(); 264 mDefaultQos = source.readParcelable(Qos.class.getClassLoader(), 265 android.telephony.data.Qos.class); 266 mQosBearerSessions = new ArrayList<>(); 267 source.readList(mQosBearerSessions, 268 QosBearerSession.class.getClassLoader(), 269 android.telephony.data.QosBearerSession.class); 270 mSliceInfo = source.readParcelable( 271 NetworkSliceInfo.class.getClassLoader(), 272 android.telephony.data.NetworkSliceInfo.class); 273 mTrafficDescriptors = new ArrayList<>(); 274 source.readList(mTrafficDescriptors, 275 TrafficDescriptor.class.getClassLoader(), 276 android.telephony.data.TrafficDescriptor.class); 277 mNetworkValidationStatus = source.readInt(); 278 } 279 280 /** 281 * @return Data call fail cause. {@link DataFailCause#NONE} indicates no error. 282 */ 283 @DataFailureCause getCause()284 public int getCause() { return mCause; } 285 286 /** 287 * @return The suggested data retry time in milliseconds. 0 when network does not 288 * suggest a retry time (Note this is different from the replacement 289 * {@link #getRetryDurationMillis()}). 290 * 291 * @deprecated Use {@link #getRetryDurationMillis()} instead. 292 */ 293 @Deprecated getSuggestedRetryTime()294 public int getSuggestedRetryTime() { 295 // To match the pre-deprecated getSuggestedRetryTime() behavior. 296 if (mSuggestedRetryTime == RETRY_DURATION_UNDEFINED) { 297 return 0; 298 } else if (mSuggestedRetryTime > Integer.MAX_VALUE) { 299 return Integer.MAX_VALUE; 300 } 301 return (int) mSuggestedRetryTime; 302 } 303 304 /** 305 * @return The network suggested data retry duration in milliseconds as specified in 306 * 3GPP TS 24.302 section 8.2.9.1. The APN associated to this data call will be throttled for 307 * the specified duration unless {@link DataServiceCallback#onApnUnthrottled} is called. 308 * {@code Long.MAX_VALUE} indicates data retry should not occur. 309 * {@link #RETRY_DURATION_UNDEFINED} indicates network did not suggest any retry duration. 310 */ getRetryDurationMillis()311 public long getRetryDurationMillis() { 312 return mSuggestedRetryTime; 313 } 314 315 /** 316 * @return The unique id of the data connection. 317 */ getId()318 public int getId() { return mId; } 319 320 /** 321 * @return The link status 322 */ getLinkStatus()323 @LinkStatus public int getLinkStatus() { return mLinkStatus; } 324 325 /** 326 * @return The connection protocol type. 327 */ 328 @ProtocolType getProtocolType()329 public int getProtocolType() { return mProtocolType; } 330 331 /** 332 * @return The network interface name (e.g. "rmnet_data1"). 333 */ 334 @NonNull getInterfaceName()335 public String getInterfaceName() { return mInterfaceName; } 336 337 /** 338 * @return A list of addresses of this data connection. 339 */ 340 @NonNull getAddresses()341 public List<LinkAddress> getAddresses() { 342 return Collections.unmodifiableList(mAddresses); 343 } 344 345 /** 346 * @return A list of DNS server addresses, e.g., "192.0.1.3" or 347 * "192.0.1.11 2001:db8::1". Empty list if no dns server addresses returned. 348 */ 349 @NonNull getDnsAddresses()350 public List<InetAddress> getDnsAddresses() { 351 return Collections.unmodifiableList(mDnsAddresses); 352 } 353 354 /** 355 * @return A list of default gateway addresses, e.g., "192.0.1.3" or 356 * "192.0.1.11 2001:db8::1". Empty list if the addresses represent point to point connections. 357 */ 358 @NonNull getGatewayAddresses()359 public List<InetAddress> getGatewayAddresses() { 360 return Collections.unmodifiableList(mGatewayAddresses); 361 } 362 363 /** 364 * @return A list of Proxy Call State Control Function address via PCO (Protocol Configuration 365 * Option) for IMS client. 366 */ 367 @NonNull getPcscfAddresses()368 public List<InetAddress> getPcscfAddresses() { 369 return Collections.unmodifiableList(mPcscfAddresses); 370 } 371 372 /** 373 * @return MTU (maximum transmission unit) in bytes received from network. Zero or negative 374 * values means network has either not sent a value or sent an invalid value. 375 * @deprecated For IRadio 1.5 and up, use {@link #getMtuV4} or {@link #getMtuV6} instead. 376 */ 377 @Deprecated getMtu()378 public int getMtu() { 379 return mMtu; 380 } 381 382 /** 383 * This replaces the deprecated method getMtu. 384 * @return MTU (maximum transmission unit) in bytes received from network, for IPv4. 385 * Zero or negative values means network has either not sent a value or sent an invalid value. 386 */ getMtuV4()387 public int getMtuV4() { 388 return mMtuV4; 389 } 390 391 /** 392 * @return MTU (maximum transmission unit) in bytes received from network, for IPv6. 393 * Zero or negative values means network has either not sent a value or sent an invalid value. 394 */ getMtuV6()395 public int getMtuV6() { 396 return mMtuV6; 397 } 398 399 /** 400 * @return The data handover failure mode. 401 */ getHandoverFailureMode()402 public @HandoverFailureMode int getHandoverFailureMode() { 403 return mHandoverFailureMode; 404 } 405 406 /** 407 * @return The pdu session id 408 */ getPduSessionId()409 public int getPduSessionId() { 410 return mPduSessionId; 411 } 412 413 /** 414 * @return default QOS of the data connection received from the network 415 * 416 * @hide 417 */ 418 @Nullable getDefaultQos()419 public Qos getDefaultQos() { 420 return mDefaultQos; 421 } 422 423 /** 424 * @return All the dedicated bearer QOS sessions of the data connection received from the 425 * network. 426 * 427 * @hide 428 */ 429 @NonNull getQosBearerSessions()430 public List<QosBearerSession> getQosBearerSessions() { 431 return Collections.unmodifiableList(mQosBearerSessions); 432 } 433 434 /** 435 * @return The slice info related to this data connection. 436 */ 437 @Nullable getSliceInfo()438 public NetworkSliceInfo getSliceInfo() { 439 return mSliceInfo; 440 } 441 442 /** 443 * @return The traffic descriptors related to this data connection. 444 */ 445 @NonNull getTrafficDescriptors()446 public List<TrafficDescriptor> getTrafficDescriptors() { 447 return Collections.unmodifiableList(mTrafficDescriptors); 448 } 449 450 /** 451 * Return the network validation status that was initiated by {@link 452 * DataService.DataServiceProvider#requestNetworkValidation} 453 * 454 * @return The network validation status of data connection. 455 */ getNetworkValidationStatus()456 public @PreciseDataConnectionState.NetworkValidationStatus int getNetworkValidationStatus() { 457 return mNetworkValidationStatus; 458 } 459 460 @NonNull 461 @Override toString()462 public String toString() { 463 StringBuffer sb = new StringBuffer(); 464 sb.append("DataCallResponse: {") 465 .append(" cause=").append(DataFailCause.toString(mCause)) 466 .append(" retry=").append(mSuggestedRetryTime) 467 .append(" cid=").append(mId) 468 .append(" linkStatus=").append(mLinkStatus) 469 .append(" protocolType=").append(mProtocolType) 470 .append(" ifname=").append(mInterfaceName) 471 .append(" addresses=").append(mAddresses) 472 .append(" dnses=").append(mDnsAddresses) 473 .append(" gateways=").append(mGatewayAddresses) 474 .append(" pcscf=").append(mPcscfAddresses) 475 .append(" mtu=").append(getMtu()) 476 .append(" mtuV4=").append(getMtuV4()) 477 .append(" mtuV6=").append(getMtuV6()) 478 .append(" handoverFailureMode=").append(failureModeToString(mHandoverFailureMode)) 479 .append(" pduSessionId=").append(getPduSessionId()) 480 .append(" defaultQos=").append(mDefaultQos) 481 .append(" qosBearerSessions=").append(mQosBearerSessions) 482 .append(" sliceInfo=").append(mSliceInfo) 483 .append(" trafficDescriptors=").append(mTrafficDescriptors) 484 .append(" networkValidationStatus=").append(PreciseDataConnectionState 485 .networkValidationStatusToString(mNetworkValidationStatus)) 486 .append("}"); 487 return sb.toString(); 488 } 489 490 @Override equals(@ullable Object o)491 public boolean equals(@Nullable Object o) { 492 if (this == o) return true; 493 494 if (!(o instanceof DataCallResponse)) { 495 return false; 496 } 497 498 DataCallResponse other = (DataCallResponse) o; 499 500 return mCause == other.mCause 501 && mSuggestedRetryTime == other.mSuggestedRetryTime 502 && mId == other.mId 503 && mLinkStatus == other.mLinkStatus 504 && mProtocolType == other.mProtocolType 505 && mInterfaceName.equals(other.mInterfaceName) 506 && mAddresses.size() == other.mAddresses.size() 507 && mAddresses.containsAll(other.mAddresses) 508 && mDnsAddresses.size() == other.mDnsAddresses.size() 509 && mDnsAddresses.containsAll(other.mDnsAddresses) 510 && mGatewayAddresses.size() == other.mGatewayAddresses.size() 511 && mGatewayAddresses.containsAll(other.mGatewayAddresses) 512 && mPcscfAddresses.size() == other.mPcscfAddresses.size() 513 && mPcscfAddresses.containsAll(other.mPcscfAddresses) 514 && mMtu == other.mMtu 515 && mMtuV4 == other.mMtuV4 516 && mMtuV6 == other.mMtuV6 517 && mHandoverFailureMode == other.mHandoverFailureMode 518 && mPduSessionId == other.mPduSessionId 519 && Objects.equals(mDefaultQos, other.mDefaultQos) 520 && mQosBearerSessions.size() == other.mQosBearerSessions.size() // non-null 521 && mQosBearerSessions.containsAll(other.mQosBearerSessions) // non-null 522 && Objects.equals(mSliceInfo, other.mSliceInfo) 523 && mTrafficDescriptors.size() == other.mTrafficDescriptors.size() // non-null 524 && mTrafficDescriptors.containsAll(other.mTrafficDescriptors) // non-null 525 && mNetworkValidationStatus == other.mNetworkValidationStatus; 526 } 527 528 @Override hashCode()529 public int hashCode() { 530 return Objects.hash(mCause, mSuggestedRetryTime, mId, mLinkStatus, mProtocolType, 531 mInterfaceName, Set.copyOf(mAddresses), Set.copyOf(mDnsAddresses), 532 Set.copyOf(mGatewayAddresses), Set.copyOf(mPcscfAddresses), mMtu, mMtuV4, mMtuV6, 533 mHandoverFailureMode, mPduSessionId, mDefaultQos, Set.copyOf(mQosBearerSessions), 534 mSliceInfo, Set.copyOf(mTrafficDescriptors), mNetworkValidationStatus); 535 } 536 537 @Override describeContents()538 public int describeContents() { 539 return 0; 540 } 541 542 @Override writeToParcel(Parcel dest, int flags)543 public void writeToParcel(Parcel dest, int flags) { 544 dest.writeInt(mCause); 545 dest.writeLong(mSuggestedRetryTime); 546 dest.writeInt(mId); 547 dest.writeInt(mLinkStatus); 548 dest.writeInt(mProtocolType); 549 dest.writeString(mInterfaceName); 550 dest.writeList(mAddresses); 551 dest.writeList(mDnsAddresses); 552 dest.writeList(mGatewayAddresses); 553 dest.writeList(mPcscfAddresses); 554 dest.writeInt(mMtu); 555 dest.writeInt(mMtuV4); 556 dest.writeInt(mMtuV6); 557 dest.writeInt(mHandoverFailureMode); 558 dest.writeInt(mPduSessionId); 559 dest.writeParcelable(mDefaultQos, flags); 560 dest.writeList(mQosBearerSessions); 561 dest.writeParcelable(mSliceInfo, flags); 562 dest.writeList(mTrafficDescriptors); 563 dest.writeInt(mNetworkValidationStatus); 564 } 565 566 public static final @android.annotation.NonNull Parcelable.Creator<DataCallResponse> CREATOR = 567 new Parcelable.Creator<DataCallResponse>() { 568 @Override 569 public DataCallResponse createFromParcel(Parcel source) { 570 return new DataCallResponse(source); 571 } 572 573 @Override 574 public DataCallResponse[] newArray(int size) { 575 return new DataCallResponse[size]; 576 } 577 }; 578 579 /** 580 * Convert handover failure mode to string. 581 * 582 * @param handoverFailureMode Handover failure mode 583 * @return Handover failure mode in string 584 * 585 * @hide 586 */ failureModeToString(@andoverFailureMode int handoverFailureMode)587 public static String failureModeToString(@HandoverFailureMode int handoverFailureMode) { 588 switch (handoverFailureMode) { 589 case HANDOVER_FAILURE_MODE_UNKNOWN: return "unknown"; 590 case HANDOVER_FAILURE_MODE_LEGACY: return "legacy"; 591 case HANDOVER_FAILURE_MODE_DO_FALLBACK: return "fallback"; 592 case HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_HANDOVER: return "retry handover"; 593 case HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_SETUP_NORMAL: return "retry setup new one"; 594 default: return Integer.toString(handoverFailureMode); 595 } 596 } 597 598 /** 599 * Provides a convenient way to set the fields of a {@link DataCallResponse} when creating a new 600 * instance. 601 * 602 * <p>The example below shows how you might create a new {@code DataCallResponse}: 603 * 604 * <pre><code> 605 * 606 * DataCallResponse response = new DataCallResponse.Builder() 607 * .setAddresses(Arrays.asList("192.168.1.2")) 608 * .setProtocolType(ApnSetting.PROTOCOL_IPV4V6) 609 * .build(); 610 * </code></pre> 611 */ 612 public static final class Builder { 613 private @DataFailureCause int mCause; 614 615 private long mSuggestedRetryTime = RETRY_DURATION_UNDEFINED; 616 617 private int mId; 618 619 private @LinkStatus int mLinkStatus; 620 621 private @ProtocolType int mProtocolType; 622 623 private String mInterfaceName = ""; 624 625 private List<LinkAddress> mAddresses = Collections.emptyList(); 626 627 private List<InetAddress> mDnsAddresses = Collections.emptyList(); 628 629 private List<InetAddress> mGatewayAddresses = Collections.emptyList(); 630 631 private List<InetAddress> mPcscfAddresses = Collections.emptyList(); 632 633 private int mMtu; 634 635 private int mMtuV4; 636 637 private int mMtuV6; 638 639 private @HandoverFailureMode int mHandoverFailureMode = HANDOVER_FAILURE_MODE_LEGACY; 640 641 private int mPduSessionId = PDU_SESSION_ID_NOT_SET; 642 643 private @Nullable Qos mDefaultQos; 644 645 private List<QosBearerSession> mQosBearerSessions = new ArrayList<>(); 646 647 private @Nullable NetworkSliceInfo mSliceInfo; 648 649 private List<TrafficDescriptor> mTrafficDescriptors = new ArrayList<>(); 650 651 private @PreciseDataConnectionState.NetworkValidationStatus int mNetworkValidationStatus = 652 PreciseDataConnectionState.NETWORK_VALIDATION_UNSUPPORTED; 653 654 /** 655 * Default constructor for Builder. 656 */ Builder()657 public Builder() { 658 } 659 660 /** 661 * Set data call fail cause. 662 * 663 * @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error, which 664 * is the only valid value for data calls that are {@link LINK_STATUS_ACTIVE} or 665 * {@link LINK_STATUS_DORMANT}. 666 * @return The same instance of the builder. 667 */ setCause(@ataFailureCause int cause)668 public @NonNull Builder setCause(@DataFailureCause int cause) { 669 mCause = cause; 670 return this; 671 } 672 673 /** 674 * Set the suggested data retry time. 675 * 676 * @param suggestedRetryTime The suggested data retry time in milliseconds. 677 * @return The same instance of the builder. 678 * 679 * @deprecated Use {@link #setRetryDurationMillis(long)} instead. 680 */ 681 @Deprecated setSuggestedRetryTime(int suggestedRetryTime)682 public @NonNull Builder setSuggestedRetryTime(int suggestedRetryTime) { 683 mSuggestedRetryTime = (long) suggestedRetryTime; 684 return this; 685 } 686 687 /** 688 * Set the network suggested data retry duration. 689 * 690 * @param retryDurationMillis The suggested data retry duration in milliseconds. 691 * @return The same instance of the builder. 692 */ setRetryDurationMillis(long retryDurationMillis)693 public @NonNull Builder setRetryDurationMillis(long retryDurationMillis) { 694 mSuggestedRetryTime = retryDurationMillis; 695 return this; 696 } 697 698 /** 699 * Set the unique id of the data connection. 700 * 701 * @param id The unique id of the data connection. 702 * @return The same instance of the builder. 703 */ setId(int id)704 public @NonNull Builder setId(int id) { 705 mId = id; 706 return this; 707 } 708 709 /** 710 * Set the link status 711 * 712 * @param linkStatus The link status 713 * @return The same instance of the builder. 714 */ setLinkStatus(@inkStatus int linkStatus)715 public @NonNull Builder setLinkStatus(@LinkStatus int linkStatus) { 716 mLinkStatus = linkStatus; 717 return this; 718 } 719 720 /** 721 * Set the connection protocol type. 722 * 723 * @param protocolType The connection protocol type. 724 * @return The same instance of the builder. 725 */ setProtocolType(@rotocolType int protocolType)726 public @NonNull Builder setProtocolType(@ProtocolType int protocolType) { 727 mProtocolType = protocolType; 728 return this; 729 } 730 731 /** 732 * Set the network interface name. 733 * 734 * @param interfaceName The network interface name (e.g. "rmnet_data1"). This value may not 735 * be null for valid data calls (those that are {@link LINK_STATUS_ACTIVE} or 736 * {@link LINK_STATUS_DORMANT}). 737 * @return The same instance of the builder. 738 */ setInterfaceName(@ullable String interfaceName)739 public @NonNull Builder setInterfaceName(@Nullable String interfaceName) { 740 if (interfaceName == null) interfaceName = ""; 741 mInterfaceName = interfaceName; 742 return this; 743 } 744 745 /** 746 * Set the addresses of this data connection. 747 * 748 * @param addresses The list of address of the data connection. 749 * @return The same instance of the builder. 750 */ setAddresses(@onNull List<LinkAddress> addresses)751 public @NonNull Builder setAddresses(@NonNull List<LinkAddress> addresses) { 752 Objects.requireNonNull(addresses); 753 mAddresses = addresses; 754 return this; 755 } 756 757 /** 758 * Set the DNS addresses of this data connection 759 * 760 * @param dnsAddresses The list of DNS address of the data connection. 761 * @return The same instance of the builder. 762 */ setDnsAddresses(@onNull List<InetAddress> dnsAddresses)763 public @NonNull Builder setDnsAddresses(@NonNull List<InetAddress> dnsAddresses) { 764 Objects.requireNonNull(dnsAddresses); 765 mDnsAddresses = dnsAddresses; 766 return this; 767 } 768 769 /** 770 * Set the gateway addresses of this data connection 771 * 772 * @param gatewayAddresses The list of gateway address of the data connection. 773 * @return The same instance of the builder. 774 */ setGatewayAddresses(@onNull List<InetAddress> gatewayAddresses)775 public @NonNull Builder setGatewayAddresses(@NonNull List<InetAddress> gatewayAddresses) { 776 Objects.requireNonNull(gatewayAddresses); 777 mGatewayAddresses = gatewayAddresses; 778 return this; 779 } 780 781 /** 782 * Set the Proxy Call State Control Function address via PCO(Protocol Configuration 783 * Option) for IMS client. 784 * 785 * @param pcscfAddresses The list of pcscf address of the data connection. 786 * @return The same instance of the builder. 787 */ setPcscfAddresses(@onNull List<InetAddress> pcscfAddresses)788 public @NonNull Builder setPcscfAddresses(@NonNull List<InetAddress> pcscfAddresses) { 789 Objects.requireNonNull(pcscfAddresses); 790 mPcscfAddresses = pcscfAddresses; 791 return this; 792 } 793 794 /** 795 * Set maximum transmission unit of the data connection. 796 * 797 * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or 798 * negative values means network has either not sent a value or sent an invalid value. 799 * 800 * @return The same instance of the builder. 801 * @deprecated For IRadio 1.5 and up, use {@link #setMtuV4} or {@link #setMtuV6} instead. 802 */ setMtu(int mtu)803 public @NonNull Builder setMtu(int mtu) { 804 mMtu = mtu; 805 return this; 806 } 807 808 /** 809 * Set maximum transmission unit of the data connection, for IPv4. 810 * 811 * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or 812 * negative values means network has either not sent a value or sent an invalid value. 813 * 814 * @return The same instance of the builder. 815 */ setMtuV4(int mtu)816 public @NonNull Builder setMtuV4(int mtu) { 817 mMtuV4 = mtu; 818 return this; 819 } 820 821 /** 822 * Set maximum transmission unit of the data connection, for IPv6. 823 * 824 * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or 825 * negative values means network has either not sent a value or sent an invalid value. 826 * 827 * @return The same instance of the builder. 828 */ setMtuV6(int mtu)829 public @NonNull Builder setMtuV6(int mtu) { 830 mMtuV6 = mtu; 831 return this; 832 } 833 834 /** 835 * Set data handover failure mode for the data call response. 836 * 837 * @param failureMode Handover failure mode. 838 * @return The same instance of the builder. 839 */ setHandoverFailureMode(@andoverFailureMode int failureMode)840 public @NonNull Builder setHandoverFailureMode(@HandoverFailureMode int failureMode) { 841 mHandoverFailureMode = failureMode; 842 return this; 843 } 844 845 /** 846 * Set pdu session id. 847 * <p/> 848 * The id must be between 1 and 15 when linked to a pdu session. If no pdu session 849 * exists for the current data call, the id must be set to {@link #PDU_SESSION_ID_NOT_SET}. 850 * 851 * @param pduSessionId Pdu Session Id of the data call. 852 * @return The same instance of the builder. 853 */ setPduSessionId( @ntRangefrom = PDU_SESSION_ID_NOT_SET, to = 15) int pduSessionId)854 public @NonNull Builder setPduSessionId( 855 @IntRange(from = PDU_SESSION_ID_NOT_SET, to = 15) int pduSessionId) { 856 Preconditions.checkArgument(pduSessionId >= PDU_SESSION_ID_NOT_SET, 857 "pduSessionId must be greater than or equal to" + PDU_SESSION_ID_NOT_SET); 858 Preconditions.checkArgument(pduSessionId <= 15, 859 "pduSessionId must be less than or equal to 15."); 860 mPduSessionId = pduSessionId; 861 return this; 862 } 863 864 /** 865 * Set the default QOS for this data connection. 866 * 867 * @param defaultQos QOS (Quality Of Service) received from network. 868 * 869 * @return The same instance of the builder. 870 * 871 * @hide 872 */ setDefaultQos(@ullable Qos defaultQos)873 public @NonNull Builder setDefaultQos(@Nullable Qos defaultQos) { 874 mDefaultQos = defaultQos; 875 return this; 876 } 877 878 /** 879 * Set the dedicated bearer QOS sessions for this data connection. 880 * 881 * @param qosBearerSessions Dedicated bearer QOS (Quality Of Service) sessions received 882 * from network. 883 * 884 * @return The same instance of the builder. 885 * 886 * @hide 887 */ setQosBearerSessions( @onNull List<QosBearerSession> qosBearerSessions)888 public @NonNull Builder setQosBearerSessions( 889 @NonNull List<QosBearerSession> qosBearerSessions) { 890 Objects.requireNonNull(qosBearerSessions); 891 mQosBearerSessions = qosBearerSessions; 892 return this; 893 } 894 895 /** 896 * The Slice used for this data connection. 897 * <p/> 898 * If a handover occurs from EPDG to 5G, 899 * this is the {@link NetworkSliceInfo} used in {@link DataService#setupDataCall}. 900 * 901 * @param sliceInfo the slice info for the data call 902 * 903 * @return The same instance of the builder. 904 */ setSliceInfo(@ullable NetworkSliceInfo sliceInfo)905 public @NonNull Builder setSliceInfo(@Nullable NetworkSliceInfo sliceInfo) { 906 mSliceInfo = sliceInfo; 907 return this; 908 } 909 910 /** 911 * The traffic descriptors for this data connection, as defined in 3GPP TS 24.526 912 * Section 5.2. They are used for URSP traffic matching as described in 3GPP TS 24.526 913 * Section 4.2.2. They includes an optional DNN, which, if present, must be used for traffic 914 * matching; it does not specify the end point to be used for the data call. The end point 915 * is specified by {@link DataProfile}, which must be used as the end point if one is not 916 * specified through URSP rules. 917 * 918 * @param trafficDescriptors the traffic descriptors for the data call. 919 * 920 * @return The same instance of the builder. 921 */ setTrafficDescriptors( @onNull List<TrafficDescriptor> trafficDescriptors)922 public @NonNull Builder setTrafficDescriptors( 923 @NonNull List<TrafficDescriptor> trafficDescriptors) { 924 Objects.requireNonNull(trafficDescriptors); 925 mTrafficDescriptors = trafficDescriptors; 926 return this; 927 } 928 929 /** 930 * Set the network validation status that corresponds to the state of the network validation 931 * request started by {@link DataService.DataServiceProvider#requestNetworkValidation} 932 * 933 * @param status The network validation status. 934 * @return The same instance of the builder. 935 */ setNetworkValidationStatus( @reciseDataConnectionState.NetworkValidationStatus int status)936 public @NonNull Builder setNetworkValidationStatus( 937 @PreciseDataConnectionState.NetworkValidationStatus int status) { 938 mNetworkValidationStatus = status; 939 return this; 940 } 941 942 /** 943 * Build the DataCallResponse. 944 * 945 * @return the DataCallResponse object. 946 */ build()947 public @NonNull DataCallResponse build() { 948 return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus, 949 mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses, 950 mPcscfAddresses, mMtu, mMtuV4, mMtuV6, mHandoverFailureMode, mPduSessionId, 951 mDefaultQos, mQosBearerSessions, mSliceInfo, mTrafficDescriptors, 952 mNetworkValidationStatus); 953 } 954 } 955 } 956