• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.wifi.aware;
18 
19 import android.annotation.IntRange;
20 import android.annotation.NonNull;
21 import android.os.Handler;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 /**
26  * The resources of the Aware service.
27  */
28 public final class AwareResources implements Parcelable {
29     /**
30      * Number of the NDPs are available.
31      */
32     private int mNumOfAvailableNdps;
33 
34     /**
35      * Number of the publish sessions are available.
36      */
37     private int mNumOfAvailablePublishSessions;
38 
39     /**
40      * Number of the subscribe sessions are available.
41      */
42     private int mNumOfAvailableSubscribeSessions;
43 
44     /**
45      * Construct a {@link AwareResources} object, which represents the currently available Aware
46      * resources.
47      *
48      * @param availableDataPathsCount Number of available Aware data-path.
49      * @param availablePublishSessionsCount Number of available Aware publish sessions.
50      * @param availableSubscribeSessionsCount Number of available Aware subscribe sessions.
51      */
AwareResources(@ntRangefrom = 0) int availableDataPathsCount, @IntRange(from = 0) int availablePublishSessionsCount, @IntRange(from = 0) int availableSubscribeSessionsCount)52     public AwareResources(@IntRange(from = 0) int availableDataPathsCount,
53             @IntRange(from = 0) int availablePublishSessionsCount,
54             @IntRange(from = 0) int availableSubscribeSessionsCount) {
55         mNumOfAvailableNdps = availableDataPathsCount;
56         mNumOfAvailablePublishSessions = availablePublishSessionsCount;
57         mNumOfAvailableSubscribeSessions = availableSubscribeSessionsCount;
58     }
59 
60     /**
61      * Return the number of Aware data-paths (also known as NDPs - NAN Data Paths) which an app
62      * could create. Please refer to the {@link WifiAwareNetworkSpecifier} to create
63      * a Network Specifier and request a data-path.
64      * <p>
65      * Note that these resources aren't reserved - other apps could use them by the time you
66      * attempt to create a data-path.
67      * </p>
68      * @return A Non-negative integer, number of data-paths that could be created.
69      */
70     @IntRange(from = 0)
getAvailableDataPathsCount()71     public int getAvailableDataPathsCount() {
72         return mNumOfAvailableNdps;
73     }
74 
75     /**
76      * Return the number of Aware publish sessions which an app could create. Please refer to the
77      * {@link WifiAwareSession#publish(PublishConfig, DiscoverySessionCallback, Handler)}
78      * to create a publish session.
79      * <p>
80      * Note that these resources aren't reserved - other apps could use them by the time you
81      * attempt to create a publish session.
82      * </p>
83      * @return A Non-negative integer, number of publish sessions that could be created.
84      */
85     @IntRange(from = 0)
getAvailablePublishSessionsCount()86     public int getAvailablePublishSessionsCount() {
87         return mNumOfAvailablePublishSessions;
88     }
89 
90     /**
91      * Return the number of Aware subscribe sessions which an app could create. Please refer to the
92      * {@link WifiAwareSession#subscribe(SubscribeConfig, DiscoverySessionCallback, Handler)}
93      * to create a subscribe session.
94      * <p>
95      * Note that these resources aren't reserved - other apps could use them by the time you
96      * attempt to create a subscribe session.
97      * </p>
98      * @return A Non-negative integer, number of subscribe sessions that could be created.
99      */
100     @IntRange(from = 0)
getAvailableSubscribeSessionsCount()101     public int getAvailableSubscribeSessionsCount() {
102         return mNumOfAvailableSubscribeSessions;
103     }
104 
105     /**
106      * Set the number of the available NDPs.
107      * @hide
108      * @param numOfAvailableNdps Number of available NDPs.
109      */
setNumOfAvailableDataPaths(int numOfAvailableNdps)110     public void setNumOfAvailableDataPaths(int numOfAvailableNdps) {
111         mNumOfAvailableNdps = numOfAvailableNdps;
112     }
113 
114     /**
115      * Set the number of the available publish sessions.
116      * @hide
117      * @param numOfAvailablePublishSessions Number of available publish sessions.
118      */
setNumOfAvailablePublishSessions(int numOfAvailablePublishSessions)119     public void setNumOfAvailablePublishSessions(int numOfAvailablePublishSessions) {
120         mNumOfAvailablePublishSessions = numOfAvailablePublishSessions;
121     }
122 
123     /**
124      * Set the number of the available subscribe sessions.
125      * @hide
126      * @param numOfAvailableSubscribeSessions Number of available subscribe sessions.
127      */
setNumOfAvailableSubscribeSessions(int numOfAvailableSubscribeSessions)128     public void setNumOfAvailableSubscribeSessions(int numOfAvailableSubscribeSessions) {
129         mNumOfAvailableSubscribeSessions = numOfAvailableSubscribeSessions;
130     }
131 
132     @Override
describeContents()133     public int describeContents() {
134         return 0;
135     }
136 
137     @Override
writeToParcel(@onNull Parcel dest, int flags)138     public void writeToParcel(@NonNull Parcel dest, int flags) {
139         dest.writeInt(mNumOfAvailableNdps);
140         dest.writeInt(mNumOfAvailablePublishSessions);
141         dest.writeInt(mNumOfAvailableSubscribeSessions);
142     }
143 
144     public static final @android.annotation.NonNull Creator<AwareResources> CREATOR =
145             new Creator<AwareResources>() {
146                 @Override
147                 public AwareResources createFromParcel(Parcel in) {
148                     return new AwareResources(in.readInt(), in.readInt(), in.readInt());
149                 }
150 
151                 @Override
152                 public AwareResources[] newArray(int size) {
153                     return new AwareResources[size];
154                 }
155             };
156 }
157