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