1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 /**
26  * Provides identifying information of a QoS session.  Sent to an application through
27  * {@link QosCallback}.
28  *
29  * @hide
30  */
31 @SystemApi
32 public final class QosSession implements Parcelable {
33 
34     /**
35      * The {@link QosSession} is a LTE EPS Session.
36      */
37     public static final int TYPE_EPS_BEARER = 1;
38 
39     /**
40      * The {@link QosSession} is a NR Session.
41      */
42     public static final int TYPE_NR_BEARER = 2;
43 
44     private final int mSessionId;
45 
46     private final int mSessionType;
47 
48     /**
49      * Gets the unique id of the session that is used to differentiate sessions across different
50      * types.
51      * <p/>
52      * Note: Different qos sessions can be provided by different actors.
53      *
54      * @return the unique id
55      */
getUniqueId()56     public long getUniqueId() {
57         return (long) mSessionType << 32 | mSessionId;
58     }
59 
60     /**
61      * Gets the session id that is unique within that type.
62      * <p/>
63      * Note: The session id is set by the actor providing the qos.  It can be either manufactured by
64      * the actor, but also may have a particular meaning within that type.  For example, using the
65      * bearer id as the session id for {@link android.telephony.data.EpsBearerQosSessionAttributes}
66      * is a straight forward way to keep the sessions unique from one another within that type.
67      *
68      * @return the id of the session
69      */
getSessionId()70     public int getSessionId() {
71         return mSessionId;
72     }
73 
74     /**
75      * Gets the type of session.
76      */
77     @QosSessionType
getSessionType()78     public int getSessionType() {
79         return mSessionType;
80     }
81 
82     /**
83      * Creates a {@link QosSession}.
84      *
85      * @param sessionId uniquely identifies the session across all sessions of the same type
86      * @param sessionType the type of session
87      */
QosSession(final int sessionId, @QosSessionType final int sessionType)88     public QosSession(final int sessionId, @QosSessionType final int sessionType) {
89         //Ensures the session id is unique across types of sessions
90         mSessionId = sessionId;
91         mSessionType = sessionType;
92     }
93 
94 
95     @Override
toString()96     public String toString() {
97         return "QosSession{"
98                 + "mSessionId=" + mSessionId
99                 + ", mSessionType=" + mSessionType
100                 + '}';
101     }
102 
103     /**
104      * Annotations for types of qos sessions.
105      */
106     @IntDef(value = {
107             TYPE_EPS_BEARER,
108             TYPE_NR_BEARER,
109     })
110     @interface QosSessionType {}
111 
QosSession(final Parcel in)112     private QosSession(final Parcel in) {
113         mSessionId = in.readInt();
114         mSessionType = in.readInt();
115     }
116 
117     @NonNull
118     public static final Creator<QosSession> CREATOR = new Creator<QosSession>() {
119         @NonNull
120         @Override
121         public QosSession createFromParcel(@NonNull final Parcel in) {
122             return new QosSession(in);
123         }
124 
125         @NonNull
126         @Override
127         public QosSession[] newArray(final int size) {
128             return new QosSession[size];
129         }
130     };
131 
132     @Override
describeContents()133     public int describeContents() {
134         return 0;
135     }
136 
137     @Override
writeToParcel(@onNull final Parcel dest, final int flags)138     public void writeToParcel(@NonNull final Parcel dest, final int flags) {
139         dest.writeInt(mSessionId);
140         dest.writeInt(mSessionType);
141     }
142 }
143