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
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
|
/*
* 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 static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.ACCESS_WIFI_STATE;
import static android.Manifest.permission.READ_WIFI_CREDENTIAL;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UnsupportedAppUsage;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.Network;
import android.net.wifi.hotspot2.IProvisioningCallback;
import android.net.wifi.hotspot2.OsuProvider;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.net.wifi.hotspot2.ProvisioningCallback;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.os.WorkSource;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.AsyncChannel;
import com.android.internal.util.Protocol;
import dalvik.system.CloseGuard;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
/**
* This class provides the primary API for managing all aspects of Wi-Fi
* connectivity.
* <p>
* On releases before {@link android.os.Build.VERSION_CODES#N}, this object
* should only be obtained from an {@linkplain Context#getApplicationContext()
* application context}, and not from any other derived context to avoid memory
* leaks within the calling process.
* <p>
* It deals with several categories of items:
* </p>
* <ul>
* <li>The list of configured networks. The list can be viewed and updated, and
* attributes of individual entries can be modified.</li>
* <li>The currently active Wi-Fi network, if any. Connectivity can be
* established or torn down, and dynamic information about the state of the
* network can be queried.</li>
* <li>Results of access point scans, containing enough information to make
* decisions about what access point to connect to.</li>
* <li>It defines the names of various Intent actions that are broadcast upon
* any sort of change in Wi-Fi state.
* </ul>
* <p>
* This is the API to use when performing Wi-Fi specific operations. To perform
* operations that pertain to network connectivity at an abstract level, use
* {@link android.net.ConnectivityManager}.
* </p>
*/
@SystemService(Context.WIFI_SERVICE)
public class WifiManager {
private static final String TAG = "WifiManager";
// Supplicant error codes:
/**
* The error code if there was a problem authenticating.
* @deprecated This is no longer supported.
*/
@Deprecated
public static final int ERROR_AUTHENTICATING = 1;
/**
* The reason code if there is no error during authentication.
* It could also imply that there no authentication in progress,
* this reason code also serves as a reset value.
* @deprecated This is no longer supported.
* @hide
*/
@Deprecated
public static final int ERROR_AUTH_FAILURE_NONE = 0;
/**
* The reason code if there was a timeout authenticating.
* @deprecated This is no longer supported.
* @hide
*/
@Deprecated
public static final int ERROR_AUTH_FAILURE_TIMEOUT = 1;
/**
* The reason code if there was a wrong password while
* authenticating.
* @deprecated This is no longer supported.
* @hide
*/
@Deprecated
public static final int ERROR_AUTH_FAILURE_WRONG_PSWD = 2;
/**
* The reason code if there was EAP failure while
* authenticating.
* @deprecated This is no longer supported.
* @hide
*/
@Deprecated
public static final int ERROR_AUTH_FAILURE_EAP_FAILURE = 3;
/**
* Maximum number of active network suggestions allowed per app.
* @hide
*/
public static final int NETWORK_SUGGESTIONS_MAX_PER_APP =
ActivityManager.isLowRamDeviceStatic() ? 256 : 1024;
/**
* Reason code if all of the network suggestions were successfully added or removed.
*/
public static final int STATUS_NETWORK_SUGGESTIONS_SUCCESS = 0;
/**
* Reason code if there was an internal error in the platform while processing the addition or
* removal of suggestions.
*/
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL = 1;
/**
* Reason code if the user has disallowed "android:change_wifi_state" app-ops from the app.
* @see android.app.AppOpsManager#unsafeCheckOp(String, int, String).
*/
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED = 2;
/**
* Reason code if one or more of the network suggestions added already exists in platform's
* database.
* @see WifiNetworkSuggestion#equals(Object)
*/
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE = 3;
/**
* Reason code if the number of network suggestions provided by the app crosses the max
* threshold set per app.
* @see #getMaxNumberOfNetworkSuggestionsPerApp()
*/
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP = 4;
/**
* Reason code if one or more of the network suggestions removed does not exist in platform's
* database.
*/
public static final int STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID = 5;
/** @hide */
@IntDef(prefix = { "STATUS_NETWORK_SUGGESTIONS_" }, value = {
STATUS_NETWORK_SUGGESTIONS_SUCCESS,
STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL,
STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED,
STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE,
STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP,
STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID,
})
@Retention(RetentionPolicy.SOURCE)
public @interface NetworkSuggestionsStatusCode {}
/**
* Broadcast intent action indicating whether Wi-Fi scanning is allowed currently
* @hide
*/
public static final String WIFI_SCAN_AVAILABLE = "wifi_scan_available";
/**
* Extra int indicating scan availability, WIFI_STATE_ENABLED and WIFI_STATE_DISABLED
* @hide
*/
public static final String EXTRA_SCAN_AVAILABLE = "scan_enabled";
/**
*
*
* @hide
**/
public static final String WIFI_DATA_STALL = "com.qualcomm.qti.net.wifi.WIFI_DATA_STALL";
/**
*
* see data stall reason code
* @hide
**/
public static final String EXTRA_WIFI_DATA_STALL_REASON = "data_stall_reasoncode";
/**
* Broadcast intent action indicating that the credential of a Wi-Fi network
* has been changed. One extra provides the ssid of the network. Another
* extra provides the event type, whether the credential is saved or forgot.
* @hide
*/
@SystemApi
public static final String WIFI_CREDENTIAL_CHANGED_ACTION =
"android.net.wifi.WIFI_CREDENTIAL_CHANGED";
/** @hide */
@SystemApi
public static final String EXTRA_WIFI_CREDENTIAL_EVENT_TYPE = "et";
/** @hide */
@SystemApi
public static final String EXTRA_WIFI_CREDENTIAL_SSID = "ssid";
/** @hide */
@SystemApi
public static final int WIFI_CREDENTIAL_SAVED = 0;
/** @hide */
@SystemApi
public static final int WIFI_CREDENTIAL_FORGOT = 1;
/** @hide */
@SystemApi
public static final int PASSPOINT_HOME_NETWORK = 0;
/** @hide */
@SystemApi
public static final int PASSPOINT_ROAMING_NETWORK = 1;
/**
* Broadcast intent action indicating that a Passpoint provider icon has been received.
*
* Included extras:
* {@link #EXTRA_BSSID_LONG}
* {@link #EXTRA_FILENAME}
* {@link #EXTRA_ICON}
*
* Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
*
* <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
* components will be launched.
*
* @hide
*/
public static final String ACTION_PASSPOINT_ICON = "android.net.wifi.action.PASSPOINT_ICON";
/**
* BSSID of an AP in long representation. The {@link #EXTRA_BSSID} contains BSSID in
* String representation.
*
* Retrieve with {@link android.content.Intent#getLongExtra(String, long)}.
*
* @hide
*/
public static final String EXTRA_BSSID_LONG = "android.net.wifi.extra.BSSID_LONG";
/**
* Icon data.
*
* Retrieve with {@link android.content.Intent#getParcelableExtra(String)} and cast into
* {@link android.graphics.drawable.Icon}.
*
* @hide
*/
public static final String EXTRA_ICON = "android.net.wifi.extra.ICON";
/**
* Name of a file.
*
* Retrieve with {@link android.content.Intent#getStringExtra(String)}.
*
* @hide
*/
public static final String EXTRA_FILENAME = "android.net.wifi.extra.FILENAME";
/**
* Broadcast intent action indicating a Passpoint OSU Providers List element has been received.
*
* Included extras:
* {@link #EXTRA_BSSID_LONG}
* {@link #EXTRA_ANQP_ELEMENT_DATA}
*
* Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
*
* <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
* components will be launched.
*
* @hide
*/
public static final String ACTION_PASSPOINT_OSU_PROVIDERS_LIST =
"android.net.wifi.action.PASSPOINT_OSU_PROVIDERS_LIST";
/**
* Raw binary data of an ANQP (Access Network Query Protocol) element.
*
* Retrieve with {@link android.content.Intent#getByteArrayExtra(String)}.
*
* @hide
*/
public static final String EXTRA_ANQP_ELEMENT_DATA =
"android.net.wifi.extra.ANQP_ELEMENT_DATA";
/**
* Broadcast intent action indicating that a Passpoint Deauth Imminent frame has been received.
*
* Included extras:
* {@link #EXTRA_BSSID_LONG}
* {@link #EXTRA_ESS}
* {@link #EXTRA_DELAY}
* {@link #EXTRA_URL}
*
* Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
*
* <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
* components will be launched.
*
* @hide
*/
public static final String ACTION_PASSPOINT_DEAUTH_IMMINENT =
"android.net.wifi.action.PASSPOINT_DEAUTH_IMMINENT";
/**
* Flag indicating BSS (Basic Service Set) or ESS (Extended Service Set). This will be set to
* {@code true} for ESS.
*
* Retrieve with {@link android.content.Intent#getBooleanExtra(String, boolean)}.
*
* @hide
*/
public static final String EXTRA_ESS = "android.net.wifi.extra.ESS";
/**
* Delay in seconds.
*
* Retrieve with {@link android.content.Intent#getIntExtra(String, int)}.
*
* @hide
*/
public static final String EXTRA_DELAY = "android.net.wifi.extra.DELAY";
/**
* String representation of an URL.
*
* Retrieve with {@link android.content.Intent#getStringExtra(String)}.
*
* @hide
*/
public static final String EXTRA_URL = "android.net.wifi.extra.URL";
/**
* Broadcast intent action indicating a Passpoint subscription remediation frame has been
* received.
*
* Included extras:
* {@link #EXTRA_BSSID_LONG}
* {@link #EXTRA_SUBSCRIPTION_REMEDIATION_METHOD}
* {@link #EXTRA_URL}
*
* Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
*
* <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
* components will be launched.
*
* @hide
*/
public static final String ACTION_PASSPOINT_SUBSCRIPTION_REMEDIATION =
"android.net.wifi.action.PASSPOINT_SUBSCRIPTION_REMEDIATION";
/**
* The protocol supported by the subscription remediation server. The possible values are:
* 0 - OMA DM
* 1 - SOAP XML SPP
*
* Retrieve with {@link android.content.Intent#getIntExtra(String, int)}.
*
* @hide
*/
public static final String EXTRA_SUBSCRIPTION_REMEDIATION_METHOD =
"android.net.wifi.extra.SUBSCRIPTION_REMEDIATION_METHOD";
/**
* Activity Action: lunch OSU (Online Sign Up) view.
* Included extras:
*
* {@link #EXTRA_OSU_NETWORK}: {@link Network} instance associated with OSU AP.
* {@link #EXTRA_URL}: String representation of a server URL used for OSU process.
*
* <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
* components will be launched.
*
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_PASSPOINT_LAUNCH_OSU_VIEW =
"android.net.wifi.action.PASSPOINT_LAUNCH_OSU_VIEW";
/**
* The lookup key for a {@link android.net.Network} associated with OSU server.
*
* Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
*
* @hide
*/
public static final String EXTRA_OSU_NETWORK = "android.net.wifi.extra.OSU_NETWORK";
/**
* Broadcast intent action indicating that Wi-Fi has been enabled, disabled,
* enabling, disabling, or unknown. One extra provides this state as an int.
* Another extra provides the previous state, if available.
*
* @see #EXTRA_WIFI_STATE
* @see #EXTRA_PREVIOUS_WIFI_STATE
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_STATE_CHANGED_ACTION =
"android.net.wifi.WIFI_STATE_CHANGED";
/**
* The lookup key for an int that indicates whether Wi-Fi is enabled,
* disabled, enabling, disabling, or unknown. Retrieve it with
* {@link android.content.Intent#getIntExtra(String,int)}.
*
* @see #WIFI_STATE_DISABLED
* @see #WIFI_STATE_DISABLING
* @see #WIFI_STATE_ENABLED
* @see #WIFI_STATE_ENABLING
* @see #WIFI_STATE_UNKNOWN
*/
public static final String EXTRA_WIFI_STATE = "wifi_state";
/**
* The previous Wi-Fi state.
*
* @see #EXTRA_WIFI_STATE
*/
public static final String EXTRA_PREVIOUS_WIFI_STATE = "previous_wifi_state";
/**
* Wi-Fi is currently being disabled. The state will change to {@link #WIFI_STATE_DISABLED} if
* it finishes successfully.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_DISABLING = 0;
/**
* Wi-Fi is disabled.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_DISABLED = 1;
/**
* Wi-Fi is currently being enabled. The state will change to {@link #WIFI_STATE_ENABLED} if
* it finishes successfully.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_ENABLING = 2;
/**
* Wi-Fi is enabled.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_ENABLED = 3;
/**
* Wi-Fi is in an unknown state. This state will occur when an error happens while enabling
* or disabling.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_UNKNOWN = 4;
/**
* Broadcast intent action indicating that Wi-Fi AP has been enabled, disabled,
* enabling, disabling, or failed.
*
* @hide
*/
@SystemApi
public static final String WIFI_AP_STATE_CHANGED_ACTION =
"android.net.wifi.WIFI_AP_STATE_CHANGED";
/**
* The lookup key for an int that indicates whether Wi-Fi AP is enabled,
* disabled, enabling, disabling, or failed. Retrieve it with
* {@link android.content.Intent#getIntExtra(String,int)}.
*
* @see #WIFI_AP_STATE_DISABLED
* @see #WIFI_AP_STATE_DISABLING
* @see #WIFI_AP_STATE_ENABLED
* @see #WIFI_AP_STATE_ENABLING
* @see #WIFI_AP_STATE_FAILED
*
* @hide
*/
@SystemApi
public static final String EXTRA_WIFI_AP_STATE = "wifi_state";
/**
* The look up key for an int that indicates why softAP started failed
* currently support general and no_channel
* @see #SAP_START_FAILURE_GENERIC
* @see #SAP_START_FAILURE_NO_CHANNEL
*
* @hide
*/
public static final String EXTRA_WIFI_AP_FAILURE_REASON = "wifi_ap_error_code";
/**
* The previous Wi-Fi state.
*
* @see #EXTRA_WIFI_AP_STATE
*
* @hide
*/
@SystemApi
public static final String EXTRA_PREVIOUS_WIFI_AP_STATE = "previous_wifi_state";
/**
* The interface used for the softap.
*
* @hide
*/
public static final String EXTRA_WIFI_AP_INTERFACE_NAME = "wifi_ap_interface_name";
/**
* The intended ip mode for this softap.
* @see #IFACE_IP_MODE_TETHERED
* @see #IFACE_IP_MODE_LOCAL_ONLY
*
* @hide
*/
public static final String EXTRA_WIFI_AP_MODE = "wifi_ap_mode";
/** @hide */
@IntDef(flag = false, prefix = { "WIFI_AP_STATE_" }, value = {
WIFI_AP_STATE_DISABLING,
WIFI_AP_STATE_DISABLED,
WIFI_AP_STATE_ENABLING,
WIFI_AP_STATE_ENABLED,
WIFI_AP_STATE_FAILED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface WifiApState {}
/**
* Wi-Fi AP is currently being disabled. The state will change to
* {@link #WIFI_AP_STATE_DISABLED} if it finishes successfully.
*
* @see #WIFI_AP_STATE_CHANGED_ACTION
* @see #getWifiApState()
*
* @hide
*/
@SystemApi
public static final int WIFI_AP_STATE_DISABLING = 10;
/**
* Wi-Fi AP is disabled.
*
* @see #WIFI_AP_STATE_CHANGED_ACTION
* @see #getWifiState()
*
* @hide
*/
@SystemApi
public static final int WIFI_AP_STATE_DISABLED = 11;
/**
* Wi-Fi AP is currently being enabled. The state will change to
* {@link #WIFI_AP_STATE_ENABLED} if it finishes successfully.
*
* @see #WIFI_AP_STATE_CHANGED_ACTION
* @see #getWifiApState()
*
* @hide
*/
@SystemApi
public static final int WIFI_AP_STATE_ENABLING = 12;
/**
* Wi-Fi AP is enabled.
*
* @see #WIFI_AP_STATE_CHANGED_ACTION
* @see #getWifiApState()
*
* @hide
*/
@SystemApi
public static final int WIFI_AP_STATE_ENABLED = 13;
/**
* Wi-Fi AP is in a failed state. This state will occur when an error occurs during
* enabling or disabling
*
* @see #WIFI_AP_STATE_CHANGED_ACTION
* @see #getWifiApState()
*
* @hide
*/
@SystemApi
public static final int WIFI_AP_STATE_FAILED = 14;
/** @hide */
@IntDef(flag = false, prefix = { "SAP_START_FAILURE_" }, value = {
SAP_START_FAILURE_GENERAL,
SAP_START_FAILURE_NO_CHANNEL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface SapStartFailure {}
/**
* If WIFI AP start failed, this reason code means there is no legal channel exists on
* user selected band by regulatory
*
* @hide
*/
public static final int SAP_START_FAILURE_GENERAL= 0;
/**
* All other reason for AP start failed besides SAP_START_FAILURE_GENERAL
*
* @hide
*/
public static final int SAP_START_FAILURE_NO_CHANNEL = 1;
/**
* Interface IP mode unspecified.
*
* @see updateInterfaceIpState(String, int)
*
* @hide
*/
public static final int IFACE_IP_MODE_UNSPECIFIED = -1;
/**
* Interface IP mode for configuration error.
*
* @see updateInterfaceIpState(String, int)
*
* @hide
*/
public static final int IFACE_IP_MODE_CONFIGURATION_ERROR = 0;
/**
* Interface IP mode for tethering.
*
* @see updateInterfaceIpState(String, int)
*
* @hide
*/
public static final int IFACE_IP_MODE_TETHERED = 1;
/**
* Interface IP mode for Local Only Hotspot.
*
* @see updateInterfaceIpState(String, int)
*
* @hide
*/
public static final int IFACE_IP_MODE_LOCAL_ONLY = 2;
/**
* Broadcast intent action indicating that a connection to the supplicant has
* been established (and it is now possible
* to perform Wi-Fi operations) or the connection to the supplicant has been
* lost. One extra provides the connection state as a boolean, where {@code true}
* means CONNECTED.
* @deprecated This is no longer supported.
* @see #EXTRA_SUPPLICANT_CONNECTED
*/
@Deprecated
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SUPPLICANT_CONNECTION_CHANGE_ACTION =
"android.net.wifi.supplicant.CONNECTION_CHANGE";
/**
* The lookup key for a boolean that indicates whether a connection to
* the supplicant daemon has been gained or lost. {@code true} means
* a connection now exists.
* Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
* @deprecated This is no longer supported.
*/
@Deprecated
public static final String EXTRA_SUPPLICANT_CONNECTED = "connected";
/**
* Broadcast intent action indicating that the state of Wi-Fi connectivity
* has changed. An extra provides the new state
* in the form of a {@link android.net.NetworkInfo} object.
* @see #EXTRA_NETWORK_INFO
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
/**
* The lookup key for a {@link android.net.NetworkInfo} object associated with the
* Wi-Fi network. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
*/
public static final String EXTRA_NETWORK_INFO = "networkInfo";
/**
* The lookup key for a String giving the BSSID of the access point to which
* we are connected. No longer used.
*/
@Deprecated
public static final String EXTRA_BSSID = "bssid";
/**
* The lookup key for a {@link android.net.wifi.WifiInfo} object giving the
* information about the access point to which we are connected.
* No longer used.
*/
@Deprecated
public static final String EXTRA_WIFI_INFO = "wifiInfo";
/**
* Broadcast intent action indicating that the state of establishing a connection to
* an access point has changed.One extra provides the new
* {@link SupplicantState}. Note that the supplicant state is Wi-Fi specific, and
* is not generally the most useful thing to look at if you are just interested in
* the overall state of connectivity.
* @see #EXTRA_NEW_STATE
* @see #EXTRA_SUPPLICANT_ERROR
* @deprecated This is no longer supported.
*/
@Deprecated
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SUPPLICANT_STATE_CHANGED_ACTION =
"android.net.wifi.supplicant.STATE_CHANGE";
/**
* The lookup key for a {@link SupplicantState} describing the new state
* Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
* @deprecated This is no longer supported.
*/
@Deprecated
public static final String EXTRA_NEW_STATE = "newState";
/**
* The lookup key for a {@link SupplicantState} describing the supplicant
* error code if any
* Retrieve with
* {@link android.content.Intent#getIntExtra(String, int)}.
* @see #ERROR_AUTHENTICATING
* @deprecated This is no longer supported.
*/
@Deprecated
public static final String EXTRA_SUPPLICANT_ERROR = "supplicantError";
/**
* The lookup key for a {@link SupplicantState} describing the supplicant
* error reason if any
* Retrieve with
* {@link android.content.Intent#getIntExtra(String, int)}.
* @see #ERROR_AUTH_FAILURE_#REASON_CODE
* @deprecated This is no longer supported.
* @hide
*/
@Deprecated
public static final String EXTRA_SUPPLICANT_ERROR_REASON = "supplicantErrorReason";
/**
* Broadcast intent action indicating that the configured networks changed.
* This can be as a result of adding/updating/deleting a network. If
* {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is set to true the new configuration
* can be retreived with the {@link #EXTRA_WIFI_CONFIGURATION} extra. If multiple
* Wi-Fi configurations changed, {@link #EXTRA_WIFI_CONFIGURATION} will not be present.
* @hide
*/
@SystemApi
public static final String CONFIGURED_NETWORKS_CHANGED_ACTION =
"android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
/**
* The lookup key for a (@link android.net.wifi.WifiConfiguration} object representing
* the changed Wi-Fi configuration when the {@link #CONFIGURED_NETWORKS_CHANGED_ACTION}
* broadcast is sent.
* @hide
*/
@SystemApi
public static final String EXTRA_WIFI_CONFIGURATION = "wifiConfiguration";
/**
* Multiple network configurations have changed.
* @see #CONFIGURED_NETWORKS_CHANGED_ACTION
*
* @hide
*/
@SystemApi
public static final String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
/**
* The lookup key for an integer indicating the reason a Wi-Fi network configuration
* has changed. Only present if {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is {@code false}
* @see #CONFIGURED_NETWORKS_CHANGED_ACTION
* @hide
*/
@SystemApi
public static final String EXTRA_CHANGE_REASON = "changeReason";
/**
* The configuration is new and was added.
* @hide
*/
@SystemApi
public static final int CHANGE_REASON_ADDED = 0;
/**
* The configuration was removed and is no longer present in the system's list of
* configured networks.
* @hide
*/
@SystemApi
public static final int CHANGE_REASON_REMOVED = 1;
/**
* The configuration has changed as a result of explicit action or because the system
* took an automated action such as disabling a malfunctioning configuration.
* @hide
*/
@SystemApi
public static final int CHANGE_REASON_CONFIG_CHANGE = 2;
/**
* An access point scan has completed, and results are available.
* Call {@link #getScanResults()} to obtain the results.
* The broadcast intent may contain an extra field with the key {@link #EXTRA_RESULTS_UPDATED}
* and a {@code boolean} value indicating if the scan was successful.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SCAN_RESULTS_AVAILABLE_ACTION = "android.net.wifi.SCAN_RESULTS";
/**
* Lookup key for a {@code boolean} extra in intent {@link #SCAN_RESULTS_AVAILABLE_ACTION}
* representing if the scan was successful or not.
* Scans may fail for multiple reasons, these may include:
* <ol>
* <li>An app requested too many scans in a certain period of time.
* This may lead to additional scan request rejections via "scan throttling" for both
* foreground and background apps.
* Note: Apps holding android.Manifest.permission.NETWORK_SETTINGS permission are
* exempted from scan throttling.
* </li>
* <li>The device is idle and scanning is disabled.</li>
* <li>Wifi hardware reported a scan failure.</li>
* </ol>
* @return true scan was successful, results are updated
* @return false scan was not successful, results haven't been updated since previous scan
*/
public static final String EXTRA_RESULTS_UPDATED = "resultsUpdated";
/**
* A batch of access point scans has been completed and the results areavailable.
* Call {@link #getBatchedScanResults()} to obtain the results.
* @deprecated This API is nolonger supported.
* Use {@link android.net.wifi.WifiScanner} API
* @hide
*/
@Deprecated
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String BATCHED_SCAN_RESULTS_AVAILABLE_ACTION =
"android.net.wifi.BATCHED_RESULTS";
/**
* The RSSI (signal strength) has changed.
*
* Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
* @see {@link #EXTRA_NEW_RSSI}
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String RSSI_CHANGED_ACTION = "android.net.wifi.RSSI_CHANGED";
/**
* The lookup key for an {@code int} giving the new RSSI in dBm.
*/
public static final String EXTRA_NEW_RSSI = "newRssi";
/**
* Broadcast intent action indicating that the link configuration
* changed on wifi.
* @hide
*/
@UnsupportedAppUsage
public static final String LINK_CONFIGURATION_CHANGED_ACTION =
"android.net.wifi.LINK_CONFIGURATION_CHANGED";
/**
* The lookup key for a {@link android.net.LinkProperties} object associated with the
* Wi-Fi network. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
* @hide
*/
public static final String EXTRA_LINK_PROPERTIES = "linkProperties";
/**
* The lookup key for a {@link android.net.NetworkCapabilities} object associated with the
* Wi-Fi network. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
* @hide
*/
public static final String EXTRA_NETWORK_CAPABILITIES = "networkCapabilities";
/**
* The network IDs of the configured networks could have changed.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String NETWORK_IDS_CHANGED_ACTION = "android.net.wifi.NETWORK_IDS_CHANGED";
/**
* Broadcast intent action indicating DPP Event arrival notificaiton.
* @see #EXTRA_DPP_DATA.
* @hide
*/
public static final String DPP_EVENT_ACTION = "com.qualcomm.qti.net.wifi.DPP_EVENT";
/**
* This shall point to DppResult Type.
* @hide
*/
public static final String EXTRA_DPP_EVENT_TYPE = "dppEventType";
/**
* This shall point to WifiDppConfig object. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
* @hide
*/
public static final String EXTRA_DPP_EVENT_DATA = "dppEventData";
/**
* Activity Action: Show a system activity that allows the user to enable
* scans to be available even with Wi-Fi turned off.
*
* <p>Notification of the result of this activity is posted using the
* {@link android.app.Activity#onActivityResult} callback. The
* <code>resultCode</code>
* will be {@link android.app.Activity#RESULT_OK} if scan always mode has
* been turned on or {@link android.app.Activity#RESULT_CANCELED} if the user
* has rejected the request or an error has occurred.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE =
"android.net.wifi.action.REQUEST_SCAN_ALWAYS_AVAILABLE";
/**
* Activity Action: Pick a Wi-Fi network to connect to.
* <p>Input: Nothing.
* <p>Output: Nothing.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_PICK_WIFI_NETWORK = "android.net.wifi.PICK_WIFI_NETWORK";
/**
* Activity Action: Show UI to get user approval to enable WiFi.
* <p>Input: {@link android.content.Intent#EXTRA_PACKAGE_NAME} string extra with
* the name of the app requesting the action.
* <p>Output: Nothing.
*
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_REQUEST_ENABLE = "android.net.wifi.action.REQUEST_ENABLE";
/**
* Activity Action: Show UI to get user approval to disable WiFi.
* <p>Input: {@link android.content.Intent#EXTRA_PACKAGE_NAME} string extra with
* the name of the app requesting the action.
* <p>Output: Nothing.
*
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_REQUEST_DISABLE = "android.net.wifi.action.REQUEST_DISABLE";
/**
* Broadcast intent action indicating that WifiCountryCode was updated with new
* country code.
*
* @see #EXTRA_COUNTRY_CODE
*
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String WIFI_COUNTRY_CODE_CHANGED_ACTION =
"android.net.wifi.COUNTRY_CODE_CHANGED";
/**
* The lookup key for a string that indicates the 2 char new country code
*
* @hide
*/
public static final String EXTRA_COUNTRY_CODE = "country_code";
/**
* Broadcast intent action indicating that the user initiated Wifi OFF
* or APM ON and Wifi disconnection is in progress
* Actual Wifi disconnection happens after mDisconnectDelayDuration seconds.
* @hide
*/
public static final String ACTION_WIFI_DISCONNECT_IN_PROGRESS =
"com.qualcomm.qti.net.wifi.WIFI_DISCONNECT_IN_PROGRESS";
/**
* Directed broadcast intent action indicating that the device has connected to one of the
* network suggestions provided by the app. This will be sent post connection to a network
* which was created with {@link WifiNetworkSuggestion.Builder#setIsAppInteractionRequired()}
* flag set.
* <p>
* Note: The broadcast is sent to the app only if it holds
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission.
*
* @see #EXTRA_NETWORK_SUGGESTION
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION =
"android.net.wifi.action.WIFI_NETWORK_SUGGESTION_POST_CONNECTION";
/**
* Sent as as a part of {@link #ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION} that holds
* an instance of {@link WifiNetworkSuggestion} corresponding to the connected network.
*/
public static final String EXTRA_NETWORK_SUGGESTION =
"android.net.wifi.extra.NETWORK_SUGGESTION";
/**
* Internally used Wi-Fi lock mode representing the case were no locks are held.
* @hide
*/
public static final int WIFI_MODE_NO_LOCKS_HELD = 0;
/**
* In this Wi-Fi lock mode, Wi-Fi will be kept active,
* and will behave normally, i.e., it will attempt to automatically
* establish a connection to a remembered access point that is
* within range, and will do periodic scans if there are remembered
* access points but none are in range.
*
* @deprecated This API is non-functional and will have no impact.
*/
@Deprecated
public static final int WIFI_MODE_FULL = 1;
/**
* In this Wi-Fi lock mode, Wi-Fi will be kept active,
* but the only operation that will be supported is initiation of
* scans, and the subsequent reporting of scan results. No attempts
* will be made to automatically connect to remembered access points,
* nor will periodic scans be automatically performed looking for
* remembered access points. Scans must be explicitly requested by
* an application in this mode.
*
* @deprecated This API is non-functional and will have no impact.
*/
@Deprecated
public static final int WIFI_MODE_SCAN_ONLY = 2;
/**
* In this Wi-Fi lock mode, Wi-Fi will not go to power save.
* This results in operating with low packet latency.
* The lock is active even when the device screen is off or
* the acquiring application is running in the background.
* This mode will consume more power and hence should be used only
* when there is a need for this tradeoff.
* <p>
* An example use case is when a voice connection needs to be
* kept active even after the device screen goes off.
* Holding a {@link #WIFI_MODE_FULL_HIGH_PERF} lock for the
* duration of the voice call may improve the call quality.
* <p>
* When there is no support from the hardware, the {@link #WIFI_MODE_FULL_HIGH_PERF}
* lock will have no impact.
*/
public static final int WIFI_MODE_FULL_HIGH_PERF = 3;
/**
* In this Wi-Fi lock mode, Wi-Fi will operate with a priority to achieve low latency.
* {@link #WIFI_MODE_FULL_LOW_LATENCY} lock has the following limitations:
* <ol>
* <li>The lock is only active when the screen is on.</li>
* <li>The lock is only active when the acquiring app is running in the foreground.</li>
* </ol>
* Low latency mode optimizes for reduced packet latency,
* and as a result other performance measures may suffer when there are trade-offs to make:
* <ol>
* <li>Battery life may be reduced.</li>
* <li>Throughput may be reduced.</li>
* <li>Frequency of Wi-Fi scanning may be reduced. This may result in: </li>
* <ul>
* <li>The device may not roam or switch to the AP with highest signal quality.</li>
* <li>Location accuracy may be reduced.</li>
* </ul>
* </ol>
* <p>
* Example use cases are real time gaming or virtual reality applications where
* low latency is a key factor for user experience.
* <p>
* When there is no support from the hardware, the {@link #WIFI_MODE_FULL_LOW_LATENCY}
* lock will cause the device not to go power save.
* <p>
* Note: For an app which acquires both {@link #WIFI_MODE_FULL_LOW_LATENCY} and
* {@link #WIFI_MODE_FULL_HIGH_PERF} locks, {@link #WIFI_MODE_FULL_LOW_LATENCY}
* lock will be effective when app is running in foreground and screen is on,
* while the {@link #WIFI_MODE_FULL_HIGH_PERF} lock will take effect otherwise.
*/
public static final int WIFI_MODE_FULL_LOW_LATENCY = 4;
/** Anything worse than or equal to this will show 0 bars. */
@UnsupportedAppUsage
private static final int MIN_RSSI = -100;
/** Anything better than or equal to this will show the max bars. */
@UnsupportedAppUsage
private static final int MAX_RSSI = -55;
/**
* Number of RSSI levels used in the framework to initiate
* {@link #RSSI_CHANGED_ACTION} broadcast
* @hide
*/
@UnsupportedAppUsage
public static final int RSSI_LEVELS = 5;
/**
* Auto settings in the driver. The driver could choose to operate on both
* 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
* @hide
*/
@UnsupportedAppUsage
public static final int WIFI_FREQUENCY_BAND_AUTO = 0;
/**
* Operation on 5 GHz alone
* @hide
*/
@UnsupportedAppUsage
public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;
/**
* Operation on 2.4 GHz alone
* @hide
*/
@UnsupportedAppUsage
public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;
/** @hide */
public static final boolean DEFAULT_POOR_NETWORK_AVOIDANCE_ENABLED = false;
/* Maximum number of active locks we allow.
* This limit was added to prevent apps from creating a ridiculous number
* of locks and crashing the system by overflowing the global ref table.
*/
private static final int MAX_ACTIVE_LOCKS = 50;
/* Number of currently active WifiLocks and MulticastLocks */
@UnsupportedAppUsage
private int mActiveLockCount;
private Context mContext;
@UnsupportedAppUsage
IWifiManager mService;
private final int mTargetSdkVersion;
private static final int INVALID_KEY = 0;
private int mListenerKey = 1;
private final SparseArray mListenerMap = new SparseArray();
private final Object mListenerMapLock = new Object();
private AsyncChannel mAsyncChannel;
private CountDownLatch mConnected;
private Looper mLooper;
private boolean mVerboseLoggingEnabled = false;
/* LocalOnlyHotspot callback message types */
/** @hide */
public static final int HOTSPOT_STARTED = 0;
/** @hide */
public static final int HOTSPOT_STOPPED = 1;
/** @hide */
public static final int HOTSPOT_FAILED = 2;
/** @hide */
public static final int HOTSPOT_OBSERVER_REGISTERED = 3;
private final Object mLock = new Object(); // lock guarding access to the following vars
@GuardedBy("mLock")
private LocalOnlyHotspotCallbackProxy mLOHSCallbackProxy;
@GuardedBy("mLock")
private LocalOnlyHotspotObserverProxy mLOHSObserverProxy;
/**
* Create a new WifiManager instance.
* Applications will almost always want to use
* {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
* the standard {@link android.content.Context#WIFI_SERVICE Context.WIFI_SERVICE}.
* @param context the application context
* @param service the Binder interface
* @hide - hide this because it takes in a parameter of type IWifiManager, which
* is a system private class.
*/
public WifiManager(Context context, IWifiManager service, Looper looper) {
mContext = context;
mService = service;
mLooper = looper;
mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
updateVerboseLoggingEnabledFromService();
}
/**
* Return a list of all the networks configured for the current foreground
* user.
*
* Requires the same permissions as {@link #getScanResults}.
* If such access is not allowed, this API will always return an empty list.
*
* Not all fields of WifiConfiguration are returned. Only the following
* fields are filled in:
* <ul>
* <li>networkId</li>
* <li>SSID</li>
* <li>BSSID</li>
* <li>priority</li>
* <li>allowedProtocols</li>
* <li>allowedKeyManagement</li>
* <li>allowedAuthAlgorithms</li>
* <li>allowedPairwiseCiphers</li>
* <li>allowedGroupCiphers</li>
* </ul>
* @return a list of network configurations in the form of a list
* of {@link WifiConfiguration} objects.
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will return an empty list,
* except to callers with Carrier privilege which will receive a restricted list only
* containing configurations which they created.
*/
@Deprecated
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
public List<WifiConfiguration> getConfiguredNetworks() {
try {
ParceledListSlice<WifiConfiguration> parceledList =
mService.getConfiguredNetworks(mContext.getOpPackageName());
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@SystemApi
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE, READ_WIFI_CREDENTIAL})
public List<WifiConfiguration> getPrivilegedConfiguredNetworks() {
try {
ParceledListSlice<WifiConfiguration> parceledList =
mService.getPrivilegedConfiguredNetworks(mContext.getOpPackageName());
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns a list of all matching WifiConfigurations for a given list of ScanResult.
*
* An empty list will be returned when no configurations are installed or if no configurations
* match the ScanResult.
*
* @param scanResults a list of scanResult that represents the BSSID
* @return List that consists of {@link WifiConfiguration} and corresponding scanResults per
* network type({@link #PASSPOINT_HOME_NETWORK} and {@link #PASSPOINT_ROAMING_NETWORK}).
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public List<Pair<WifiConfiguration, Map<Integer, List<ScanResult>>>> getAllMatchingWifiConfigs(
@NonNull List<ScanResult> scanResults) {
List<Pair<WifiConfiguration, Map<Integer, List<ScanResult>>>> configs = new ArrayList<>();
try {
Map<String, Map<Integer, List<ScanResult>>> results =
mService.getAllMatchingFqdnsForScanResults(
scanResults);
if (results.isEmpty()) {
return configs;
}
List<WifiConfiguration> wifiConfigurations =
mService.getWifiConfigsForPasspointProfiles(
new ArrayList<>(results.keySet()));
for (WifiConfiguration configuration : wifiConfigurations) {
Map<Integer, List<ScanResult>> scanResultsPerNetworkType = results.get(
configuration.FQDN);
if (scanResultsPerNetworkType != null) {
configs.add(Pair.create(configuration, scanResultsPerNetworkType));
}
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
return configs;
}
/**
* Returns a list of unique Hotspot 2.0 OSU (Online Sign-Up) providers associated with a given
* list of ScanResult.
*
* An empty list will be returned if no match is found.
*
* @param scanResults a list of ScanResult
* @return Map that consists {@link OsuProvider} and a list of matching {@link ScanResult}
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public Map<OsuProvider, List<ScanResult>> getMatchingOsuProviders(
List<ScanResult> scanResults) {
try {
return mService.getMatchingOsuProviders(scanResults);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns the matching Passpoint R2 configurations for given OSU (Online Sign-Up) providers.
*
* Given a list of OSU providers, this only returns OSU providers that already have Passpoint R2
* configurations in the device.
* An empty map will be returned when there is no matching Passpoint R2 configuration for the
* given OsuProviders.
*
* @param osuProviders a set of {@link OsuProvider}
* @return Map that consists of {@link OsuProvider} and matching {@link PasspointConfiguration}.
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public Map<OsuProvider, PasspointConfiguration> getMatchingPasspointConfigsForOsuProviders(
@NonNull Set<OsuProvider> osuProviders) {
try {
return mService.getMatchingPasspointConfigsForOsuProviders(
new ArrayList<>(osuProviders));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Add a new network description to the set of configured networks.
* The {@code networkId} field of the supplied configuration object
* is ignored.
* <p/>
* The new network will be marked DISABLED by default. To enable it,
* called {@link #enableNetwork}.
*
* @param config the set of variables that describe the configuration,
* contained in a {@link WifiConfiguration} object.
* If the {@link WifiConfiguration} has an Http Proxy set
* the calling app must be System, or be provisioned as the Profile or Device Owner.
* @return the ID of the newly created network description. This is used in
* other operations to specified the network to be acted upon.
* Returns {@code -1} on failure.
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return {@code -1}.
*/
@Deprecated
public int addNetwork(WifiConfiguration config) {
if (config == null) {
return -1;
}
config.networkId = -1;
return addOrUpdateNetwork(config);
}
/**
* Update the network description of an existing configured network.
*
* @param config the set of variables that describe the configuration,
* contained in a {@link WifiConfiguration} object. It may
* be sparse, so that only the items that are being changed
* are non-<code>null</code>. The {@code networkId} field
* must be set to the ID of the existing network being updated.
* If the {@link WifiConfiguration} has an Http Proxy set
* the calling app must be System, or be provisioned as the Profile or Device Owner.
* @return Returns the {@code networkId} of the supplied
* {@code WifiConfiguration} on success.
* <br/>
* Returns {@code -1} on failure, including when the {@code networkId}
* field of the {@code WifiConfiguration} does not refer to an
* existing network.
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return {@code -1}.
*/
@Deprecated
public int updateNetwork(WifiConfiguration config) {
if (config == null || config.networkId < 0) {
return -1;
}
return addOrUpdateNetwork(config);
}
/**
* Check the WifiSharing mode.
*
* @return true if Current Sta network connected with extending coverage
* option. false if it is not.
*
* @hide no intent to publish
*/
public boolean isExtendingWifi() {
try {
return mService.isExtendingWifi();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Check Wifi coverage extend feature enabled or not.
*
* @return true if Wifi extend feature is enabled.
*
* @hide no intent to publish
*/
public boolean isWifiCoverageExtendFeatureEnabled() {
try {
return mService.isWifiCoverageExtendFeatureEnabled();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Enable/disable Wifi coverage extend feature.
*
* @hide no intent to publish
*/
public void enableWifiCoverageExtendFeature(boolean enable) {
try {
mService.enableWifiCoverageExtendFeature(enable);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Internal method for doing the RPC that creates a new network description
* or updates an existing one.
*
* @param config The possibly sparse object containing the variables that
* are to set or updated in the network description.
* @return the ID of the network on success, {@code -1} on failure.
*/
private int addOrUpdateNetwork(WifiConfiguration config) {
try {
return mService.addOrUpdateNetwork(config, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Interface for indicating user selection from the list of networks presented in the
* {@link NetworkRequestMatchCallback#onMatch(List)}.
*
* The platform will implement this callback and pass it along with the
* {@link NetworkRequestMatchCallback#onUserSelectionCallbackRegistration(
* NetworkRequestUserSelectionCallback)}. The UI component handling
* {@link NetworkRequestMatchCallback} will invoke {@link #select(WifiConfiguration)} or
* {@link #reject()} to return the user's selection back to the platform via this callback.
* @hide
*/
public interface NetworkRequestUserSelectionCallback {
/**
* User selected this network to connect to.
* @param wifiConfiguration WifiConfiguration object corresponding to the network
* user selected.
*/
void select(@NonNull WifiConfiguration wifiConfiguration);
/**
* User rejected the app's request.
*/
void reject();
}
/**
* Interface for network request callback. Should be implemented by applications and passed when
* calling {@link #registerNetworkRequestMatchCallback(NetworkRequestMatchCallback, Handler)}.
*
* This is meant to be implemented by a UI component to present the user with a list of networks
* matching the app's request. The user is allowed to pick one of these networks to connect to
* or reject the request by the app.
* @hide
*/
public interface NetworkRequestMatchCallback {
/**
* Invoked to register a callback to be invoked to convey user selection. The callback
* object paased in this method is to be invoked by the UI component after the service sends
* a list of matching scan networks using {@link #onMatch(List)} and user picks a network
* from that list.
*
* @param userSelectionCallback Callback object to send back the user selection.
*/
void onUserSelectionCallbackRegistration(
@NonNull NetworkRequestUserSelectionCallback userSelectionCallback);
/**
* Invoked when the active network request is aborted, either because
* <li> The app released the request, OR</li>
* <li> Request was overridden by a new request</li>
* This signals the end of processing for the current request and should stop the UI
* component. No subsequent calls from the UI component will be handled by the platform.
*/
void onAbort();
/**
* Invoked when a network request initiated by an app matches some networks in scan results.
* This may be invoked multiple times for a single network request as the platform finds new
* matching networks in scan results.
*
* @param scanResults List of {@link ScanResult} objects corresponding to the networks
* matching the request.
*/
void onMatch(@NonNull List<ScanResult> scanResults);
/**
* Invoked on a successful connection with the network that the user selected
* via {@link NetworkRequestUserSelectionCallback}.
*
* @param wifiConfiguration WifiConfiguration object corresponding to the network that the
* user selected.
*/
void onUserSelectionConnectSuccess(@NonNull WifiConfiguration wifiConfiguration);
/**
* Invoked on failure to establish connection with the network that the user selected
* via {@link NetworkRequestUserSelectionCallback}.
*
* @param wifiConfiguration WifiConfiguration object corresponding to the network
* user selected.
*/
void onUserSelectionConnectFailure(@NonNull WifiConfiguration wifiConfiguration);
}
/**
* Callback proxy for NetworkRequestUserSelectionCallback objects.
* @hide
*/
private class NetworkRequestUserSelectionCallbackProxy implements
NetworkRequestUserSelectionCallback {
private final INetworkRequestUserSelectionCallback mCallback;
NetworkRequestUserSelectionCallbackProxy(
INetworkRequestUserSelectionCallback callback) {
mCallback = callback;
}
@Override
public void select(@NonNull WifiConfiguration wifiConfiguration) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestUserSelectionCallbackProxy: select "
+ "wificonfiguration: " + wifiConfiguration);
}
try {
mCallback.select(wifiConfiguration);
} catch (RemoteException e) {
Log.e(TAG, "Failed to invoke onSelected", e);
throw e.rethrowFromSystemServer();
}
}
@Override
public void reject() {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestUserSelectionCallbackProxy: reject");
}
try {
mCallback.reject();
} catch (RemoteException e) {
Log.e(TAG, "Failed to invoke onRejected", e);
throw e.rethrowFromSystemServer();
}
}
}
/**
* Callback proxy for NetworkRequestMatchCallback objects.
* @hide
*/
private class NetworkRequestMatchCallbackProxy extends INetworkRequestMatchCallback.Stub {
private final Handler mHandler;
private final NetworkRequestMatchCallback mCallback;
NetworkRequestMatchCallbackProxy(Looper looper, NetworkRequestMatchCallback callback) {
mHandler = new Handler(looper);
mCallback = callback;
}
@Override
public void onUserSelectionCallbackRegistration(
INetworkRequestUserSelectionCallback userSelectionCallback) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestMatchCallbackProxy: "
+ "onUserSelectionCallbackRegistration callback: " + userSelectionCallback);
}
mHandler.post(() -> {
mCallback.onUserSelectionCallbackRegistration(
new NetworkRequestUserSelectionCallbackProxy(userSelectionCallback));
});
}
@Override
public void onAbort() {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestMatchCallbackProxy: onAbort");
}
mHandler.post(() -> {
mCallback.onAbort();
});
}
@Override
public void onMatch(List<ScanResult> scanResults) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestMatchCallbackProxy: onMatch scanResults: "
+ scanResults);
}
mHandler.post(() -> {
mCallback.onMatch(scanResults);
});
}
@Override
public void onUserSelectionConnectSuccess(WifiConfiguration wifiConfiguration) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestMatchCallbackProxy: onUserSelectionConnectSuccess "
+ " wificonfiguration: " + wifiConfiguration);
}
mHandler.post(() -> {
mCallback.onUserSelectionConnectSuccess(wifiConfiguration);
});
}
@Override
public void onUserSelectionConnectFailure(WifiConfiguration wifiConfiguration) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "NetworkRequestMatchCallbackProxy: onUserSelectionConnectFailure"
+ " wificonfiguration: " + wifiConfiguration);
}
mHandler.post(() -> {
mCallback.onUserSelectionConnectFailure(wifiConfiguration);
});
}
}
/**
* Registers a callback for NetworkRequest matches. See {@link NetworkRequestMatchCallback}.
* Caller can unregister a previously registered callback using
* {@link #unregisterNetworkRequestMatchCallback(NetworkRequestMatchCallback)}
* <p>
* Applications should have the
* {@link android.Manifest.permission#NETWORK_SETTINGS} permission. Callers
* without the permission will trigger a {@link java.lang.SecurityException}.
* <p>
*
* @param callback Callback for network match events
* @param handler The Handler on whose thread to execute the callbacks of the {@code callback}
* object. If null, then the application's main thread will be used.
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void registerNetworkRequestMatchCallback(@NonNull NetworkRequestMatchCallback callback,
@Nullable Handler handler) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "registerNetworkRequestMatchCallback: callback=" + callback
+ ", handler=" + handler);
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.registerNetworkRequestMatchCallback(
binder, new NetworkRequestMatchCallbackProxy(looper, callback),
callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Unregisters a callback for NetworkRequest matches. See {@link NetworkRequestMatchCallback}.
* <p>
* Applications should have the
* {@link android.Manifest.permission#NETWORK_SETTINGS} permission. Callers
* without the permission will trigger a {@link java.lang.SecurityException}.
* <p>
*
* @param callback Callback for network match events
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void unregisterNetworkRequestMatchCallback(
@NonNull NetworkRequestMatchCallback callback) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "unregisterNetworkRequestMatchCallback: callback=" + callback);
try {
mService.unregisterNetworkRequestMatchCallback(callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Provide a list of network suggestions to the device. See {@link WifiNetworkSuggestion}
* for a detailed explanation of the parameters.
* When the device decides to connect to one of the provided network suggestions, platform sends
* a directed broadcast {@link #ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION} to the app if
* the network was created with {@link WifiNetworkSuggestion.Builder
* #setIsAppInteractionRequired()} flag set and the app holds
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission.
*<p>
* NOTE:
* <li> These networks are just a suggestion to the platform. The platform will ultimately
* decide on which network the device connects to. </li>
* <li> When an app is uninstalled, all its suggested networks are discarded. If the device is
* currently connected to a suggested network which is being removed then the device will
* disconnect from that network.</li>
* <li> No in-place modification of existing suggestions are allowed. Apps are expected to
* remove suggestions using {@link #removeNetworkSuggestions(List)} and then add the modified
* suggestion back using this API.</li>
*
* @param networkSuggestions List of network suggestions provided by the app.
* @return Status code for the operation. One of the STATUS_NETWORK_SUGGESTIONS_ values.
* {@link WifiNetworkSuggestion#equals(Object)} any previously provided suggestions by the app.
* @throws {@link SecurityException} if the caller is missing required permissions.
*/
@RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
public @NetworkSuggestionsStatusCode int addNetworkSuggestions(
@NonNull List<WifiNetworkSuggestion> networkSuggestions) {
try {
return mService.addNetworkSuggestions(networkSuggestions, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Remove some or all of the network suggestions that were previously provided by the app.
* See {@link WifiNetworkSuggestion} for a detailed explanation of the parameters.
* See {@link WifiNetworkSuggestion#equals(Object)} for the equivalence evaluation used.
*
* @param networkSuggestions List of network suggestions to be removed. Pass an empty list
* to remove all the previous suggestions provided by the app.
* @return Status code for the operation. One of the STATUS_NETWORK_SUGGESTIONS_ values.
* Any matching suggestions are removed from the device and will not be considered for any
* further connection attempts.
*/
@RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
public @NetworkSuggestionsStatusCode int removeNetworkSuggestions(
@NonNull List<WifiNetworkSuggestion> networkSuggestions) {
try {
return mService.removeNetworkSuggestions(
networkSuggestions, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns the max number of network suggestions that are allowed per app on the device.
* @see #addNetworkSuggestions(List)
* @see #removeNetworkSuggestions(List)
*/
public int getMaxNumberOfNetworkSuggestionsPerApp() {
return NETWORK_SUGGESTIONS_MAX_PER_APP;
}
/**
* Add or update a Passpoint configuration. The configuration provides a credential
* for connecting to Passpoint networks that are operated by the Passpoint
* service provider specified in the configuration.
*
* Each configuration is uniquely identified by its FQDN (Fully Qualified Domain
* Name). In the case when there is an existing configuration with the same
* FQDN, the new configuration will replace the existing configuration.
*
* @param config The Passpoint configuration to be added
* @throws IllegalArgumentException if configuration is invalid or Passpoint is not enabled on
* the device.
*/
public void addOrUpdatePasspointConfiguration(PasspointConfiguration config) {
try {
if (!mService.addOrUpdatePasspointConfiguration(config, mContext.getOpPackageName())) {
throw new IllegalArgumentException();
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Remove the Passpoint configuration identified by its FQDN (Fully Qualified Domain Name).
*
* @param fqdn The FQDN of the Passpoint configuration to be removed
* @throws IllegalArgumentException if no configuration is associated with the given FQDN or
* Passpoint is not enabled on the device.
* @deprecated This is no longer supported.
*/
@Deprecated
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public void removePasspointConfiguration(String fqdn) {
try {
if (!mService.removePasspointConfiguration(fqdn, mContext.getOpPackageName())) {
throw new IllegalArgumentException();
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Return the list of installed Passpoint configurations.
*
* An empty list will be returned when no configurations are installed.
*
* @return A list of {@link PasspointConfiguration}
* @deprecated This is no longer supported.
*/
@Deprecated
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public List<PasspointConfiguration> getPasspointConfigurations() {
try {
return mService.getPasspointConfigurations();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Query for a Hotspot 2.0 release 2 OSU icon file. An {@link #ACTION_PASSPOINT_ICON} intent
* will be broadcasted once the request is completed. The presence of the intent extra
* {@link #EXTRA_ICON} will indicate the result of the request.
* A missing intent extra {@link #EXTRA_ICON} will indicate a failure.
*
* @param bssid The BSSID of the AP
* @param fileName Name of the icon file (remote file) to query from the AP
*
* @throws UnsupportedOperationException if Passpoint is not enabled on the device.
* @hide
*/
public void queryPasspointIcon(long bssid, String fileName) {
try {
mService.queryPasspointIcon(bssid, fileName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Match the currently associated network against the SP matching the given FQDN
* @param fqdn FQDN of the SP
* @return ordinal [HomeProvider, RoamingProvider, Incomplete, None, Declined]
* @hide
*/
public int matchProviderWithCurrentNetwork(String fqdn) {
try {
return mService.matchProviderWithCurrentNetwork(fqdn);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Deauthenticate and set the re-authentication hold off time for the current network
* @param holdoff hold off time in milliseconds
* @param ess set if the hold off pertains to an ESS rather than a BSS
* @hide
*/
public void deauthenticateNetwork(long holdoff, boolean ess) {
try {
mService.deauthenticateNetwork(holdoff, ess);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Remove the specified network from the list of configured networks.
* This may result in the asynchronous delivery of state change
* events.
*
* Applications are not allowed to remove networks created by other
* applications.
*
* @param netId the ID of the network as returned by {@link #addNetwork} or {@link
* #getConfiguredNetworks}.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean removeNetwork(int netId) {
try {
return mService.removeNetwork(netId, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Allow a previously configured network to be associated with. If
* <code>attemptConnect</code> is true, an attempt to connect to the selected
* network is initiated. This may result in the asynchronous delivery
* of state change events.
* <p>
* <b>Note:</b> Network communication may not use Wi-Fi even if Wi-Fi is connected;
* traffic may instead be sent through another network, such as cellular data,
* Bluetooth tethering, or Ethernet. For example, traffic will never use a
* Wi-Fi network that does not provide Internet access (e.g. a wireless
* printer), if another network that does offer Internet access (e.g.
* cellular data) is available. Applications that need to ensure that their
* network traffic uses Wi-Fi should use APIs such as
* {@link Network#bindSocket(java.net.Socket)},
* {@link Network#openConnection(java.net.URL)}, or
* {@link ConnectivityManager#bindProcessToNetwork} to do so.
*
* Applications are not allowed to enable networks created by other
* applications.
*
* @param netId the ID of the network as returned by {@link #addNetwork} or {@link
* #getConfiguredNetworks}.
* @param attemptConnect The way to select a particular network to connect to is specify
* {@code true} for this parameter.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean enableNetwork(int netId, boolean attemptConnect) {
boolean success;
try {
success = mService.enableNetwork(netId, attemptConnect, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
return success;
}
/**
* Disable a configured network. The specified network will not be
* a candidate for associating. This may result in the asynchronous
* delivery of state change events.
*
* Applications are not allowed to disable networks created by other
* applications.
*
* @param netId the ID of the network as returned by {@link #addNetwork} or {@link
* #getConfiguredNetworks}.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean disableNetwork(int netId) {
try {
return mService.disableNetwork(netId, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Disassociate from the currently active access point. This may result
* in the asynchronous delivery of state change events.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean disconnect() {
try {
return mService.disconnect(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Reconnect to the currently active access point, if we are currently
* disconnected. This may result in the asynchronous delivery of state
* change events.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean reconnect() {
try {
return mService.reconnect(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Reconnect to the currently active access point, even if we are already
* connected. This may result in the asynchronous delivery of state
* change events.
* @return {@code true} if the operation succeeded
*
* @deprecated
* a) See {@link WifiNetworkSpecifier.Builder#build()} for new
* mechanism to trigger connection to a Wi-Fi network.
* b) See {@link #addNetworkSuggestions(List)},
* {@link #removeNetworkSuggestions(List)} for new API to add Wi-Fi networks for consideration
* when auto-connecting to wifi.
* <b>Compatibility Note:</b> For applications targeting
* {@link android.os.Build.VERSION_CODES#Q} or above, this API will always return false.
*/
@Deprecated
public boolean reassociate() {
try {
return mService.reassociate(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Check that the supplicant daemon is responding to requests.
* @return {@code true} if we were able to communicate with the supplicant and
* it returned the expected response to the PING message.
* @deprecated Will return the output of {@link #isWifiEnabled()} instead.
*/
@Deprecated
public boolean pingSupplicant() {
return isWifiEnabled();
}
/** @hide */
public static final int WIFI_FEATURE_INFRA = 0x0001; // Basic infrastructure mode
/** @hide */
public static final int WIFI_FEATURE_INFRA_5G = 0x0002; // Support for 5 GHz Band
/** @hide */
public static final int WIFI_FEATURE_PASSPOINT = 0x0004; // Support for GAS/ANQP
/** @hide */
public static final int WIFI_FEATURE_P2P = 0x0008; // Wifi-Direct
/** @hide */
public static final int WIFI_FEATURE_MOBILE_HOTSPOT = 0x0010; // Soft AP
/** @hide */
public static final int WIFI_FEATURE_SCANNER = 0x0020; // WifiScanner APIs
/** @hide */
public static final int WIFI_FEATURE_AWARE = 0x0040; // Wi-Fi AWare networking
/** @hide */
public static final int WIFI_FEATURE_D2D_RTT = 0x0080; // Device-to-device RTT
/** @hide */
public static final int WIFI_FEATURE_D2AP_RTT = 0x0100; // Device-to-AP RTT
/** @hide */
public static final int WIFI_FEATURE_BATCH_SCAN = 0x0200; // Batched Scan (deprecated)
/** @hide */
public static final int WIFI_FEATURE_PNO = 0x0400; // Preferred network offload
/** @hide */
public static final int WIFI_FEATURE_ADDITIONAL_STA = 0x0800; // Support for two STAs
/** @hide */
public static final int WIFI_FEATURE_TDLS = 0x1000; // Tunnel directed link setup
/** @hide */
public static final int WIFI_FEATURE_TDLS_OFFCHANNEL = 0x2000; // Support for TDLS off channel
/** @hide */
public static final int WIFI_FEATURE_EPR = 0x4000; // Enhanced power reporting
/** @hide */
public static final int WIFI_FEATURE_AP_STA = 0x8000; // AP STA Concurrency
/** @hide */
public static final int WIFI_FEATURE_LINK_LAYER_STATS = 0x10000; // Link layer stats collection
/** @hide */
public static final int WIFI_FEATURE_LOGGER = 0x20000; // WiFi Logger
/** @hide */
public static final int WIFI_FEATURE_HAL_EPNO = 0x40000; // Enhanced PNO
/** @hide */
public static final int WIFI_FEATURE_RSSI_MONITOR = 0x80000; // RSSI Monitor
/** @hide */
public static final int WIFI_FEATURE_MKEEP_ALIVE = 0x100000; // mkeep_alive
/** @hide */
public static final int WIFI_FEATURE_CONFIG_NDO = 0x200000; // ND offload
/** @hide */
public static final int WIFI_FEATURE_TRANSMIT_POWER = 0x400000; // Capture transmit power
/** @hide */
public static final int WIFI_FEATURE_CONTROL_ROAMING = 0x800000; // Control firmware roaming
/** @hide */
public static final int WIFI_FEATURE_IE_WHITELIST = 0x1000000; // Probe IE white listing
/** @hide */
public static final int WIFI_FEATURE_SCAN_RAND = 0x2000000; // Random MAC & Probe seq
/** @hide */
public static final int WIFI_FEATURE_TX_POWER_LIMIT = 0x4000000; // Set Tx power limit
/** @hide */
public static final int WIFI_FEATURE_WPA3_SAE = 0x8000000; // WPA3-Personal SAE
/** @hide */
public static final int WIFI_FEATURE_WPA3_SUITE_B = 0x10000000; // WPA3-Enterprise Suite-B
/** @hide */
public static final int WIFI_FEATURE_OWE = 0x20000000; // Enhanced Open
/** @hide */
public static final int WIFI_FEATURE_LOW_LATENCY = 0x40000000; // Low Latency modes
/** @hide */
public static final int WIFI_FEATURE_DPP = 0x80000000; // DPP (Easy-Connect)
/** @hide */
public static final long WIFI_FEATURE_P2P_RAND_MAC = 0x100000000L; // Random P2P MAC
private long getSupportedFeatures() {
try {
return mService.getSupportedFeatures();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private boolean isFeatureSupported(long feature) {
return (getSupportedFeatures() & feature) == feature;
}
/**
* @return true if this adapter supports 5 GHz band
*/
public boolean is5GHzBandSupported() {
return isFeatureSupported(WIFI_FEATURE_INFRA_5G);
}
/**
* @return true if this adapter supports Passpoint
* @hide
*/
public boolean isPasspointSupported() {
return isFeatureSupported(WIFI_FEATURE_PASSPOINT);
}
/**
* @return true if this adapter supports WifiP2pManager (Wi-Fi Direct)
*/
public boolean isP2pSupported() {
return isFeatureSupported(WIFI_FEATURE_P2P);
}
/**
* @return true if this adapter supports portable Wi-Fi hotspot
* @hide
*/
@SystemApi
public boolean isPortableHotspotSupported() {
return isFeatureSupported(WIFI_FEATURE_MOBILE_HOTSPOT);
}
/**
* @return true if this adapter supports WifiScanner APIs
* @hide
*/
@SystemApi
public boolean isWifiScannerSupported() {
return isFeatureSupported(WIFI_FEATURE_SCANNER);
}
/**
* @return true if this adapter supports Neighbour Awareness Network APIs
* @hide
*/
public boolean isWifiAwareSupported() {
return isFeatureSupported(WIFI_FEATURE_AWARE);
}
/**
* @return true if this adapter supports Device-to-device RTT
* @hide
*/
@SystemApi
public boolean isDeviceToDeviceRttSupported() {
return isFeatureSupported(WIFI_FEATURE_D2D_RTT);
}
/**
* @return true if this adapter supports Device-to-AP RTT
*/
public boolean isDeviceToApRttSupported() {
return isFeatureSupported(WIFI_FEATURE_D2AP_RTT);
}
/**
* @return true if this adapter supports offloaded connectivity scan
*/
public boolean isPreferredNetworkOffloadSupported() {
return isFeatureSupported(WIFI_FEATURE_PNO);
}
/**
* @return true if this adapter supports multiple simultaneous connections
* @hide
*/
public boolean isAdditionalStaSupported() {
return isFeatureSupported(WIFI_FEATURE_ADDITIONAL_STA);
}
/**
* @return true if this adapter supports Tunnel Directed Link Setup
*/
public boolean isTdlsSupported() {
return isFeatureSupported(WIFI_FEATURE_TDLS);
}
/**
* @return true if this adapter supports Off Channel Tunnel Directed Link Setup
* @hide
*/
public boolean isOffChannelTdlsSupported() {
return isFeatureSupported(WIFI_FEATURE_TDLS_OFFCHANNEL);
}
/**
* @return true if this adapter supports advanced power/performance counters
*/
public boolean isEnhancedPowerReportingSupported() {
return isFeatureSupported(WIFI_FEATURE_LINK_LAYER_STATS);
}
/**
* Return the record of {@link WifiActivityEnergyInfo} object that
* has the activity and energy info. This can be used to ascertain what
* the controller has been up to, since the last sample.
*
* @return a record with {@link WifiActivityEnergyInfo} or null if
* report is unavailable or unsupported
* @hide
*/
public WifiActivityEnergyInfo getControllerActivityEnergyInfo() {
if (mService == null) return null;
try {
synchronized(this) {
return mService.reportActivityInfo();
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Request a scan for access points. Returns immediately. The availability
* of the results is made known later by means of an asynchronous event sent
* on completion of the scan.
* <p>
* To initiate a Wi-Fi scan, declare the
* {@link android.Manifest.permission#CHANGE_WIFI_STATE}
* permission in the manifest, and perform these steps:
* </p>
* <ol style="1">
* <li>Invoke the following method:
* {@code ((WifiManager) getSystemService(WIFI_SERVICE)).startScan()}</li>
* <li>
* Register a BroadcastReceiver to listen to
* {@code SCAN_RESULTS_AVAILABLE_ACTION}.</li>
* <li>When a broadcast is received, call:
* {@code ((WifiManager) getSystemService(WIFI_SERVICE)).getScanResults()}</li>
* </ol>
* @return {@code true} if the operation succeeded, i.e., the scan was initiated.
* @deprecated The ability for apps to trigger scan requests will be removed in a future
* release.
*/
@Deprecated
public boolean startScan() {
return startScan(null);
}
/** @hide */
@SystemApi
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
public boolean startScan(WorkSource workSource) {
try {
String packageName = mContext.getOpPackageName();
return mService.startScan(packageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* WPS has been deprecated from Client mode operation.
*
* @return null
* @hide
* @deprecated This API is deprecated
*/
public String getCurrentNetworkWpsNfcConfigurationToken() {
return null;
}
/**
* Return dynamic information about the current Wi-Fi connection, if any is active.
* <p>
* In the connected state, access to the SSID and BSSID requires
* the same permissions as {@link #getScanResults}. If such access is not allowed,
* {@link WifiInfo#getSSID} will return {@code "<unknown ssid>"} and
* {@link WifiInfo#getBSSID} will return {@code "02:00:00:00:00:00"}.
*
* @return the Wi-Fi information, contained in {@link WifiInfo}.
*/
public WifiInfo getConnectionInfo() {
try {
return mService.getConnectionInfo(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Return the results of the latest access point scan.
* @return the list of access points found in the most recent scan. An app must hold
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION} permission
* in order to get valid results.
*/
public List<ScanResult> getScanResults() {
android.util.SeempLog.record(55);
try {
return mService.getScanResults(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Check if scanning is always available.
*
* If this return {@code true}, apps can issue {@link #startScan} and fetch scan results
* even when Wi-Fi is turned off.
*
* To change this setting, see {@link #ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE}.
* @deprecated The ability for apps to trigger scan requests will be removed in a future
* release.
*/
@Deprecated
public boolean isScanAlwaysAvailable() {
try {
return mService.isScanAlwaysAvailable();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Tell the device to persist the current list of configured networks.
* <p>
* Note: It is possible for this method to change the network IDs of
* existing networks. You should assume the network IDs can be different
* after calling this method.
*
* @return {@code false}.
* @deprecated There is no need to call this method -
* {@link #addNetwork(WifiConfiguration)}, {@link #updateNetwork(WifiConfiguration)}
* and {@link #removeNetwork(int)} already persist the configurations automatically.
*/
@Deprecated
public boolean saveConfiguration() {
return false;
}
/**
* Set the country code.
* @param countryCode country code in ISO 3166 format.
*
* @hide
*/
public void setCountryCode(@NonNull String country) {
try {
mService.setCountryCode(country);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* get the country code.
* @return the country code in ISO 3166 format.
*
* @hide
*/
@UnsupportedAppUsage
public String getCountryCode() {
try {
String country = mService.getCountryCode();
return country;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
* @return {@code true} if supported, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage
public boolean isDualBandSupported() {
try {
return mService.isDualBandSupported();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Check if the chipset requires conversion of 5GHz Only apBand to ANY.
* @return {@code true} if required, {@code false} otherwise.
* @hide
*/
public boolean isDualModeSupported() {
try {
return mService.needs5GHzToAnyApBandConversion();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.
* @return the DHCP information
*/
public DhcpInfo getDhcpInfo() {
try {
return mService.getDhcpInfo();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Enable or disable Wi-Fi.
* <p>
* Applications must have the {@link android.Manifest.permission#CHANGE_WIFI_STATE}
* permission to toggle wifi.
*
* @param enabled {@code true} to enable, {@code false} to disable.
* @return {@code false} if the request cannot be satisfied; {@code true} indicates that wifi is
* either already in the requested state, or in progress toward the requested state.
* @throws {@link java.lang.SecurityException} if the caller is missing required permissions.
*
* @deprecated Starting with Build.VERSION_CODES#Q, applications are not allowed to
* enable/disable Wi-Fi regardless of application's target SDK. This API will have no effect
* and will always return false.
*/
@Deprecated
public boolean setWifiEnabled(boolean enabled) {
try {
return mService.setWifiEnabled(mContext.getOpPackageName(), enabled);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Gets the Wi-Fi enabled state.
* @return One of {@link #WIFI_STATE_DISABLED},
* {@link #WIFI_STATE_DISABLING}, {@link #WIFI_STATE_ENABLED},
* {@link #WIFI_STATE_ENABLING}, {@link #WIFI_STATE_UNKNOWN}
* @see #isWifiEnabled()
*/
public int getWifiState() {
try {
return mService.getWifiEnabledState();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Return whether Wi-Fi is enabled or disabled.
* @return {@code true} if Wi-Fi is enabled
* @see #getWifiState()
*/
public boolean isWifiEnabled() {
return getWifiState() == WIFI_STATE_ENABLED;
}
/**
* Return TX packet counter, for CTS test of WiFi watchdog.
* @param listener is the interface to receive result
*
* @hide for CTS test only
*/
public void getTxPacketCount(TxPacketCountListener listener) {
getChannel().sendMessage(RSSI_PKTCNT_FETCH, 0, putListener(listener));
}
/**
* Calculates the level of the signal. This should be used any time a signal
* is being shown.
*
* @param rssi The power of the signal measured in RSSI.
* @param numLevels The number of levels to consider in the calculated
* level.
* @return A level of the signal, given in the range of 0 to numLevels-1
* (both inclusive).
*/
public static int calculateSignalLevel(int rssi, int numLevels) {
if (rssi <= MIN_RSSI) {
return 0;
} else if (rssi >= MAX_RSSI) {
return numLevels - 1;
} else {
float inputRange = (MAX_RSSI - MIN_RSSI);
float outputRange = (numLevels - 1);
return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
}
}
/**
* Compares two signal strengths.
*
* @param rssiA The power of the first signal measured in RSSI.
* @param rssiB The power of the second signal measured in RSSI.
* @return Returns <0 if the first signal is weaker than the second signal,
* 0 if the two signals have the same strength, and >0 if the first
* signal is stronger than the second signal.
*/
public static int compareSignalLevel(int rssiA, int rssiB) {
return rssiA - rssiB;
}
/**
* Call allowing ConnectivityService to update WifiService with interface mode changes.
*
* The possible modes include: {@link IFACE_IP_MODE_TETHERED},
* {@link IFACE_IP_MODE_LOCAL_ONLY},
* {@link IFACE_IP_MODE_CONFIGURATION_ERROR}
*
* @param ifaceName String name of the updated interface
* @param mode int representing the new mode
*
* @hide
*/
public void updateInterfaceIpState(String ifaceName, int mode) {
try {
mService.updateInterfaceIpState(ifaceName, mode);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start SoftAp mode with the specified configuration.
* Note that starting in access point mode disables station
* mode operation
* @param wifiConfig SSID, security and channel details as
* part of WifiConfiguration
* @return {@code true} if the operation succeeds, {@code false} otherwise
*
* @hide
*/
public boolean startSoftAp(@Nullable WifiConfiguration wifiConfig) {
try {
return mService.startSoftAp(wifiConfig);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop SoftAp mode.
* Note that stopping softap mode will restore the previous wifi mode.
* @return {@code true} if the operation succeeds, {@code false} otherwise
*
* @hide
*/
public boolean stopSoftAp() {
try {
return mService.stopSoftAp();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Request a local only hotspot that an application can use to communicate between co-located
* devices connected to the created WiFi hotspot. The network created by this method will not
* have Internet access. Each application can make a single request for the hotspot, but
* multiple applications could be requesting the hotspot at the same time. When multiple
* applications have successfully registered concurrently, they will be sharing the underlying
* hotspot. {@link LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} is called
* when the hotspot is ready for use by the application.
* <p>
* Each application can make a single active call to this method. The {@link
* LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} callback supplies the
* requestor with a {@link LocalOnlyHotspotReservation} that contains a
* {@link WifiConfiguration} with the SSID, security type and credentials needed to connect
* to the hotspot. Communicating this information is up to the application.
* <p>
* If the LocalOnlyHotspot cannot be created, the {@link LocalOnlyHotspotCallback#onFailed(int)}
* method will be called. Example failures include errors bringing up the network or if
* there is an incompatible operating mode. For example, if the user is currently using Wifi
* Tethering to provide an upstream to another device, LocalOnlyHotspot will not start due to
* an incompatible mode. The possible error codes include:
* {@link LocalOnlyHotspotCallback#ERROR_NO_CHANNEL},
* {@link LocalOnlyHotspotCallback#ERROR_GENERIC},
* {@link LocalOnlyHotspotCallback#ERROR_INCOMPATIBLE_MODE} and
* {@link LocalOnlyHotspotCallback#ERROR_TETHERING_DISALLOWED}.
* <p>
* Internally, requests will be tracked to prevent the hotspot from being torn down while apps
* are still using it. The {@link LocalOnlyHotspotReservation} object passed in the {@link
* LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} call should be closed when
* the LocalOnlyHotspot is no longer needed using {@link LocalOnlyHotspotReservation#close()}.
* Since the hotspot may be shared among multiple applications, removing the final registered
* application request will trigger the hotspot teardown. This means that applications should
* not listen to broadcasts containing wifi state to determine if the hotspot was stopped after
* they are done using it. Additionally, once {@link LocalOnlyHotspotReservation#close()} is
* called, applications will not receive callbacks of any kind.
* <p>
* Applications should be aware that the user may also stop the LocalOnlyHotspot through the
* Settings UI; it is not guaranteed to stay up as long as there is a requesting application.
* The requestors will be notified of this case via
* {@link LocalOnlyHotspotCallback#onStopped()}. Other cases may arise where the hotspot is
* torn down (Emergency mode, etc). Application developers should be aware that it can stop
* unexpectedly, but they will receive a notification if they have properly registered.
* <p>
* Applications should also be aware that this network will be shared with other applications.
* Applications are responsible for protecting their data on this network (e.g., TLS).
* <p>
* Applications need to have the following permissions to start LocalOnlyHotspot: {@link
* android.Manifest.permission#CHANGE_WIFI_STATE} and {@link
* android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION}. Callers without
* the permissions will trigger a {@link java.lang.SecurityException}.
* <p>
* @param callback LocalOnlyHotspotCallback for the application to receive updates about
* operating status.
* @param handler Handler to be used for callbacks. If the caller passes a null Handler, the
* main thread will be used.
*/
public void startLocalOnlyHotspot(LocalOnlyHotspotCallback callback,
@Nullable Handler handler) {
synchronized (mLock) {
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper();
LocalOnlyHotspotCallbackProxy proxy =
new LocalOnlyHotspotCallbackProxy(this, looper, callback);
try {
String packageName = mContext.getOpPackageName();
int returnCode = mService.startLocalOnlyHotspot(
proxy.getMessenger(), new Binder(), packageName);
if (returnCode != LocalOnlyHotspotCallback.REQUEST_REGISTERED) {
// Send message to the proxy to make sure we call back on the correct thread
proxy.notifyFailed(returnCode);
return;
}
mLOHSCallbackProxy = proxy;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Cancels a pending local only hotspot request. This can be used by the calling application to
* cancel the existing request if the provided callback has not been triggered. Calling this
* method will be equivalent to closing the returned LocalOnlyHotspotReservation, but it is not
* explicitly required.
* <p>
* When cancelling this request, application developers should be aware that there may still be
* outstanding local only hotspot requests and the hotspot may still start, or continue running.
* Additionally, if a callback was registered, it will no longer be triggered after calling
* cancel.
*
* @hide
*/
@UnsupportedAppUsage
public void cancelLocalOnlyHotspotRequest() {
synchronized (mLock) {
stopLocalOnlyHotspot();
}
}
/**
* Method used to inform WifiService that the LocalOnlyHotspot is no longer needed. This
* method is used by WifiManager to release LocalOnlyHotspotReservations held by calling
* applications and removes the internal tracking for the hotspot request. When all requesting
* applications are finished using the hotspot, it will be stopped and WiFi will return to the
* previous operational mode.
*
* This method should not be called by applications. Instead, they should call the close()
* method on their LocalOnlyHotspotReservation.
*/
private void stopLocalOnlyHotspot() {
synchronized (mLock) {
if (mLOHSCallbackProxy == null) {
// nothing to do, the callback was already cleaned up.
return;
}
mLOHSCallbackProxy = null;
try {
mService.stopLocalOnlyHotspot();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Allow callers (Settings UI) to watch LocalOnlyHotspot state changes. Callers will
* receive a {@link LocalOnlyHotspotSubscription} object as a parameter of the
* {@link LocalOnlyHotspotObserver#onRegistered(LocalOnlyHotspotSubscription)}. The registered
* callers will receive the {@link LocalOnlyHotspotObserver#onStarted(WifiConfiguration)} and
* {@link LocalOnlyHotspotObserver#onStopped()} callbacks.
* <p>
* Applications should have the
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION ACCESS_FINE_LOCATION}
* permission. Callers without the permission will trigger a
* {@link java.lang.SecurityException}.
* <p>
* @param observer LocalOnlyHotspotObserver callback.
* @param handler Handler to use for callbacks
*
* @hide
*/
public void watchLocalOnlyHotspot(LocalOnlyHotspotObserver observer,
@Nullable Handler handler) {
synchronized (mLock) {
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper();
mLOHSObserverProxy = new LocalOnlyHotspotObserverProxy(this, looper, observer);
try {
mService.startWatchLocalOnlyHotspot(
mLOHSObserverProxy.getMessenger(), new Binder());
mLOHSObserverProxy.registered();
} catch (RemoteException e) {
mLOHSObserverProxy = null;
throw e.rethrowFromSystemServer();
}
}
}
/**
* Allow callers to stop watching LocalOnlyHotspot state changes. After calling this method,
* applications will no longer receive callbacks.
*
* @hide
*/
public void unregisterLocalOnlyHotspotObserver() {
synchronized (mLock) {
if (mLOHSObserverProxy == null) {
// nothing to do, the callback was already cleaned up
return;
}
mLOHSObserverProxy = null;
try {
mService.stopWatchLocalOnlyHotspot();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Gets the Wi-Fi enabled state.
* @return One of {@link #WIFI_AP_STATE_DISABLED},
* {@link #WIFI_AP_STATE_DISABLING}, {@link #WIFI_AP_STATE_ENABLED},
* {@link #WIFI_AP_STATE_ENABLING}, {@link #WIFI_AP_STATE_FAILED}
* @see #isWifiApEnabled()
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE)
public int getWifiApState() {
try {
return mService.getWifiApEnabledState();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Return whether Wi-Fi AP is enabled or disabled.
* @return {@code true} if Wi-Fi AP is enabled
* @see #getWifiApState()
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE)
public boolean isWifiApEnabled() {
return getWifiApState() == WIFI_AP_STATE_ENABLED;
}
/**
* Gets the Wi-Fi AP Configuration.
* @return AP details in WifiConfiguration
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE)
public WifiConfiguration getWifiApConfiguration() {
try {
return mService.getWifiApConfiguration();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Sets the Wi-Fi AP Configuration. The AP configuration must either be open or
* WPA2 PSK networks.
* @return {@code true} if the operation succeeded, {@code false} otherwise
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
try {
return mService.setWifiApConfiguration(wifiConfig, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Method that triggers a notification to the user about a conversion to their saved AP config.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void notifyUserOfApBandConversion() {
Log.d(TAG, "apBand was converted, notify the user");
try {
mService.notifyUserOfApBandConversion(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Enable/Disable TDLS on a specific local route.
*
* <p>
* TDLS enables two wireless endpoints to talk to each other directly
* without going through the access point that is managing the local
* network. It saves bandwidth and improves quality of the link.
* </p>
* <p>
* This API enables/disables the option of using TDLS. If enabled, the
* underlying hardware is free to use TDLS or a hop through the access
* point. If disabled, existing TDLS session is torn down and
* hardware is restricted to use access point for transferring wireless
* packets. Default value for all routes is 'disabled', meaning restricted
* to use access point for transferring packets.
* </p>
*
* @param remoteIPAddress IP address of the endpoint to setup TDLS with
* @param enable true = setup and false = tear down TDLS
*/
public void setTdlsEnabled(InetAddress remoteIPAddress, boolean enable) {
try {
mService.enableTdls(remoteIPAddress.getHostAddress(), enable);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Similar to {@link #setTdlsEnabled(InetAddress, boolean) }, except
* this version allows you to specify remote endpoint with a MAC address.
* @param remoteMacAddress MAC address of the remote endpoint such as 00:00:0c:9f:f2:ab
* @param enable true = setup and false = tear down TDLS
*/
public void setTdlsEnabledWithMacAddress(String remoteMacAddress, boolean enable) {
try {
mService.enableTdlsWithMacAddress(remoteMacAddress, enable);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/* TODO: deprecate synchronous API and open up the following API */
private static final int BASE = Protocol.BASE_WIFI_MANAGER;
/* Commands to WifiService */
/** @hide */
public static final int CONNECT_NETWORK = BASE + 1;
/** @hide */
public static final int CONNECT_NETWORK_FAILED = BASE + 2;
/** @hide */
public static final int CONNECT_NETWORK_SUCCEEDED = BASE + 3;
/** @hide */
public static final int FORGET_NETWORK = BASE + 4;
/** @hide */
public static final int FORGET_NETWORK_FAILED = BASE + 5;
/** @hide */
public static final int FORGET_NETWORK_SUCCEEDED = BASE + 6;
/** @hide */
public static final int SAVE_NETWORK = BASE + 7;
/** @hide */
public static final int SAVE_NETWORK_FAILED = BASE + 8;
/** @hide */
public static final int SAVE_NETWORK_SUCCEEDED = BASE + 9;
/** @hide
* @deprecated This is deprecated
*/
public static final int START_WPS = BASE + 10;
/** @hide
* @deprecated This is deprecated
*/
public static final int START_WPS_SUCCEEDED = BASE + 11;
/** @hide
* @deprecated This is deprecated
*/
public static final int WPS_FAILED = BASE + 12;
/** @hide
* @deprecated This is deprecated
*/
public static final int WPS_COMPLETED = BASE + 13;
/** @hide
* @deprecated This is deprecated
*/
public static final int CANCEL_WPS = BASE + 14;
/** @hide
* @deprecated This is deprecated
*/
public static final int CANCEL_WPS_FAILED = BASE + 15;
/** @hide
* @deprecated This is deprecated
*/
public static final int CANCEL_WPS_SUCCEDED = BASE + 16;
/** @hide */
public static final int DISABLE_NETWORK = BASE + 17;
/** @hide */
public static final int DISABLE_NETWORK_FAILED = BASE + 18;
/** @hide */
public static final int DISABLE_NETWORK_SUCCEEDED = BASE + 19;
/** @hide */
public static final int RSSI_PKTCNT_FETCH = BASE + 20;
/** @hide */
public static final int RSSI_PKTCNT_FETCH_SUCCEEDED = BASE + 21;
/** @hide */
public static final int RSSI_PKTCNT_FETCH_FAILED = BASE + 22;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed due to an internal error.
* @hide
*/
public static final int ERROR = 0;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation is already in progress
* @hide
*/
public static final int IN_PROGRESS = 1;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed because the framework is busy and
* unable to service the request
* @hide
*/
public static final int BUSY = 2;
/* WPS specific errors */
/** WPS overlap detected
* @deprecated This is deprecated
*/
public static final int WPS_OVERLAP_ERROR = 3;
/** WEP on WPS is prohibited
* @deprecated This is deprecated
*/
public static final int WPS_WEP_PROHIBITED = 4;
/** TKIP only prohibited
* @deprecated This is deprecated
*/
public static final int WPS_TKIP_ONLY_PROHIBITED = 5;
/** Authentication failure on WPS
* @deprecated This is deprecated
*/
public static final int WPS_AUTH_FAILURE = 6;
/** WPS timed out
* @deprecated This is deprecated
*/
public static final int WPS_TIMED_OUT = 7;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed due to invalid inputs
* @hide
*/
public static final int INVALID_ARGS = 8;
/**
* Passed with {@link ActionListener#onFailure}.
* Indicates that the operation failed due to user permissions.
* @hide
*/
public static final int NOT_AUTHORIZED = 9;
/**
* Interface for callback invocation on an application action
* @hide
*/
@SystemApi
public interface ActionListener {
/**
* The operation succeeded.
* This is called when the scan request has been validated and ready
* to sent to driver.
*/
public void onSuccess();
/**
* The operation failed.
* This is called when the scan request failed.
* @param reason The reason for failure could be one of the following:
* {@link #REASON_INVALID_REQUEST}} is specified when scan request parameters are invalid.
* {@link #REASON_NOT_AUTHORIZED} is specified when requesting app doesn't have the required
* permission to request a scan.
* {@link #REASON_UNSPECIFIED} is specified when driver reports a scan failure.
*/
public void onFailure(int reason);
}
/** Interface for callback invocation on a start WPS action
* @deprecated This is deprecated
*/
public static abstract class WpsCallback {
/** WPS start succeeded
* @deprecated This API is deprecated
*/
public abstract void onStarted(String pin);
/** WPS operation completed successfully
* @deprecated This API is deprecated
*/
public abstract void onSucceeded();
/**
* WPS operation failed
* @param reason The reason for failure could be one of
* {@link #WPS_TKIP_ONLY_PROHIBITED}, {@link #WPS_OVERLAP_ERROR},
* {@link #WPS_WEP_PROHIBITED}, {@link #WPS_TIMED_OUT} or {@link #WPS_AUTH_FAILURE}
* and some generic errors.
* @deprecated This API is deprecated
*/
public abstract void onFailed(int reason);
}
/** Interface for callback invocation on a TX packet count poll action {@hide} */
public interface TxPacketCountListener {
/**
* The operation succeeded
* @param count TX packet counter
*/
public void onSuccess(int count);
/**
* The operation failed
* @param reason The reason for failure could be one of
* {@link #ERROR}, {@link #IN_PROGRESS} or {@link #BUSY}
*/
public void onFailure(int reason);
}
/**
* Base class for soft AP callback. Should be extended by applications and set when calling
* {@link WifiManager#registerSoftApCallback(SoftApCallback, Handler)}.
*
* @hide
*/
public interface SoftApCallback {
/**
* Called when soft AP state changes.
*
* @param state new new AP state. One of {@link #WIFI_AP_STATE_DISABLED},
* {@link #WIFI_AP_STATE_DISABLING}, {@link #WIFI_AP_STATE_ENABLED},
* {@link #WIFI_AP_STATE_ENABLING}, {@link #WIFI_AP_STATE_FAILED}
* @param failureReason reason when in failed state. One of
* {@link #SAP_START_FAILURE_GENERAL}, {@link #SAP_START_FAILURE_NO_CHANNEL}
*/
public abstract void onStateChanged(@WifiApState int state,
@SapStartFailure int failureReason);
/**
* Called when number of connected clients to soft AP changes.
*
* @param numClients number of connected clients
*/
public abstract void onNumClientsChanged(int numClients);
/**
* Called when Stations connected to soft AP.
*
* @param Macaddr Mac Address of connected Stations to soft AP
* @param numClients number of connected clients
*/
public abstract void onStaConnected(String Macaddr, int numClients);
/**
* Called when Stations disconnected to soft AP.
*
* @param Macaddr Mac Address of Disconnected Stations to soft AP
* @param numClients number of connected clients
*/
public abstract void onStaDisconnected(String Macaddr, int numClients);
}
/**
* Callback proxy for SoftApCallback objects.
*
* @hide
*/
private class SoftApCallbackProxy extends ISoftApCallback.Stub {
private final Handler mHandler;
private final SoftApCallback mCallback;
SoftApCallbackProxy(Looper looper, SoftApCallback callback) {
mHandler = new Handler(looper);
mCallback = callback;
}
@Override
public void onStateChanged(int state, int failureReason) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "SoftApCallbackProxy: onStateChanged: state=" + state
+ ", failureReason=" + failureReason);
}
mHandler.post(() -> {
mCallback.onStateChanged(state, failureReason);
});
}
@Override
public void onNumClientsChanged(int numClients) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "SoftApCallbackProxy: onNumClientsChanged: numClients=" + numClients);
}
mHandler.post(() -> {
mCallback.onNumClientsChanged(numClients);
});
}
@Override
public void onStaConnected(String Macaddr, int numClients) throws RemoteException {
Log.v(TAG, "SoftApCallbackProxy: [" + numClients + "]onStaConnected Macaddr =" + Macaddr);
mHandler.post(() -> {
mCallback.onStaConnected(Macaddr, numClients);
});
}
@Override
public void onStaDisconnected(String Macaddr, int numClients) throws RemoteException {
Log.v(TAG, "SoftApCallbackProxy: [" + numClients + "]onStaDisconnected Macaddr =" + Macaddr);
mHandler.post(() -> {
mCallback.onStaDisconnected(Macaddr, numClients);
});
}
}
/**
* Registers a callback for Soft AP. See {@link SoftApCallback}. Caller will receive the current
* soft AP state and number of connected devices immediately after a successful call to this API
* via callback. Note that receiving an immediate WIFI_AP_STATE_FAILED value for soft AP state
* indicates that the latest attempt to start soft AP has failed. Caller can unregister a
* previously registered callback using {@link unregisterSoftApCallback}
* <p>
* Applications should have the
* {@link android.Manifest.permission#NETWORK_SETTINGS NETWORK_SETTINGS} permission. Callers
* without the permission will trigger a {@link java.lang.SecurityException}.
* <p>
*
* @param callback Callback for soft AP events
* @param handler The Handler on whose thread to execute the callbacks of the {@code callback}
* object. If null, then the application's main thread will be used.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void registerSoftApCallback(@NonNull SoftApCallback callback,
@Nullable Handler handler) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "registerSoftApCallback: callback=" + callback + ", handler=" + handler);
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.registerSoftApCallback(binder, new SoftApCallbackProxy(looper, callback),
callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Allow callers to unregister a previously registered callback. After calling this method,
* applications will no longer receive soft AP events.
*
* @param callback Callback to unregister for soft AP events
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void unregisterSoftApCallback(@NonNull SoftApCallback callback) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "unregisterSoftApCallback: callback=" + callback);
try {
mService.unregisterSoftApCallback(callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* LocalOnlyHotspotReservation that contains the {@link WifiConfiguration} for the active
* LocalOnlyHotspot request.
* <p>
* Applications requesting LocalOnlyHotspot for sharing will receive an instance of the
* LocalOnlyHotspotReservation in the
* {@link LocalOnlyHotspotCallback#onStarted(LocalOnlyHotspotReservation)} call. This
* reservation contains the relevant {@link WifiConfiguration}.
* When an application is done with the LocalOnlyHotspot, they should call {@link
* LocalOnlyHotspotReservation#close()}. Once this happens, the application will not receive
* any further callbacks. If the LocalOnlyHotspot is stopped due to a
* user triggered mode change, applications will be notified via the {@link
* LocalOnlyHotspotCallback#onStopped()} callback.
*/
public class LocalOnlyHotspotReservation implements AutoCloseable {
private final CloseGuard mCloseGuard = CloseGuard.get();
private final WifiConfiguration mConfig;
/** @hide */
@VisibleForTesting
public LocalOnlyHotspotReservation(WifiConfiguration config) {
mConfig = config;
mCloseGuard.open("close");
}
public WifiConfiguration getWifiConfiguration() {
return mConfig;
}
@Override
public void close() {
try {
stopLocalOnlyHotspot();
mCloseGuard.close();
} catch (Exception e) {
Log.e(TAG, "Failed to stop Local Only Hotspot.");
}
}
@Override
protected void finalize() throws Throwable {
try {
if (mCloseGuard != null) {
mCloseGuard.warnIfOpen();
}
close();
} finally {
super.finalize();
}
}
}
/**
* Callback class for applications to receive updates about the LocalOnlyHotspot status.
*/
public static class LocalOnlyHotspotCallback {
/** @hide */
public static final int REQUEST_REGISTERED = 0;
public static final int ERROR_NO_CHANNEL = 1;
public static final int ERROR_GENERIC = 2;
public static final int ERROR_INCOMPATIBLE_MODE = 3;
public static final int ERROR_TETHERING_DISALLOWED = 4;
/** LocalOnlyHotspot start succeeded. */
public void onStarted(LocalOnlyHotspotReservation reservation) {};
/**
* LocalOnlyHotspot stopped.
* <p>
* The LocalOnlyHotspot can be disabled at any time by the user. When this happens,
* applications will be notified that it was stopped. This will not be invoked when an
* application calls {@link LocalOnlyHotspotReservation#close()}.
*/
public void onStopped() {};
/**
* LocalOnlyHotspot failed to start.
* <p>
* Applications can attempt to call
* {@link WifiManager#startLocalOnlyHotspot(LocalOnlyHotspotCallback, Handler)} again at
* a later time.
* <p>
* @param reason The reason for failure could be one of: {@link
* #ERROR_TETHERING_DISALLOWED}, {@link #ERROR_INCOMPATIBLE_MODE},
* {@link #ERROR_NO_CHANNEL}, or {@link #ERROR_GENERIC}.
*/
public void onFailed(int reason) { };
}
/**
* Callback proxy for LocalOnlyHotspotCallback objects.
*/
private static class LocalOnlyHotspotCallbackProxy {
private final Handler mHandler;
private final WeakReference<WifiManager> mWifiManager;
private final Looper mLooper;
private final Messenger mMessenger;
/**
* Constructs a {@link LocalOnlyHotspotCallback} using the specified looper. All callbacks
* will be delivered on the thread of the specified looper.
*
* @param manager WifiManager
* @param looper Looper for delivering callbacks
* @param callback LocalOnlyHotspotCallback to notify the calling application.
*/
LocalOnlyHotspotCallbackProxy(WifiManager manager, Looper looper,
final LocalOnlyHotspotCallback callback) {
mWifiManager = new WeakReference<>(manager);
mLooper = looper;
mHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
Log.d(TAG, "LocalOnlyHotspotCallbackProxy: handle message what: "
+ msg.what + " msg: " + msg);
WifiManager manager = mWifiManager.get();
if (manager == null) {
Log.w(TAG, "LocalOnlyHotspotCallbackProxy: handle message post GC");
return;
}
switch (msg.what) {
case HOTSPOT_STARTED:
WifiConfiguration config = (WifiConfiguration) msg.obj;
if (config == null) {
Log.e(TAG, "LocalOnlyHotspotCallbackProxy: config cannot be null.");
callback.onFailed(LocalOnlyHotspotCallback.ERROR_GENERIC);
return;
}
callback.onStarted(manager.new LocalOnlyHotspotReservation(config));
break;
case HOTSPOT_STOPPED:
Log.w(TAG, "LocalOnlyHotspotCallbackProxy: hotspot stopped");
callback.onStopped();
break;
case HOTSPOT_FAILED:
int reasonCode = msg.arg1;
Log.w(TAG, "LocalOnlyHotspotCallbackProxy: failed to start. reason: "
+ reasonCode);
callback.onFailed(reasonCode);
Log.w(TAG, "done with the callback...");
break;
default:
Log.e(TAG, "LocalOnlyHotspotCallbackProxy unhandled message. type: "
+ msg.what);
}
}
};
mMessenger = new Messenger(mHandler);
}
public Messenger getMessenger() {
return mMessenger;
}
/**
* Helper method allowing the the incoming application call to move the onFailed callback
* over to the desired callback thread.
*
* @param reason int representing the error type
*/
public void notifyFailed(int reason) throws RemoteException {
Message msg = Message.obtain();
msg.what = HOTSPOT_FAILED;
msg.arg1 = reason;
mMessenger.send(msg);
}
}
/**
* LocalOnlyHotspotSubscription that is an AutoCloseable object for tracking applications
* watching for LocalOnlyHotspot changes.
*
* @hide
*/
public class LocalOnlyHotspotSubscription implements AutoCloseable {
private final CloseGuard mCloseGuard = CloseGuard.get();
/** @hide */
@VisibleForTesting
public LocalOnlyHotspotSubscription() {
mCloseGuard.open("close");
}
@Override
public void close() {
try {
unregisterLocalOnlyHotspotObserver();
mCloseGuard.close();
} catch (Exception e) {
Log.e(TAG, "Failed to unregister LocalOnlyHotspotObserver.");
}
}
@Override
protected void finalize() throws Throwable {
try {
if (mCloseGuard != null) {
mCloseGuard.warnIfOpen();
}
close();
} finally {
super.finalize();
}
}
}
/**
* Class to notify calling applications that watch for changes in LocalOnlyHotspot of updates.
*
* @hide
*/
public static class LocalOnlyHotspotObserver {
/**
* Confirm registration for LocalOnlyHotspotChanges by returning a
* LocalOnlyHotspotSubscription.
*/
public void onRegistered(LocalOnlyHotspotSubscription subscription) {};
/**
* LocalOnlyHotspot started with the supplied config.
*/
public void onStarted(WifiConfiguration config) {};
/**
* LocalOnlyHotspot stopped.
*/
public void onStopped() {};
}
/**
* Callback proxy for LocalOnlyHotspotObserver objects.
*/
private static class LocalOnlyHotspotObserverProxy {
private final Handler mHandler;
private final WeakReference<WifiManager> mWifiManager;
private final Looper mLooper;
private final Messenger mMessenger;
/**
* Constructs a {@link LocalOnlyHotspotObserverProxy} using the specified looper.
* All callbacks will be delivered on the thread of the specified looper.
*
* @param manager WifiManager
* @param looper Looper for delivering callbacks
* @param observer LocalOnlyHotspotObserver to notify the calling application.
*/
LocalOnlyHotspotObserverProxy(WifiManager manager, Looper looper,
final LocalOnlyHotspotObserver observer) {
mWifiManager = new WeakReference<>(manager);
mLooper = looper;
mHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
Log.d(TAG, "LocalOnlyHotspotObserverProxy: handle message what: "
+ msg.what + " msg: " + msg);
WifiManager manager = mWifiManager.get();
if (manager == null) {
Log.w(TAG, "LocalOnlyHotspotObserverProxy: handle message post GC");
return;
}
switch (msg.what) {
case HOTSPOT_OBSERVER_REGISTERED:
observer.onRegistered(manager.new LocalOnlyHotspotSubscription());
break;
case HOTSPOT_STARTED:
WifiConfiguration config = (WifiConfiguration) msg.obj;
if (config == null) {
Log.e(TAG, "LocalOnlyHotspotObserverProxy: config cannot be null.");
return;
}
observer.onStarted(config);
break;
case HOTSPOT_STOPPED:
observer.onStopped();
break;
default:
Log.e(TAG, "LocalOnlyHotspotObserverProxy unhandled message. type: "
+ msg.what);
}
}
};
mMessenger = new Messenger(mHandler);
}
public Messenger getMessenger() {
return mMessenger;
}
public void registered() throws RemoteException {
Message msg = Message.obtain();
msg.what = HOTSPOT_OBSERVER_REGISTERED;
mMessenger.send(msg);
}
}
// Ensure that multiple ServiceHandler threads do not interleave message dispatch.
private static final Object sServiceHandlerDispatchLock = new Object();
private class ServiceHandler extends Handler {
ServiceHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message message) {
synchronized (sServiceHandlerDispatchLock) {
dispatchMessageToListeners(message);
}
}
private void dispatchMessageToListeners(Message message) {
Object listener = removeListener(message.arg2);
switch (message.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
if (message.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
mAsyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
} else {
Log.e(TAG, "Failed to set up channel connection");
// This will cause all further async API calls on the WifiManager
// to fail and throw an exception
mAsyncChannel = null;
}
mConnected.countDown();
break;
case AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED:
// Ignore
break;
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
Log.e(TAG, "Channel connection lost");
// This will cause all further async API calls on the WifiManager
// to fail and throw an exception
mAsyncChannel = null;
getLooper().quit();
break;
/* ActionListeners grouped together */
case WifiManager.CONNECT_NETWORK_FAILED:
case WifiManager.FORGET_NETWORK_FAILED:
case WifiManager.SAVE_NETWORK_FAILED:
case WifiManager.DISABLE_NETWORK_FAILED:
if (listener != null) {
((ActionListener) listener).onFailure(message.arg1);
}
break;
/* ActionListeners grouped together */
case WifiManager.CONNECT_NETWORK_SUCCEEDED:
case WifiManager.FORGET_NETWORK_SUCCEEDED:
case WifiManager.SAVE_NETWORK_SUCCEEDED:
case WifiManager.DISABLE_NETWORK_SUCCEEDED:
if (listener != null) {
((ActionListener) listener).onSuccess();
}
break;
case WifiManager.RSSI_PKTCNT_FETCH_SUCCEEDED:
if (listener != null) {
RssiPacketCountInfo info = (RssiPacketCountInfo) message.obj;
if (info != null)
((TxPacketCountListener) listener).onSuccess(info.txgood + info.txbad);
else
((TxPacketCountListener) listener).onFailure(ERROR);
}
break;
case WifiManager.RSSI_PKTCNT_FETCH_FAILED:
if (listener != null) {
((TxPacketCountListener) listener).onFailure(message.arg1);
}
break;
default:
//ignore
break;
}
}
}
private int putListener(Object listener) {
if (listener == null) return INVALID_KEY;
int key;
synchronized (mListenerMapLock) {
do {
key = mListenerKey++;
} while (key == INVALID_KEY);
mListenerMap.put(key, listener);
}
return key;
}
private Object removeListener(int key) {
if (key == INVALID_KEY) return null;
synchronized (mListenerMapLock) {
Object listener = mListenerMap.get(key);
mListenerMap.remove(key);
return listener;
}
}
private synchronized AsyncChannel getChannel() {
if (mAsyncChannel == null) {
Messenger messenger = getWifiServiceMessenger();
if (messenger == null) {
throw new IllegalStateException(
"getWifiServiceMessenger() returned null! This is invalid.");
}
mAsyncChannel = new AsyncChannel();
mConnected = new CountDownLatch(1);
Handler handler = new ServiceHandler(mLooper);
mAsyncChannel.connect(mContext, handler, messenger);
try {
mConnected.await();
} catch (InterruptedException e) {
Log.e(TAG, "interrupted wait at init");
}
}
return mAsyncChannel;
}
/**
* Connect to a network with the given configuration. The network also
* gets added to the list of configured networks for the foreground user.
*
* For a new network, this function is used instead of a
* sequence of addNetwork(), enableNetwork(), and reconnect()
*
* @param config the set of variables that describe the configuration,
* contained in a {@link WifiConfiguration} object.
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be
* initialized again
*
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD,
android.Manifest.permission.NETWORK_STACK
})
public void connect(WifiConfiguration config, ActionListener listener) {
if (config == null) throw new IllegalArgumentException("config cannot be null");
// Use INVALID_NETWORK_ID for arg1 when passing a config object
// arg1 is used to pass network id when the network already exists
getChannel().sendMessage(CONNECT_NETWORK, WifiConfiguration.INVALID_NETWORK_ID,
putListener(listener), config);
}
/**
* Connect to a network with the given networkId.
*
* This function is used instead of a enableNetwork() and reconnect()
*
* @param networkId the ID of the network as returned by {@link #addNetwork} or {@link
* getConfiguredNetworks}.
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be
* initialized again
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD,
android.Manifest.permission.NETWORK_STACK
})
public void connect(int networkId, ActionListener listener) {
if (networkId < 0) throw new IllegalArgumentException("Network id cannot be negative");
getChannel().sendMessage(CONNECT_NETWORK, networkId, putListener(listener));
}
/**
* Save the given network to the list of configured networks for the
* foreground user. If the network already exists, the configuration
* is updated. Any new network is enabled by default.
*
* For a new network, this function is used instead of a
* sequence of addNetwork() and enableNetwork().
*
* For an existing network, it accomplishes the task of updateNetwork()
*
* This API will cause reconnect if the crecdentials of the current active
* connection has been changed.
*
* @param config the set of variables that describe the configuration,
* contained in a {@link WifiConfiguration} object.
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be
* initialized again
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD,
android.Manifest.permission.NETWORK_STACK
})
public void save(WifiConfiguration config, ActionListener listener) {
if (config == null) throw new IllegalArgumentException("config cannot be null");
getChannel().sendMessage(SAVE_NETWORK, 0, putListener(listener), config);
}
/**
* Delete the network from the list of configured networks for the
* foreground user.
*
* This function is used instead of a sequence of removeNetwork()
*
* @param config the set of variables that describe the configuration,
* contained in a {@link WifiConfiguration} object.
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be
* initialized again
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD,
android.Manifest.permission.NETWORK_STACK
})
public void forget(int netId, ActionListener listener) {
if (netId < 0) throw new IllegalArgumentException("Network id cannot be negative");
getChannel().sendMessage(FORGET_NETWORK, netId, putListener(listener));
}
/**
* Disable network
*
* @param netId is the network Id
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be
* initialized again
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD,
android.Manifest.permission.NETWORK_STACK
})
public void disable(int netId, ActionListener listener) {
if (netId < 0) throw new IllegalArgumentException("Network id cannot be negative");
getChannel().sendMessage(DISABLE_NETWORK, netId, putListener(listener));
}
/**
* Disable ephemeral Network
*
* @param SSID, in the format of WifiConfiguration's SSID.
* @hide
*/
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_STACK
})
public void disableEphemeralNetwork(String SSID) {
if (SSID == null) throw new IllegalArgumentException("SSID cannot be null");
try {
mService.disableEphemeralNetwork(SSID, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* WPS suport has been deprecated from Client mode and this method will immediately trigger
* {@link WpsCallback#onFailed(int)} with a generic error.
*
* @param config WPS configuration (does not support {@link WpsInfo#LABEL})
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be initialized again
* @deprecated This API is deprecated
*/
public void startWps(WpsInfo config, WpsCallback listener) {
if (listener != null ) {
listener.onFailed(ERROR);
}
}
/**
* WPS support has been deprecated from Client mode and this method will immediately trigger
* {@link WpsCallback#onFailed(int)} with a generic error.
*
* @param listener for callbacks on success or failure. Can be null.
* @throws IllegalStateException if the WifiManager instance needs to be initialized again
* @deprecated This API is deprecated
*/
public void cancelWps(WpsCallback listener) {
if (listener != null) {
listener.onFailed(ERROR);
}
}
/**
* Get a reference to WifiService handler. This is used by a client to establish
* an AsyncChannel communication with WifiService
*
* @return Messenger pointing to the WifiService handler
*/
@UnsupportedAppUsage
private Messenger getWifiServiceMessenger() {
try {
return mService.getWifiServiceMessenger(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Allows an application to keep the Wi-Fi radio awake.
* Normally the Wi-Fi radio may turn off when the user has not used the device in a while.
* Acquiring a WifiLock will keep the radio on until the lock is released. Multiple
* applications may hold WifiLocks, and the radio will only be allowed to turn off when no
* WifiLocks are held in any application.
* <p>
* Before using a WifiLock, consider carefully if your application requires Wi-Fi access, or
* could function over a mobile network, if available. A program that needs to download large
* files should hold a WifiLock to ensure that the download will complete, but a program whose
* network usage is occasional or low-bandwidth should not hold a WifiLock to avoid adversely
* affecting battery life.
* <p>
* Note that WifiLocks cannot override the user-level "Wi-Fi Enabled" setting, nor Airplane
* Mode. They simply keep the radio from turning off when Wi-Fi is already on but the device
* is idle.
* <p>
* Any application using a WifiLock must request the {@code android.permission.WAKE_LOCK}
* permission in an {@code <uses-permission>} element of the application's manifest.
*/
public class WifiLock {
private String mTag;
private final IBinder mBinder;
private int mRefCount;
int mLockType;
private boolean mRefCounted;
private boolean mHeld;
private WorkSource mWorkSource;
private WifiLock(int lockType, String tag) {
mTag = tag;
mLockType = lockType;
mBinder = new Binder();
mRefCount = 0;
mRefCounted = true;
mHeld = false;
}
/**
* Locks the Wi-Fi radio on until {@link #release} is called.
*
* If this WifiLock is reference-counted, each call to {@code acquire} will increment the
* reference count, and the radio will remain locked as long as the reference count is
* above zero.
*
* If this WifiLock is not reference-counted, the first call to {@code acquire} will lock
* the radio, but subsequent calls will be ignored. Only one call to {@link #release}
* will be required, regardless of the number of times that {@code acquire} is called.
*/
public void acquire() {
synchronized (mBinder) {
if (mRefCounted ? (++mRefCount == 1) : (!mHeld)) {
try {
mService.acquireWifiLock(mBinder, mLockType, mTag, mWorkSource);
synchronized (WifiManager.this) {
if (mActiveLockCount >= MAX_ACTIVE_LOCKS) {
mService.releaseWifiLock(mBinder);
throw new UnsupportedOperationException(
"Exceeded maximum number of wifi locks");
}
mActiveLockCount++;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
mHeld = true;
}
}
}
/**
* Unlocks the Wi-Fi radio, allowing it to turn off when the device is idle.
*
* If this WifiLock is reference-counted, each call to {@code release} will decrement the
* reference count, and the radio will be unlocked only when the reference count reaches
* zero. If the reference count goes below zero (that is, if {@code release} is called
* a greater number of times than {@link #acquire}), an exception is thrown.
*
* If this WifiLock is not reference-counted, the first call to {@code release} (after
* the radio was locked using {@link #acquire}) will unlock the radio, and subsequent
* calls will be ignored.
*/
public void release() {
synchronized (mBinder) {
if (mRefCounted ? (--mRefCount == 0) : (mHeld)) {
try {
mService.releaseWifiLock(mBinder);
synchronized (WifiManager.this) {
mActiveLockCount--;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
mHeld = false;
}
if (mRefCount < 0) {
throw new RuntimeException("WifiLock under-locked " + mTag);
}
}
}
/**
* Controls whether this is a reference-counted or non-reference-counted WifiLock.
*
* Reference-counted WifiLocks keep track of the number of calls to {@link #acquire} and
* {@link #release}, and only allow the radio to sleep when every call to {@link #acquire}
* has been balanced with a call to {@link #release}. Non-reference-counted WifiLocks
* lock the radio whenever {@link #acquire} is called and it is unlocked, and unlock the
* radio whenever {@link #release} is called and it is locked.
*
* @param refCounted true if this WifiLock should keep a reference count
*/
public void setReferenceCounted(boolean refCounted) {
mRefCounted = refCounted;
}
/**
* Checks whether this WifiLock is currently held.
*
* @return true if this WifiLock is held, false otherwise
*/
public boolean isHeld() {
synchronized (mBinder) {
return mHeld;
}
}
public void setWorkSource(WorkSource ws) {
synchronized (mBinder) {
if (ws != null && ws.isEmpty()) {
ws = null;
}
boolean changed = true;
if (ws == null) {
mWorkSource = null;
} else {
ws.clearNames();
if (mWorkSource == null) {
changed = mWorkSource != null;
mWorkSource = new WorkSource(ws);
} else {
changed = !mWorkSource.equals(ws);
if (changed) {
mWorkSource.set(ws);
}
}
}
if (changed && mHeld) {
try {
mService.updateWifiLockWorkSource(mBinder, mWorkSource);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
public String toString() {
String s1, s2, s3;
synchronized (mBinder) {
s1 = Integer.toHexString(System.identityHashCode(this));
s2 = mHeld ? "held; " : "";
if (mRefCounted) {
s3 = "refcounted: refcount = " + mRefCount;
} else {
s3 = "not refcounted";
}
return "WifiLock{ " + s1 + "; " + s2 + s3 + " }";
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
synchronized (mBinder) {
if (mHeld) {
try {
mService.releaseWifiLock(mBinder);
synchronized (WifiManager.this) {
mActiveLockCount--;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
}
/**
* Creates a new WifiLock.
*
* @param lockType the type of lock to create. See {@link #WIFI_MODE_FULL_HIGH_PERF}
* and {@link #WIFI_MODE_FULL_LOW_LATENCY} for descriptions of the types of Wi-Fi locks.
* @param tag a tag for the WifiLock to identify it in debugging messages. This string is
* never shown to the user under normal conditions, but should be descriptive
* enough to identify your application and the specific WifiLock within it, if it
* holds multiple WifiLocks.
*
* @return a new, unacquired WifiLock with the given tag.
*
* @see WifiLock
*/
public WifiLock createWifiLock(int lockType, String tag) {
return new WifiLock(lockType, tag);
}
/**
* Creates a new WifiLock.
*
* @param tag a tag for the WifiLock to identify it in debugging messages. This string is
* never shown to the user under normal conditions, but should be descriptive
* enough to identify your application and the specific WifiLock within it, if it
* holds multiple WifiLocks.
*
* @return a new, unacquired WifiLock with the given tag.
*
* @see WifiLock
*
* @deprecated This API is non-functional.
*/
@Deprecated
public WifiLock createWifiLock(String tag) {
return new WifiLock(WIFI_MODE_FULL, tag);
}
/**
* Create a new MulticastLock
*
* @param tag a tag for the MulticastLock to identify it in debugging
* messages. This string is never shown to the user under
* normal conditions, but should be descriptive enough to
* identify your application and the specific MulticastLock
* within it, if it holds multiple MulticastLocks.
*
* @return a new, unacquired MulticastLock with the given tag.
*
* @see MulticastLock
*/
public MulticastLock createMulticastLock(String tag) {
return new MulticastLock(tag);
}
/**
* Allows an application to receive Wifi Multicast packets.
* Normally the Wifi stack filters out packets not explicitly
* addressed to this device. Acquring a MulticastLock will
* cause the stack to receive packets addressed to multicast
* addresses. Processing these extra packets can cause a noticeable
* battery drain and should be disabled when not needed.
*/
public class MulticastLock {
private String mTag;
private final IBinder mBinder;
private int mRefCount;
private boolean mRefCounted;
private boolean mHeld;
private MulticastLock(String tag) {
mTag = tag;
mBinder = new Binder();
mRefCount = 0;
mRefCounted = true;
mHeld = false;
}
/**
* Locks Wifi Multicast on until {@link #release} is called.
*
* If this MulticastLock is reference-counted each call to
* {@code acquire} will increment the reference count, and the
* wifi interface will receive multicast packets as long as the
* reference count is above zero.
*
* If this MulticastLock is not reference-counted, the first call to
* {@code acquire} will turn on the multicast packets, but subsequent
* calls will be ignored. Only one call to {@link #release} will
* be required, regardless of the number of times that {@code acquire}
* is called.
*
* Note that other applications may also lock Wifi Multicast on.
* Only they can relinquish their lock.
*
* Also note that applications cannot leave Multicast locked on.
* When an app exits or crashes, any Multicast locks will be released.
*/
public void acquire() {
synchronized (mBinder) {
if (mRefCounted ? (++mRefCount == 1) : (!mHeld)) {
try {
mService.acquireMulticastLock(mBinder, mTag);
synchronized (WifiManager.this) {
if (mActiveLockCount >= MAX_ACTIVE_LOCKS) {
mService.releaseMulticastLock(mTag);
throw new UnsupportedOperationException(
"Exceeded maximum number of wifi locks");
}
mActiveLockCount++;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
mHeld = true;
}
}
}
/**
* Unlocks Wifi Multicast, restoring the filter of packets
* not addressed specifically to this device and saving power.
*
* If this MulticastLock is reference-counted, each call to
* {@code release} will decrement the reference count, and the
* multicast packets will only stop being received when the reference
* count reaches zero. If the reference count goes below zero (that
* is, if {@code release} is called a greater number of times than
* {@link #acquire}), an exception is thrown.
*
* If this MulticastLock is not reference-counted, the first call to
* {@code release} (after the radio was multicast locked using
* {@link #acquire}) will unlock the multicast, and subsequent calls
* will be ignored.
*
* Note that if any other Wifi Multicast Locks are still outstanding
* this {@code release} call will not have an immediate effect. Only
* when all applications have released all their Multicast Locks will
* the Multicast filter be turned back on.
*
* Also note that when an app exits or crashes all of its Multicast
* Locks will be automatically released.
*/
public void release() {
synchronized (mBinder) {
if (mRefCounted ? (--mRefCount == 0) : (mHeld)) {
try {
mService.releaseMulticastLock(mTag);
synchronized (WifiManager.this) {
mActiveLockCount--;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
mHeld = false;
}
if (mRefCount < 0) {
throw new RuntimeException("MulticastLock under-locked "
+ mTag);
}
}
}
/**
* Controls whether this is a reference-counted or non-reference-
* counted MulticastLock.
*
* Reference-counted MulticastLocks keep track of the number of calls
* to {@link #acquire} and {@link #release}, and only stop the
* reception of multicast packets when every call to {@link #acquire}
* has been balanced with a call to {@link #release}. Non-reference-
* counted MulticastLocks allow the reception of multicast packets
* whenever {@link #acquire} is called and stop accepting multicast
* packets whenever {@link #release} is called.
*
* @param refCounted true if this MulticastLock should keep a reference
* count
*/
public void setReferenceCounted(boolean refCounted) {
mRefCounted = refCounted;
}
/**
* Checks whether this MulticastLock is currently held.
*
* @return true if this MulticastLock is held, false otherwise
*/
public boolean isHeld() {
synchronized (mBinder) {
return mHeld;
}
}
public String toString() {
String s1, s2, s3;
synchronized (mBinder) {
s1 = Integer.toHexString(System.identityHashCode(this));
s2 = mHeld ? "held; " : "";
if (mRefCounted) {
s3 = "refcounted: refcount = " + mRefCount;
} else {
s3 = "not refcounted";
}
return "MulticastLock{ " + s1 + "; " + s2 + s3 + " }";
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
setReferenceCounted(false);
release();
}
}
/**
* Check multicast filter status.
*
* @return true if multicast packets are allowed.
*
* @hide pending API council approval
*/
public boolean isMulticastEnabled() {
try {
return mService.isMulticastEnabled();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Initialize the multicast filtering to 'on'
* @hide no intent to publish
*/
@UnsupportedAppUsage
public boolean initializeMulticastFiltering() {
try {
mService.initializeMulticastFiltering();
return true;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
protected void finalize() throws Throwable {
try {
if (mAsyncChannel != null) {
mAsyncChannel.disconnect();
}
} finally {
super.finalize();
}
}
/**
* Set wifi verbose log. Called from developer settings.
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
@UnsupportedAppUsage
public void enableVerboseLogging (int verbose) {
try {
mService.enableVerboseLogging(verbose);
} catch (Exception e) {
//ignore any failure here
Log.e(TAG, "enableVerboseLogging " + e.toString());
}
}
/**
* Get the WiFi verbose logging level.This is used by settings
* to decide what to show within the picker.
* @hide
*/
@UnsupportedAppUsage
public int getVerboseLoggingLevel() {
try {
return mService.getVerboseLoggingLevel();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Removes all saved wifi networks.
*
* @hide
*/
public void factoryReset() {
try {
mService.factoryReset(mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Get Network object of current wifi network
* @return Get Network object of current wifi network
* @hide
*/
@UnsupportedAppUsage
public Network getCurrentNetwork() {
try {
return mService.getCurrentNetwork();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Deprecated
* returns false
* @hide
* @deprecated
*/
public boolean setEnableAutoJoinWhenAssociated(boolean enabled) {
return false;
}
/**
* Deprecated
* returns false
* @hide
* @deprecated
*/
public boolean getEnableAutoJoinWhenAssociated() {
return false;
}
/**
* Enable/disable WifiConnectivityManager
* @hide
*/
public void enableWifiConnectivityManager(boolean enabled) {
try {
mService.enableWifiConnectivityManager(enabled);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve the data to be backed to save the current state.
* @hide
*/
public byte[] retrieveBackupData() {
try {
return mService.retrieveBackupData();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Restore state from the backed up data.
* @hide
*/
public void restoreBackupData(byte[] data) {
try {
mService.restoreBackupData(data);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Restore state from the older version of back up data.
* The old backup data was essentially a backup of wpa_supplicant.conf
* and ipconfig.txt file.
* @deprecated this is no longer supported.
* @hide
*/
@Deprecated
public void restoreSupplicantBackupData(byte[] supplicantData, byte[] ipConfigData) {
try {
mService.restoreSupplicantBackupData(supplicantData, ipConfigData);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start subscription provisioning flow
* @param provider {@link OsuProvider} to provision with
* @param callback {@link ProvisioningCallback} for updates regarding provisioning flow
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD
})
public void startSubscriptionProvisioning(OsuProvider provider, ProvisioningCallback callback,
@Nullable Handler handler) {
Looper looper = (handler == null) ? Looper.getMainLooper() : handler.getLooper();
try {
mService.startSubscriptionProvisioning(provider,
new ProvisioningCallbackProxy(looper, callback));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private static class ProvisioningCallbackProxy extends IProvisioningCallback.Stub {
private final Handler mHandler;
private final ProvisioningCallback mCallback;
ProvisioningCallbackProxy(Looper looper, ProvisioningCallback callback) {
mHandler = new Handler(looper);
mCallback = callback;
}
@Override
public void onProvisioningStatus(int status) {
mHandler.post(() -> {
mCallback.onProvisioningStatus(status);
});
}
@Override
public void onProvisioningFailure(int status) {
mHandler.post(() -> {
mCallback.onProvisioningFailure(status);
});
}
@Override
public void onProvisioningComplete() {
mHandler.post(() -> {
mCallback.onProvisioningComplete();
});
}
}
/**
* Base class for Traffic state callback. Should be extended by applications and set when
* calling {@link WifiManager#registerTrafficStateCallback(TrafficStateCallback, Handler)}.
* @hide
*/
public interface TrafficStateCallback {
/**
* Lowest bit indicates data reception and the second lowest
* bit indicates data transmitted
*/
/** @hide */
int DATA_ACTIVITY_NONE = 0x00;
/** @hide */
int DATA_ACTIVITY_IN = 0x01;
/** @hide */
int DATA_ACTIVITY_OUT = 0x02;
/** @hide */
int DATA_ACTIVITY_INOUT = 0x03;
/**
* Callback invoked to inform clients about the current traffic state.
*
* @param state One of the values: {@link #DATA_ACTIVITY_NONE}, {@link #DATA_ACTIVITY_IN},
* {@link #DATA_ACTIVITY_OUT} & {@link #DATA_ACTIVITY_INOUT}.
* @hide
*/
void onStateChanged(int state);
}
/**
* Callback proxy for TrafficStateCallback objects.
*
* @hide
*/
private class TrafficStateCallbackProxy extends ITrafficStateCallback.Stub {
private final Handler mHandler;
private final TrafficStateCallback mCallback;
TrafficStateCallbackProxy(Looper looper, TrafficStateCallback callback) {
mHandler = new Handler(looper);
mCallback = callback;
}
@Override
public void onStateChanged(int state) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "TrafficStateCallbackProxy: onStateChanged state=" + state);
}
mHandler.post(() -> {
mCallback.onStateChanged(state);
});
}
}
/**
* Registers a callback for monitoring traffic state. See {@link TrafficStateCallback}. These
* callbacks will be invoked periodically by platform to inform clients about the current
* traffic state. Caller can unregister a previously registered callback using
* {@link #unregisterTrafficStateCallback(TrafficStateCallback)}
* <p>
* Applications should have the
* {@link android.Manifest.permission#NETWORK_SETTINGS NETWORK_SETTINGS} permission. Callers
* without the permission will trigger a {@link java.lang.SecurityException}.
* <p>
*
* @param callback Callback for traffic state events
* @param handler The Handler on whose thread to execute the callbacks of the {@code callback}
* object. If null, then the application's main thread will be used.
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void registerTrafficStateCallback(@NonNull TrafficStateCallback callback,
@Nullable Handler handler) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "registerTrafficStateCallback: callback=" + callback + ", handler=" + handler);
Looper looper = (handler == null) ? mContext.getMainLooper() : handler.getLooper();
Binder binder = new Binder();
try {
mService.registerTrafficStateCallback(
binder, new TrafficStateCallbackProxy(looper, callback), callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Allow callers to unregister a previously registered callback. After calling this method,
* applications will no longer receive traffic state notifications.
*
* @param callback Callback to unregister for traffic state events
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public void unregisterTrafficStateCallback(@NonNull TrafficStateCallback callback) {
if (callback == null) throw new IllegalArgumentException("callback cannot be null");
Log.v(TAG, "unregisterTrafficStateCallback: callback=" + callback);
try {
mService.unregisterTrafficStateCallback(callback.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Helper method to update the local verbose logging flag based on the verbose logging
* level from wifi service.
*/
private void updateVerboseLoggingEnabledFromService() {
mVerboseLoggingEnabled = getVerboseLoggingLevel() > 0;
}
/**
* Get driver Capabilities.
*
* @param capaType ASCII string, capability type ex: key_mgmt.
* @return String of capabilities from driver for type capaParameter.
* {@hide}
*/
public String getCapabilities(String capaType) {
try {
return mService.getCapabilities(capaType);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Add the DPP bootstrap info obtained from QR code.
*
* @param uri:The URI obtained from the QR code reader.
*
* @return: Handle to strored info else -1 on failure
* @hide
*/
public int dppAddBootstrapQrCode(String uri) {
try {
return mService.dppAddBootstrapQrCode(uri);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Generate bootstrap URI based on the passed arguments
*
* @param config – bootstrap generate config, mandatory parameters
* are: type, frequency, mac_addr, curve, key.
*
* @return: Handle to strored URI info else -1 on failure
* @hide
*/
public int dppBootstrapGenerate(WifiDppConfig config) {
try {
return mService.dppBootstrapGenerate(config);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Get bootstrap URI based on bootstrap ID
*
* @param bootstrap_id: Stored bootstrap ID
*
* @return: URI string else -1 on failure
* @hide
*/
public String dppGetUri(int bootstrap_id) {
try {
return mService.dppGetUri(bootstrap_id);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Remove bootstrap URI based on bootstrap ID.
*
* @param bootstrap_id: Stored bootstrap ID. 0 to remove all.
*
* @return: 0 – Success or -1 on failure
* @hide
*/
public int dppBootstrapRemove(int bootstrap_id) {
try {
return mService.dppBootstrapRemove(bootstrap_id);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* start listen on the channel specified waiting to receive
* the DPP Authentication request.
*
* @param frequency: DPP listen frequency
* @param dpp_role: Configurator/Enrollee role
* @param qr_mutual: Mutual authentication required
* @param netrole_ap: network role
*
* @return: Returns 0 if a DPP-listen work is successfully
* queued and -1 on failure.
* @hide
*/
public int dppListen(String frequency, int dpp_role, boolean qr_mutual,
boolean netrole_ap) {
try {
return mService.dppListen(frequency, dpp_role, qr_mutual, netrole_ap);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* stop ongoing dpp listen.
*
* @hide
*/
public void dppStopListen() {
try {
mService.dppStopListen();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Adds the DPP configurator
*
* @param curve curve used for dpp encryption
* @param key private key
* @param expiry timeout in seconds
*
* @return: Identifier of the added configurator or -1 on failure
* @hide
*/
public int dppConfiguratorAdd(String curve, String key, int expiry) {
try {
return mService.dppConfiguratorAdd(curve, key, expiry);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Remove the added configurator through dppConfiguratorAdd.
*
* @param config_id: DPP Configurator ID. 0 to remove all.
*
* @return: Handle to strored info else -1 on failure
* @hide
*/
public int dppConfiguratorRemove(int config_id) {
try {
return mService.dppConfiguratorRemove(config_id);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start DPP authentication and provisioning with the specified peer
*
* @param config – dpp auth init config mandatory parameters
* are: peer_bootstrap_id, own_bootstrap_id, dpp_role,
* ssid, passphrase, isDpp, conf_id, expiry.
*
* @return: 0 if DPP auth request was transmitted and -1 on failure
* @hide
*/
public int dppStartAuth(WifiDppConfig config) {
try {
return mService.dppStartAuth(config);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve Private key to be used for configurator
*
* @param id: id of configurator
*
* @return: KEY string else -1 on failure
* @hide
*/
public String dppConfiguratorGetKey(int id) {
try {
return mService.dppConfiguratorGetKey(id);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @return true if this device supports WPA3-Personal SAE
*/
public boolean isWpa3SaeSupported() {
return isFeatureSupported(WIFI_FEATURE_WPA3_SAE);
}
/**
* @return true if this device supports WPA3-Enterprise Suite-B-192
*/
public boolean isWpa3SuiteBSupported() {
return isFeatureSupported(WIFI_FEATURE_WPA3_SUITE_B);
}
/**
* @return true if this device supports Wi-Fi Enhanced Open (OWE)
*/
public boolean isOweSupported() {
return isFeatureSupported(WIFI_FEATURE_OWE);
}
/**
* Wi-Fi Easy Connect (DPP) introduces standardized mechanisms to simplify the provisioning and
* configuration of Wi-Fi devices.
* For more details, visit <a href="https://www.wi-fi.org/">https://www.wi-fi.org/</a> and
* search for "Easy Connect" or "Device Provisioning Protocol specification".
*
* @return true if this device supports Wi-Fi Easy-connect (Device Provisioning Protocol)
*/
public boolean isEasyConnectSupported() {
return isFeatureSupported(WIFI_FEATURE_DPP);
}
/**
* Gets the factory Wi-Fi MAC addresses.
* @return Array of String representing Wi-Fi MAC addresses sorted lexically or an empty Array
* if failed.
* @hide
*/
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
public String[] getFactoryMacAddresses() {
try {
return mService.getFactoryMacAddresses();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"DEVICE_MOBILITY_STATE_"}, value = {
DEVICE_MOBILITY_STATE_UNKNOWN,
DEVICE_MOBILITY_STATE_HIGH_MVMT,
DEVICE_MOBILITY_STATE_LOW_MVMT,
DEVICE_MOBILITY_STATE_STATIONARY})
public @interface DeviceMobilityState {}
/**
* Unknown device mobility state
*
* @see #setDeviceMobilityState(int)
*
* @hide
*/
@SystemApi
public static final int DEVICE_MOBILITY_STATE_UNKNOWN = 0;
/**
* High movement device mobility state
*
* @see #setDeviceMobilityState(int)
*
* @hide
*/
@SystemApi
public static final int DEVICE_MOBILITY_STATE_HIGH_MVMT = 1;
/**
* Low movement device mobility state
*
* @see #setDeviceMobilityState(int)
*
* @hide
*/
@SystemApi
public static final int DEVICE_MOBILITY_STATE_LOW_MVMT = 2;
/**
* Stationary device mobility state
*
* @see #setDeviceMobilityState(int)
*
* @hide
*/
@SystemApi
public static final int DEVICE_MOBILITY_STATE_STATIONARY = 3;
/**
* Updates the device mobility state. Wifi uses this information to adjust the interval between
* Wifi scans in order to balance power consumption with scan accuracy.
* @param state the updated device mobility state
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE)
public void setDeviceMobilityState(@DeviceMobilityState int state) {
try {
mService.setDeviceMobilityState(state);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/* Easy Connect - AKA Device Provisioning Protocol (DPP) */
/**
* Easy Connect Network role: Station.
*
* @hide
*/
@SystemApi
public static final int EASY_CONNECT_NETWORK_ROLE_STA = 0;
/**
* Easy Connect Network role: Access Point.
*
* @hide
*/
@SystemApi
public static final int EASY_CONNECT_NETWORK_ROLE_AP = 1;
/** @hide */
@IntDef(prefix = {"EASY_CONNECT_NETWORK_ROLE_"}, value = {
EASY_CONNECT_NETWORK_ROLE_STA,
EASY_CONNECT_NETWORK_ROLE_AP,
})
@Retention(RetentionPolicy.SOURCE)
public @interface EasyConnectNetworkRole {
}
/**
* Start Easy Connect (DPP) in Configurator-Initiator role. The current device will initiate
* Easy Connect bootstrapping with a peer, and configure the peer with the SSID and password of
* the specified network using the Easy Connect protocol on an encrypted link.
*
* @param enrolleeUri URI of the Enrollee obtained separately (e.g. QR code scanning)
* @param selectedNetworkId Selected network ID to be sent to the peer
* @param enrolleeNetworkRole The network role of the enrollee
* @param callback Callback for status updates
* @param executor The Executor on which to run the callback.
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
public void startEasyConnectAsConfiguratorInitiator(@NonNull String enrolleeUri,
int selectedNetworkId, @EasyConnectNetworkRole int enrolleeNetworkRole,
@NonNull @CallbackExecutor Executor executor,
@NonNull EasyConnectStatusCallback callback) {
Binder binder = new Binder();
try {
mService.startDppAsConfiguratorInitiator(binder, enrolleeUri, selectedNetworkId,
enrolleeNetworkRole, new EasyConnectCallbackProxy(executor, callback));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start Easy Connect (DPP) in Enrollee-Initiator role. The current device will initiate Easy
* Connect bootstrapping with a peer, and receive the SSID and password from the peer
* configurator.
*
* @param configuratorUri URI of the Configurator obtained separately (e.g. QR code scanning)
* @param callback Callback for status updates
* @param executor The Executor on which to run the callback.
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
public void startEasyConnectAsEnrolleeInitiator(@NonNull String configuratorUri,
@NonNull @CallbackExecutor Executor executor,
@NonNull EasyConnectStatusCallback callback) {
Binder binder = new Binder();
try {
mService.startDppAsEnrolleeInitiator(binder, configuratorUri,
new EasyConnectCallbackProxy(executor, callback));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop or abort a current Easy Connect (DPP) session. This call, once processed, will
* terminate any ongoing transaction, and clean up all associated resources. Caller should not
* expect any callbacks once this call is made. However, due to the asynchronous nature of
* this call, a callback may be fired if it was already pending in the queue.
*
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.NETWORK_SETTINGS,
android.Manifest.permission.NETWORK_SETUP_WIZARD})
public void stopEasyConnectSession() {
try {
/* Request lower layers to stop/abort and clear resources */
mService.stopDppSession();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Helper class to support Easy Connect (DPP) callbacks
*
* @hide
*/
@SystemApi
private static class EasyConnectCallbackProxy extends IDppCallback.Stub {
private final Executor mExecutor;
private final EasyConnectStatusCallback mEasyConnectStatusCallback;
EasyConnectCallbackProxy(Executor executor,
EasyConnectStatusCallback easyConnectStatusCallback) {
mExecutor = executor;
mEasyConnectStatusCallback = easyConnectStatusCallback;
}
@Override
public void onSuccessConfigReceived(int newNetworkId) {
Log.d(TAG, "Easy Connect onSuccessConfigReceived callback");
mExecutor.execute(() -> {
mEasyConnectStatusCallback.onEnrolleeSuccess(newNetworkId);
});
}
@Override
public void onSuccess(int status) {
Log.d(TAG, "Easy Connect onSuccess callback");
mExecutor.execute(() -> {
mEasyConnectStatusCallback.onConfiguratorSuccess(status);
});
}
@Override
public void onFailure(int status) {
Log.d(TAG, "Easy Connect onFailure callback");
mExecutor.execute(() -> {
mEasyConnectStatusCallback.onFailure(status);
});
}
@Override
public void onProgress(int status) {
Log.d(TAG, "Easy Connect onProgress callback");
mExecutor.execute(() -> {
mEasyConnectStatusCallback.onProgress(status);
});
}
}
/**
* Interface for Wi-Fi usability statistics listener. Should be implemented by applications and
* set when calling {@link WifiManager#addWifiUsabilityStatsListener(Executor,
* WifiUsabilityStatsListener)}.
*
* @hide
*/
@SystemApi
public interface WifiUsabilityStatsListener {
/**
* Called when Wi-Fi usability statistics is updated.
*
* @param seqNum The sequence number of statistics, used to derive the timing of updated
* Wi-Fi usability statistics, set by framework and incremented by one after
* each update.
* @param isSameBssidAndFreq The flag to indicate whether the BSSID and the frequency of
* network stays the same or not relative to the last update of
* Wi-Fi usability stats.
* @param stats The updated Wi-Fi usability statistics.
*/
void onStatsUpdated(int seqNum, boolean isSameBssidAndFreq,
WifiUsabilityStatsEntry stats);
}
/**
* Adds a listener for Wi-Fi usability statistics. See {@link WifiUsabilityStatsListener}.
* Multiple listeners can be added. Callers will be invoked periodically by framework to
* inform clients about the current Wi-Fi usability statistics. Callers can remove a previously
* added listener using {@link removeWifiUsabilityStatsListener}.
*
* @param executor The executor on which callback will be invoked.
* @param listener Listener for Wifi usability statistics.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE)
public void addWifiUsabilityStatsListener(@NonNull @CallbackExecutor Executor executor,
@NonNull WifiUsabilityStatsListener listener) {
if (executor == null) throw new IllegalArgumentException("executor cannot be null");
if (listener == null) throw new IllegalArgumentException("listener cannot be null");
if (mVerboseLoggingEnabled) {
Log.v(TAG, "addWifiUsabilityStatsListener: listener=" + listener);
}
try {
mService.addWifiUsabilityStatsListener(new Binder(),
new IWifiUsabilityStatsListener.Stub() {
@Override
public void onStatsUpdated(int seqNum, boolean isSameBssidAndFreq,
WifiUsabilityStatsEntry stats) {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "WifiUsabilityStatsListener: onStatsUpdated: seqNum="
+ seqNum);
}
Binder.withCleanCallingIdentity(() ->
executor.execute(() -> listener.onStatsUpdated(seqNum,
isSameBssidAndFreq, stats)));
}
},
listener.hashCode()
);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Allow callers to remove a previously registered listener. After calling this method,
* applications will no longer receive Wi-Fi usability statistics.
*
* @param listener Listener to remove the Wi-Fi usability statistics.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE)
public void removeWifiUsabilityStatsListener(@NonNull WifiUsabilityStatsListener listener) {
if (listener == null) throw new IllegalArgumentException("listener cannot be null");
if (mVerboseLoggingEnabled) {
Log.v(TAG, "removeWifiUsabilityStatsListener: listener=" + listener);
}
try {
mService.removeWifiUsabilityStatsListener(listener.hashCode());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Provide a Wi-Fi usability score information to be recorded (but not acted upon) by the
* framework. The Wi-Fi usability score is derived from {@link WifiUsabilityStatsListener}
* where a score is matched to Wi-Fi usability statistics using the sequence number. The score
* is used to quantify whether Wi-Fi is usable in a future time.
*
* @param seqNum Sequence number of the Wi-Fi usability score.
* @param score The Wi-Fi usability score.
* @param predictionHorizonSec Prediction horizon of the Wi-Fi usability score.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE)
public void updateWifiUsabilityScore(int seqNum, int score, int predictionHorizonSec) {
try {
mService.updateWifiUsabilityScore(seqNum, score, predictionHorizonSec);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
|