• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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());
245         mDnsAddresses = new ArrayList<>();
246         source.readList(mDnsAddresses, InetAddress.class.getClassLoader());
247         mGatewayAddresses = new ArrayList<>();
248         source.readList(mGatewayAddresses, InetAddress.class.getClassLoader());
249         mPcscfAddresses = new ArrayList<>();
250         source.readList(mPcscfAddresses, InetAddress.class.getClassLoader());
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());
257         mQosBearerSessions = new ArrayList<>();
258         source.readList(mQosBearerSessions, QosBearerSession.class.getClassLoader());
259         mSliceInfo = source.readParcelable(NetworkSliceInfo.class.getClassLoader());
260         mTrafficDescriptors = new ArrayList<>();
261         source.readList(mTrafficDescriptors, TrafficDescriptor.class.getClassLoader());
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(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         return Objects.hash(mCause, mSuggestedRetryTime, mId, mLinkStatus, mProtocolType,
508                 mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses, mPcscfAddresses,
509                 mMtu, mMtuV4, mMtuV6, mHandoverFailureMode, mPduSessionId, mDefaultQos,
510                 mQosBearerSessions, mSliceInfo, mTrafficDescriptors);
511     }
512 
513     @Override
describeContents()514     public int describeContents() {
515         return 0;
516     }
517 
518     @Override
writeToParcel(Parcel dest, int flags)519     public void writeToParcel(Parcel dest, int flags) {
520         dest.writeInt(mCause);
521         dest.writeLong(mSuggestedRetryTime);
522         dest.writeInt(mId);
523         dest.writeInt(mLinkStatus);
524         dest.writeInt(mProtocolType);
525         dest.writeString(mInterfaceName);
526         dest.writeList(mAddresses);
527         dest.writeList(mDnsAddresses);
528         dest.writeList(mGatewayAddresses);
529         dest.writeList(mPcscfAddresses);
530         dest.writeInt(mMtu);
531         dest.writeInt(mMtuV4);
532         dest.writeInt(mMtuV6);
533         dest.writeInt(mHandoverFailureMode);
534         dest.writeInt(mPduSessionId);
535         if (mDefaultQos != null) {
536             if (mDefaultQos.getType() == Qos.QOS_TYPE_EPS) {
537                 dest.writeParcelable((EpsQos) mDefaultQos, flags);
538             } else {
539                 dest.writeParcelable((NrQos) mDefaultQos, flags);
540             }
541         } else {
542             dest.writeParcelable(null, flags);
543         }
544         dest.writeList(mQosBearerSessions);
545         dest.writeParcelable(mSliceInfo, flags);
546         dest.writeList(mTrafficDescriptors);
547     }
548 
549     public static final @android.annotation.NonNull Parcelable.Creator<DataCallResponse> CREATOR =
550             new Parcelable.Creator<DataCallResponse>() {
551                 @Override
552                 public DataCallResponse createFromParcel(Parcel source) {
553                     return new DataCallResponse(source);
554                 }
555 
556                 @Override
557                 public DataCallResponse[] newArray(int size) {
558                     return new DataCallResponse[size];
559                 }
560             };
561 
562     /**
563      * Convert handover failure mode to string.
564      *
565      * @param handoverFailureMode Handover failure mode
566      * @return Handover failure mode in string
567      *
568      * @hide
569      */
failureModeToString(@andoverFailureMode int handoverFailureMode)570     public static String failureModeToString(@HandoverFailureMode int handoverFailureMode) {
571         switch (handoverFailureMode) {
572             case HANDOVER_FAILURE_MODE_UNKNOWN: return "unknown";
573             case HANDOVER_FAILURE_MODE_LEGACY: return "legacy";
574             case HANDOVER_FAILURE_MODE_DO_FALLBACK: return "fallback";
575             case HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_HANDOVER: return "retry handover";
576             case HANDOVER_FAILURE_MODE_NO_FALLBACK_RETRY_SETUP_NORMAL: return "retry setup new one";
577             default: return Integer.toString(handoverFailureMode);
578         }
579     }
580 
581     /**
582      * Provides a convenient way to set the fields of a {@link DataCallResponse} when creating a new
583      * instance.
584      *
585      * <p>The example below shows how you might create a new {@code DataCallResponse}:
586      *
587      * <pre><code>
588      *
589      * DataCallResponse response = new DataCallResponse.Builder()
590      *     .setAddresses(Arrays.asList("192.168.1.2"))
591      *     .setProtocolType(ApnSetting.PROTOCOL_IPV4V6)
592      *     .build();
593      * </code></pre>
594      */
595     public static final class Builder {
596         private @DataFailureCause int mCause;
597 
598         private long mSuggestedRetryTime = RETRY_DURATION_UNDEFINED;
599 
600         private int mId;
601 
602         private @LinkStatus int mLinkStatus;
603 
604         private @ProtocolType int mProtocolType;
605 
606         private String mInterfaceName;
607 
608         private List<LinkAddress> mAddresses;
609 
610         private List<InetAddress> mDnsAddresses;
611 
612         private List<InetAddress> mGatewayAddresses;
613 
614         private List<InetAddress> mPcscfAddresses;
615 
616         private int mMtu;
617 
618         private int mMtuV4;
619 
620         private int mMtuV6;
621 
622         private @HandoverFailureMode int mHandoverFailureMode = HANDOVER_FAILURE_MODE_LEGACY;
623 
624         private int mPduSessionId = PDU_SESSION_ID_NOT_SET;
625 
626         private Qos mDefaultQos;
627 
628         private List<QosBearerSession> mQosBearerSessions = new ArrayList<>();
629 
630         private NetworkSliceInfo mSliceInfo;
631 
632         private List<TrafficDescriptor> mTrafficDescriptors = new ArrayList<>();
633 
634         /**
635          * Default constructor for Builder.
636          */
Builder()637         public Builder() {
638         }
639 
640         /**
641          * Set data call fail cause.
642          *
643          * @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error.
644          * @return The same instance of the builder.
645          */
setCause(@ataFailureCause int cause)646         public @NonNull Builder setCause(@DataFailureCause int cause) {
647             mCause = cause;
648             return this;
649         }
650 
651         /**
652          * Set the suggested data retry time.
653          *
654          * @param suggestedRetryTime The suggested data retry time in milliseconds.
655          * @return The same instance of the builder.
656          *
657          * @deprecated Use {@link #setRetryDurationMillis(long)} instead.
658          */
659         @Deprecated
setSuggestedRetryTime(int suggestedRetryTime)660         public @NonNull Builder setSuggestedRetryTime(int suggestedRetryTime) {
661             mSuggestedRetryTime = (long) suggestedRetryTime;
662             return this;
663         }
664 
665         /**
666          * Set the network suggested data retry duration.
667          *
668          * @param retryDurationMillis The suggested data retry duration in milliseconds.
669          * @return The same instance of the builder.
670          */
setRetryDurationMillis(long retryDurationMillis)671         public @NonNull Builder setRetryDurationMillis(long retryDurationMillis) {
672             mSuggestedRetryTime = retryDurationMillis;
673             return this;
674         }
675 
676         /**
677          * Set the unique id of the data connection.
678          *
679          * @param id The unique id of the data connection.
680          * @return The same instance of the builder.
681          */
setId(int id)682         public @NonNull Builder setId(int id) {
683             mId = id;
684             return this;
685         }
686 
687         /**
688          * Set the link status
689          *
690          * @param linkStatus The link status
691          * @return The same instance of the builder.
692          */
setLinkStatus(@inkStatus int linkStatus)693         public @NonNull Builder setLinkStatus(@LinkStatus int linkStatus) {
694             mLinkStatus = linkStatus;
695             return this;
696         }
697 
698         /**
699          * Set the connection protocol type.
700          *
701          * @param protocolType The connection protocol type.
702          * @return The same instance of the builder.
703          */
setProtocolType(@rotocolType int protocolType)704         public @NonNull Builder setProtocolType(@ProtocolType int protocolType) {
705             mProtocolType = protocolType;
706             return this;
707         }
708 
709         /**
710          * Set the network interface name.
711          *
712          * @param interfaceName The network interface name (e.g. "rmnet_data1").
713          * @return The same instance of the builder.
714          */
setInterfaceName(@onNull String interfaceName)715         public @NonNull Builder setInterfaceName(@NonNull String interfaceName) {
716             mInterfaceName = interfaceName;
717             return this;
718         }
719 
720         /**
721          * Set the addresses of this data connection.
722          *
723          * @param addresses The list of address of the data connection.
724          * @return The same instance of the builder.
725          */
setAddresses(@onNull List<LinkAddress> addresses)726         public @NonNull Builder setAddresses(@NonNull List<LinkAddress> addresses) {
727             mAddresses = addresses;
728             return this;
729         }
730 
731         /**
732          * Set the DNS addresses of this data connection
733          *
734          * @param dnsAddresses The list of DNS address of the data connection.
735          * @return The same instance of the builder.
736          */
setDnsAddresses(@onNull List<InetAddress> dnsAddresses)737         public @NonNull Builder setDnsAddresses(@NonNull List<InetAddress> dnsAddresses) {
738             mDnsAddresses = dnsAddresses;
739             return this;
740         }
741 
742         /**
743          * Set the gateway addresses of this data connection
744          *
745          * @param gatewayAddresses The list of gateway address of the data connection.
746          * @return The same instance of the builder.
747          */
setGatewayAddresses(@onNull List<InetAddress> gatewayAddresses)748         public @NonNull Builder setGatewayAddresses(@NonNull List<InetAddress> gatewayAddresses) {
749             mGatewayAddresses = gatewayAddresses;
750             return this;
751         }
752 
753         /**
754          * Set the Proxy Call State Control Function address via PCO(Protocol Configuration
755          * Option) for IMS client.
756          *
757          * @param pcscfAddresses The list of pcscf address of the data connection.
758          * @return The same instance of the builder.
759          */
setPcscfAddresses(@onNull List<InetAddress> pcscfAddresses)760         public @NonNull Builder setPcscfAddresses(@NonNull List<InetAddress> pcscfAddresses) {
761             mPcscfAddresses = pcscfAddresses;
762             return this;
763         }
764 
765         /**
766          * Set maximum transmission unit of the data connection.
767          *
768          * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or
769          * negative values means network has either not sent a value or sent an invalid value.
770          *
771          * @return The same instance of the builder.
772          * @deprecated For IRadio 1.5 and up, use {@link #setMtuV4} or {@link #setMtuV6} instead.
773          */
setMtu(int mtu)774         public @NonNull Builder setMtu(int mtu) {
775             mMtu = mtu;
776             return this;
777         }
778 
779         /**
780          * Set maximum transmission unit of the data connection, for IPv4.
781          *
782          * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or
783          * negative values means network has either not sent a value or sent an invalid value.
784          *
785          * @return The same instance of the builder.
786          */
setMtuV4(int mtu)787         public @NonNull Builder setMtuV4(int mtu) {
788             mMtuV4 = mtu;
789             return this;
790         }
791 
792         /**
793          * Set maximum transmission unit of the data connection, for IPv6.
794          *
795          * @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or
796          * negative values means network has either not sent a value or sent an invalid value.
797          *
798          * @return The same instance of the builder.
799          */
setMtuV6(int mtu)800         public @NonNull Builder setMtuV6(int mtu) {
801             mMtuV6 = mtu;
802             return this;
803         }
804 
805         /**
806          * Set data handover failure mode for the data call response.
807          *
808          * @param failureMode Handover failure mode.
809          * @return The same instance of the builder.
810          */
setHandoverFailureMode(@andoverFailureMode int failureMode)811         public @NonNull Builder setHandoverFailureMode(@HandoverFailureMode int failureMode) {
812             mHandoverFailureMode = failureMode;
813             return this;
814         }
815 
816         /**
817          * Set pdu session id.
818          * <p/>
819          * The id must be between 1 and 15 when linked to a pdu session.  If no pdu session
820          * exists for the current data call, the id must be set to {@link PDU_SESSION_ID_NOT_SET}.
821          *
822          * @param pduSessionId Pdu Session Id of the data call.
823          * @return The same instance of the builder.
824          */
setPduSessionId( @ntRangefrom = PDU_SESSION_ID_NOT_SET, to = 15) int pduSessionId)825         public @NonNull Builder setPduSessionId(
826                 @IntRange(from = PDU_SESSION_ID_NOT_SET, to = 15) int pduSessionId) {
827             Preconditions.checkArgument(pduSessionId >= PDU_SESSION_ID_NOT_SET,
828                     "pduSessionId must be greater than or equal to" + PDU_SESSION_ID_NOT_SET);
829             Preconditions.checkArgument(pduSessionId <= 15,
830                     "pduSessionId must be less than or equal to 15.");
831             mPduSessionId = pduSessionId;
832             return this;
833         }
834 
835         /**
836          * Set the default QOS for this data connection.
837          *
838          * @param defaultQos QOS (Quality Of Service) received from network.
839          *
840          * @return The same instance of the builder.
841          *
842          * @hide
843          */
setDefaultQos(@ullable Qos defaultQos)844         public @NonNull Builder setDefaultQos(@Nullable Qos defaultQos) {
845             mDefaultQos = defaultQos;
846             return this;
847         }
848 
849         /**
850          * Set the dedicated bearer QOS sessions for this data connection.
851          *
852          * @param qosBearerSessions Dedicated bearer QOS (Quality Of Service) sessions received
853          * from network.
854          *
855          * @return The same instance of the builder.
856          *
857          * @hide
858          */
setQosBearerSessions( @onNull List<QosBearerSession> qosBearerSessions)859         public @NonNull Builder setQosBearerSessions(
860                 @NonNull List<QosBearerSession> qosBearerSessions) {
861             mQosBearerSessions = qosBearerSessions;
862             return this;
863         }
864 
865         /**
866          * The Slice used for this data connection.
867          * <p/>
868          * If a handover occurs from EPDG to 5G,
869          * this is the {@link NetworkSliceInfo} used in {@link DataService#setupDataCall}.
870          *
871          * @param sliceInfo the slice info for the data call
872          *
873          * @return The same instance of the builder.
874          */
setSliceInfo(@ullable NetworkSliceInfo sliceInfo)875         public @NonNull Builder setSliceInfo(@Nullable NetworkSliceInfo sliceInfo) {
876             mSliceInfo = sliceInfo;
877             return this;
878         }
879 
880         /**
881          * The traffic descriptors for this data connection, as defined in 3GPP TS 24.526
882          * Section 5.2. They are used for URSP traffic matching as described in 3GPP TS 24.526
883          * Section 4.2.2. They includes an optional DNN, which, if present, must be used for traffic
884          * matching; it does not specify the end point to be used for the data call. The end point
885          * is specified by {@link DataProfile}, which must be used as the end point if one is not
886          * specified through URSP rules.
887          *
888          * @param trafficDescriptors the traffic descriptors for the data call.
889          *
890          * @return The same instance of the builder.
891          */
setTrafficDescriptors( @onNull List<TrafficDescriptor> trafficDescriptors)892         public @NonNull Builder setTrafficDescriptors(
893                 @NonNull List<TrafficDescriptor> trafficDescriptors) {
894             mTrafficDescriptors = trafficDescriptors;
895             return this;
896         }
897 
898         /**
899          * Build the DataCallResponse.
900          *
901          * @return the DataCallResponse object.
902          */
build()903         public @NonNull DataCallResponse build() {
904             return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus,
905                     mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses,
906                     mPcscfAddresses, mMtu, mMtuV4, mMtuV6, mHandoverFailureMode, mPduSessionId,
907                     mDefaultQos, mQosBearerSessions, mSliceInfo, mTrafficDescriptors);
908         }
909     }
910 }
911