1 /*
2  * Copyright (C) 2016 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.os.Bundle;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * The characteristics of the Wi-Fi Aware implementation.
25  */
26 public final class Characteristics implements Parcelable {
27     /** @hide */
28     public static final String KEY_MAX_SERVICE_NAME_LENGTH = "key_max_service_name_length";
29     /** @hide */
30     public static final String KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH =
31             "key_max_service_specific_info_length";
32     /** @hide */
33     public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length";
34 
35     private Bundle mCharacteristics = new Bundle();
36 
37     /** @hide : should not be created by apps */
Characteristics(Bundle characteristics)38     public Characteristics(Bundle characteristics) {
39         mCharacteristics = characteristics;
40     }
41 
42     /**
43      * Returns the maximum string length that can be used to specify a Aware service name. Restricts
44      * the parameters of the {@link PublishConfig.Builder#setServiceName(String)} and
45      * {@link SubscribeConfig.Builder#setServiceName(String)}.
46      *
47      * @return A positive integer, maximum string length of Aware service name.
48      */
getMaxServiceNameLength()49     public int getMaxServiceNameLength() {
50         return mCharacteristics.getInt(KEY_MAX_SERVICE_NAME_LENGTH);
51     }
52 
53     /**
54      * Returns the maximum length of byte array that can be used to specify a Aware service specific
55      * information field: the arbitrary load used in discovery or the message length of Aware
56      * message exchange. Restricts the parameters of the
57      * {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])},
58      * {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}, and
59      * {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])}
60      * variants.
61      *
62      * @return A positive integer, maximum length of byte array for Aware messaging.
63      */
getMaxServiceSpecificInfoLength()64     public int getMaxServiceSpecificInfoLength() {
65         return mCharacteristics.getInt(KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH);
66     }
67 
68     /**
69      * Returns the maximum length of byte array that can be used to specify a Aware match filter.
70      * Restricts the parameters of the
71      * {@link PublishConfig.Builder#setMatchFilter(java.util.List)} and
72      * {@link SubscribeConfig.Builder#setMatchFilter(java.util.List)}.
73      *
74      * @return A positive integer, maximum legngth of byte array for Aware discovery match filter.
75      */
getMaxMatchFilterLength()76     public int getMaxMatchFilterLength() {
77         return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH);
78     }
79 
80     @Override
writeToParcel(Parcel dest, int flags)81     public void writeToParcel(Parcel dest, int flags) {
82         dest.writeBundle(mCharacteristics);
83     }
84 
85     @Override
describeContents()86     public int describeContents() {
87         return 0;
88     }
89 
90     public static final @android.annotation.NonNull Creator<Characteristics> CREATOR =
91             new Creator<Characteristics>() {
92                 @Override
93                 public Characteristics createFromParcel(Parcel in) {
94                     Characteristics c = new Characteristics(in.readBundle());
95                     return c;
96                 }
97 
98                 @Override
99                 public Characteristics[] newArray(int size) {
100                     return new Characteristics[size];
101                 }
102             };
103 }
104