diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 05912a3f2f3..dbf7eb1df7d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,6 +178,9 @@ Please peruse the working on anything non-trivial. These guidelines are intended to keep the code consistent and avoid common pitfalls. +**Important:** When modifying multiple packages, **create a different branch and pull request per package.** +This facilitates maintenance, the review process, and generating changelogs. + ### 5.1 Getting started To start working on a patch: @@ -221,7 +224,7 @@ To send us a pull request: Please make sure all your check-ins have detailed commit messages explaining the patch. When naming the title of your pull request, please follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.4/) -guide. For example, for a fix to the `sensor_plus` plugin: +guide, and include the package name in parenthesis. For example, for a fix to the `sensor_plus` plugin: `fix(sensor_plus): fixed a bug!` diff --git a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt index ac0a21bca30..3c97c7d2b78 100644 --- a/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt +++ b/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/DeviceInfoPlusPlugin.kt @@ -4,27 +4,52 @@ import android.content.Context import android.content.pm.PackageManager import android.view.WindowManager import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.activity.ActivityAware +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.MethodChannel /** DeviceInfoPlusPlugin */ -class DeviceInfoPlusPlugin : FlutterPlugin { +class DeviceInfoPlusPlugin : FlutterPlugin, ActivityAware { private lateinit var methodChannel: MethodChannel override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { - setupMethodChannel(binding.binaryMessenger, binding.applicationContext) + setupMethodChannel(binding.binaryMessenger) } override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { methodChannel.setMethodCallHandler(null) } - private fun setupMethodChannel(messenger: BinaryMessenger, context: Context) { + private fun setupMethodChannel(messenger: BinaryMessenger) { methodChannel = MethodChannel(messenger, "dev.fluttercommunity.plus/device_info") + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + configureMethodCallHandler(binding) + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + configureMethodCallHandler(binding) + } + + override fun onDetachedFromActivityForConfigChanges() { + methodChannel.setMethodCallHandler(null) + } + + override fun onDetachedFromActivity() { + methodChannel.setMethodCallHandler(null) + } + + private fun configureMethodCallHandler(binding: ActivityPluginBinding) { + val context = binding.activity as Context val packageManager: PackageManager = context.packageManager - val windowManager: WindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager + // WindowManager must be obtained from Activity Context + val windowManager: WindowManager = + context.getSystemService(Context.WINDOW_SERVICE) as WindowManager val handler = MethodCallHandlerImpl(packageManager, windowManager) methodChannel.setMethodCallHandler(handler) } + } diff --git a/packages/device_info_plus/device_info_plus/example/android/app/build.gradle b/packages/device_info_plus/device_info_plus/example/android/app/build.gradle index aeae2d5775c..2aec806bca3 100644 --- a/packages/device_info_plus/device_info_plus/example/android/app/build.gradle +++ b/packages/device_info_plus/device_info_plus/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 33 + compileSdk 34 namespace 'io.flutter.plugins.deviceinfoexample.example' diff --git a/packages/device_info_plus/device_info_plus/example/android/app/src/main/kotlin/io/flutter/plugins/deviceinfoexample/example/MainActivity.kt b/packages/device_info_plus/device_info_plus/example/android/app/src/main/kotlin/io/flutter/plugins/deviceinfoexample/example/MainActivity.kt index 69d0e0bfdd0..e2bd9925757 100644 --- a/packages/device_info_plus/device_info_plus/example/android/app/src/main/kotlin/io/flutter/plugins/deviceinfoexample/example/MainActivity.kt +++ b/packages/device_info_plus/device_info_plus/example/android/app/src/main/kotlin/io/flutter/plugins/deviceinfoexample/example/MainActivity.kt @@ -1,5 +1,21 @@ package io.flutter.plugins.deviceinfoexample.example +import android.os.Build +import android.os.Bundle +import android.os.StrictMode import io.flutter.embedding.android.FlutterActivity -class MainActivity: FlutterActivity() +class MainActivity: FlutterActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + // Ensures correct use of Activity Context to obtain the WindowManager + StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder() + .detectIncorrectContextUse() + .penaltyLog() + .penaltyDeath() + .build()) + } + super.onCreate(savedInstanceState) + } +} diff --git a/packages/device_info_plus/device_info_plus/example/lib/main.dart b/packages/device_info_plus/device_info_plus/example/lib/main.dart index 3510430bd29..aa94cca50d3 100644 --- a/packages/device_info_plus/device_info_plus/example/lib/main.dart +++ b/packages/device_info_plus/device_info_plus/example/lib/main.dart @@ -148,7 +148,7 @@ class _MyAppState extends State { Map _readWebBrowserInfo(WebBrowserInfo data) { return { - 'browserName': describeEnum(data.browserName), + 'browserName': data.browserName.name, 'appCodeName': data.appCodeName, 'appName': data.appName, 'appVersion': data.appVersion, diff --git a/packages/network_info_plus/network_info_plus/README.md b/packages/network_info_plus/network_info_plus/README.md index 02adc768c8a..86dcf0927ca 100644 --- a/packages/network_info_plus/network_info_plus/README.md +++ b/packages/network_info_plus/network_info_plus/README.md @@ -99,6 +99,34 @@ Make sure to add the following keys to your _Info.plist_ file, located in `CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/project.pbxproj b/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/project.pbxproj index c0d1a3e79c6..281a9f5c821 100644 --- a/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/project.pbxproj @@ -42,6 +42,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 118BE7CF2BA1DA0E00123575 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; @@ -97,7 +98,6 @@ DEBC0AFCA2032CC36403231F /* Pods-RunnerTests.release.xcconfig */, 7387B463A2D7284D71C2F4E8 /* Pods-RunnerTests.profile.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -144,6 +144,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 118BE7CF2BA1DA0E00123575 /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, @@ -215,7 +216,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { @@ -467,6 +468,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -645,6 +647,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -667,6 +670,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e42adcb34c2..8e3ca5dfe19 100644 --- a/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName @@ -24,6 +26,10 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + NSLocationWhenInUseUsageDescription + Obtain WIFI Name + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -43,9 +49,5 @@ UIViewControllerBasedStatusBarAppearance - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner/Runner.entitlements b/packages/network_info_plus/network_info_plus/example/ios/Runner/Runner.entitlements new file mode 100644 index 00000000000..ba21fbdaf29 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner/Runner.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.developer.networking.wifi-info + + + diff --git a/packages/network_info_plus/network_info_plus/example/lib/main.dart b/packages/network_info_plus/network_info_plus/example/lib/main.dart index b97cfa82d31..c6b548ea31d 100644 --- a/packages/network_info_plus/network_info_plus/example/lib/main.dart +++ b/packages/network_info_plus/network_info_plus/example/lib/main.dart @@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:network_info_plus/network_info_plus.dart'; +import 'package:permission_handler/permission_handler.dart'; // Sets a platform override for desktop to avoid exceptions. See // https://flutter.dev/desktop#target-platform-override for more info. @@ -97,18 +98,13 @@ class _MyHomePageState extends State { wifiSubmask; try { - if (!kIsWeb && Platform.isIOS) { - // ignore: deprecated_member_use - var status = await _networkInfo.getLocationServiceAuthorization(); - if (status == LocationAuthorizationStatus.notDetermined) { - // ignore: deprecated_member_use - status = await _networkInfo.requestLocationServiceAuthorization(); - } - if (status == LocationAuthorizationStatus.authorizedAlways || - status == LocationAuthorizationStatus.authorizedWhenInUse) { + if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { + // Request permissions as recommended by the plugin documentation: + // https://github.com/fluttercommunity/plus_plugins/tree/main/packages/network_info_plus/network_info_plus + if (await Permission.locationWhenInUse.request().isGranted) { wifiName = await _networkInfo.getWifiName(); } else { - wifiName = await _networkInfo.getWifiName(); + wifiName = 'Unauthorized to get Wifi Name'; } } else { wifiName = await _networkInfo.getWifiName(); @@ -119,21 +115,16 @@ class _MyHomePageState extends State { } try { - if (!kIsWeb && Platform.isIOS) { - // ignore: deprecated_member_use - var status = await _networkInfo.getLocationServiceAuthorization(); - if (status == LocationAuthorizationStatus.notDetermined) { - // ignore: deprecated_member_use - status = await _networkInfo.requestLocationServiceAuthorization(); - } - if (status == LocationAuthorizationStatus.authorizedAlways || - status == LocationAuthorizationStatus.authorizedWhenInUse) { + if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { + // Request permissions as recommended by the plugin documentation: + // https://github.com/fluttercommunity/plus_plugins/tree/main/packages/network_info_plus/network_info_plus + if (await Permission.locationWhenInUse.request().isGranted) { wifiBSSID = await _networkInfo.getWifiBSSID(); } else { - wifiBSSID = await _networkInfo.getWifiBSSID(); + wifiBSSID = 'Unauthorized to get Wifi BSSID'; } } else { - wifiBSSID = await _networkInfo.getWifiBSSID(); + wifiName = await _networkInfo.getWifiName(); } } on PlatformException catch (e) { developer.log('Failed to get Wifi BSSID', error: e); diff --git a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj index f07cb673e6e..487a081530f 100644 --- a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj +++ b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/project.pbxproj @@ -259,7 +259,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 331C80D4294CF70F00263BE5 = { diff --git a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c8ac8331f3f..427f4e1735b 100644 --- a/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/network_info_plus/network_info_plus/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -@class FPPNetworkInfoLocationPlusDelegate; - -typedef void (^FPPNetworkInfoLocationPlusCompletion)(CLAuthorizationStatus); - -@interface FPPNetworkInfoLocationPlusHandler : NSObject - -+ (CLAuthorizationStatus)locationAuthorizationStatus; - -- (void)requestLocationAuthorization:(BOOL)always - completion: - (_Nonnull FPPNetworkInfoLocationPlusCompletion) - completionHnadler; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoLocationPlusHandler.m b/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoLocationPlusHandler.m deleted file mode 100644 index ae64577044b..00000000000 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoLocationPlusHandler.m +++ /dev/null @@ -1,59 +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 "FPPNetworkInfoLocationPlusHandler.h" - -@interface FPPNetworkInfoLocationPlusHandler () - -@property(copy, nonatomic) FPPNetworkInfoLocationPlusCompletion completion; -@property(strong, nonatomic) CLLocationManager *locationManager; - -@end - -@implementation FPPNetworkInfoLocationPlusHandler - -+ (CLAuthorizationStatus)locationAuthorizationStatus { - return CLLocationManager.authorizationStatus; -} - -- (void)requestLocationAuthorization:(BOOL)always - completion:(FPPNetworkInfoLocationPlusCompletion) - 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/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoPlusPlugin.m b/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoPlusPlugin.m index 204d3880c1d..e2bbb2ece49 100644 --- a/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoPlusPlugin.m +++ b/packages/network_info_plus/network_info_plus/ios/Classes/FPPNetworkInfoPlusPlugin.m @@ -7,7 +7,6 @@ #import "FPPCaptiveNetworkInfoProvider.h" #import "FPPHotspotNetworkInfoProvider.h" #import "FPPNetworkInfo.h" -#import "FPPNetworkInfoLocationPlusHandler.h" #import "FPPNetworkInfoProvider.h" #import "SystemConfiguration/CaptiveNetwork.h" #import "getgateway.h" @@ -20,7 +19,6 @@ @interface FPPNetworkInfoPlusPlugin () -@property(strong, nonatomic) FPPNetworkInfoLocationPlusHandler *locationHandler; @property(strong, nonatomic) id networkInfoProvider; - (instancetype)initWithNetworkInfoProvider: @@ -103,30 +101,6 @@ - (NSString *)getWifiBroadcast { return addr; } -- (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"; - } - } -} - - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([call.method isEqualToString:@"wifiName"]) { @@ -149,33 +123,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result([self getWifiBroadcast]); } else if ([call.method isEqualToString:@"wifiGatewayAddress"]) { result([self getGatewayIP]); - } else if ([call.method isEqualToString:@"getLocationServiceAuthorization"]) { - result([self - convertCLAuthorizationStatusToString:[FPPNetworkInfoLocationPlusHandler - 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); } } -- (FPPNetworkInfoLocationPlusHandler *)locationHandler { - if (!_locationHandler) { - _locationHandler = [FPPNetworkInfoLocationPlusHandler new]; - } - return _locationHandler; -} - #pragma mark - Utils - (void)enumerateWifiAddresses:(NSInteger)family diff --git a/packages/network_info_plus/network_info_plus/lib/network_info_plus.dart b/packages/network_info_plus/network_info_plus/lib/network_info_plus.dart index b4e79f4ec46..a7e51fb42e0 100644 --- a/packages/network_info_plus/network_info_plus/lib/network_info_plus.dart +++ b/packages/network_info_plus/network_info_plus/lib/network_info_plus.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:flutter/services.dart'; import 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; // Export enums from the platform_interface so plugin users can use them directly. @@ -83,106 +82,4 @@ class NetworkInfo { Future getWifiBroadcast() { return _platform.getWifiBroadcast(); } - - /// 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 `/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 _networkInfo.getLocationServiceAuthorization(); - /// if (status == LocationAuthorizationStatus.notDetermined) { - /// status = await _networkInfo.requestLocationServiceAuthorization(); - /// } - /// if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) { - /// wifiBSSID = await _networkInfo.getWifiName(); - /// } else { - /// print('location service is not authorized, the data might not be correct'); - /// wifiBSSID = await _networkInfo.getWifiName(); - /// } - /// } else { - /// wifiBSSID = await _networkInfo.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( - 'Plugin users should use the permission_handler plugin to request permissions. ' - 'See README.md for more details.') - Future 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 _networkInfo.getLocationServiceAuthorization(); - /// if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) { - /// wifiBSSID = await _networkInfo.getWifiName(); - /// } else { - /// print('location service is not authorized, the data might not be correct'); - /// wifiBSSID = await _networkInfo.getWifiName(); - /// } - /// } else { - /// wifiBSSID = await _networkInfo.getWifiName(); - /// } - /// ``` - /// - /// See also [requestLocationServiceAuthorization] for requesting a location service authorization. - @Deprecated( - 'Plugin users should use the permission_handler plugin to request permissions. ' - 'See README.md for more details.') - Future getLocationServiceAuthorization() { - return _platform.getLocationServiceAuthorization(); - } } diff --git a/packages/network_info_plus/network_info_plus/test/network_info_test.dart b/packages/network_info_plus/network_info_plus/test/network_info_test.dart index f5741a827e0..20efe9493f4 100644 --- a/packages/network_info_plus/network_info_plus/test/network_info_test.dart +++ b/packages/network_info_plus/network_info_plus/test/network_info_test.dart @@ -64,18 +64,6 @@ void main() { final result = await networkInfo.getWifiGatewayIP(); expect(result, kWifiGatewayIP); }); - - test('requestLocationServiceAuthorization', () async { - // ignore: deprecated_member_use_from_same_package - final result = await networkInfo.requestLocationServiceAuthorization(); - expect(result, kRequestLocationResult); - }); - - test('getLocationServiceAuthorization', () async { - // ignore: deprecated_member_use_from_same_package - final result = await networkInfo.getLocationServiceAuthorization(); - expect(result, kRequestLocationResult); - }); }); } @@ -116,16 +104,4 @@ class MockNetworkInfoPlatform extends Mock Future getWifiIP() async { return kWifiIpAddressResult; } - - @override - Future requestLocationServiceAuthorization({ - bool requestAlwaysLocationUsage = false, - }) async { - return kRequestLocationResult; - } - - @override - Future getLocationServiceAuthorization() async { - return kGetLocationResult; - } } diff --git a/packages/network_info_plus/network_info_plus_platform_interface/lib/method_channel_network_info.dart b/packages/network_info_plus/network_info_plus_platform_interface/lib/method_channel_network_info.dart index 9581fbcf8ad..8c5c6b5253a 100644 --- a/packages/network_info_plus/network_info_plus_platform_interface/lib/method_channel_network_info.dart +++ b/packages/network_info_plus/network_info_plus_platform_interface/lib/method_channel_network_info.dart @@ -8,8 +8,6 @@ import 'package:network_info_plus_platform_interface/network_info_plus_platform_ import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; -import 'src/utils.dart'; - /// An implementation of [NetworkInfoPlatform] that uses method channels. class MethodChannelNetworkInfo extends NetworkInfoPlatform { /// The method channel used to interact with the native platform. @@ -57,21 +55,4 @@ class MethodChannelNetworkInfo extends NetworkInfoPlatform { Future getWifiBroadcast() { return methodChannel.invokeMethod('wifiBroadcast'); } - - @override - Future requestLocationServiceAuthorization({ - bool requestAlwaysLocationUsage = false, - }) { - return methodChannel.invokeMethod( - 'requestLocationServiceAuthorization', [ - requestAlwaysLocationUsage - ]).then(parseLocationAuthorizationStatus); - } - - @override - Future getLocationServiceAuthorization() { - return methodChannel - .invokeMethod('getLocationServiceAuthorization') - .then(parseLocationAuthorizationStatus); - } } diff --git a/packages/network_info_plus/network_info_plus_platform_interface/lib/network_info_plus_platform_interface.dart b/packages/network_info_plus/network_info_plus_platform_interface/lib/network_info_plus_platform_interface.dart index f219ee4f90d..2438f51258d 100644 --- a/packages/network_info_plus/network_info_plus_platform_interface/lib/network_info_plus_platform_interface.dart +++ b/packages/network_info_plus/network_info_plus_platform_interface/lib/network_info_plus_platform_interface.dart @@ -7,7 +7,6 @@ import 'dart:async'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'method_channel_network_info.dart'; -import 'src/enums.dart'; export 'src/enums.dart'; @@ -72,17 +71,4 @@ abstract class NetworkInfoPlatform extends PlatformInterface { Future getWifiBroadcast() { throw UnimplementedError('getWifiBroadcast() has not been implemented.'); } - - /// Request to authorize the location service (Only on iOS). - Future requestLocationServiceAuthorization( - {bool requestAlwaysLocationUsage = false}) { - throw UnimplementedError( - 'requestLocationServiceAuthorization() has not been implemented.'); - } - - /// Get the current location service authorization (Only on iOS). - Future getLocationServiceAuthorization() { - throw UnimplementedError( - 'getLocationServiceAuthorization() has not been implemented.'); - } } diff --git a/packages/network_info_plus/network_info_plus_platform_interface/test/method_channel_network_info_test.dart b/packages/network_info_plus/network_info_plus_platform_interface/test/method_channel_network_info_test.dart index 4e7e72dcad8..4cd4d12525e 100644 --- a/packages/network_info_plus/network_info_plus_platform_interface/test/method_channel_network_info_test.dart +++ b/packages/network_info_plus/network_info_plus_platform_interface/test/method_channel_network_info_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 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:network_info_plus_platform_interface/method_channel_network_info.dart'; @@ -146,35 +145,5 @@ void main() { ], ); }); - - test('requestLocationServiceAuthorization', () async { - final result = - await methodChannelNetworkInfo.requestLocationServiceAuthorization(); - expect(result, LocationAuthorizationStatus.authorizedAlways); - expect( - log, - [ - isMethodCall( - 'requestLocationServiceAuthorization', - arguments: [false], - ), - ], - ); - }); - - test('getLocationServiceAuthorization', () async { - final result = - await methodChannelNetworkInfo.getLocationServiceAuthorization(); - expect(result, LocationAuthorizationStatus.authorizedAlways); - expect( - log, - [ - isMethodCall( - 'getLocationServiceAuthorization', - arguments: null, - ), - ], - ); - }); }); } diff --git a/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart b/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart index bda9a39f666..093b0cebaf2 100644 --- a/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart +++ b/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart @@ -4,7 +4,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:http/http.dart'; import 'package:package_info_plus_platform_interface/package_info_data.dart'; import 'package:package_info_plus_platform_interface/package_info_platform_interface.dart'; -import 'package:web/helpers.dart' as web; +import 'package:web/web.dart' as web; /// The web implementation of [PackageInfoPlatform]. ///