1 /*
2  * Copyright (C) 2019 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;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /**
28  * A class representing information about SoftAp.
29  * {@see WifiManager}
30  *
31  * @hide
32  */
33 @SystemApi
34 public final class SoftApInfo implements Parcelable {
35 
36     /**
37      * AP Channel bandwidth is invalid.
38      *
39      * @see #getBandwidth()
40      */
41     public static final int CHANNEL_WIDTH_INVALID = 0;
42 
43     /**
44      * AP Channel bandwidth is 20 MHZ but no HT.
45      *
46      * @see #getBandwidth()
47      */
48     public static final int CHANNEL_WIDTH_20MHZ_NOHT = 1;
49 
50     /**
51      * AP Channel bandwidth is 20 MHZ.
52      *
53      * @see #getBandwidth()
54      */
55     public static final int CHANNEL_WIDTH_20MHZ = 2;
56 
57     /**
58      * AP Channel bandwidth is 40 MHZ.
59      *
60      * @see #getBandwidth()
61      */
62     public static final int CHANNEL_WIDTH_40MHZ = 3;
63 
64     /**
65      * AP Channel bandwidth is 80 MHZ.
66      *
67      * @see #getBandwidth()
68      */
69     public static final int CHANNEL_WIDTH_80MHZ = 4;
70 
71     /**
72      * AP Channel bandwidth is 160 MHZ, but 80MHZ + 80MHZ.
73      *
74      * @see #getBandwidth()
75      */
76     public static final int CHANNEL_WIDTH_80MHZ_PLUS_MHZ = 5;
77 
78     /**
79      * AP Channel bandwidth is 160 MHZ.
80      *
81      * @see #getBandwidth()
82      */
83     public static final int CHANNEL_WIDTH_160MHZ = 6;
84 
85 
86 
87     /** The frequency which AP resides on.  */
88     private int mFrequency = 0;
89 
90     @WifiAnnotations.Bandwidth
91     private int mBandwidth = CHANNEL_WIDTH_INVALID;
92 
93     /**
94      * Get the frequency which AP resides on.
95      */
getFrequency()96     public int getFrequency() {
97         return mFrequency;
98     }
99 
100     /**
101      * Set the frequency which AP resides on.
102      * @hide
103      */
setFrequency(int freq)104     public void setFrequency(int freq) {
105         mFrequency = freq;
106     }
107 
108     /**
109      * Get AP Channel bandwidth.
110      *
111      * @return One of {@link #CHANNEL_WIDTH_20MHZ}, {@link #CHANNEL_WIDTH_40MHZ},
112      * {@link #CHANNEL_WIDTH_80MHZ}, {@link #CHANNEL_WIDTH_160MHZ},
113      * {@link #CHANNEL_WIDTH_80MHZ_PLUS_MHZ} or {@link #CHANNEL_WIDTH_INVALID}.
114      */
115     @WifiAnnotations.Bandwidth
getBandwidth()116     public int getBandwidth() {
117         return mBandwidth;
118     }
119 
120     /**
121      * Set AP Channel bandwidth.
122      * @hide
123      */
setBandwidth(@ifiAnnotations.Bandwidth int bandwidth)124     public void setBandwidth(@WifiAnnotations.Bandwidth int bandwidth) {
125         mBandwidth = bandwidth;
126     }
127 
128     /**
129      * @hide
130      */
SoftApInfo(@ullable SoftApInfo source)131     public SoftApInfo(@Nullable SoftApInfo source) {
132         if (source != null) {
133             mFrequency = source.mFrequency;
134             mBandwidth = source.mBandwidth;
135         }
136     }
137 
138     /**
139      * @hide
140      */
SoftApInfo()141     public SoftApInfo() {
142     }
143 
144     @Override
145     /** Implement the Parcelable interface. */
describeContents()146     public int describeContents() {
147         return 0;
148     }
149 
150     @Override
151     /** Implement the Parcelable interface */
writeToParcel(@onNull Parcel dest, int flags)152     public void writeToParcel(@NonNull Parcel dest, int flags) {
153         dest.writeInt(mFrequency);
154         dest.writeInt(mBandwidth);
155     }
156 
157     @NonNull
158     /** Implement the Parcelable interface */
159     public static final Creator<SoftApInfo> CREATOR = new Creator<SoftApInfo>() {
160         public SoftApInfo createFromParcel(Parcel in) {
161             SoftApInfo info = new SoftApInfo();
162             info.mFrequency = in.readInt();
163             info.mBandwidth = in.readInt();
164             return info;
165         }
166 
167         public SoftApInfo[] newArray(int size) {
168             return new SoftApInfo[size];
169         }
170     };
171 
172     @NonNull
173     @Override
toString()174     public String toString() {
175         return "SoftApInfo{"
176                 + "bandwidth= " + mBandwidth
177                 + ",frequency= " + mFrequency
178                 + '}';
179     }
180 
181     @Override
equals(@onNull Object o)182     public boolean equals(@NonNull Object o) {
183         if (this == o) return true;
184         if (!(o instanceof SoftApInfo)) return false;
185         SoftApInfo softApInfo = (SoftApInfo) o;
186         return mFrequency == softApInfo.mFrequency
187                 && mBandwidth == softApInfo.mBandwidth;
188     }
189 
190     @Override
hashCode()191     public int hashCode() {
192         return Objects.hash(mFrequency, mBandwidth);
193     }
194 }
195