1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.wifi;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.NetworkInfo.DetailedState;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.android.net.module.util.Inet4AddressUtils;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.EnumMap;
import java.util.Locale;
/**
* Describes the state of any Wi-Fi connection that is active or
* is in the process of being set up.
*/
public class WifiInfo implements Parcelable {
private static final String TAG = "WifiInfo";
/**
* This is the map described in the Javadoc comment above. The positions
* of the elements of the array must correspond to the ordinal values
* of <code>DetailedState</code>.
*/
private static final EnumMap<SupplicantState, DetailedState> stateMap =
new EnumMap<SupplicantState, DetailedState>(SupplicantState.class);
/**
* Default MAC address reported to a client that does not have the
* android.permission.LOCAL_MAC_ADDRESS permission.
*
* @hide
*/
@SystemApi
public static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";
static {
stateMap.put(SupplicantState.DISCONNECTED, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.INTERFACE_DISABLED, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.INACTIVE, DetailedState.IDLE);
stateMap.put(SupplicantState.SCANNING, DetailedState.SCANNING);
stateMap.put(SupplicantState.AUTHENTICATING, DetailedState.CONNECTING);
stateMap.put(SupplicantState.ASSOCIATING, DetailedState.CONNECTING);
stateMap.put(SupplicantState.ASSOCIATED, DetailedState.CONNECTING);
stateMap.put(SupplicantState.FOUR_WAY_HANDSHAKE, DetailedState.AUTHENTICATING);
stateMap.put(SupplicantState.GROUP_HANDSHAKE, DetailedState.AUTHENTICATING);
stateMap.put(SupplicantState.COMPLETED, DetailedState.OBTAINING_IPADDR);
stateMap.put(SupplicantState.DORMANT, DetailedState.DISCONNECTED);
stateMap.put(SupplicantState.UNINITIALIZED, DetailedState.IDLE);
stateMap.put(SupplicantState.INVALID, DetailedState.FAILED);
}
private SupplicantState mSupplicantState;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private String mBSSID;
@UnsupportedAppUsage
private WifiSsid mWifiSsid;
private int mNetworkId;
/**
* Used to indicate that the RSSI is invalid, for example if no RSSI measurements are available
* yet.
* @hide
*/
@SystemApi
public static final int INVALID_RSSI = -127;
/** @hide **/
public static final int MIN_RSSI = -126;
/** @hide **/
public static final int MAX_RSSI = 200;
/**
* Received Signal Strength Indicator
*/
private int mRssi;
/**
* Wi-Fi standard for the connection
*/
private @WifiAnnotations.WifiStandard int mWifiStandard;
/**
* The unit in which links speeds are expressed.
*/
public static final String LINK_SPEED_UNITS = "Mbps";
private int mLinkSpeed;
/**
* Constant for unknown link speed.
*/
public static final int LINK_SPEED_UNKNOWN = -1;
/**
* Tx(transmit) Link speed in Mbps
*/
private int mTxLinkSpeed;
/**
* Max supported Tx(transmit) link speed in Mbps
*/
private int mMaxSupportedTxLinkSpeed;
/**
* Rx(receive) Link speed in Mbps
*/
private int mRxLinkSpeed;
/**
* Max supported Rx(receive) link speed in Mbps
*/
private int mMaxSupportedRxLinkSpeed;
/**
* Frequency in MHz
*/
public static final String FREQUENCY_UNITS = "MHz";
private int mFrequency;
@UnsupportedAppUsage
private InetAddress mIpAddress;
@UnsupportedAppUsage
private String mMacAddress = DEFAULT_MAC_ADDRESS;
/**
* Whether the network is ephemeral or not.
*/
private boolean mEphemeral;
/**
* Whether the network is trusted or not.
*/
private boolean mTrusted;
/**
* Whether the network is oem paid or not.
*/
private boolean mOemPaid;
/**
* OSU (Online Sign Up) AP for Passpoint R2.
*/
private boolean mOsuAp;
/**
* Fully qualified domain name of a Passpoint configuration
*/
private String mFqdn;
/**
* Name of Passpoint credential provider
*/
private String mProviderFriendlyName;
/**
* If connected to a network suggestion or specifier, store the package name of the app,
* else null.
*/
private String mRequestingPackageName;
/**
* Running total count of lost (not ACKed) transmitted unicast data packets.
* @hide
*/
public long txBad;
/**
* Running total count of transmitted unicast data retry packets.
* @hide
*/
public long txRetries;
/**
* Running total count of successfully transmitted (ACKed) unicast data packets.
* @hide
*/
public long txSuccess;
/**
* Running total count of received unicast data packets.
* @hide
*/
public long rxSuccess;
private double mLostTxPacketsPerSecond;
/**
* Average rate of lost transmitted packets, in units of packets per second.
* @hide
*/
@SystemApi
public double getLostTxPacketsPerSecond() {
return mLostTxPacketsPerSecond;
}
/** @hide */
public void setLostTxPacketsPerSecond(double lostTxPacketsPerSecond) {
mLostTxPacketsPerSecond = lostTxPacketsPerSecond;
}
private double mTxRetriedTxPacketsPerSecond;
/**
* Average rate of transmitted retry packets, in units of packets per second.
* @hide
*/
@SystemApi
public double getRetriedTxPacketsPerSecond() {
return mTxRetriedTxPacketsPerSecond;
}
/** @hide */
public void setRetriedTxPacketsRate(double txRetriedTxPacketsPerSecond) {
mTxRetriedTxPacketsPerSecond = txRetriedTxPacketsPerSecond;
}
private double mSuccessfulTxPacketsPerSecond;
/**
* Average rate of successfully transmitted unicast packets, in units of packets per second.
* @hide
*/
@SystemApi
public double getSuccessfulTxPacketsPerSecond() {
return mSuccessfulTxPacketsPerSecond;
}
/** @hide */
public void setSuccessfulTxPacketsPerSecond(double successfulTxPacketsPerSecond) {
mSuccessfulTxPacketsPerSecond = successfulTxPacketsPerSecond;
}
private double mSuccessfulRxPacketsPerSecond;
/**
* Average rate of received unicast data packets, in units of packets per second.
* @hide
*/
@SystemApi
public double getSuccessfulRxPacketsPerSecond() {
return mSuccessfulRxPacketsPerSecond;
}
/** @hide */
public void setSuccessfulRxPacketsPerSecond(double successfulRxPacketsPerSecond) {
mSuccessfulRxPacketsPerSecond = successfulRxPacketsPerSecond;
}
/** @hide */
@UnsupportedAppUsage
public int score;
/**
* The current Wifi score.
* NOTE: this value should only be used for debugging purposes. Do not rely on this value for
* any computations. The meaning of this value can and will change at any time without warning.
* @hide
*/
@SystemApi
public int getScore() {
return score;
}
/** @hide */
public void setScore(int score) {
this.score = score;
}
/**
* Flag indicating that AP has hinted that upstream connection is metered,
* and sensitive to heavy data transfers.
*/
private boolean mMeteredHint;
/**
* Passpoint unique key
*/
private String mPasspointUniqueId;
private boolean mVhtMax8SpatialStreamsSupport;
private boolean mHe8ssCapableAp;
/** @hide */
@UnsupportedAppUsage
public WifiInfo() {
mWifiSsid = null;
mBSSID = null;
mNetworkId = -1;
mSupplicantState = SupplicantState.UNINITIALIZED;
mRssi = INVALID_RSSI;
mLinkSpeed = LINK_SPEED_UNKNOWN;
mFrequency = -1;
}
/** @hide */
public void reset() {
setInetAddress(null);
setBSSID(null);
setSSID(null);
setNetworkId(-1);
setRssi(INVALID_RSSI);
setLinkSpeed(LINK_SPEED_UNKNOWN);
setTxLinkSpeedMbps(LINK_SPEED_UNKNOWN);
setRxLinkSpeedMbps(LINK_SPEED_UNKNOWN);
setMaxSupportedTxLinkSpeedMbps(LINK_SPEED_UNKNOWN);
setMaxSupportedRxLinkSpeedMbps(LINK_SPEED_UNKNOWN);
setFrequency(-1);
setMeteredHint(false);
setEphemeral(false);
setOsuAp(false);
setRequestingPackageName(null);
setFQDN(null);
setProviderFriendlyName(null);
setPasspointUniqueId(null);
setHe8ssCapableAp(false);
setVhtMax8SpatialStreamsSupport(false);
txBad = 0;
txSuccess = 0;
rxSuccess = 0;
txRetries = 0;
mLostTxPacketsPerSecond = 0;
mSuccessfulTxPacketsPerSecond = 0;
mSuccessfulRxPacketsPerSecond = 0;
mTxRetriedTxPacketsPerSecond = 0;
score = 0;
}
/**
* Copy constructor
* @hide
*/
public WifiInfo(WifiInfo source) {
if (source != null) {
mSupplicantState = source.mSupplicantState;
mBSSID = source.mBSSID;
mWifiSsid = source.mWifiSsid;
mNetworkId = source.mNetworkId;
mRssi = source.mRssi;
mLinkSpeed = source.mLinkSpeed;
mTxLinkSpeed = source.mTxLinkSpeed;
mRxLinkSpeed = source.mRxLinkSpeed;
mFrequency = source.mFrequency;
mIpAddress = source.mIpAddress;
mMacAddress = source.mMacAddress;
mMeteredHint = source.mMeteredHint;
mEphemeral = source.mEphemeral;
mTrusted = source.mTrusted;
mTrusted = source.mOemPaid;
mRequestingPackageName =
source.mRequestingPackageName;
mOsuAp = source.mOsuAp;
mFqdn = source.mFqdn;
mProviderFriendlyName = source.mProviderFriendlyName;
mVhtMax8SpatialStreamsSupport = source.mVhtMax8SpatialStreamsSupport;
mHe8ssCapableAp = source.mHe8ssCapableAp;
txBad = source.txBad;
txRetries = source.txRetries;
txSuccess = source.txSuccess;
rxSuccess = source.rxSuccess;
mLostTxPacketsPerSecond = source.mLostTxPacketsPerSecond;
mTxRetriedTxPacketsPerSecond = source.mTxRetriedTxPacketsPerSecond;
mSuccessfulTxPacketsPerSecond = source.mSuccessfulTxPacketsPerSecond;
mSuccessfulRxPacketsPerSecond = source.mSuccessfulRxPacketsPerSecond;
score = source.score;
mWifiStandard = source.mWifiStandard;
mMaxSupportedTxLinkSpeed = source.mMaxSupportedTxLinkSpeed;
mMaxSupportedRxLinkSpeed = source.mMaxSupportedRxLinkSpeed;
mPasspointUniqueId = source.mPasspointUniqueId;
}
}
/** Builder for WifiInfo */
public static final class Builder {
private final WifiInfo mWifiInfo = new WifiInfo();
/**
* Set the SSID, in the form of a raw byte array.
* @see WifiInfo#getSSID()
*/
@NonNull
public Builder setSsid(@NonNull byte[] ssid) {
mWifiInfo.setSSID(WifiSsid.createFromByteArray(ssid));
return this;
}
/**
* Set the BSSID.
* @see WifiInfo#getBSSID()
*/
@NonNull
public Builder setBssid(@NonNull String bssid) {
mWifiInfo.setBSSID(bssid);
return this;
}
/**
* Set the RSSI, in dBm.
* @see WifiInfo#getRssi()
*/
@NonNull
public Builder setRssi(int rssi) {
mWifiInfo.setRssi(rssi);
return this;
}
/**
* Set the network ID.
* @see WifiInfo#getNetworkId()
*/
@NonNull
public Builder setNetworkId(int networkId) {
mWifiInfo.setNetworkId(networkId);
return this;
}
/**
* Build a WifiInfo object.
*/
@NonNull
public WifiInfo build() {
return new WifiInfo(mWifiInfo);
}
}
/** @hide */
public void setSSID(WifiSsid wifiSsid) {
mWifiSsid = wifiSsid;
}
/**
* Returns the service set identifier (SSID) of the current 802.11 network.
* <p>
* If the SSID can be decoded as UTF-8, it will be returned surrounded by double
* quotation marks. Otherwise, it is returned as a string of hex digits.
* The SSID may be {@link WifiManager#UNKNOWN_SSID}, if there is no network currently connected
* or if the caller has insufficient permissions to access the SSID.
* </p>
* <p>
* Prior to {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}, this method
* always returned the SSID with no quotes around it.
* </p>
*
* @return the SSID.
*/
public String getSSID() {
if (mWifiSsid != null) {
String unicode = mWifiSsid.toString();
if (!TextUtils.isEmpty(unicode)) {
return "\"" + unicode + "\"";
} else {
String hex = mWifiSsid.getHexString();
return (hex != null) ? hex : WifiManager.UNKNOWN_SSID;
}
}
return WifiManager.UNKNOWN_SSID;
}
/** @hide */
@UnsupportedAppUsage
public WifiSsid getWifiSsid() {
return mWifiSsid;
}
/** @hide */
@UnsupportedAppUsage
public void setBSSID(String BSSID) {
mBSSID = BSSID;
}
/**
* Return the basic service set identifier (BSSID) of the current access point.
* <p>
* The BSSID may be
* <lt>{@code null}, if there is no network currently connected.</lt>
* <lt>{@code "02:00:00:00:00:00"}, if the caller has insufficient permissions to access the
* BSSID.<lt>
* </p>
*
* @return the BSSID, in the form of a six-byte MAC address: {@code XX:XX:XX:XX:XX:XX}
*/
public String getBSSID() {
return mBSSID;
}
/**
* Returns the received signal strength indicator of the current 802.11
* network, in dBm.
*
* <p>Use {@link android.net.wifi.WifiManager#calculateSignalLevel} to convert this number into
* an absolute signal level which can be displayed to a user.
*
* @return the RSSI.
*/
public int getRssi() {
return mRssi;
}
/** @hide */
@UnsupportedAppUsage
public void setRssi(int rssi) {
if (rssi < INVALID_RSSI)
rssi = INVALID_RSSI;
if (rssi > MAX_RSSI)
rssi = MAX_RSSI;
mRssi = rssi;
}
/**
* Sets the Wi-Fi standard
* @hide
*/
public void setWifiStandard(@WifiAnnotations.WifiStandard int wifiStandard) {
mWifiStandard = wifiStandard;
}
/**
* Get connection Wi-Fi standard
* @return the connection Wi-Fi standard
*/
public @WifiAnnotations.WifiStandard int getWifiStandard() {
return mWifiStandard;
}
/**
* Returns the current link speed in {@link #LINK_SPEED_UNITS}.
* @return the link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is unknown.
* @see #LINK_SPEED_UNITS
* @see #LINK_SPEED_UNKNOWN
*/
public int getLinkSpeed() {
return mLinkSpeed;
}
/** @hide */
@UnsupportedAppUsage
public void setLinkSpeed(int linkSpeed) {
mLinkSpeed = linkSpeed;
}
/**
* Returns the current transmit link speed in Mbps.
* @return the Tx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is unknown.
* @see #LINK_SPEED_UNKNOWN
*/
@IntRange(from = -1)
public int getTxLinkSpeedMbps() {
return mTxLinkSpeed;
}
/**
* Returns the maximum supported transmit link speed in Mbps
* @return the max supported tx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is
* unknown. @see #LINK_SPEED_UNKNOWN
*/
public int getMaxSupportedTxLinkSpeedMbps() {
return mMaxSupportedTxLinkSpeed;
}
/**
* Update the last transmitted packet bit rate in Mbps.
* @hide
*/
public void setTxLinkSpeedMbps(int txLinkSpeed) {
mTxLinkSpeed = txLinkSpeed;
}
/**
* Set the maximum supported transmit link speed in Mbps
* @hide
*/
public void setMaxSupportedTxLinkSpeedMbps(int maxSupportedTxLinkSpeed) {
mMaxSupportedTxLinkSpeed = maxSupportedTxLinkSpeed;
}
/**
* Returns the current receive link speed in Mbps.
* @return the Rx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is unknown.
* @see #LINK_SPEED_UNKNOWN
*/
@IntRange(from = -1)
public int getRxLinkSpeedMbps() {
return mRxLinkSpeed;
}
/**
* Returns the maximum supported receive link speed in Mbps
* @return the max supported Rx link speed or {@link #LINK_SPEED_UNKNOWN} if link speed is
* unknown. @see #LINK_SPEED_UNKNOWN
*/
public int getMaxSupportedRxLinkSpeedMbps() {
return mMaxSupportedRxLinkSpeed;
}
/**
* Update the last received packet bit rate in Mbps.
* @hide
*/
public void setRxLinkSpeedMbps(int rxLinkSpeed) {
mRxLinkSpeed = rxLinkSpeed;
}
/**
* Set the maximum supported receive link speed in Mbps
* @hide
*/
public void setMaxSupportedRxLinkSpeedMbps(int maxSupportedRxLinkSpeed) {
mMaxSupportedRxLinkSpeed = maxSupportedRxLinkSpeed;
}
/**
* Returns the current frequency in {@link #FREQUENCY_UNITS}.
* @return the frequency.
* @see #FREQUENCY_UNITS
*/
public int getFrequency() {
return mFrequency;
}
/** @hide */
public void setFrequency(int frequency) {
this.mFrequency = frequency;
}
/**
* @hide
*/
public boolean is24GHz() {
return ScanResult.is24GHz(mFrequency);
}
/**
* @hide
*/
@UnsupportedAppUsage
public boolean is5GHz() {
return ScanResult.is5GHz(mFrequency);
}
/**
* @hide
*/
public boolean is6GHz() {
return ScanResult.is6GHz(mFrequency);
}
/**
* Record the MAC address of the WLAN interface
* @param macAddress the MAC address in {@code XX:XX:XX:XX:XX:XX} form
* @hide
*/
@UnsupportedAppUsage
public void setMacAddress(String macAddress) {
this.mMacAddress = macAddress;
}
public String getMacAddress() {
return mMacAddress;
}
/**
* @return true if {@link #getMacAddress()} has a real MAC address.
*
* @hide
*/
public boolean hasRealMacAddress() {
return mMacAddress != null && !DEFAULT_MAC_ADDRESS.equals(mMacAddress);
}
/**
* Indicates if we've dynamically detected this active network connection as
* being metered.
*
* @see WifiConfiguration#isMetered(WifiConfiguration, WifiInfo)
* @hide
*/
public void setMeteredHint(boolean meteredHint) {
mMeteredHint = meteredHint;
}
/** {@hide} */
@UnsupportedAppUsage
public boolean getMeteredHint() {
return mMeteredHint;
}
/** {@hide} */
public void setEphemeral(boolean ephemeral) {
mEphemeral = ephemeral;
}
/**
* Returns true if the current Wifi network is ephemeral, false otherwise.
* An ephemeral network is a network that is temporary and not persisted in the system.
* Ephemeral networks cannot be forgotten, only disabled with
* {@link WifiManager#disableEphemeralNetwork(String)}.
*
* @hide
*/
@SystemApi
public boolean isEphemeral() {
return mEphemeral;
}
/** {@hide} */
public void setTrusted(boolean trusted) {
mTrusted = trusted;
}
/** {@hide} */
public boolean isTrusted() {
return mTrusted;
}
/** {@hide} */
public void setOemPaid(boolean oemPaid) {
mOemPaid = oemPaid;
}
/** {@hide} */
public boolean isOemPaid() {
return mOemPaid;
}
/** {@hide} */
public void setOsuAp(boolean osuAp) {
mOsuAp = osuAp;
}
/** {@hide} */
@SystemApi
public boolean isOsuAp() {
return mOsuAp;
}
/** {@hide} */
@SystemApi
public boolean isPasspointAp() {
return mFqdn != null && mProviderFriendlyName != null;
}
/** {@hide} */
public void setFQDN(@Nullable String fqdn) {
mFqdn = fqdn;
}
/**
* Returns the Fully Qualified Domain Name of the network if it is a Passpoint network.
* <p>
* The FQDN may be
* <lt>{@code null} if no network currently connected, currently connected network is not
* passpoint network or the caller has insufficient permissions to access the FQDN.</lt>
* </p>
*/
public @Nullable String getPasspointFqdn() {
return mFqdn;
}
/** {@hide} */
public void setProviderFriendlyName(@Nullable String providerFriendlyName) {
mProviderFriendlyName = providerFriendlyName;
}
/**
* Returns the Provider Friendly Name of the network if it is a Passpoint network.
* <p>
* The Provider Friendly Name may be
* <lt>{@code null} if no network currently connected, currently connected network is not
* passpoint network or the caller has insufficient permissions to access the Provider Friendly
* Name. </lt>
* </p>
*/
public @Nullable String getPasspointProviderFriendlyName() {
return mProviderFriendlyName;
}
/** {@hide} */
public void setRequestingPackageName(@Nullable String packageName) {
mRequestingPackageName = packageName;
}
/**
* If this network was created in response to an app request (e.g. through Network Suggestion
* or Network Specifier), return the package name of the app that made the request.
* Null otherwise.
* @hide
*/
@SystemApi
public @Nullable String getRequestingPackageName() {
return mRequestingPackageName;
}
/** @hide */
@UnsupportedAppUsage
public void setNetworkId(int id) {
mNetworkId = id;
}
/**
* Each configured network has a unique small integer ID, used to identify
* the network. This method returns the ID for the currently connected network.
* <p>
* The networkId may be {@code -1} if there is no currently connected network or if the caller
* has insufficient permissions to access the network ID.
* </p>
*
* @return the network ID.
*/
public int getNetworkId() {
return mNetworkId;
}
/**
* Return the detailed state of the supplicant's negotiation with an
* access point, in the form of a {@link SupplicantState SupplicantState} object.
* @return the current {@link SupplicantState SupplicantState}
*/
public SupplicantState getSupplicantState() {
return mSupplicantState;
}
/** @hide */
@UnsupportedAppUsage
public void setSupplicantState(SupplicantState state) {
mSupplicantState = state;
}
/** @hide */
public void setInetAddress(InetAddress address) {
mIpAddress = address;
}
public int getIpAddress() {
int result = 0;
if (mIpAddress instanceof Inet4Address) {
result = Inet4AddressUtils.inet4AddressToIntHTL((Inet4Address) mIpAddress);
}
return result;
}
/**
* @return {@code true} if this network does not broadcast its SSID, so an
* SSID-specific probe request must be used for scans.
*/
public boolean getHiddenSSID() {
if (mWifiSsid == null) return false;
return mWifiSsid.isHidden();
}
/**
* Map a supplicant state into a fine-grained network connectivity state.
* @param suppState the supplicant state
* @return the corresponding {@link DetailedState}
*/
public static DetailedState getDetailedStateOf(SupplicantState suppState) {
return stateMap.get(suppState);
}
/**
* Set the <code>SupplicantState</code> from the string name
* of the state.
* @param stateName the name of the state, as a <code>String</code> returned
* in an event sent by {@code wpa_supplicant}.
*/
@UnsupportedAppUsage
void setSupplicantState(String stateName) {
mSupplicantState = valueOf(stateName);
}
static SupplicantState valueOf(String stateName) {
if ("4WAY_HANDSHAKE".equalsIgnoreCase(stateName))
return SupplicantState.FOUR_WAY_HANDSHAKE;
else {
try {
return SupplicantState.valueOf(stateName.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
return SupplicantState.INVALID;
}
}
}
/** @hide */
public void setVhtMax8SpatialStreamsSupport(boolean vhtMax8SpatialStreamsSupport) {
mVhtMax8SpatialStreamsSupport = vhtMax8SpatialStreamsSupport;
}
/** @hide */
public boolean isVhtMax8SpatialStreamsSupported() {
return mVhtMax8SpatialStreamsSupport;
}
/** @hide */
public void setHe8ssCapableAp(boolean he8ssCapableAp) {
mHe8ssCapableAp = he8ssCapableAp;
}
/** @hide */
public boolean isHe8ssCapableAp() {
return mHe8ssCapableAp;
}
/**
* Remove double quotes (") surrounding a SSID string, if present. Otherwise, return the
* string unmodified. Return null if the input string was null.
* @hide
*/
@Nullable
@SystemApi
public static String sanitizeSsid(@Nullable String string) {
return removeDoubleQuotes(string);
}
/** @hide */
@UnsupportedAppUsage
@Nullable
public static String removeDoubleQuotes(@Nullable String string) {
if (string == null) return null;
final int length = string.length();
if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) {
return string.substring(1, length - 1);
}
return string;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
String none = "<none>";
sb.append("SSID: ").append(mWifiSsid == null ? WifiManager.UNKNOWN_SSID : mWifiSsid)
.append(", BSSID: ").append(mBSSID == null ? none : mBSSID)
.append(", MAC: ").append(mMacAddress == null ? none : mMacAddress)
.append(", Supplicant state: ")
.append(mSupplicantState == null ? none : mSupplicantState)
.append(", HE Eight Max VHT Spatial Streams Supported AP: ").append(mHe8ssCapableAp)
.append(", Eight Max VHT Spatial streams support: ").append(mVhtMax8SpatialStreamsSupport)
.append(", Wi-Fi standard: ").append(mWifiStandard)
.append(", RSSI: ").append(mRssi)
.append(", Link speed: ").append(mLinkSpeed).append(LINK_SPEED_UNITS)
.append(", Tx Link speed: ").append(mTxLinkSpeed).append(LINK_SPEED_UNITS)
.append(", Max Supported Tx Link speed: ")
.append(mMaxSupportedTxLinkSpeed).append(LINK_SPEED_UNITS)
.append(", Rx Link speed: ").append(mRxLinkSpeed).append(LINK_SPEED_UNITS)
.append(", Max Supported Rx Link speed: ")
.append(mMaxSupportedRxLinkSpeed).append(LINK_SPEED_UNITS)
.append(", Frequency: ").append(mFrequency).append(FREQUENCY_UNITS)
.append(", Net ID: ").append(mNetworkId)
.append(", Metered hint: ").append(mMeteredHint)
.append(", score: ").append(Integer.toString(score));
return sb.toString();
}
/** Implement the Parcelable interface {@hide} */
public int describeContents() {
return 0;
}
/** Implement the Parcelable interface {@hide} */
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mNetworkId);
dest.writeInt(mRssi);
dest.writeInt(mLinkSpeed);
dest.writeInt(mTxLinkSpeed);
dest.writeInt(mRxLinkSpeed);
dest.writeInt(mFrequency);
if (mIpAddress != null) {
dest.writeByte((byte)1);
dest.writeByteArray(mIpAddress.getAddress());
} else {
dest.writeByte((byte)0);
}
if (mWifiSsid != null) {
dest.writeInt(1);
mWifiSsid.writeToParcel(dest, flags);
} else {
dest.writeInt(0);
}
dest.writeString(mBSSID);
dest.writeString(mMacAddress);
dest.writeInt(mMeteredHint ? 1 : 0);
dest.writeInt(mEphemeral ? 1 : 0);
dest.writeInt(mTrusted ? 1 : 0);
dest.writeInt(mOemPaid ? 1 : 0);
dest.writeInt(score);
dest.writeLong(txSuccess);
dest.writeDouble(mSuccessfulTxPacketsPerSecond);
dest.writeLong(txRetries);
dest.writeDouble(mTxRetriedTxPacketsPerSecond);
dest.writeLong(txBad);
dest.writeDouble(mLostTxPacketsPerSecond);
dest.writeLong(rxSuccess);
dest.writeDouble(mSuccessfulRxPacketsPerSecond);
mSupplicantState.writeToParcel(dest, flags);
dest.writeInt(mOsuAp ? 1 : 0);
dest.writeString(mRequestingPackageName);
dest.writeString(mFqdn);
dest.writeString(mProviderFriendlyName);
dest.writeInt(mVhtMax8SpatialStreamsSupport ? 1 : 0);
dest.writeInt(mHe8ssCapableAp ? 1 : 0);
dest.writeInt(mWifiStandard);
dest.writeInt(mMaxSupportedTxLinkSpeed);
dest.writeInt(mMaxSupportedRxLinkSpeed);
dest.writeString(mPasspointUniqueId);
}
/** Implement the Parcelable interface {@hide} */
@UnsupportedAppUsage
public static final @android.annotation.NonNull Creator<WifiInfo> CREATOR =
new Creator<WifiInfo>() {
public WifiInfo createFromParcel(Parcel in) {
WifiInfo info = new WifiInfo();
info.setNetworkId(in.readInt());
info.setRssi(in.readInt());
info.setLinkSpeed(in.readInt());
info.setTxLinkSpeedMbps(in.readInt());
info.setRxLinkSpeedMbps(in.readInt());
info.setFrequency(in.readInt());
if (in.readByte() == 1) {
try {
info.setInetAddress(InetAddress.getByAddress(in.createByteArray()));
} catch (UnknownHostException e) {}
}
if (in.readInt() == 1) {
info.mWifiSsid = WifiSsid.CREATOR.createFromParcel(in);
}
info.mBSSID = in.readString();
info.mMacAddress = in.readString();
info.mMeteredHint = in.readInt() != 0;
info.mEphemeral = in.readInt() != 0;
info.mTrusted = in.readInt() != 0;
info.mOemPaid = in.readInt() != 0;
info.score = in.readInt();
info.txSuccess = in.readLong();
info.mSuccessfulTxPacketsPerSecond = in.readDouble();
info.txRetries = in.readLong();
info.mTxRetriedTxPacketsPerSecond = in.readDouble();
info.txBad = in.readLong();
info.mLostTxPacketsPerSecond = in.readDouble();
info.rxSuccess = in.readLong();
info.mSuccessfulRxPacketsPerSecond = in.readDouble();
info.mSupplicantState = SupplicantState.CREATOR.createFromParcel(in);
info.mOsuAp = in.readInt() != 0;
info.mRequestingPackageName = in.readString();
info.mFqdn = in.readString();
info.mProviderFriendlyName = in.readString();
info.mVhtMax8SpatialStreamsSupport = in.readInt() != 0;
info.mHe8ssCapableAp = in.readInt() != 0;
info.mWifiStandard = in.readInt();
info.mMaxSupportedTxLinkSpeed = in.readInt();
info.mMaxSupportedRxLinkSpeed = in.readInt();
info.mPasspointUniqueId = in.readString();
return info;
}
public WifiInfo[] newArray(int size) {
return new WifiInfo[size];
}
};
/**
* Set the Passpoint unique identifier for the current connection
*
* @param passpointUniqueId Unique identifier
* @hide
*/
public void setPasspointUniqueId(@Nullable String passpointUniqueId) {
mPasspointUniqueId = passpointUniqueId;
}
/**
* Get the Passpoint unique identifier for the current connection
*
* @return Passpoint unique identifier
* @hide
*/
public @Nullable String getPasspointUniqueId() {
return mPasspointUniqueId;
}
}
|