• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.usd;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.SystemApi;
21 import android.net.wifi.flags.Flags;
22 import android.os.Bundle;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import androidx.annotation.NonNull;
27 
28 import java.util.List;
29 import java.util.concurrent.Executor;
30 import java.util.function.Consumer;
31 
32 /**
33  * The characteristics of the USD implementation.
34  *
35  * @hide
36  */
37 @SystemApi
38 @FlaggedApi(Flags.FLAG_USD)
39 public final class Characteristics implements Parcelable {
40     private final Bundle mCharacteristics;
41     /** @hide */
42     public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length";
43     /** @hide */
44     public static final String KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH =
45             "key_max_service_specific_info_length";
46     /** @hide */
47     public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length";
48     /** @hide */
49     public static final String KEY_MAX_NUM_PUBLISH_SESSIONS = "key_max_num_publish_session";
50     /** @hide */
51     public static final String KEY_MAX_NUM_SUBSCRIBE_SESSIONS = "key_max_num_subscribe_session";
52 
53 
54     /** @hide : should not be created by apps */
Characteristics(Bundle characteristics)55     public Characteristics(Bundle characteristics) {
56         mCharacteristics = characteristics;
57     }
58 
Characteristics(@onNull Parcel in)59     private Characteristics(@NonNull Parcel in) {
60         mCharacteristics = in.readBundle(getClass().getClassLoader());
61     }
62 
63     @NonNull
64     public static final Creator<Characteristics> CREATOR = new Creator<Characteristics>() {
65         @Override
66         public Characteristics createFromParcel(Parcel in) {
67             return new Characteristics(in);
68         }
69 
70         @Override
71         public Characteristics[] newArray(int size) {
72             return new Characteristics[size];
73         }
74     };
75 
76     /**
77      * Returns the maximum string length that can be used to specify a USD service name.
78      *
79      * @return A positive integer, maximum string length of USD service name.
80      */
getMaxServiceNameLength()81     public int getMaxServiceNameLength() {
82         return mCharacteristics.getInt(KEY_MAX_SERVICE_NAME_LENGTH);
83     }
84 
85     /**
86      * Returns the maximum length of byte array that can be used to specify a service specific
87      * information field: the arbitrary load used in discovery or the message length of USD
88      * message exchange. Restricts the parameters of the
89      * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])},
90      * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])},
91      * {@link PublishSession#sendMessage(int, byte[], Executor, Consumer)}  and
92      * {@link SubscribeSession#sendMessage(int, byte[], Executor, Consumer)}
93      * variants.
94      *
95      * @return A positive integer, maximum length of byte array for USD messaging.
96      */
getMaxServiceSpecificInfoLength()97     public int getMaxServiceSpecificInfoLength() {
98         return mCharacteristics.getInt(KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH);
99     }
100 
101     /**
102      * Returns the maximum length of byte array that can be used to specify a USD match filter.
103      * Restricts the parameters of the
104      * {@link PublishConfig.Builder#setTxMatchFilter(List)},
105      * {@link PublishConfig.Builder#setRxMatchFilter(List)},
106      * {@link SubscribeConfig.Builder#setTxMatchFilter(List)} and
107      * {@link SubscribeConfig.Builder#setRxMatchFilter(List)}
108      *
109      * @return A positive integer, maximum length of byte array for USD discovery match filter.
110      */
getMaxMatchFilterLength()111     public int getMaxMatchFilterLength() {
112         return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH);
113     }
114 
115     /**
116      * Returns the maximum number of publish sessions supported by USD
117      *
118      * @return A positive integer
119      */
getMaxNumberOfPublishSessions()120     public int getMaxNumberOfPublishSessions() {
121         return mCharacteristics.getInt(KEY_MAX_NUM_PUBLISH_SESSIONS);
122     }
123 
124     /**
125      * Returns the maximum number of subscribe sessions supported by USD
126      *
127      * @return A positive integer
128      */
getMaxNumberOfSubscribeSessions()129     public int getMaxNumberOfSubscribeSessions() {
130         return mCharacteristics.getInt(KEY_MAX_NUM_SUBSCRIBE_SESSIONS);
131     }
132 
133     @Override
describeContents()134     public int describeContents() {
135         return 0;
136     }
137 
138     /**
139      * Flatten this object in to a Parcel.
140      *
141      * @param dest  The Parcel in which the object should be written.
142      * @param flags Additional flags about how the object should be written.
143      *              May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
144      */
145     @Override
writeToParcel(@onNull Parcel dest, int flags)146     public void writeToParcel(@NonNull Parcel dest, int flags) {
147         dest.writeBundle(mCharacteristics);
148     }
149 }
150