blob: d1edae998ba8d0ea54773c90edfe78f3fcf6896c [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
Anton Hanssonf5fa3c62023-11-10 13:27:50 +000025import java.lang.annotation.Retention;
26import java.lang.annotation.RetentionPolicy;
27
Daniel Brightf9e945b2020-06-15 16:10:01 -070028/**
29 * Provides identifying information of a QoS session. Sent to an application through
30 * {@link QosCallback}.
31 *
32 * @hide
33 */
34@SystemApi
35public final class QosSession implements Parcelable {
36
37 /**
38 * The {@link QosSession} is a LTE EPS Session.
39 */
40 public static final int TYPE_EPS_BEARER = 1;
41
Jayachandran C6cdedae2021-03-15 15:58:11 -070042 /**
43 * The {@link QosSession} is a NR Session.
44 */
45 public static final int TYPE_NR_BEARER = 2;
46
Daniel Brightf9e945b2020-06-15 16:10:01 -070047 private final int mSessionId;
48
49 private final int mSessionType;
50
51 /**
52 * Gets the unique id of the session that is used to differentiate sessions across different
53 * types.
54 * <p/>
55 * Note: Different qos sessions can be provided by different actors.
56 *
57 * @return the unique id
58 */
59 public long getUniqueId() {
60 return (long) mSessionType << 32 | mSessionId;
61 }
62
63 /**
sewookseo5f703fe2022-03-10 07:24:03 +000064 * Gets the {@link QosSession} identifier which is set by the actor providing the QoS.
Daniel Brightf9e945b2020-06-15 16:10:01 -070065 * <p/>
sewookseo5f703fe2022-03-10 07:24:03 +000066 * Note: It can be either manufactured by the actor, but also may have a particular meaning
67 * within that type. For example, using the bearer id as the session id for
68 * {@link android.telephony.data.EpsBearerQosSessionAttributes} is a straight forward way to
69 * keep the sessions unique from one another within that type.
Daniel Brightf9e945b2020-06-15 16:10:01 -070070 *
71 * @return the id of the session
72 */
73 public int getSessionId() {
74 return mSessionId;
75 }
76
77 /**
78 * Gets the type of session.
79 */
80 @QosSessionType
81 public int getSessionType() {
82 return mSessionType;
83 }
84
85 /**
86 * Creates a {@link QosSession}.
87 *
88 * @param sessionId uniquely identifies the session across all sessions of the same type
89 * @param sessionType the type of session
90 */
91 public QosSession(final int sessionId, @QosSessionType final int sessionType) {
92 //Ensures the session id is unique across types of sessions
93 mSessionId = sessionId;
94 mSessionType = sessionType;
95 }
96
97
98 @Override
99 public String toString() {
100 return "QosSession{"
101 + "mSessionId=" + mSessionId
102 + ", mSessionType=" + mSessionType
103 + '}';
104 }
105
106 /**
107 * Annotations for types of qos sessions.
108 */
109 @IntDef(value = {
110 TYPE_EPS_BEARER,
Jayachandran C6cdedae2021-03-15 15:58:11 -0700111 TYPE_NR_BEARER,
Daniel Brightf9e945b2020-06-15 16:10:01 -0700112 })
Anton Hanssonf5fa3c62023-11-10 13:27:50 +0000113 @Retention(RetentionPolicy.SOURCE)
Daniel Brightf9e945b2020-06-15 16:10:01 -0700114 @interface QosSessionType {}
115
116 private QosSession(final Parcel in) {
117 mSessionId = in.readInt();
118 mSessionType = in.readInt();
119 }
120
121 @NonNull
122 public static final Creator<QosSession> CREATOR = new Creator<QosSession>() {
123 @NonNull
124 @Override
125 public QosSession createFromParcel(@NonNull final Parcel in) {
126 return new QosSession(in);
127 }
128
129 @NonNull
130 @Override
131 public QosSession[] newArray(final int size) {
132 return new QosSession[size];
133 }
134 };
135
136 @Override
137 public int describeContents() {
138 return 0;
139 }
140
141 @Override
142 public void writeToParcel(@NonNull final Parcel dest, final int flags) {
143 dest.writeInt(mSessionId);
144 dest.writeInt(mSessionType);
145 }
146}