[Connectivity] wifi removal (#3173)
diff --git a/packages/connectivity/connectivity/CHANGELOG.md b/packages/connectivity/connectivity/CHANGELOG.md
index 03213e4..8e2802a 100644
--- a/packages/connectivity/connectivity/CHANGELOG.md
+++ b/packages/connectivity/connectivity/CHANGELOG.md
@@ -1,3 +1,17 @@
+## 2.0.0
+
+* [Breaking Change] The `getWifiName`, `getWifiBSSID` and `getWifiIP` are removed to [wifi_info_flutter](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter)
+* Migration guide:
+
+ 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`
+
+ 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.
+ For example, to migrate `getWifiName`, use the new plugin:
+ ```dart
+ final WifiInfo _wifiInfo = WifiInfo();
+ final String wifiName = await _wifiInfo.getWifiName();
+ ```
+
## 1.0.0
* Mark wifi related code deprecated.
diff --git a/packages/connectivity/connectivity/README.md b/packages/connectivity/connectivity/README.md
index 0a13749..a6a1dcc 100644
--- a/packages/connectivity/connectivity/README.md
+++ b/packages/connectivity/connectivity/README.md
@@ -7,13 +7,6 @@
> Note that on Android, this does not guarantee connection to Internet. For instance,
the app might have wifi access but it might be a VPN or a hotel WiFi with no access.
-**Please set your constraint to `connectivity: '>=0.4.y+x <2.0.0'`**
-
-## Backward compatible 1.0.0 version is coming
-The plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.4.y+z`.
-Please use `connectivity: '>=0.4.y+x <2.0.0'` as your dependency constraint to allow a smoother ecosystem migration.
-For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
-
## Usage
Sample usage to check current status:
@@ -59,58 +52,6 @@
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.
-To successfully get WiFi Name or Wi-Fi BSSID starting with Android O, ensure all of the following conditions are met:
-
- * If your app is targeting Android 10 (API level 29) SDK or higher, your app has the ACCESS_FINE_LOCATION permission.
-
- * 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.
-
- * Location services are enabled on the device (under Settings > Location).
-
-You can get wi-fi related information using:
-
-```dart
-import 'package:connectivity/connectivity.dart';
-
-var wifiBSSID = await (Connectivity().getWifiBSSID());
-var wifiIP = await (Connectivity().getWifiIP());network
-var wifiName = await (Connectivity().getWifiName());wifi network
-```
-
-### iOS 12
-
-To use `.getWifiBSSID()` and `.getWifiName()` on iOS >= 12, the `Access WiFi information capability` in XCode must be enabled. Otherwise, both methods will return null.
-
-### iOS 13
-
-The methods `.getWifiBSSID()` and `.getWifiName()` utilize the [`CNCopyCurrentNetworkInfo`](https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo) function on iOS.
-
-As of iOS 13, Apple announced that these APIs will no longer return valid information.
-An app linked against iOS 12 or earlier receives pseudo-values such as:
-
- * SSID: "Wi-Fi" or "WLAN" ("WLAN" will be returned for the China SKU).
-
- * BSSID: "00:00:00:00:00:00"
-
-An app linked against iOS 13 or later receives `null`.
-
-The `CNCopyCurrentNetworkInfo` will work for Apps that:
-
- * The app uses Core Location, and has the user’s authorization to use location information.
-
- * The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
-
- * The app has active VPN configurations installed.
-
-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,
-and you still need to access the wifi information, you should request user's authorization to use location information.
-
-There is a helper method provided in this plugin to request the location authorization: `requestLocationServiceAuthorization`.
-To request location authorization, make sure to add the following keys to your _Info.plist_ file, located in `<project root>/ios/Runner/Info.plist`:
-
-* `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.
-* `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.
-
## Getting Started
For help getting started with Flutter, view our online
diff --git a/packages/connectivity/connectivity/android/src/main/AndroidManifest.xml b/packages/connectivity/connectivity/android/src/main/AndroidManifest.xml
index f4eafe4..52bbe9e 100644
--- a/packages/connectivity/connectivity/android/src/main/AndroidManifest.xml
+++ b/packages/connectivity/connectivity/android/src/main/AndroidManifest.xml
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.connectivity">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
diff --git a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java
index 47feabd..0a3a6ba 100644
--- a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java
+++ b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java
@@ -7,18 +7,14 @@
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
import android.os.Build;
/** Reports connectivity related information such as connectivity type and wifi information. */
class Connectivity {
private ConnectivityManager connectivityManager;
- private WifiManager wifiManager;
- Connectivity(ConnectivityManager connectivityManager, WifiManager wifiManager) {
+ Connectivity(ConnectivityManager connectivityManager) {
this.connectivityManager = connectivityManager;
- this.wifiManager = wifiManager;
}
String getNetworkType() {
@@ -40,44 +36,6 @@
return getNetworkTypeLegacy();
}
- String getWifiName() {
- WifiInfo wifiInfo = getWifiInfo();
- String ssid = null;
- if (wifiInfo != null) ssid = wifiInfo.getSSID();
- if (ssid != null) ssid = ssid.replaceAll("\"", ""); // Android returns "SSID"
- return ssid;
- }
-
- String getWifiBSSID() {
- WifiInfo wifiInfo = getWifiInfo();
- String bssid = null;
- if (wifiInfo != null) {
- bssid = wifiInfo.getBSSID();
- }
- return bssid;
- }
-
- String getWifiIPAddress() {
- WifiInfo wifiInfo = null;
- if (wifiManager != null) wifiInfo = wifiManager.getConnectionInfo();
-
- String ip = null;
- int i_ip = 0;
- if (wifiInfo != null) i_ip = wifiInfo.getIpAddress();
-
- if (i_ip != 0)
- ip =
- String.format(
- "%d.%d.%d.%d",
- (i_ip & 0xff), (i_ip >> 8 & 0xff), (i_ip >> 16 & 0xff), (i_ip >> 24 & 0xff));
-
- return ip;
- }
-
- private WifiInfo getWifiInfo() {
- return wifiManager == null ? null : wifiManager.getConnectionInfo();
- }
-
@SuppressWarnings("deprecation")
private String getNetworkTypeLegacy() {
// handle type for Android versions less than Android 9
diff --git a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityMethodChannelHandler.java b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityMethodChannelHandler.java
index 931b702..de1958a 100644
--- a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityMethodChannelHandler.java
+++ b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityMethodChannelHandler.java
@@ -31,15 +31,6 @@
case "check":
result.success(connectivity.getNetworkType());
break;
- case "wifiName":
- result.success(connectivity.getWifiName());
- break;
- case "wifiBSSID":
- result.success(connectivity.getWifiBSSID());
- break;
- case "wifiIPAddress":
- result.success(connectivity.getWifiIPAddress());
- break;
default:
result.notImplemented();
break;
diff --git a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java
index f036a8a..3de60f0 100644
--- a/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java
+++ b/packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java
@@ -6,7 +6,6 @@
import android.content.Context;
import android.net.ConnectivityManager;
-import android.net.wifi.WifiManager;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
@@ -41,10 +40,8 @@
eventChannel = new EventChannel(messenger, "plugins.flutter.io/connectivity_status");
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- WifiManager wifiManager =
- (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- Connectivity connectivity = new Connectivity(connectivityManager, wifiManager);
+ Connectivity connectivity = new Connectivity(connectivityManager);
ConnectivityMethodChannelHandler methodChannelHandler =
new ConnectivityMethodChannelHandler(connectivity);
diff --git a/packages/connectivity/connectivity/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/connectivity/connectivity/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
index d22f10b..8122b0a 100644
--- a/packages/connectivity/connectivity/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
+++ b/packages/connectivity/connectivity/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -1,116 +1,121 @@
{
"images" : [
{
- "size" : "20x20",
- "idiom" : "iphone",
"filename" : "Icon-App-20x20@2x.png",
- "scale" : "2x"
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "20x20"
},
{
- "size" : "20x20",
- "idiom" : "iphone",
"filename" : "Icon-App-20x20@3x.png",
- "scale" : "3x"
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "20x20"
},
{
- "size" : "29x29",
- "idiom" : "iphone",
"filename" : "Icon-App-29x29@1x.png",
- "scale" : "1x"
+ "idiom" : "iphone",
+ "scale" : "1x",
+ "size" : "29x29"
},
{
- "size" : "29x29",
- "idiom" : "iphone",
"filename" : "Icon-App-29x29@2x.png",
- "scale" : "2x"
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "29x29"
},
{
- "size" : "29x29",
- "idiom" : "iphone",
"filename" : "Icon-App-29x29@3x.png",
- "scale" : "3x"
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "29x29"
},
{
- "size" : "40x40",
- "idiom" : "iphone",
"filename" : "Icon-App-40x40@2x.png",
- "scale" : "2x"
+ "idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "40x40"
},
{
- "size" : "40x40",
- "idiom" : "iphone",
"filename" : "Icon-App-40x40@3x.png",
- "scale" : "3x"
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "40x40"
},
{
- "size" : "60x60",
- "idiom" : "iphone",
"filename" : "Icon-App-60x60@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "60x60",
"idiom" : "iphone",
+ "scale" : "2x",
+ "size" : "60x60"
+ },
+ {
"filename" : "Icon-App-60x60@3x.png",
- "scale" : "3x"
+ "idiom" : "iphone",
+ "scale" : "3x",
+ "size" : "60x60"
},
{
- "size" : "20x20",
- "idiom" : "ipad",
"filename" : "Icon-App-20x20@1x.png",
- "scale" : "1x"
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "20x20"
},
{
- "size" : "20x20",
- "idiom" : "ipad",
"filename" : "Icon-App-20x20@2x.png",
- "scale" : "2x"
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "20x20"
},
{
- "size" : "29x29",
- "idiom" : "ipad",
"filename" : "Icon-App-29x29@1x.png",
- "scale" : "1x"
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "29x29"
},
{
- "size" : "29x29",
- "idiom" : "ipad",
"filename" : "Icon-App-29x29@2x.png",
- "scale" : "2x"
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "29x29"
},
{
- "size" : "40x40",
- "idiom" : "ipad",
"filename" : "Icon-App-40x40@1x.png",
- "scale" : "1x"
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "40x40"
},
{
- "size" : "40x40",
- "idiom" : "ipad",
"filename" : "Icon-App-40x40@2x.png",
- "scale" : "2x"
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "40x40"
},
{
- "size" : "76x76",
- "idiom" : "ipad",
"filename" : "Icon-App-76x76@1x.png",
- "scale" : "1x"
+ "idiom" : "ipad",
+ "scale" : "1x",
+ "size" : "76x76"
},
{
- "size" : "76x76",
- "idiom" : "ipad",
"filename" : "Icon-App-76x76@2x.png",
- "scale" : "2x"
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "76x76"
},
{
- "size" : "83.5x83.5",
- "idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
- "scale" : "2x"
+ "idiom" : "ipad",
+ "scale" : "2x",
+ "size" : "83.5x83.5"
+ },
+ {
+ "idiom" : "ios-marketing",
+ "scale" : "1x",
+ "size" : "1024x1024"
}
],
"info" : {
- "version" : 1,
- "author" : "xcode"
+ "author" : "xcode",
+ "version" : 1
}
}
diff --git a/packages/connectivity/connectivity/example/ios/Runner/Info.plist b/packages/connectivity/connectivity/example/ios/Runner/Info.plist
index babbd80..d76382b 100644
--- a/packages/connectivity/connectivity/example/ios/Runner/Info.plist
+++ b/packages/connectivity/connectivity/example/ios/Runner/Info.plist
@@ -22,10 +22,6 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
- <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
- <string>This app requires accessing your location information all the time to get wi-fi information.</string>
- <key>NSLocationWhenInUseUsageDescription</key>
- <string>This app requires accessing your location information when the app is in foreground to get wi-fi information.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
diff --git a/packages/connectivity/connectivity/example/lib/main.dart b/packages/connectivity/connectivity/example/lib/main.dart
index 87612ea..e054971 100644
--- a/packages/connectivity/connectivity/example/lib/main.dart
+++ b/packages/connectivity/connectivity/example/lib/main.dart
@@ -100,77 +100,6 @@
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
switch (result) {
case ConnectivityResult.wifi:
- String wifiName, wifiBSSID, wifiIP;
-
- try {
- if (!kIsWeb && Platform.isIOS) {
- LocationAuthorizationStatus status =
- // ignore: deprecated_member_use
- await _connectivity.getLocationServiceAuthorization();
- if (status == LocationAuthorizationStatus.notDetermined) {
- status =
- // ignore: deprecated_member_use
- await _connectivity.requestLocationServiceAuthorization();
- }
- if (status == LocationAuthorizationStatus.authorizedAlways ||
- status == LocationAuthorizationStatus.authorizedWhenInUse) {
- // ignore: deprecated_member_use
- wifiName = await _connectivity.getWifiName();
- } else {
- // ignore: deprecated_member_use
- wifiName = await _connectivity.getWifiName();
- }
- } else {
- // ignore: deprecated_member_use
- wifiName = await _connectivity.getWifiName();
- }
- } on PlatformException catch (e) {
- print(e.toString());
- wifiName = "Failed to get Wifi Name";
- }
-
- try {
- if (!kIsWeb && Platform.isIOS) {
- LocationAuthorizationStatus status =
- // ignore: deprecated_member_use
- await _connectivity.getLocationServiceAuthorization();
- if (status == LocationAuthorizationStatus.notDetermined) {
- status =
- // ignore: deprecated_member_use
- await _connectivity.requestLocationServiceAuthorization();
- }
- if (status == LocationAuthorizationStatus.authorizedAlways ||
- status == LocationAuthorizationStatus.authorizedWhenInUse) {
- // ignore: deprecated_member_use
- wifiBSSID = await _connectivity.getWifiBSSID();
- } else {
- // ignore: deprecated_member_use
- wifiBSSID = await _connectivity.getWifiBSSID();
- }
- } else {
- // ignore: deprecated_member_use
- wifiBSSID = await _connectivity.getWifiBSSID();
- }
- } on PlatformException catch (e) {
- print(e.toString());
- wifiBSSID = "Failed to get Wifi BSSID";
- }
-
- try {
- // ignore: deprecated_member_use
- wifiIP = await _connectivity.getWifiIP();
- } on PlatformException catch (e) {
- print(e.toString());
- wifiIP = "Failed to get Wifi IP";
- }
-
- setState(() {
- _connectionStatus = '$result\n'
- 'Wifi Name: $wifiName\n'
- 'Wifi BSSID: $wifiBSSID\n'
- 'Wifi IP: $wifiIP\n';
- });
- break;
case ConnectivityResult.mobile:
case ConnectivityResult.none:
setState(() => _connectionStatus = result.toString());
diff --git a/packages/connectivity/connectivity/example/test_driver/integration_test/connectivity_test.dart b/packages/connectivity/connectivity/example/test_driver/integration_test/connectivity_test.dart
index 773ad10..d48deae 100644
--- a/packages/connectivity/connectivity/example/test_driver/integration_test/connectivity_test.dart
+++ b/packages/connectivity/connectivity/example/test_driver/integration_test/connectivity_test.dart
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:io';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:connectivity/connectivity.dart';
@@ -20,26 +19,6 @@
testWidgets('test connectivity result', (WidgetTester tester) async {
final ConnectivityResult result = await _connectivity.checkConnectivity();
expect(result, isNotNull);
- switch (result) {
- case ConnectivityResult.wifi:
- // ignore: deprecated_member_use
- expect(_connectivity.getWifiName(), completes);
- // ignore: deprecated_member_use
- expect(_connectivity.getWifiBSSID(), completes);
- // ignore: deprecated_member_use
- expect((await _connectivity.getWifiIP()), isNotNull);
- break;
- default:
- break;
- }
- });
-
- testWidgets('test location methods, iOS only', (WidgetTester tester) async {
- if (Platform.isIOS) {
- // ignore: deprecated_member_use
- expect((await _connectivity.getLocationServiceAuthorization()),
- LocationAuthorizationStatus.notDetermined);
- }
});
});
}
diff --git a/packages/connectivity/connectivity/integration_test/connectivity_test.dart b/packages/connectivity/connectivity/integration_test/connectivity_test.dart
index 1b8675b..d48deae 100644
--- a/packages/connectivity/connectivity/integration_test/connectivity_test.dart
+++ b/packages/connectivity/connectivity/integration_test/connectivity_test.dart
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:io';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:connectivity/connectivity.dart';
@@ -20,26 +19,6 @@
testWidgets('test connectivity result', (WidgetTester tester) async {
final ConnectivityResult result = await _connectivity.checkConnectivity();
expect(result, isNotNull);
- switch (result) {
- case ConnectivityResult.wifi:
- // ignore: deprecated_member_use_from_same_package
- expect(_connectivity.getWifiName(), completes);
- // ignore: deprecated_member_use_from_same_package
- expect(_connectivity.getWifiBSSID(), completes);
- // ignore: deprecated_member_use_from_same_package
- expect((await _connectivity.getWifiIP()), isNotNull);
- break;
- default:
- break;
- }
- });
-
- testWidgets('test location methods, iOS only', (WidgetTester tester) async {
- if (Platform.isIOS) {
- // ignore: deprecated_member_use_from_same_package
- expect((await _connectivity.getLocationServiceAuthorization()),
- LocationAuthorizationStatus.notDetermined);
- }
});
});
}
diff --git a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.h b/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.h
deleted file mode 100644
index 1731d56..0000000
--- a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-#import <CoreLocation/CoreLocation.h>
-#import <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@class FLTConnectivityLocationDelegate;
-
-typedef void (^FLTConnectivityLocationCompletion)(CLAuthorizationStatus);
-
-@interface FLTConnectivityLocationHandler : NSObject
-
-+ (CLAuthorizationStatus)locationAuthorizationStatus;
-
-- (void)requestLocationAuthorization:(BOOL)always
- completion:(_Nonnull FLTConnectivityLocationCompletion)completionHnadler;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.m b/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.m
deleted file mode 100644
index bbb93ae..0000000
--- a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityLocationHandler.m
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "FLTConnectivityLocationHandler.h"
-
-@interface FLTConnectivityLocationHandler () <CLLocationManagerDelegate>
-
-@property(copy, nonatomic) FLTConnectivityLocationCompletion completion;
-@property(strong, nonatomic) CLLocationManager *locationManager;
-
-@end
-
-@implementation FLTConnectivityLocationHandler
-
-+ (CLAuthorizationStatus)locationAuthorizationStatus {
- return CLLocationManager.authorizationStatus;
-}
-
-- (void)requestLocationAuthorization:(BOOL)always
- completion:(FLTConnectivityLocationCompletion)completionHandler {
- CLAuthorizationStatus status = CLLocationManager.authorizationStatus;
- if (status != kCLAuthorizationStatusAuthorizedWhenInUse && always) {
- completionHandler(kCLAuthorizationStatusDenied);
- return;
- } else if (status != kCLAuthorizationStatusNotDetermined) {
- completionHandler(status);
- return;
- }
-
- if (self.completion) {
- // If a request is still in process, immediately return.
- completionHandler(kCLAuthorizationStatusNotDetermined);
- return;
- }
-
- self.completion = completionHandler;
- self.locationManager = [CLLocationManager new];
- self.locationManager.delegate = self;
- if (always) {
- [self.locationManager requestAlwaysAuthorization];
- } else {
- [self.locationManager requestWhenInUseAuthorization];
- }
-}
-
-- (void)locationManager:(CLLocationManager *)manager
- didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
- if (status == kCLAuthorizationStatusNotDetermined) {
- return;
- }
- if (self.completion) {
- self.completion(status);
- self.completion = nil;
- }
-}
-
-@end
diff --git a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityPlugin.m b/packages/connectivity/connectivity/ios/Classes/FLTConnectivityPlugin.m
index 526bee2..fb996c1 100644
--- a/packages/connectivity/connectivity/ios/Classes/FLTConnectivityPlugin.m
+++ b/packages/connectivity/connectivity/ios/Classes/FLTConnectivityPlugin.m
@@ -7,7 +7,6 @@
#import "Reachability/Reachability.h"
#import <CoreLocation/CoreLocation.h>
-#import "FLTConnectivityLocationHandler.h"
#import "SystemConfiguration/CaptiveNetwork.h"
#include <ifaddrs.h>
@@ -16,8 +15,6 @@
@interface FLTConnectivityPlugin () <FlutterStreamHandler, CLLocationManagerDelegate>
-@property(strong, nonatomic) FLTConnectivityLocationHandler* locationHandler;
-
@end
@implementation FLTConnectivityPlugin {
@@ -39,58 +36,6 @@
[streamChannel setStreamHandler:instance];
}
-- (NSString*)findNetworkInfo:(NSString*)key {
- NSString* info = nil;
- NSArray* interfaceNames = (__bridge_transfer id)CNCopySupportedInterfaces();
- for (NSString* interfaceName in interfaceNames) {
- NSDictionary* networkInfo =
- (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName);
- if (networkInfo[key]) {
- info = networkInfo[key];
- }
- }
- return info;
-}
-
-- (NSString*)getWifiName {
- return [self findNetworkInfo:@"SSID"];
-}
-
-- (NSString*)getBSSID {
- return [self findNetworkInfo:@"BSSID"];
-}
-
-- (NSString*)getWifiIP {
- NSString* address = @"error";
- struct ifaddrs* interfaces = NULL;
- struct ifaddrs* temp_addr = NULL;
- int success = 0;
-
- // retrieve the current interfaces - returns 0 on success
- success = getifaddrs(&interfaces);
- if (success == 0) {
- // Loop through linked list of interfaces
- temp_addr = interfaces;
- while (temp_addr != NULL) {
- if (temp_addr->ifa_addr->sa_family == AF_INET) {
- // Check if interface is en0 which is the wifi connection on the iPhone
- if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
- // Get NSString from C String
- address = [NSString
- stringWithUTF8String:inet_ntoa(((struct sockaddr_in*)temp_addr->ifa_addr)->sin_addr)];
- }
- }
-
- temp_addr = temp_addr->ifa_next;
- }
- }
-
- // Free memory
- freeifaddrs(interfaces);
-
- return address;
-}
-
- (NSString*)statusFromReachability:(Reachability*)reachability {
NetworkStatus status = [reachability currentReachabilityStatus];
switch (status) {
@@ -111,24 +56,6 @@
// and the code
// gets more involved. So for now, this will do.
result([self statusFromReachability:[Reachability reachabilityForInternetConnection]]);
- } else if ([call.method isEqualToString:@"wifiName"]) {
- result([self getWifiName]);
- } else if ([call.method isEqualToString:@"wifiBSSID"]) {
- result([self getBSSID]);
- } else if ([call.method isEqualToString:@"wifiIPAddress"]) {
- result([self getWifiIP]);
- } else if ([call.method isEqualToString:@"getLocationServiceAuthorization"]) {
- result([self convertCLAuthorizationStatusToString:[FLTConnectivityLocationHandler
- locationAuthorizationStatus]]);
- } else if ([call.method isEqualToString:@"requestLocationServiceAuthorization"]) {
- NSArray* arguments = call.arguments;
- BOOL always = [arguments.firstObject boolValue];
- __weak typeof(self) weakSelf = self;
- [self.locationHandler
- requestLocationAuthorization:always
- completion:^(CLAuthorizationStatus status) {
- result([weakSelf convertCLAuthorizationStatusToString:status]);
- }];
} else {
result(FlutterMethodNotImplemented);
}
@@ -139,34 +66,6 @@
_eventSink([self statusFromReachability:curReach]);
}
-- (NSString*)convertCLAuthorizationStatusToString:(CLAuthorizationStatus)status {
- switch (status) {
- case kCLAuthorizationStatusNotDetermined: {
- return @"notDetermined";
- }
- case kCLAuthorizationStatusRestricted: {
- return @"restricted";
- }
- case kCLAuthorizationStatusDenied: {
- return @"denied";
- }
- case kCLAuthorizationStatusAuthorizedAlways: {
- return @"authorizedAlways";
- }
- case kCLAuthorizationStatusAuthorizedWhenInUse: {
- return @"authorizedWhenInUse";
- }
- default: { return @"unknown"; }
- }
-}
-
-- (FLTConnectivityLocationHandler*)locationHandler {
- if (!_locationHandler) {
- _locationHandler = [FLTConnectivityLocationHandler new];
- }
- return _locationHandler;
-}
-
#pragma mark FlutterStreamHandler impl
- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)eventSink {
diff --git a/packages/connectivity/connectivity/lib/connectivity.dart b/packages/connectivity/connectivity/lib/connectivity.dart
index e3fdba7..c965536 100644
--- a/packages/connectivity/connectivity/lib/connectivity.dart
+++ b/packages/connectivity/connectivity/lib/connectivity.dart
@@ -4,7 +4,6 @@
import 'dart:async';
-import 'package:flutter/services.dart';
import 'package:connectivity_platform_interface/connectivity_platform_interface.dart';
// Export enums from the platform_interface so plugin users can use them directly.
@@ -46,135 +45,4 @@
Future<ConnectivityResult> checkConnectivity() {
return _platform.checkConnectivity();
}
-
- /// Obtains the wifi name (SSID) of the connected network
- ///
- /// Please note that it DOESN'T WORK on emulators (returns null).
- ///
- /// From android 8.0 onwards the GPS must be ON (high accuracy)
- /// in order to be able to obtain the SSID.
- @Deprecated(
- 'This method is deprecated. Please use wifi_info_flutter instead. See https://github.com/flutter/plugins/blob/master/packages/wifi_info_flutter/wifi_info_flutter/README.md')
- Future<String> getWifiName() {
- return _platform.getWifiName();
- }
-
- /// Obtains the wifi BSSID of the connected network.
- ///
- /// Please note that it DOESN'T WORK on emulators (returns null).
- ///
- /// From Android 8.0 onwards the GPS must be ON (high accuracy)
- /// in order to be able to obtain the BSSID.
- @Deprecated(
- 'This method is deprecated. Please use wifi_info_flutter instead. See https://github.com/flutter/plugins/blob/master/packages/wifi_info_flutter/wifi_info_flutter/README.md')
- Future<String> getWifiBSSID() {
- return _platform.getWifiBSSID();
- }
-
- /// Obtains the IP address of the connected wifi network
- @Deprecated(
- 'This method is deprecated. Please use wifi_info_flutter instead. See https://github.com/flutter/plugins/blob/master/packages/wifi_info_flutter/wifi_info_flutter/README.md')
- Future<String> getWifiIP() {
- return _platform.getWifiIP();
- }
-
- /// Request to authorize the location service (Only on iOS).
- ///
- /// This method will throw a [PlatformException] on Android.
- ///
- /// Returns a [LocationAuthorizationStatus] after user authorized or denied the location on this request.
- ///
- /// If the location information needs to be accessible all the time, set `requestAlwaysLocationUsage` to true. If user has
- /// already granted a [LocationAuthorizationStatus.authorizedWhenInUse] prior to requesting an "always" access, it will return [LocationAuthorizationStatus.denied].
- ///
- /// If the location service authorization is not determined prior to making this call, a platform standard UI of requesting a location service will pop up.
- /// This UI will only show once unless the user re-install the app to their phone which resets the location service authorization to not determined.
- ///
- /// This method is a helper to get the location authorization that is necessary for certain functionality of this plugin.
- /// It can be replaced with other permission handling code/plugin if preferred.
- /// To request location authorization, make sure to add the following keys to your _Info.plist_ file, located in `<project root>/ios/Runner/Info.plist`:
- /// * `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.
- /// * `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.
- ///
- /// Starting from iOS 13, `getWifiBSSID` and `getWifiIP` will only work properly if:
- ///
- /// * The app uses Core Location, and has the user’s authorization to use location information.
- /// * The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
- /// * The app has active VPN configurations installed.
- ///
- /// If the app falls into the first category, call this method before calling `getWifiBSSID` or `getWifiIP`.
- /// For example,
- /// ```dart
- /// if (Platform.isIOS) {
- /// LocationAuthorizationStatus status = await _connectivity.getLocationServiceAuthorization();
- /// if (status == LocationAuthorizationStatus.notDetermined) {
- /// status = await _connectivity.requestLocationServiceAuthorization();
- /// }
- /// if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) {
- /// wifiBSSID = await _connectivity.getWifiName();
- /// } else {
- /// print('location service is not authorized, the data might not be correct');
- /// wifiBSSID = await _connectivity.getWifiName();
- /// }
- /// } else {
- /// wifiBSSID = await _connectivity.getWifiName();
- /// }
- /// ```
- ///
- /// Ideally, a location service authorization should only be requested if the current authorization status is not determined.
- ///
- /// See also [getLocationServiceAuthorization] to obtain current location service status.
- @Deprecated(
- 'This method is deprecated. Please use wifi_info_flutter instead. See https://github.com/flutter/plugins/blob/master/packages/wifi_info_flutter/wifi_info_flutter/README.md')
- Future<LocationAuthorizationStatus> requestLocationServiceAuthorization({
- bool requestAlwaysLocationUsage = false,
- }) {
- return _platform.requestLocationServiceAuthorization(
- requestAlwaysLocationUsage: requestAlwaysLocationUsage,
- );
- }
-
- /// Get the current location service authorization (Only on iOS).
- ///
- /// This method will throw a [PlatformException] on Android.
- ///
- /// Returns a [LocationAuthorizationStatus].
- /// If the returned value is [LocationAuthorizationStatus.notDetermined], a subsequent [requestLocationServiceAuthorization] call
- /// can request the authorization.
- /// If the returned value is not [LocationAuthorizationStatus.notDetermined], a subsequent [requestLocationServiceAuthorization]
- /// will not initiate another request. It will instead return the "determined" status.
- ///
- /// This method is a helper to get the location authorization that is necessary for certain functionality of this plugin.
- /// It can be replaced with other permission handling code/plugin if preferred.
- ///
- /// Starting from iOS 13, `getWifiBSSID` and `getWifiIP` will only work properly if:
- ///
- /// * The app uses Core Location, and has the user’s authorization to use location information.
- /// * The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
- /// * The app has active VPN configurations installed.
- ///
- /// If the app falls into the first category, call this method before calling `getWifiBSSID` or `getWifiIP`.
- /// For example,
- /// ```dart
- /// if (Platform.isIOS) {
- /// LocationAuthorizationStatus status = await _connectivity.getLocationServiceAuthorization();
- /// if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) {
- /// wifiBSSID = await _connectivity.getWifiName();
- /// } else {
- /// print('location service is not authorized, the data might not be correct');
- /// wifiBSSID = await _connectivity.getWifiName();
- /// }
- /// } else {
- /// wifiBSSID = await _connectivity.getWifiName();
- /// }
- /// ```
- ///
- /// See also [requestLocationServiceAuthorization] for requesting a location service authorization.
- @Deprecated(
- 'This method is deprecated. Please use wifi_info_flutter instead. See https://github.com/flutter/plugins/blob/master/packages/wifi_info_flutter/wifi_info_flutter/README.md')
- Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
- return _platform.getLocationServiceAuthorization();
- }
}
diff --git a/packages/connectivity/connectivity/pubspec.yaml b/packages/connectivity/connectivity/pubspec.yaml
index a8994bf..af26f70 100644
--- a/packages/connectivity/connectivity/pubspec.yaml
+++ b/packages/connectivity/connectivity/pubspec.yaml
@@ -2,7 +2,7 @@
description: Flutter plugin for discovering the state of the network (WiFi &
mobile/cellular) connectivity on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity
-version: 1.0.0
+version: 2.0.0
flutter:
plugin:
diff --git a/packages/connectivity/connectivity/test/connectivity_test.dart b/packages/connectivity/connectivity/test/connectivity_test.dart
index 98bdf3a..b7749ca 100644
--- a/packages/connectivity/connectivity/test/connectivity_test.dart
+++ b/packages/connectivity/connectivity/test/connectivity_test.dart
@@ -11,9 +11,6 @@
import 'package:mockito/mockito.dart';
const ConnectivityResult kCheckConnectivityResult = ConnectivityResult.wifi;
-const String kWifiNameResult = '1337wifi';
-const String kWifiBSSIDResult = 'c0:ff:33:c0:d3:55';
-const String kWifiIpAddressResult = '127.0.0.1';
const LocationAuthorizationStatus kRequestLocationResult =
LocationAuthorizationStatus.authorizedAlways;
const LocationAuthorizationStatus kGetLocationResult =
@@ -33,38 +30,6 @@
ConnectivityResult result = await connectivity.checkConnectivity();
expect(result, kCheckConnectivityResult);
});
-
- test('getWifiName', () async {
- // ignore: deprecated_member_use_from_same_package
- String result = await connectivity.getWifiName();
- expect(result, kWifiNameResult);
- });
-
- test('getWifiBSSID', () async {
- // ignore: deprecated_member_use_from_same_package
- String result = await connectivity.getWifiBSSID();
- expect(result, kWifiBSSIDResult);
- });
-
- test('getWifiIP', () async {
- // ignore: deprecated_member_use_from_same_package
- String result = await connectivity.getWifiIP();
- expect(result, kWifiIpAddressResult);
- });
-
- test('requestLocationServiceAuthorization', () async {
- LocationAuthorizationStatus result =
- // ignore: deprecated_member_use_from_same_package
- await connectivity.requestLocationServiceAuthorization();
- expect(result, kRequestLocationResult);
- });
-
- test('getLocationServiceAuthorization', () async {
- LocationAuthorizationStatus result =
- // ignore: deprecated_member_use_from_same_package
- await connectivity.getLocationServiceAuthorization();
- expect(result, kRequestLocationResult);
- });
});
}
@@ -74,26 +39,4 @@
Future<ConnectivityResult> checkConnectivity() async {
return kCheckConnectivityResult;
}
-
- Future<String> getWifiName() async {
- return kWifiNameResult;
- }
-
- Future<String> getWifiBSSID() async {
- return kWifiBSSIDResult;
- }
-
- Future<String> getWifiIP() async {
- return kWifiIpAddressResult;
- }
-
- Future<LocationAuthorizationStatus> requestLocationServiceAuthorization({
- bool requestAlwaysLocationUsage = false,
- }) async {
- return kRequestLocationResult;
- }
-
- Future<LocationAuthorizationStatus> getLocationServiceAuthorization() async {
- return kGetLocationResult;
- }
}