• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.net.MacAddress;
24 import android.os.Build;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 
28 import androidx.annotation.RequiresApi;
29 
30 import com.android.internal.util.Preconditions;
31 import com.android.modules.utils.build.SdkLevel;
32 import com.android.wifi.flags.Flags;
33 
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Objects;
38 
39 /**
40  * A class representing information about a specific SoftAP instance. A SoftAP instance may be a
41  * single band AP or a bridged AP (across multiple bands). To get the state of the AP interface
42  * itself, use {@link android.net.wifi.WifiManager.SoftApCallback#onStateChanged(SoftApState)}.
43  * {@see WifiManager}
44  *
45  * @hide
46  */
47 @SystemApi
48 public final class SoftApInfo implements Parcelable {
49 
50     /**
51      * AP Channel bandwidth is automatically selected by the chip.
52      *
53      * @see #getBandwidth()
54      */
55     public static final int CHANNEL_WIDTH_AUTO = -1;
56 
57    /**
58      * AP Channel bandwidth is invalid.
59      *
60      * @see #getBandwidth()
61      */
62     public static final int CHANNEL_WIDTH_INVALID = 0;
63 
64     /**
65      * AP Channel bandwidth is 20 MHZ but no HT.
66      *
67      * @see #getBandwidth()
68      */
69     public static final int CHANNEL_WIDTH_20MHZ_NOHT = 1;
70 
71     /**
72      * AP Channel bandwidth is 20 MHZ.
73      *
74      * @see #getBandwidth()
75      */
76     public static final int CHANNEL_WIDTH_20MHZ = 2;
77 
78     /**
79      * AP Channel bandwidth is 40 MHZ.
80      *
81      * @see #getBandwidth()
82      */
83     public static final int CHANNEL_WIDTH_40MHZ = 3;
84 
85     /**
86      * AP Channel bandwidth is 80 MHZ.
87      *
88      * @see #getBandwidth()
89      */
90     public static final int CHANNEL_WIDTH_80MHZ = 4;
91 
92     /**
93      * AP Channel bandwidth is 160 MHZ, but 80MHZ + 80MHZ.
94      *
95      * @see #getBandwidth()
96      */
97     public static final int CHANNEL_WIDTH_80MHZ_PLUS_MHZ = 5;
98 
99     /**
100      * AP Channel bandwidth is 160 MHZ.
101      *
102      * @see #getBandwidth()
103      */
104     public static final int CHANNEL_WIDTH_160MHZ = 6;
105 
106     /**
107      * AP Channel bandwidth is 2160 MHZ.
108      *
109      * @see #getBandwidth()
110      */
111     public static final int CHANNEL_WIDTH_2160MHZ = 7;
112 
113     /**
114      * AP Channel bandwidth is 4320 MHZ.
115      *
116      * @see #getBandwidth()
117      */
118     public static final int CHANNEL_WIDTH_4320MHZ = 8;
119 
120     /**
121      * AP Channel bandwidth is 6480 MHZ.
122      *
123      * @see #getBandwidth()
124      */
125     public static final int CHANNEL_WIDTH_6480MHZ = 9;
126 
127     /**
128      * AP Channel bandwidth is 8640 MHZ.
129      *
130      * @see #getBandwidth()
131      */
132     public static final int CHANNEL_WIDTH_8640MHZ = 10;
133 
134     /**
135      * AP Channel bandwidth is 320 MHZ.
136      *
137      * @see #getBandwidth()
138      */
139     public static final int CHANNEL_WIDTH_320MHZ = 11;
140 
141 
142     /** The frequency which AP resides on.  */
143     private int mFrequency = 0;
144 
145     @WifiAnnotations.Bandwidth
146     private int mBandwidth = CHANNEL_WIDTH_INVALID;
147 
148     /** The MAC Address which AP resides on. */
149     @Nullable
150     private MacAddress mBssid;
151 
152     /** The identifier of the AP instance which AP resides on with current info. */
153     @Nullable
154     private String mApInstanceIdentifier;
155 
156     /**
157      * The operational mode of the AP.
158      */
159     private @WifiAnnotations.WifiStandard int mWifiStandard = ScanResult.WIFI_STANDARD_UNKNOWN;
160 
161     /**
162      * The current shutdown timeout millis which applied on Soft AP.
163      */
164     private long mIdleShutdownTimeoutMillis;
165 
166     /** List of {@link OuiKeyedData} containing vendor-specific configuration data. */
167     private List<OuiKeyedData> mVendorData = Collections.emptyList();
168 
169     /** The multiple link device (MLD) MAC Address which Wi-Fi 7 AP resides on. */
170     @Nullable
171     private MacAddress mMldAddress;
172 
173     /**
174      * Get the frequency which AP resides on.
175      */
getFrequency()176     public int getFrequency() {
177         return mFrequency;
178     }
179 
180     /**
181      * Set the frequency which AP resides on.
182      * @hide
183      */
setFrequency(int freq)184     public void setFrequency(int freq) {
185         mFrequency = freq;
186     }
187 
188     /**
189      * Get AP Channel bandwidth.
190      *
191      * @return One of {@link #CHANNEL_WIDTH_20MHZ}, {@link #CHANNEL_WIDTH_40MHZ},
192      * {@link #CHANNEL_WIDTH_80MHZ}, {@link #CHANNEL_WIDTH_160MHZ},
193      * {@link #CHANNEL_WIDTH_80MHZ_PLUS_MHZ}, {@link #CHANNEL_WIDTH_320MHZ},
194      * {@link #CHANNEL_WIDTH_2160MHZ}, {@link #CHANNEL_WIDTH_4320MHZ},
195      * {@link #CHANNEL_WIDTH_6480MHZ}, {@link #CHANNEL_WIDTH_8640MHZ},
196      * {@link #CHANNEL_WIDTH_AUTO} ,or {@link #CHANNEL_WIDTH_INVALID}.
197      */
198     @WifiAnnotations.Bandwidth
getBandwidth()199     public int getBandwidth() {
200         return mBandwidth;
201     }
202 
203     /**
204      * Set AP Channel bandwidth.
205      * @hide
206      */
setBandwidth(@ifiAnnotations.Bandwidth int bandwidth)207     public void setBandwidth(@WifiAnnotations.Bandwidth int bandwidth) {
208         mBandwidth = bandwidth;
209     }
210 
211     /**
212      * Get the MAC address (BSSID) of the AP. Null when AP disabled.
213      */
214     @RequiresApi(Build.VERSION_CODES.S)
215     @Nullable
getBssid()216     public MacAddress getBssid() {
217         if (!SdkLevel.isAtLeastS()) {
218             throw new UnsupportedOperationException();
219         }
220         return getBssidInternal();
221     }
222 
223     /**
224      * @hide
225      */
226     @Nullable
getBssidInternal()227     public MacAddress getBssidInternal() {
228         return mBssid;
229     }
230 
231     /**
232       * Set the MAC address which AP resides on.
233       * <p>
234       * <li>If not set, defaults to null.</li>
235       * @param bssid BSSID, The caller is responsible for avoiding collisions.
236       * @throws IllegalArgumentException when the given BSSID is the all-zero or broadcast MAC
237       *                                  address.
238       *
239       * @hide
240       */
setBssid(@ullable MacAddress bssid)241     public void setBssid(@Nullable MacAddress bssid) {
242         if (bssid != null) {
243             Preconditions.checkArgument(!bssid.equals(WifiManager.ALL_ZEROS_MAC_ADDRESS));
244             Preconditions.checkArgument(!bssid.equals(MacAddress.BROADCAST_ADDRESS));
245         }
246         mBssid = bssid;
247     }
248 
249     /**
250      * Set the operational mode of the AP.
251      *
252      * @param wifiStandard values from {@link ScanResult}'s {@code WIFI_STANDARD_}
253      * @hide
254      */
setWifiStandard(@ifiAnnotations.WifiStandard int wifiStandard)255     public void setWifiStandard(@WifiAnnotations.WifiStandard int wifiStandard) {
256         mWifiStandard = wifiStandard;
257     }
258 
259     /**
260      * Get the operational mode of the AP.
261      * @return valid values from {@link ScanResult}'s {@code WIFI_STANDARD_}
262      */
263     @RequiresApi(Build.VERSION_CODES.S)
getWifiStandard()264     public @WifiAnnotations.WifiStandard int getWifiStandard() {
265         if (!SdkLevel.isAtLeastS()) {
266             throw new UnsupportedOperationException();
267         }
268         return getWifiStandardInternal();
269     }
270 
271     /**
272      * @hide
273      */
getWifiStandardInternal()274     public @WifiAnnotations.WifiStandard int getWifiStandardInternal() {
275         return mWifiStandard;
276     }
277 
278     /**
279      * Set the AP instance identifier.
280      * @hide
281      */
setApInstanceIdentifier(@onNull String apInstanceIdentifier)282     public void setApInstanceIdentifier(@NonNull String apInstanceIdentifier) {
283         mApInstanceIdentifier = apInstanceIdentifier;
284     }
285 
286     /**
287      * Get the AP instance identifier.
288      *
289      * The AP instance identifier is a unique identity which can be used to
290      * associate the {@link SoftApInfo} to a specific {@link WifiClient}
291      * - see {@link WifiClient#getApInstanceIdentifier()}
292      *
293      * @hide
294      */
295     @Nullable
getApInstanceIdentifier()296     public String getApInstanceIdentifier() {
297         return mApInstanceIdentifier;
298     }
299 
300 
301     /**
302      * Set current shutdown timeout millis which applied on Soft AP.
303      * @hide
304      */
setAutoShutdownTimeoutMillis(long idleShutdownTimeoutMillis)305     public void setAutoShutdownTimeoutMillis(long idleShutdownTimeoutMillis) {
306         mIdleShutdownTimeoutMillis = idleShutdownTimeoutMillis;
307     }
308 
309     /**
310      * Get auto shutdown timeout in millis.
311      *
312      * The shutdown timeout value is configured by
313      * {@link SoftApConfiguration.Builder#setAutoShutdownEnabled(int)} or
314      * the default timeout setting defined in device overlays.
315      *
316      * A value of 0 means that auto shutdown is disabled.
317      * {@see SoftApConfiguration#isAutoShutdownEnabled()}
318      */
getAutoShutdownTimeoutMillis()319     public long getAutoShutdownTimeoutMillis() {
320         return mIdleShutdownTimeoutMillis;
321     }
322 
323     /**
324      * Set additional vendor-provided configuration data.
325      *
326      * @param vendorData List of {@link android.net.wifi.OuiKeyedData} containing the
327      *                   vendor-provided configuration data. Note that multiple elements with
328      *                   the same OUI are allowed.
329      * @hide
330      */
331     @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
332     @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
333     @SystemApi
setVendorData(@onNull List<OuiKeyedData> vendorData)334     public void setVendorData(@NonNull List<OuiKeyedData> vendorData) {
335         if (!SdkLevel.isAtLeastV()) {
336             throw new UnsupportedOperationException();
337         }
338         if (vendorData == null) {
339             throw new IllegalArgumentException("setVendorData received a null value");
340         }
341         mVendorData = new ArrayList<>(vendorData);
342     }
343 
344     /**
345      * Get the vendor-provided configuration data, if it exists.
346      *
347      * @return Vendor configuration data, or empty list if it does not exist.
348      * @hide
349      */
350     @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
351     @FlaggedApi(Flags.FLAG_ANDROID_V_WIFI_API)
352     @SystemApi
353     @NonNull
getVendorData()354     public List<OuiKeyedData> getVendorData() {
355         if (!SdkLevel.isAtLeastV()) {
356             throw new UnsupportedOperationException();
357         }
358         return mVendorData;
359     }
360 
361     /**
362      * Get the multiple link device MAC address which Wi-Fi AP resides on.
363      * Null when AP disabled or non Wi-Fi 7 AP.
364      */
365     @FlaggedApi(Flags.FLAG_MLO_SAP)
366     @Nullable
getMldAddress()367     public MacAddress getMldAddress() {
368         return mMldAddress;
369     }
370 
371     /**
372      * Set the multi-link address (MLA) of the multi-link device (MLD) on the Wi-Fi AP.
373      * <p>
374      * <li>If not set (non Wi-Fi 7 Soft AP), defaults to null.</li>
375      * @param mldAddress  multiple link device MAC address.
376      *
377      * @hide
378      */
setMldAddress(@ullable MacAddress mldAddress)379     public void setMldAddress(@Nullable MacAddress mldAddress) {
380         mMldAddress = mldAddress;
381     }
382 
383     /**
384      * @hide
385      */
SoftApInfo(@ullable SoftApInfo source)386     public SoftApInfo(@Nullable SoftApInfo source) {
387         if (source != null) {
388             mFrequency = source.mFrequency;
389             mBandwidth = source.mBandwidth;
390             mBssid = source.mBssid;
391             mWifiStandard = source.mWifiStandard;
392             mApInstanceIdentifier = source.mApInstanceIdentifier;
393             mIdleShutdownTimeoutMillis = source.mIdleShutdownTimeoutMillis;
394             mVendorData = new ArrayList<>(source.mVendorData);
395             mMldAddress = source.mMldAddress;
396         }
397     }
398 
399     /**
400      * @hide
401      */
SoftApInfo()402     public SoftApInfo() {
403     }
404 
405     @Override
406     /** Implement the Parcelable interface. */
describeContents()407     public int describeContents() {
408         return 0;
409     }
410 
411     @Override
412     /** Implement the Parcelable interface */
writeToParcel(@onNull Parcel dest, int flags)413     public void writeToParcel(@NonNull Parcel dest, int flags) {
414         dest.writeInt(mFrequency);
415         dest.writeInt(mBandwidth);
416         dest.writeParcelable(mBssid, flags);
417         dest.writeInt(mWifiStandard);
418         dest.writeString(mApInstanceIdentifier);
419         dest.writeLong(mIdleShutdownTimeoutMillis);
420         dest.writeList(mVendorData);
421         dest.writeParcelable(mMldAddress, flags);
422     }
423 
424     @NonNull
425     /** Implement the Parcelable interface */
426     public static final Creator<SoftApInfo> CREATOR = new Creator<SoftApInfo>() {
427         public SoftApInfo createFromParcel(Parcel in) {
428             SoftApInfo info = new SoftApInfo();
429             info.mFrequency = in.readInt();
430             info.mBandwidth = in.readInt();
431             info.mBssid = in.readParcelable(MacAddress.class.getClassLoader());
432             info.mWifiStandard = in.readInt();
433             info.mApInstanceIdentifier = in.readString();
434             info.mIdleShutdownTimeoutMillis = in.readLong();
435             info.mVendorData = ParcelUtil.readOuiKeyedDataList(in);
436             info.mMldAddress = in.readParcelable(MacAddress.class.getClassLoader());
437             return info;
438         }
439 
440         public SoftApInfo[] newArray(int size) {
441             return new SoftApInfo[size];
442         }
443     };
444 
445     @NonNull
446     @Override
toString()447     public String toString() {
448         StringBuilder sbuf = new StringBuilder();
449         sbuf.append("SoftApInfo{");
450         sbuf.append("bandwidth= ").append(mBandwidth);
451         sbuf.append(", frequency= ").append(mFrequency);
452         if (mBssid != null) sbuf.append(",bssid=").append(mBssid.toString());
453         sbuf.append(", wifiStandard= ").append(mWifiStandard);
454         sbuf.append(", mApInstanceIdentifier= ").append(mApInstanceIdentifier);
455         sbuf.append(", mIdleShutdownTimeoutMillis= ").append(mIdleShutdownTimeoutMillis);
456         sbuf.append(", mVendorData= ").append(mVendorData);
457         if (mMldAddress != null) sbuf.append(",mMldAddress=").append(mMldAddress.toString());
458         sbuf.append("}");
459         return sbuf.toString();
460     }
461 
462     @Override
equals(@ullable Object o)463     public boolean equals(@Nullable Object o) {
464         if (this == o) return true;
465         if (!(o instanceof SoftApInfo)) return false;
466         SoftApInfo softApInfo = (SoftApInfo) o;
467         return mFrequency == softApInfo.mFrequency
468                 && mBandwidth == softApInfo.mBandwidth
469                 && Objects.equals(mBssid, softApInfo.mBssid)
470                 && mWifiStandard == softApInfo.mWifiStandard
471                 && Objects.equals(mApInstanceIdentifier, softApInfo.mApInstanceIdentifier)
472                 && mIdleShutdownTimeoutMillis == softApInfo.mIdleShutdownTimeoutMillis
473                 && Objects.equals(mVendorData, softApInfo.mVendorData)
474                 && Objects.equals(mMldAddress, softApInfo.mMldAddress);
475     }
476 
477     @Override
hashCode()478     public int hashCode() {
479         return Objects.hash(mFrequency, mBandwidth, mBssid, mWifiStandard, mApInstanceIdentifier,
480                 mIdleShutdownTimeoutMillis, mVendorData, mMldAddress);
481     }
482 }
483