blob: 25f3965f1e06f2a24d055bcaf53348e256ece009 [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
Jayachandran C6cdedae2021-03-15 15:58:11 -070039 /**
40 * The {@link QosSession} is a NR Session.
41 */
42 public static final int TYPE_NR_BEARER = 2;
43
Daniel Brightf9e945b2020-06-15 16:10:01 -070044 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 */
56 public long getUniqueId() {
57 return (long) mSessionType << 32 | mSessionId;
58 }
59
60 /**
sewookseo5f703fe2022-03-10 07:24:03 +000061 * Gets the {@link QosSession} identifier which is set by the actor providing the QoS.
Daniel Brightf9e945b2020-06-15 16:10:01 -070062 * <p/>
sewookseo5f703fe2022-03-10 07:24:03 +000063 * Note: It can be either manufactured by the actor, but also may have a particular meaning
64 * within that type. For example, using the bearer id as the session id for
65 * {@link android.telephony.data.EpsBearerQosSessionAttributes} is a straight forward way to
66 * keep the sessions unique from one another within that type.
Daniel Brightf9e945b2020-06-15 16:10:01 -070067 *
68 * @return the id of the session
69 */
70 public int getSessionId() {
71 return mSessionId;
72 }
73
74 /**
75 * Gets the type of session.
76 */
77 @QosSessionType
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 */
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
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,
Jayachandran C6cdedae2021-03-15 15:58:11 -0700108 TYPE_NR_BEARER,
Daniel Brightf9e945b2020-06-15 16:10:01 -0700109 })
110 @interface QosSessionType {}
111
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
133 public int describeContents() {
134 return 0;
135 }
136
137 @Override
138 public void writeToParcel(@NonNull final Parcel dest, final int flags) {
139 dest.writeInt(mSessionId);
140 dest.writeInt(mSessionType);
141 }
142}