diff --git a/packages/connectivity_plus/connectivity_plus/android/gradle/wrapper/gradle-wrapper.properties b/packages/connectivity_plus/connectivity_plus/android/gradle/wrapper/gradle-wrapper.properties index 62dbe3c1308..681c1b40ad3 100644 --- a/packages/connectivity_plus/connectivity_plus/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/connectivity_plus/connectivity_plus/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Tue Feb 20 19:54:18 GST 2024 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/Connectivity.java b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/Connectivity.java index 33886de59bc..3942342ced5 100644 --- a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/Connectivity.java +++ b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/Connectivity.java @@ -19,6 +19,7 @@ public class Connectivity { static final String CONNECTIVITY_ETHERNET = "ethernet"; static final String CONNECTIVITY_BLUETOOTH = "bluetooth"; static final String CONNECTIVITY_VPN = "vpn"; + static final String CONNECTIVITY_OTHER = "other"; private final ConnectivityManager connectivityManager; public Connectivity(ConnectivityManager connectivityManager) { @@ -30,11 +31,13 @@ List getNetworkTypes() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Network network = connectivityManager.getActiveNetwork(); NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network); - if (capabilities == null) { + if (capabilities == null + || !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { types.add(CONNECTIVITY_NONE); return types; } - if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) + || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI_AWARE)) { types.add(CONNECTIVITY_WIFI); } if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) { @@ -49,9 +52,12 @@ List getNetworkTypes() { if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH)) { types.add(CONNECTIVITY_BLUETOOTH); } + if (types.isEmpty() + && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) { + types.add(CONNECTIVITY_OTHER); + } if (types.isEmpty()) { types.add(CONNECTIVITY_NONE); - return types; } } else { // For legacy versions, return a single type as before or adapt similarly if multiple types need to be supported @@ -91,7 +97,7 @@ private List getNetworkTypesLegacy() { types.add(CONNECTIVITY_MOBILE); break; default: - types.add(CONNECTIVITY_NONE); + types.add(CONNECTIVITY_OTHER); } return types; } diff --git a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.java b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.java index 2380b440421..aa334e50475 100644 --- a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.java +++ b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.java @@ -78,12 +78,12 @@ public void onCancel(Object arguments) { @Override public void onReceive(Context context, Intent intent) { if (events != null) { - events.success(String.join(",", connectivity.getNetworkTypes())); + events.success(connectivity.getNetworkTypes()); } } private void sendEvent() { - Runnable runnable = () -> events.success(String.join(",", connectivity.getNetworkTypes())); + Runnable runnable = () -> events.success(connectivity.getNetworkTypes()); mainHandler.post(runnable); } diff --git a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.java b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.java index 8c6e394e4a6..e6cfbf1c2f1 100644 --- a/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.java +++ b/packages/connectivity_plus/connectivity_plus/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityMethodChannelHandler.java @@ -29,7 +29,7 @@ class ConnectivityMethodChannelHandler implements MethodChannel.MethodCallHandle @Override public void onMethodCall(MethodCall call, @NonNull MethodChannel.Result result) { if ("check".equals(call.method)) { - result.success(String.join(",", connectivity.getNetworkTypes())); + result.success(connectivity.getNetworkTypes()); } else { result.notImplemented(); } diff --git a/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/project.pbxproj b/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/project.pbxproj index 922e2dea2e1..e65736f1f9d 100644 --- a/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/project.pbxproj @@ -214,7 +214,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { diff --git a/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 87131a09bea..8e3ca5dfe19 100644 --- a/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/connectivity_plus/connectivity_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ NWPathMonitor { - if (_pathMonitor == nil) { + if (pathMonitor == nil) { let pathMonitor = NWPathMonitor() pathMonitor.start(queue: queue) pathMonitor.pathUpdateHandler = pathUpdateHandler - _pathMonitor = pathMonitor + self.pathMonitor = pathMonitor } - return _pathMonitor! + return self.pathMonitor! } private func pathUpdateHandler(path: NWPath) { diff --git a/packages/connectivity_plus/connectivity_plus/ios/Classes/ReachabilityConnectivityProvider.swift b/packages/connectivity_plus/connectivity_plus/ios/Classes/ReachabilityConnectivityProvider.swift index a3ca5427ab7..929b849cbf8 100644 --- a/packages/connectivity_plus/connectivity_plus/ios/Classes/ReachabilityConnectivityProvider.swift +++ b/packages/connectivity_plus/connectivity_plus/ios/Classes/ReachabilityConnectivityProvider.swift @@ -2,13 +2,14 @@ import Foundation import Reachability public class ReachabilityConnectivityProvider: NSObject, ConnectivityProvider { - private var _reachability: Reachability? + private var reachability: Reachability? public var currentConnectivityTypes: [ConnectivityType] { - guard let reachability = _reachability else { + guard let reachability = reachability else { return [.none] } + // Supported types https://github.com/ashleymills/Reachability.swift/blob/master/Sources/Reachability.swift#L99 switch reachability.connection { case .wifi: return [.wifi] @@ -42,23 +43,23 @@ public class ReachabilityConnectivityProvider: NSObject, ConnectivityProvider { NotificationCenter.default.removeObserver( self, name: .reachabilityChanged, - object: _reachability) + object: reachability) - _reachability?.stopNotifier() - _reachability = nil + reachability?.stopNotifier() + reachability = nil } private func ensureReachability() -> Reachability { - if (_reachability == nil) { + if (reachability == nil) { let reachability = try? Reachability() - _reachability = reachability + self.reachability = reachability } - return _reachability! + return reachability! } @objc private func reachabilityChanged(notification: NSNotification) { if let reachability = notification.object as? Reachability { - _reachability = reachability + self.reachability = reachability connectivityUpdateHandler?(currentConnectivityTypes) } } diff --git a/packages/connectivity_plus/connectivity_plus/ios/Classes/SwiftConnectivityPlusPlugin.swift b/packages/connectivity_plus/connectivity_plus/ios/Classes/SwiftConnectivityPlusPlugin.swift index 0b93aedca25..105c752317b 100644 --- a/packages/connectivity_plus/connectivity_plus/ios/Classes/SwiftConnectivityPlusPlugin.swift +++ b/packages/connectivity_plus/connectivity_plus/ios/Classes/SwiftConnectivityPlusPlugin.swift @@ -65,10 +65,10 @@ public class SwiftConnectivityPlusPlugin: NSObject, FlutterPlugin, FlutterStream } } - private func statusFrom(connectivityTypes: [ConnectivityType]) -> String { + private func statusFrom(connectivityTypes: [ConnectivityType]) -> [String] { return connectivityTypes.map { self.statusFrom(connectivityType: $0) - }.joined(separator: ",") + } } public func onListen( diff --git a/packages/connectivity_plus/connectivity_plus/macos/Classes/ConnectivityPlugin.swift b/packages/connectivity_plus/connectivity_plus/macos/Classes/ConnectivityPlugin.swift index 0e4fd0dd72f..b9035e52e9a 100644 --- a/packages/connectivity_plus/connectivity_plus/macos/Classes/ConnectivityPlugin.swift +++ b/packages/connectivity_plus/connectivity_plus/macos/Classes/ConnectivityPlugin.swift @@ -66,10 +66,10 @@ public class ConnectivityPlugin: NSObject, FlutterPlugin, FlutterStreamHandler { } } - private func statusFrom(connectivityTypes: [ConnectivityType]) -> String { + private func statusFrom(connectivityTypes: [ConnectivityType]) -> [String] { return connectivityTypes.map { self.statusFrom(connectivityType: $0) - }.joined(separator: ",") + } } public func onListen( diff --git a/packages/connectivity_plus/connectivity_plus/macos/Classes/PathMonitorConnectivityProvider.swift b/packages/connectivity_plus/connectivity_plus/macos/Classes/PathMonitorConnectivityProvider.swift index d15b8d487ab..cc9d9ec1a62 100644 --- a/packages/connectivity_plus/connectivity_plus/macos/Classes/PathMonitorConnectivityProvider.swift +++ b/packages/connectivity_plus/connectivity_plus/macos/Classes/PathMonitorConnectivityProvider.swift @@ -6,7 +6,7 @@ public class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider { private let queue = DispatchQueue.global(qos: .background) - private var _pathMonitor: NWPathMonitor? + private var pathMonitor: NWPathMonitor? public var currentConnectivityTypes: [ConnectivityType] { let path = ensurePathMonitor().currentPath @@ -43,18 +43,18 @@ public class PathMonitorConnectivityProvider: NSObject, ConnectivityProvider { } public func stop() { - _pathMonitor?.cancel() - _pathMonitor = nil + pathMonitor?.cancel() + pathMonitor = nil } private func ensurePathMonitor() -> NWPathMonitor { - if (_pathMonitor == nil) { + if (pathMonitor == nil) { let pathMonitor = NWPathMonitor() pathMonitor.start(queue: queue) pathMonitor.pathUpdateHandler = pathUpdateHandler - _pathMonitor = pathMonitor + self.pathMonitor = pathMonitor } - return _pathMonitor! + return self.pathMonitor! } private func pathUpdateHandler(path: NWPath) { diff --git a/packages/connectivity_plus/connectivity_plus/macos/Classes/ReachabilityConnectivityProvider.swift b/packages/connectivity_plus/connectivity_plus/macos/Classes/ReachabilityConnectivityProvider.swift index a3ca5427ab7..749132bcbc7 100644 --- a/packages/connectivity_plus/connectivity_plus/macos/Classes/ReachabilityConnectivityProvider.swift +++ b/packages/connectivity_plus/connectivity_plus/macos/Classes/ReachabilityConnectivityProvider.swift @@ -2,10 +2,10 @@ import Foundation import Reachability public class ReachabilityConnectivityProvider: NSObject, ConnectivityProvider { - private var _reachability: Reachability? + private var reachability: Reachability? public var currentConnectivityTypes: [ConnectivityType] { - guard let reachability = _reachability else { + guard let reachability = reachability else { return [.none] } @@ -42,23 +42,23 @@ public class ReachabilityConnectivityProvider: NSObject, ConnectivityProvider { NotificationCenter.default.removeObserver( self, name: .reachabilityChanged, - object: _reachability) + object: reachability) - _reachability?.stopNotifier() - _reachability = nil + reachability?.stopNotifier() + reachability = nil } private func ensureReachability() -> Reachability { - if (_reachability == nil) { + if (reachability == nil) { let reachability = try? Reachability() - _reachability = reachability + self.reachability = reachability } - return _reachability! + return self.reachability! } @objc private func reachabilityChanged(notification: NSNotification) { if let reachability = notification.object as? Reachability { - _reachability = reachability + self.reachability = reachability connectivityUpdateHandler?(currentConnectivityTypes) } } diff --git a/packages/connectivity_plus/connectivity_plus/windows/connectivity_plus_plugin.cpp b/packages/connectivity_plus/connectivity_plus/windows/connectivity_plus_plugin.cpp index 9b47c491c7c..cb6ae1f936f 100644 --- a/packages/connectivity_plus/connectivity_plus/windows/connectivity_plus_plugin.cpp +++ b/packages/connectivity_plus/connectivity_plus/windows/connectivity_plus_plugin.cpp @@ -114,29 +114,29 @@ static std::string ConnectivityToString(ConnectivityType connectivityType) { } } -static std::string -ConnectivityToString(std::set connectivityTypes) { +static flutter::EncodableList +EncodeConnectivityTypes(std::set connectivityTypes) { + flutter::EncodableList encodedList; + if (connectivityTypes.empty()) { - return "none"; + encodedList.push_back( + flutter::EncodableValue(ConnectivityToString(ConnectivityType::None))); + return encodedList; } - std::string connectivity; - for (auto type : connectivityTypes) { - if (!connectivity.empty()) { - connectivity += ','; - } - connectivity += ConnectivityToString(type); + for (const auto &type : connectivityTypes) { + std::string connectivityString = ConnectivityToString(type); + encodedList.push_back(flutter::EncodableValue(connectivityString)); } - return connectivity; + + return encodedList; } void ConnectivityPlusWindowsPlugin::HandleMethodCall( const flutter::MethodCall &method_call, std::unique_ptr> result) { if (method_call.method_name().compare("check") == 0) { - std::string connectivity = - ConnectivityToString(manager->GetConnectivityTypes()); - result->Success(flutter::EncodableValue(connectivity)); + result->Success(EncodeConnectivityTypes(manager->GetConnectivityTypes())); } else { result->NotImplemented(); } @@ -149,9 +149,7 @@ ConnectivityStreamHandler::ConnectivityStreamHandler( ConnectivityStreamHandler::~ConnectivityStreamHandler() {} void ConnectivityStreamHandler::AddConnectivityEvent() { - std::string connectivity = - ConnectivityToString(manager->GetConnectivityTypes()); - sink->Success(flutter::EncodableValue(connectivity)); + sink->Success(EncodeConnectivityTypes(manager->GetConnectivityTypes())); } std::unique_ptr diff --git a/packages/connectivity_plus/connectivity_plus_platform_interface/lib/method_channel_connectivity.dart b/packages/connectivity_plus/connectivity_plus_platform_interface/lib/method_channel_connectivity.dart index 5fa96e8eb94..95dcea4e50b 100644 --- a/packages/connectivity_plus/connectivity_plus_platform_interface/lib/method_channel_connectivity.dart +++ b/packages/connectivity_plus/connectivity_plus_platform_interface/lib/method_channel_connectivity.dart @@ -29,7 +29,7 @@ class MethodChannelConnectivity extends ConnectivityPlatform { Stream> get onConnectivityChanged { _onConnectivityChanged ??= eventChannel .receiveBroadcastStream() - .map((dynamic result) => result.toString()) + .map((dynamic result) => List.from(result)) .map(parseConnectivityResults); return _onConnectivityChanged!; } @@ -37,7 +37,7 @@ class MethodChannelConnectivity extends ConnectivityPlatform { @override Future> checkConnectivity() { return methodChannel - .invokeMethod('check') - .then((value) => parseConnectivityResults(value ?? '')); + .invokeListMethod('check') + .then((value) => parseConnectivityResults(value ?? [])); } } diff --git a/packages/connectivity_plus/connectivity_plus_platform_interface/lib/src/utils.dart b/packages/connectivity_plus/connectivity_plus_platform_interface/lib/src/utils.dart index 026faf09282..019a49a3aab 100644 --- a/packages/connectivity_plus/connectivity_plus_platform_interface/lib/src/utils.dart +++ b/packages/connectivity_plus/connectivity_plus_platform_interface/lib/src/utils.dart @@ -1,8 +1,8 @@ import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart'; /// Convert a comma-separated String to a list of ConnectivityResult values. -List parseConnectivityResults(String states) { - return states.split(',').map((state) { +List parseConnectivityResults(List states) { + return states.map((state) { switch (state.trim()) { case 'bluetooth': return ConnectivityResult.bluetooth; diff --git a/packages/connectivity_plus/connectivity_plus_platform_interface/test/method_channel_connectivity_test.dart b/packages/connectivity_plus/connectivity_plus_platform_interface/test/method_channel_connectivity_test.dart index 66ee13b67b9..244ffd9852a 100644 --- a/packages/connectivity_plus/connectivity_plus_platform_interface/test/method_channel_connectivity_test.dart +++ b/packages/connectivity_plus/connectivity_plus_platform_interface/test/method_channel_connectivity_test.dart @@ -24,8 +24,8 @@ void main() { log.add(methodCall); switch (methodCall.method) { case 'check': - // Simulate returning a comma-separated string of connectivity statuses - return 'wifi,mobile'; + // Simulate returning a list of string of connectivity statuses + return ['wifi', 'mobile']; default: return null; } @@ -45,7 +45,7 @@ void main() { .handlePlatformMessage( methodChannelConnectivity.eventChannel.name, methodChannelConnectivity.eventChannel.codec - .encodeSuccessEnvelope('wifi,mobile'), + .encodeSuccessEnvelope(['wifi', 'mobile']), (_) {}, ); break;