blob: 4f3bb77c587791fe4210b74de69d9fd50a57909e [file] [log] [blame]
Daniel Brightf9e945b2020-06-15 16:10:01 -07001/*
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
17package android.net;
18
19import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.SystemApi;
22import android.os.Parcel;
23import 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
32public 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 private final int mSessionId;
40
41 private final int mSessionType;
42
43 /**
44 * Gets the unique id of the session that is used to differentiate sessions across different
45 * types.
46 * <p/>
47 * Note: Different qos sessions can be provided by different actors.
48 *
49 * @return the unique id
50 */
51 public long getUniqueId() {
52 return (long) mSessionType << 32 | mSessionId;
53 }
54
55 /**
56 * Gets the session id that is unique within that type.
57 * <p/>
58 * Note: The session id is set by the actor providing the qos. It can be either manufactured by
59 * the actor, but also may have a particular meaning within that type. For example, using the
60 * bearer id as the session id for {@link android.telephony.data.EpsBearerQosSessionAttributes}
61 * is a straight forward way to keep the sessions unique from one another within that type.
62 *
63 * @return the id of the session
64 */
65 public int getSessionId() {
66 return mSessionId;
67 }
68
69 /**
70 * Gets the type of session.
71 */
72 @QosSessionType
73 public int getSessionType() {
74 return mSessionType;
75 }
76
77 /**
78 * Creates a {@link QosSession}.
79 *
80 * @param sessionId uniquely identifies the session across all sessions of the same type
81 * @param sessionType the type of session
82 */
83 public QosSession(final int sessionId, @QosSessionType final int sessionType) {
84 //Ensures the session id is unique across types of sessions
85 mSessionId = sessionId;
86 mSessionType = sessionType;
87 }
88
89
90 @Override
91 public String toString() {
92 return "QosSession{"
93 + "mSessionId=" + mSessionId
94 + ", mSessionType=" + mSessionType
95 + '}';
96 }
97
98 /**
99 * Annotations for types of qos sessions.
100 */
101 @IntDef(value = {
102 TYPE_EPS_BEARER,
103 })
104 @interface QosSessionType {}
105
106 private QosSession(final Parcel in) {
107 mSessionId = in.readInt();
108 mSessionType = in.readInt();
109 }
110
111 @NonNull
112 public static final Creator<QosSession> CREATOR = new Creator<QosSession>() {
113 @NonNull
114 @Override
115 public QosSession createFromParcel(@NonNull final Parcel in) {
116 return new QosSession(in);
117 }
118
119 @NonNull
120 @Override
121 public QosSession[] newArray(final int size) {
122 return new QosSession[size];
123 }
124 };
125
126 @Override
127 public int describeContents() {
128 return 0;
129 }
130
131 @Override
132 public void writeToParcel(@NonNull final Parcel dest, final int flags) {
133 dest.writeInt(mSessionId);
134 dest.writeInt(mSessionType);
135 }
136}