Skip to content

Commit

Permalink
Merge branch 'main' into refactor/update-super-constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
OutdatedGuy authored Mar 15, 2024
2 parents 1dcb160 + a71a27c commit 701ec9d
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 373 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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!`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _MyAppState extends State<MyApp> {

Map<String, dynamic> _readWebBrowserInfo(WebBrowserInfo data) {
return <String, dynamic>{
'browserName': describeEnum(data.browserName),
'browserName': data.browserName.name,
'appCodeName': data.appCodeName,
'appName': data.appName,
'appVersion': data.appVersion,
Expand Down
28 changes: 28 additions & 0 deletions packages/network_info_plus/network_info_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ Make sure to add the following keys to your _Info.plist_ file, located in `<proj
- `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.

#### iOS 14

Starting on iOS 14, the plugin uses the method `NEHotspotNetwork.fetchCurrentWithCompletionHandler` to obtain the WIFI SSID (name) and BSSID.

According to this method documentation:

```
* @discussion This method returns SSID, BSSID and security type of the current Wi-Fi network when the
* requesting application meets one of following 4 requirements -.
* 1. application is using CoreLocation API and has user's authorization to access precise location.
* 2. application has used NEHotspotConfiguration API to configure the current Wi-Fi network.
* 3. application has active VPN configurations installed.
* 4. application has active NEDNSSettingsManager configuration installed.
* An application will receive nil if it fails to meet any of the above 4 requirements.
* An application will receive nil if does not have the "com.apple.developer.networking.wifi-info" entitlement.
```

**You will have to comply with ONE of the 4 conditions listed.**

The example application for this project, implements number 1 using the [permission_handler](https://pub.dev/packages/permission_handler) plugin.

Also, **your application needs the "com.apple.developer.networking.wifi-info" entitlement.**

This entitlement can be configured in xcode with the name "Access Wi-Fi information", and it is also found in the file `Runner.entitlements` in the example project. However,
**this entitlement is only possible when using a professional development team** and not a "Personal development team".

Without complying with these conditions, the calls to `.getWifiBSSID()` and `.getWifiName()` will return null.

## Learn more

- [API Documentation](https://pub.dev/documentation/network_info_plus/latest/network_info_plus/network_info_plus-library.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34

namespace 'dev.fluttercommunity.plus.network_info_plus_example'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:network_info_plus/network_info_plus.dart';
Expand All @@ -16,14 +14,6 @@ void main() {
networkInfo = NetworkInfo();
});

testWidgets('test location methods, iOS only', (WidgetTester tester) async {
if (Platform.isIOS) {
// ignore: deprecated_member_use
expect((await networkInfo.getLocationServiceAuthorization()),
LocationAuthorizationStatus.notDetermined);
}
}, skip: !Platform.isIOS);

testWidgets('test non-null network value', (WidgetTester tester) async {
expect(networkInfo.getWifiName(), isNotNull);
expect(networkInfo.getWifiBSSID(), isNotNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
118BE7CF2BA1DA0E00123575 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -97,7 +98,6 @@
DEBC0AFCA2032CC36403231F /* Pods-RunnerTests.release.xcconfig */,
7387B463A2D7284D71C2F4E8 /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -144,6 +144,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
118BE7CF2BA1DA0E00123575 /* Runner.entitlements */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -215,7 +216,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -24,6 +26,10 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Obtain WIFI Name</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,9 +49,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
</dict>
</plist>
33 changes: 12 additions & 21 deletions packages/network_info_plus/network_info_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -97,18 +98,13 @@ class _MyHomePageState extends State<MyHomePage> {
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();
Expand All @@ -119,21 +115,16 @@ class _MyHomePageState extends State<MyHomePage> {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
flutter:
sdk: flutter
network_info_plus: ^4.1.0+1
permission_handler: ^11.3.0

dev_dependencies:
flutter_test:
Expand Down
Loading

0 comments on commit 701ec9d

Please sign in to comment.