Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f608743

Browse files
author
Chris Yang
authored
[Connectivity] wifi removal (#3173)
1 parent 4d7de6c commit f608743

File tree

17 files changed

+78
-660
lines changed

17 files changed

+78
-660
lines changed

packages/connectivity/connectivity/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 2.0.0
2+
3+
* [Breaking Change] The `getWifiName`, `getWifiBSSID` and `getWifiIP` are removed to [wifi_info_flutter](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter)
4+
* Migration guide:
5+
6+
If you don't use any of the above APIs, your code should work as is. In addition, you can also remove `NSLocationAlwaysAndWhenInUseUsageDescription` and `NSLocationWhenInUseUsageDescription` in `ios/Runner/Info.plist`
7+
8+
If you use any of the above APIs, you can find the same APIs in the [wifi_info_flutter](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter) plugin.
9+
For example, to migrate `getWifiName`, use the new plugin:
10+
```dart
11+
final WifiInfo _wifiInfo = WifiInfo();
12+
final String wifiName = await _wifiInfo.getWifiName();
13+
```
14+
115
## 1.0.0
216

317
* Mark wifi related code deprecated.

packages/connectivity/connectivity/README.md

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ This plugin works for iOS and Android.
77
> Note that on Android, this does not guarantee connection to Internet. For instance,
88
the app might have wifi access but it might be a VPN or a hotel WiFi with no access.
99

10-
**Please set your constraint to `connectivity: '>=0.4.y+x <2.0.0'`**
11-
12-
## Backward compatible 1.0.0 version is coming
13-
The plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.4.y+z`.
14-
Please use `connectivity: '>=0.4.y+x <2.0.0'` as your dependency constraint to allow a smoother ecosystem migration.
15-
For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
16-
1710
## Usage
1811

1912
Sample usage to check current status:
@@ -59,58 +52,6 @@ dispose() {
5952

6053
Note that connectivity changes are no longer communicated to Android apps in the background starting with Android O. *You should always check for connectivity status when your app is resumed.* The broadcast is only useful when your application is in the foreground.
6154

62-
To successfully get WiFi Name or Wi-Fi BSSID starting with Android O, ensure all of the following conditions are met:
63-
64-
* If your app is targeting Android 10 (API level 29) SDK or higher, your app has the ACCESS_FINE_LOCATION permission.
65-
66-
* If your app is targeting SDK lower than Android 10 (API level 29), your app has the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
67-
68-
* Location services are enabled on the device (under Settings > Location).
69-
70-
You can get wi-fi related information using:
71-
72-
```dart
73-
import 'package:connectivity/connectivity.dart';
74-
75-
var wifiBSSID = await (Connectivity().getWifiBSSID());
76-
var wifiIP = await (Connectivity().getWifiIP());network
77-
var wifiName = await (Connectivity().getWifiName());wifi network
78-
```
79-
80-
### iOS 12
81-
82-
To use `.getWifiBSSID()` and `.getWifiName()` on iOS >= 12, the `Access WiFi information capability` in XCode must be enabled. Otherwise, both methods will return null.
83-
84-
### iOS 13
85-
86-
The methods `.getWifiBSSID()` and `.getWifiName()` utilize the [`CNCopyCurrentNetworkInfo`](https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo) function on iOS.
87-
88-
As of iOS 13, Apple announced that these APIs will no longer return valid information.
89-
An app linked against iOS 12 or earlier receives pseudo-values such as:
90-
91-
* SSID: "Wi-Fi" or "WLAN" ("WLAN" will be returned for the China SKU).
92-
93-
* BSSID: "00:00:00:00:00:00"
94-
95-
An app linked against iOS 13 or later receives `null`.
96-
97-
The `CNCopyCurrentNetworkInfo` will work for Apps that:
98-
99-
* The app uses Core Location, and has the user’s authorization to use location information.
100-
101-
* The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
102-
103-
* The app has active VPN configurations installed.
104-
105-
If your app falls into the last two categories, it will work as it is. If your app doesn't fall into the last two categories,
106-
and you still need to access the wifi information, you should request user's authorization to use location information.
107-
108-
There is a helper method provided in this plugin to request the location authorization: `requestLocationServiceAuthorization`.
109-
To request location authorization, make sure to add the following keys to your _Info.plist_ file, located in `<project root>/ios/Runner/Info.plist`:
110-
111-
* `NSLocationAlwaysAndWhenInUseUsageDescription` - describe why the app needs access to the user’s location information all the time (foreground and background). This is called _Privacy - Location Always and When In Use Usage Description_ in the visual editor.
112-
* `NSLocationWhenInUseUsageDescription` - describe why the app needs access to the user’s location information when the app is running in the foreground. This is called _Privacy - Location When In Use Usage Description_ in the visual editor.
113-
11455
## Getting Started
11556

11657
For help getting started with Flutter, view our online
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="io.flutter.plugins.connectivity">
33
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
4-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
54
</manifest>

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77
import android.net.ConnectivityManager;
88
import android.net.Network;
99
import android.net.NetworkCapabilities;
10-
import android.net.wifi.WifiInfo;
11-
import android.net.wifi.WifiManager;
1210
import android.os.Build;
1311

1412
/** Reports connectivity related information such as connectivity type and wifi information. */
1513
class Connectivity {
1614
private ConnectivityManager connectivityManager;
17-
private WifiManager wifiManager;
1815

19-
Connectivity(ConnectivityManager connectivityManager, WifiManager wifiManager) {
16+
Connectivity(ConnectivityManager connectivityManager) {
2017
this.connectivityManager = connectivityManager;
21-
this.wifiManager = wifiManager;
2218
}
2319

2420
String getNetworkType() {
@@ -40,44 +36,6 @@ String getNetworkType() {
4036
return getNetworkTypeLegacy();
4137
}
4238

43-
String getWifiName() {
44-
WifiInfo wifiInfo = getWifiInfo();
45-
String ssid = null;
46-
if (wifiInfo != null) ssid = wifiInfo.getSSID();
47-
if (ssid != null) ssid = ssid.replaceAll("\"", ""); // Android returns "SSID"
48-
return ssid;
49-
}
50-
51-
String getWifiBSSID() {
52-
WifiInfo wifiInfo = getWifiInfo();
53-
String bssid = null;
54-
if (wifiInfo != null) {
55-
bssid = wifiInfo.getBSSID();
56-
}
57-
return bssid;
58-
}
59-
60-
String getWifiIPAddress() {
61-
WifiInfo wifiInfo = null;
62-
if (wifiManager != null) wifiInfo = wifiManager.getConnectionInfo();
63-
64-
String ip = null;
65-
int i_ip = 0;
66-
if (wifiInfo != null) i_ip = wifiInfo.getIpAddress();
67-
68-
if (i_ip != 0)
69-
ip =
70-
String.format(
71-
"%d.%d.%d.%d",
72-
(i_ip & 0xff), (i_ip >> 8 & 0xff), (i_ip >> 16 & 0xff), (i_ip >> 24 & 0xff));
73-
74-
return ip;
75-
}
76-
77-
private WifiInfo getWifiInfo() {
78-
return wifiManager == null ? null : wifiManager.getConnectionInfo();
79-
}
80-
8139
@SuppressWarnings("deprecation")
8240
private String getNetworkTypeLegacy() {
8341
// handle type for Android versions less than Android 9

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityMethodChannelHandler.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
3131
case "check":
3232
result.success(connectivity.getNetworkType());
3333
break;
34-
case "wifiName":
35-
result.success(connectivity.getWifiName());
36-
break;
37-
case "wifiBSSID":
38-
result.success(connectivity.getWifiBSSID());
39-
break;
40-
case "wifiIPAddress":
41-
result.success(connectivity.getWifiIPAddress());
42-
break;
4334
default:
4435
result.notImplemented();
4536
break;

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import android.content.Context;
88
import android.net.ConnectivityManager;
9-
import android.net.wifi.WifiManager;
109
import io.flutter.embedding.engine.plugins.FlutterPlugin;
1110
import io.flutter.plugin.common.BinaryMessenger;
1211
import io.flutter.plugin.common.EventChannel;
@@ -41,10 +40,8 @@ private void setupChannels(BinaryMessenger messenger, Context context) {
4140
eventChannel = new EventChannel(messenger, "plugins.flutter.io/connectivity_status");
4241
ConnectivityManager connectivityManager =
4342
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
44-
WifiManager wifiManager =
45-
(WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
4643

47-
Connectivity connectivity = new Connectivity(connectivityManager, wifiManager);
44+
Connectivity connectivity = new Connectivity(connectivityManager);
4845

4946
ConnectivityMethodChannelHandler methodChannelHandler =
5047
new ConnectivityMethodChannelHandler(connectivity);
Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,121 @@
11
{
22
"images" : [
33
{
4-
"size" : "20x20",
5-
"idiom" : "iphone",
64
"filename" : "[email protected]",
7-
"scale" : "2x"
5+
"idiom" : "iphone",
6+
"scale" : "2x",
7+
"size" : "20x20"
88
},
99
{
10-
"size" : "20x20",
11-
"idiom" : "iphone",
1210
"filename" : "[email protected]",
13-
"scale" : "3x"
11+
"idiom" : "iphone",
12+
"scale" : "3x",
13+
"size" : "20x20"
1414
},
1515
{
16-
"size" : "29x29",
17-
"idiom" : "iphone",
1816
"filename" : "[email protected]",
19-
"scale" : "1x"
17+
"idiom" : "iphone",
18+
"scale" : "1x",
19+
"size" : "29x29"
2020
},
2121
{
22-
"size" : "29x29",
23-
"idiom" : "iphone",
2422
"filename" : "[email protected]",
25-
"scale" : "2x"
23+
"idiom" : "iphone",
24+
"scale" : "2x",
25+
"size" : "29x29"
2626
},
2727
{
28-
"size" : "29x29",
29-
"idiom" : "iphone",
3028
"filename" : "[email protected]",
31-
"scale" : "3x"
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "29x29"
3232
},
3333
{
34-
"size" : "40x40",
35-
"idiom" : "iphone",
3634
"filename" : "[email protected]",
37-
"scale" : "2x"
35+
"idiom" : "iphone",
36+
"scale" : "2x",
37+
"size" : "40x40"
3838
},
3939
{
40-
"size" : "40x40",
41-
"idiom" : "iphone",
4240
"filename" : "[email protected]",
43-
"scale" : "3x"
41+
"idiom" : "iphone",
42+
"scale" : "3x",
43+
"size" : "40x40"
4444
},
4545
{
46-
"size" : "60x60",
47-
"idiom" : "iphone",
4846
"filename" : "[email protected]",
49-
"scale" : "2x"
47+
"idiom" : "iphone",
48+
"scale" : "2x",
49+
"size" : "60x60"
5050
},
5151
{
52-
"size" : "60x60",
53-
"idiom" : "iphone",
5452
"filename" : "[email protected]",
55-
"scale" : "3x"
53+
"idiom" : "iphone",
54+
"scale" : "3x",
55+
"size" : "60x60"
5656
},
5757
{
58-
"size" : "20x20",
59-
"idiom" : "ipad",
6058
"filename" : "[email protected]",
61-
"scale" : "1x"
59+
"idiom" : "ipad",
60+
"scale" : "1x",
61+
"size" : "20x20"
6262
},
6363
{
64-
"size" : "20x20",
65-
"idiom" : "ipad",
6664
"filename" : "[email protected]",
67-
"scale" : "2x"
65+
"idiom" : "ipad",
66+
"scale" : "2x",
67+
"size" : "20x20"
6868
},
6969
{
70-
"size" : "29x29",
71-
"idiom" : "ipad",
7270
"filename" : "[email protected]",
73-
"scale" : "1x"
71+
"idiom" : "ipad",
72+
"scale" : "1x",
73+
"size" : "29x29"
7474
},
7575
{
76-
"size" : "29x29",
77-
"idiom" : "ipad",
7876
"filename" : "[email protected]",
79-
"scale" : "2x"
77+
"idiom" : "ipad",
78+
"scale" : "2x",
79+
"size" : "29x29"
8080
},
8181
{
82-
"size" : "40x40",
83-
"idiom" : "ipad",
8482
"filename" : "[email protected]",
85-
"scale" : "1x"
83+
"idiom" : "ipad",
84+
"scale" : "1x",
85+
"size" : "40x40"
8686
},
8787
{
88-
"size" : "40x40",
89-
"idiom" : "ipad",
9088
"filename" : "[email protected]",
91-
"scale" : "2x"
89+
"idiom" : "ipad",
90+
"scale" : "2x",
91+
"size" : "40x40"
9292
},
9393
{
94-
"size" : "76x76",
95-
"idiom" : "ipad",
9694
"filename" : "[email protected]",
97-
"scale" : "1x"
95+
"idiom" : "ipad",
96+
"scale" : "1x",
97+
"size" : "76x76"
9898
},
9999
{
100-
"size" : "76x76",
101-
"idiom" : "ipad",
102100
"filename" : "[email protected]",
103-
"scale" : "2x"
101+
"idiom" : "ipad",
102+
"scale" : "2x",
103+
"size" : "76x76"
104104
},
105105
{
106-
"size" : "83.5x83.5",
107-
"idiom" : "ipad",
108106
"filename" : "[email protected]",
109-
"scale" : "2x"
107+
"idiom" : "ipad",
108+
"scale" : "2x",
109+
"size" : "83.5x83.5"
110+
},
111+
{
112+
"idiom" : "ios-marketing",
113+
"scale" : "1x",
114+
"size" : "1024x1024"
110115
}
111116
],
112117
"info" : {
113-
"version" : 1,
114-
"author" : "xcode"
118+
"author" : "xcode",
119+
"version" : 1
115120
}
116121
}

packages/connectivity/connectivity/example/ios/Runner/Info.plist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
<string>1</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
25-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
26-
<string>This app requires accessing your location information all the time to get wi-fi information.</string>
27-
<key>NSLocationWhenInUseUsageDescription</key>
28-
<string>This app requires accessing your location information when the app is in foreground to get wi-fi information.</string>
2925
<key>UILaunchStoryboardName</key>
3026
<string>LaunchScreen</string>
3127
<key>UIMainStoryboardFile</key>

0 commit comments

Comments
 (0)