From 6c031385967fd8a524158e606015c04943ad83ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E4=BC=9Fx?= Date: Wed, 6 Nov 2024 16:49:34 +0800 Subject: [PATCH] =?UTF-8?q?network=5Finfo=5Fplus=E9=80=82=E9=85=8Dohos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 任伟x --- OAT.xml | 2 + .../network_info_plus_ohos/.gitignore | 30 +++ .../network_info_plus_ohos/.metadata | 30 +++ .../network_info_plus_ohos/CHANGELOG.md | 3 + .../network_info_plus_ohos/LICENSE | 59 ++++++ .../network_info_plus_ohos/README.md | 33 +++ .../analysis_options.yaml | 4 + .../network_info_plus_ohos/example/.gitignore | 44 ++++ .../network_info_plus_ohos/example/README.md | 16 ++ .../example/analysis_options.yaml | 29 +++ .../example/lib/main.dart | 196 +++++++++++++++++ .../example/ohos/.gitignore | 19 ++ .../example/ohos/AppScope/app.json5 | 10 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes .../example/ohos/build-profile.json5 | 27 +++ .../example/ohos/entry/.gitignore | 7 + .../example/ohos/entry/build-profile.json5 | 29 +++ .../example/ohos/entry/hvigorfile.ts | 17 ++ .../example/ohos/entry/oh-package.json5 | 11 + .../main/ets/entryability/EntryAbility.ets | 24 +++ .../ohos/entry/src/main/ets/pages/Index.ets | 38 ++++ .../ets/plugins/GeneratedPluginRegistrant.ets | 41 ++++ .../example/ohos/entry/src/main/module.json5 | 54 +++++ .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 16 ++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 16 ++ .../main/resources/zh_CN/element/string.json | 16 ++ .../src/ohosTest/ets/test/Ability.test.ets | 50 +++++ .../entry/src/ohosTest/ets/test/List.test.ets | 20 ++ .../ohosTest/ets/testability/TestAbility.ets | 63 ++++++ .../ohosTest/ets/testability/pages/Index.ets | 49 +++++ .../ets/testrunner/OpenHarmonyTestRunner.ts | 64 ++++++ .../ohos/entry/src/ohosTest/module.json5 | 51 +++++ .../resources/base/element/color.json | 8 + .../resources/base/element/string.json | 16 ++ .../ohosTest/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + .../example/ohos/hvigor/hvigor-config.json5 | 23 ++ .../example/ohos/hvigorfile.ts | 21 ++ .../example/ohos/oh-package.json5 | 20 ++ .../example/pubspec.yaml | 83 ++++++++ .../example/test/widget_test.dart | 27 +++ .../lib/network_info_plus_ohos.dart | 188 +++++++++++++++++ .../lib/src/network_info_plus_linux.dart | 131 ++++++++++++ .../lib/src/network_info_plus_macos.dart | 3 + .../lib/src/network_info_plus_web.dart | 29 +++ .../lib/src/network_info_plus_windows.dart | 175 +++++++++++++++ .../network_info_plus_ohos/ohos/.gitignore | 9 + .../ohos/build-profile.json5 | 10 + .../network_info_plus_ohos/ohos/hvigorfile.ts | 2 + .../network_info_plus_ohos/ohos/index.ets | 17 ++ .../ohos/oh-package.json5 | 11 + .../plugin/NetworkInfoPlusOhosPlugin.ets | 199 ++++++++++++++++++ .../ohos/src/main/module.json5 | 10 + .../network_info_plus_ohos/pubspec.yaml | 79 +++++++ .../test/network_info_test.dart | 93 ++++++++ 59 files changed, 2248 insertions(+) create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/.gitignore create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/.metadata create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/CHANGELOG.md create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/LICENSE create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/README.md create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/analysis_options.yaml create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/.gitignore create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/README.md create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/analysis_options.yaml create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/lib/main.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/.gitignore create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/app.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/element/string.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/media/app_icon.png create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/build-profile.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/.gitignore create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/build-profile.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/hvigorfile.ts create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/oh-package.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/ets/pages/Index.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/ets/plugins/GeneratedPluginRegistrant.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/module.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/base/element/color.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/base/element/string.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/base/media/icon.png create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/module.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/hvigor/hvigor-config.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/hvigorfile.ts create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/oh-package.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/pubspec.yaml create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/test/widget_test.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/network_info_plus_ohos.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_linux.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_macos.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_web.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_windows.dart create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/.gitignore create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/build-profile.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/hvigorfile.ts create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/index.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/oh-package.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/ets/components/plugin/NetworkInfoPlusOhosPlugin.ets create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/module.json5 create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/pubspec.yaml create mode 100644 packages/network_info_plus/network_info_plus/network_info_plus_ohos/test/network_info_test.dart diff --git a/OAT.xml b/OAT.xml index a3f824e9..75e2c5cc 100644 --- a/OAT.xml +++ b/OAT.xml @@ -143,9 +143,11 @@ + + diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.gitignore b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.gitignore new file mode 100644 index 00000000..96486fd9 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.metadata b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.metadata new file mode 100644 index 00000000..797f5fa5 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 57c6427dd2a6d4acaf92936b986ccd30c744e488 + channel: dev + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 57c6427dd2a6d4acaf92936b986ccd30c744e488 + base_revision: 57c6427dd2a6d4acaf92936b986ccd30c744e488 + - platform: ohos + create_revision: 57c6427dd2a6d4acaf92936b986ccd30c744e488 + base_revision: 57c6427dd2a6d4acaf92936b986ccd30c744e488 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/CHANGELOG.md b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/CHANGELOG.md new file mode 100644 index 00000000..0b2cc337 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +* Support OpenHarmony. diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/LICENSE b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/LICENSE new file mode 100644 index 00000000..5e3a9163 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/LICENSE @@ -0,0 +1,59 @@ +Copyright 2017 The Chromium Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-------------------------------------------------------------------------------- +libnatpmp + +BSD 3-Clause License + +Copyright (c) 2007-2022, Thomas BERNARD +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/README.md b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/README.md new file mode 100644 index 00000000..e0f748fe --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/README.md @@ -0,0 +1,33 @@ +# network_info_plus_ohos + +Flutter插件,用于从发现网络的信息(例如WiFi详细信息). + +## Usage + +```yaml +dependencies: + network_info_plus: 4.0.2 + network_info_plus_ohos: 1.0.0 +``` + +## Getting Started + +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/developing-packages/), +a specialized package that includes platform-specific implementation code for +ohos. + +For help getting started with Flutter development, view the +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. + +## 支持格式 +|格式|android|ios| OpenHarmony | +|:----|:----:|:----:|:--------------:| +|getWifiName| ✅ | ✅ | ✅ | +|getWifiBSSID| ✅ | ✅ | ✅ | +|getWifiIP| ✅ | ✅ | ✅ | +|getWifiIPv6| ✅ | ✅ | ✅ | +|getWifiSubmask| ✅ | ✅ | ✅ | +|getWifiGatewayIP|✅ | ✅ | ✅ | +|getWifiBroadcast|✅ | ✅ | ✅ | \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/analysis_options.yaml b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/.gitignore b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/.gitignore new file mode 100644 index 00000000..24476c5d --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/README.md b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/README.md new file mode 100644 index 00000000..31f45230 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/README.md @@ -0,0 +1,16 @@ +# network_info_plus_ohos_example + +Demonstrates how to use the network_info_plus_ohos plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/analysis_options.yaml b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/lib/main.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/lib/main.dart new file mode 100644 index 00000000..7137b9c9 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/lib/main.dart @@ -0,0 +1,196 @@ +// Copyright 2017 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. + +// ignore_for_file: public_member_api_docs + +import 'dart:async'; +import 'dart:developer' as developer; +import 'dart:io'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:network_info_plus_ohos/network_info_plus_ohos.dart'; + +// Sets a platform override for desktop to avoid exceptions. See +// https://flutter.dev/desktop#target-platform-override for more info. +void _enablePlatformOverrideForDesktop() { + if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) { + debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; + } +} + +void main() { + _enablePlatformOverrideForDesktop(); + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + useMaterial3: true, + colorSchemeSeed: const Color(0x9f4376f8), + ), + home: const MyHomePage(title: 'Flutter Demo Home Page'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({Key? key, this.title}) : super(key: key); + + final String? title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + String _connectionStatus = 'Unknown'; + final NetworkInfo _networkInfo = NetworkInfo(); + + @override + void initState() { + super.initState(); + _initNetworkInfo(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('NetworkInfoPlus example'), + elevation: 4, + ), + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text( + 'Network info', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 16), + Text(_connectionStatus), + ], + )), + ); + } + + Future _initNetworkInfo() async { + String? wifiName, + wifiBSSID, + wifiIPv4, + wifiIPv6, + wifiGatewayIP, + wifiBroadcast, + 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) { + wifiName = await _networkInfo.getWifiName(); + } else { + wifiName = await _networkInfo.getWifiName(); + } + } else { + wifiName = await _networkInfo.getWifiName(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi Name', error: e); + wifiName = 'Failed to get Wifi Name'; + } + + 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) { + wifiBSSID = await _networkInfo.getWifiBSSID(); + } else { + wifiBSSID = await _networkInfo.getWifiBSSID(); + } + } else { + wifiBSSID = await _networkInfo.getWifiBSSID(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi BSSID', error: e); + wifiBSSID = 'Failed to get Wifi BSSID'; + } + + try { + wifiIPv4 = await _networkInfo.getWifiIP(); + } on PlatformException catch (e) { + developer.log('Failed to get Wifi IPv4', error: e); + wifiIPv4 = 'Failed to get Wifi IPv4'; + } + + try { + if (!Platform.isWindows) { + wifiIPv6 = await _networkInfo.getWifiIPv6(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi IPv6', error: e); + wifiIPv6 = 'Failed to get Wifi IPv6'; + } + + try { + if (!Platform.isWindows) { + wifiSubmask = await _networkInfo.getWifiSubmask(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi submask address', error: e); + wifiSubmask = 'Failed to get Wifi submask address'; + } + + try { + if (!Platform.isWindows) { + wifiBroadcast = await _networkInfo.getWifiBroadcast(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi broadcast', error: e); + wifiBroadcast = 'Failed to get Wifi broadcast'; + } + + try { + if (!Platform.isWindows) { + wifiGatewayIP = await _networkInfo.getWifiGatewayIP(); + } + } on PlatformException catch (e) { + developer.log('Failed to get Wifi gateway address', error: e); + wifiGatewayIP = 'Failed to get Wifi gateway address'; + } + + setState(() { + _connectionStatus = 'Wifi Name: $wifiName\n' + 'Wifi BSSID: $wifiBSSID\n' + 'Wifi IPv4: $wifiIPv4\n' + 'Wifi IPv6: $wifiIPv6\n' + 'Wifi Broadcast: $wifiBroadcast\n' + 'Wifi Gateway: $wifiGatewayIP\n' + 'Wifi Submask: $wifiSubmask\n'; + }); + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/.gitignore b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/.gitignore new file mode 100644 index 00000000..6ca13b31 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/.gitignore @@ -0,0 +1,19 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +*.har +**/BuildProfile.ets +**/oh-package-lock.json5 + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/arm64-v8a/libapp.so +**/libs/arm64-v8a/libflutter.so +**/libs/arm64-v8a/libvmservice_snapshot.so diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/app.json5 b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/app.json5 new file mode 100644 index 00000000..8abc3141 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "dev.fluttercommunity.plus.network_info_plus_ohos_example", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/element/string.json b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 00000000..837dfad1 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "network_info_plus_ohos_example" + } + ] +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/media/app_icon.png b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcn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I=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 00000000..cef0447c --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 00000000..1def08f2 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/module.json5 b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 00000000..fab77ce2 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 00000000..3c712962 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 00000000..65d8fa5a --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_FpjoHev5fEV7RhJ>r=mh-jp$fqbqRJ=obwdgLDVP5+s zy1=_DWG0Y-Jb3t^WXmkr(d9~08k-|#Ly zaNOmT(^9tIb&eb4%CzIT zAm3CUtWSr1t4?h1kk#NBi{U|pJslvME{q|_eS^3En>SOqSxyuN1x;Is@8~m?*>}** znrRFArP!K_52RpX*&JHMR<^lVdm8ypJ}0R(SD(51j;6@ni$6bQ+2XL+R^|NnSp5}(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{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y=2.19.6 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + network_info_plus_ohos: + # When depending on this package from a real application you should use: + # network_info_plus_ohos: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/test/widget_test.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/test/widget_test.dart new file mode 100644 index 00000000..4f0d1d68 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/example/test/widget_test.dart @@ -0,0 +1,27 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:network_info_plus_ohos_example/main.dart'; + +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Text && + widget.data!.startsWith('Running on:'), + ), + findsOneWidget, + ); + }); +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/network_info_plus_ohos.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/network_info_plus_ohos.dart new file mode 100644 index 00000000..b4e79f4e --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/network_info_plus_ohos.dart @@ -0,0 +1,188 @@ +// Copyright 2017 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: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. +export 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart' + show LocationAuthorizationStatus; + +export 'src/network_info_plus_linux.dart'; +export 'src/network_info_plus_windows.dart' + if (dart.library.html) 'src/network_info_plus_web.dart'; + +/// Discover network info: check WI-FI details and more. +class NetworkInfo { + /// Constructs a singleton instance of [NetworkInfo]. + /// + /// [NetworkInfo] is designed to work as a singleton. + // When a second instance is created, the first instance will not be able to listen to the + // EventChannel because it is overridden. Forcing the class to be a singleton class can prevent + // misuse of creating a second instance from a programmer. + factory NetworkInfo() { + _singleton ??= NetworkInfo._(); + return _singleton!; + } + + NetworkInfo._(); + + static NetworkInfo? _singleton; + + // This is to manually endorse Dart implementations until automatic + // registration of Dart plugins is implemented. For details see + // https://github.com/flutter/flutter/issues/52267. + static NetworkInfoPlatform get _platform { + return NetworkInfoPlatform.instance; + } + + /// 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. + Future 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. + Future getWifiBSSID() { + return _platform.getWifiBSSID(); + } + + /// Obtains the IPv4 address of the connected wifi network + Future getWifiIP() { + return _platform.getWifiIP(); + } + + /// Obtains the IPv6 address of the connected wifi network + Future getWifiIPv6() { + return _platform.getWifiIPv6(); + } + + /// Obtains the submask of the connected wifi network + Future getWifiSubmask() { + return _platform.getWifiSubmask(); + } + + /// Obtains the gateway IP address of the connected wifi network + Future getWifiGatewayIP() { + return _platform.getWifiGatewayIP(); + } + + /// Obtains the broadcast of the connected wifi network + 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/network_info_plus_ohos/lib/src/network_info_plus_linux.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_linux.dart new file mode 100644 index 00000000..b4bf1211 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_linux.dart @@ -0,0 +1,131 @@ +import 'dart:async'; + +import 'package:collection/collection.dart'; +import 'package:meta/meta.dart'; +import 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; +import 'package:nm/nm.dart'; + +// Used internally +// ignore_for_file: public_member_api_docs + +typedef _DeviceGetter = Future Function(NetworkManagerDevice? device); +typedef _ConnectionGetter = Future Function( + NetworkManagerActiveConnection? connection); + +@visibleForTesting +typedef NetworkManagerClientFactory = NetworkManagerClient Function(); + +/// The Linux implementation of NetworkInfoPlatform. +class NetworkInfoPlusLinuxPlugin extends NetworkInfoPlatform { + /// Register this dart class as the platform implementation for linux + static void registerWith() { + NetworkInfoPlatform.instance = NetworkInfoPlusLinuxPlugin(); + } + + /// Obtains the wifi name (SSID) of the connected network + @override + Future getWifiName() { + return _getConnectionValue((connection) async => connection?.id); + } + + /// Obtains the IP v4 address of the connected wifi network + @override + Future getWifiIP() { + return _getConnectionValue( + (connection) async => _getIpAddress(connection?.ip4Config?.addressData), + ); + } + + /// Obtains the IP v6 address of the connected wifi network + @override + Future getWifiIPv6() { + return _getConnectionValue( + (connection) async => _getIpAddress(connection?.ip6Config?.addressData), + ); + } + + /// Obtains the wifi BSSID of the connected network. + @override + Future getWifiBSSID() { + return _getDeviceValue((device) async => device?.wireless?.permHwAddress); + } + + /// Obtains the submask of the connected wifi network + @override + Future getWifiSubmask() { + return _getConnectionValue( + (connection) async => _getSubnetMask(connection?.ip4Config?.addressData), + ); + } + + /// Obtains the gateway IP address of the connected wifi network + @override + Future getWifiGatewayIP() { + return _getConnectionValue( + (connection) async => connection?.ip4Config?.gateway, + ); + } + + /// Obtains the broadcast of the connected wifi network + @override + Future getWifiBroadcast() { + return _getConnectionValue( + (connection) async => _getBroadcast(connection?.ip4Config?.addressData), + ); + } + + Future _getDeviceValue(_DeviceGetter getter) { + return _getConnectionValue((connection) { + final device = connection?.devices + .firstWhereOrNull((device) => device.wireless != null); + return getter(device); + }); + } + + Future _getConnectionValue(_ConnectionGetter getter) async { + final client = createClient(); + await client.connect(); + final value = getter(client.primaryConnection); + await client.close(); + return value; + } + + String? _getIpAddress(List>? data) { + return data?.firstOrNull?['address'] as String?; + } + + String? _getSubnetMask(List>? data) { + final prefix = data?.firstOrNull?['prefix'] as int; + final mask = 0xffffffff >> (32 - prefix); + return mask.toIpString(); + } + + String? _getBroadcast(List>? data) { + final ip = _getIpAddress(data)?.toIpInt() ?? 0; + final mask = _getSubnetMask(data)?.toIpInt() ?? 0; + return (ip | (mask ^ 0xffffffff)).toIpString(); + } + + @visibleForTesting + // ignore: prefer_function_declarations_over_variables + NetworkManagerClientFactory createClient = () => NetworkManagerClient(); +} + +extension _IpInt on int { + int byteAt(int i) => (this >> (i * 8)) & 0xff; + String toIpString() => '${byteAt(0)}.${byteAt(1)}.${byteAt(2)}.${byteAt(3)}'; +} + +extension _IpString on String { + int toIpInt() { + final parts = split('.'); + return parts.intAtOrZero(3) << 24 | + parts.intAtOrZero(2) << 16 | + parts.intAtOrZero(1) << 8 | + parts.intAtOrZero(0); + } +} + +extension _IntOrZero on List { + int intAtOrZero(int i) => i < 0 || i >= length ? 0 : int.parse(this[i]); +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_macos.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_macos.dart new file mode 100644 index 00000000..ba7fc71d --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_macos.dart @@ -0,0 +1,3 @@ +// Analyze will fail if there is no main.dart file. This file should +// be removed once an example app has been added to network_info_plus_macos. +// https://github.com/flutter/flutter/issues/51007 diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_web.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_web.dart new file mode 100644 index 00000000..38734c60 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_web.dart @@ -0,0 +1,29 @@ +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; + +/// A stub implementation of the NetworkInfoPlatform interface for Web. +class NetworkInfoPlusWebPlugin extends NetworkInfoPlatform { + /// Factory method that initializes the network info plugin platform with + /// an instance of the plugin for the web. + static void registerWith(Registrar registrar) { + NetworkInfoPlatform.instance = NetworkInfoPlusWebPlugin(); + } + + /// Obtains the wifi name (SSID) of the connected network + @override + Future getWifiName() { + throw UnsupportedError('getWifiName() is not supported on Web.'); + } + + /// Obtains the wifi BSSID of the connected network. + @override + Future getWifiBSSID() { + throw UnsupportedError('getWifiBSSID() is not supported on Web.'); + } + + /// Obtains the IP address of the connected wifi network + @override + Future getWifiIP() { + throw UnsupportedError('getWifiIP() is not supported on Web.'); + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_windows.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_windows.dart new file mode 100644 index 00000000..102ca049 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/lib/src/network_info_plus_windows.dart @@ -0,0 +1,175 @@ +/// The Windows implementation of `network_info_plus`. +// ignore_for_file: constant_identifier_names + +library network_info_plus_windows; + +import 'dart:ffi'; + +import 'package:ffi/ffi.dart'; +import 'package:win32/win32.dart'; +import 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; +import 'package:win32/winsock2.dart'; + +typedef WlanQuery = String Function( + Pointer pGuid, Pointer pAttributes); + +class NetworkInfoPlusWindowsPlugin extends NetworkInfoPlatform { + int clientHandle = NULL; + + static void registerWith() { + NetworkInfoPlatform.instance = NetworkInfoPlusWindowsPlugin(); + } + + void openHandle() { + if (clientHandle != NULL) return; + + const WLAN_API_VERSION_2_0 = 0x00000002; + final phClientHandle = calloc(); + final pdwNegotiatedVersion = calloc(); + + try { + final hr = WlanOpenHandle( + WLAN_API_VERSION_2_0, nullptr, pdwNegotiatedVersion, phClientHandle); + if (hr == ERROR_SERVICE_NOT_ACTIVE) return; + clientHandle = phClientHandle.value; + } finally { + free(pdwNegotiatedVersion); + free(phClientHandle); + } + } + + void closeHandle() { + if (clientHandle != NULL) { + WlanCloseHandle(clientHandle, nullptr); + + clientHandle = NULL; + } + } + + String query(WlanQuery query) { + openHandle(); + final ppInterfaceList = calloc>(); + + try { + var hr = WlanEnumInterfaces(clientHandle, nullptr, ppInterfaceList); + if (hr != ERROR_SUCCESS) return ''; // no wifi interface available + + for (var i = 0; i < ppInterfaceList.value.ref.dwNumberOfItems; i++) { + final pInterfaceGuid = calloc() + ..ref.setGUID(ppInterfaceList.value.ref.InterfaceInfo[i].InterfaceGuid + .toString()); + + const opCode = 7; // wlan_intf_opcode_current_connection + final pdwDataSize = calloc(); + final pAttributes = calloc(); + + try { + hr = WlanQueryInterface(clientHandle, pInterfaceGuid, opCode, nullptr, + pdwDataSize, pAttributes.cast(), nullptr); + if (hr != ERROR_SUCCESS) break; + if (pAttributes.ref.isState != 0) { + return query(pInterfaceGuid, pAttributes); + } + } finally { + free(pInterfaceGuid); + free(pdwDataSize); + free(pAttributes); + } + } + return ''; + } finally { + WlanFreeMemory(ppInterfaceList); + closeHandle(); + } + } + + String formatBssid(List bssid) => + bssid.map((e) => e.toRadixString(16).padLeft(2, '0')).join(':'); + + String formatIPAddress(Pointer pIpAdapterAddress) { + var pAddr = pIpAdapterAddress.ref.FirstUnicastAddress; + + while (pAddr.ref.Next != nullptr) { + pAddr = pAddr.ref.Next; + } + + final buffer = calloc(64).cast(); + try { + // Rather messy way to find the right pointer for the IP Address + final sinAddr = pAddr.ref.Address.lpSockaddr.cast().elementAt(4); + + inet_ntop(AF_INET, sinAddr, buffer, 64); + return buffer.cast().toDartString(); + } finally { + free(buffer); + } + } + + String getAdapterAddress(Pointer pGuid, + Pointer pIpAdapterAddresses) { + final ifLuid = calloc(); + try { + if (ConvertInterfaceGuidToLuid(pGuid, ifLuid) != NO_ERROR) { + return ''; + } + + var pCurrent = pIpAdapterAddresses; + while (pCurrent.address != 0) { + if (pCurrent.ref.Luid.Value == ifLuid.ref.Value) { + return formatIPAddress(pCurrent); + } + pCurrent = pCurrent.ref.Next; + } + return ''; + } finally { + free(ifLuid); + } + } + + @override + Future getWifiName() { + return Future.value(query((pGuid, pAttributes) { + final DOT11_SSID ssid = + pAttributes.ref.wlanAssociationAttributes.dot11Ssid; + final charCodes = []; + for (var i = 0; i < ssid.uSSIDLength; i++) { + if (ssid.ucSSID[i] == 0x00) break; + charCodes.add(ssid.ucSSID[i]); + } + return String.fromCharCodes(charCodes); + })); + } + + /// Obtains the wifi BSSID of the connected network. + @override + Future getWifiBSSID() { + return Future.value(query((pGuid, pAttributes) { + return formatBssid([ + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[0], + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[1], + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[2], + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[3], + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[4], + pAttributes.ref.wlanAssociationAttributes.dot11Bssid[5], + ]); + })); + } + + /// Obtains the IP v4 address of the connected wifi network + @override + Future getWifiIP() { + return Future.value(query((pGuid, pAttributes) { + final ulSize = calloc(); + Pointer pIpAdapterAddress = nullptr; + try { + GetAdaptersAddresses(AF_INET, 0, nullptr, nullptr, ulSize); + pIpAdapterAddress = HeapAlloc(GetProcessHeap(), 0, ulSize.value).cast(); + GetAdaptersAddresses(AF_INET, 0, nullptr, pIpAdapterAddress, ulSize); + return getAdapterAddress(pGuid, pIpAdapterAddress); + } finally { + free(ulSize); + if (pIpAdapterAddress != nullptr) free(pIpAdapterAddress); + } + })); + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/.gitignore b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/.gitignore new file mode 100644 index 00000000..c0f9ca4c --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/.gitignore @@ -0,0 +1,9 @@ +/node_modules +/oh_modules +/.preview +/.idea +/build +/.cxx +/.test +/BuildProfile.ets +/oh-package-lock.json5 diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/build-profile.json5 b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/build-profile.json5 new file mode 100644 index 00000000..79961f96 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/hvigorfile.ts b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/hvigorfile.ts new file mode 100644 index 00000000..47e6e1f8 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { harTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/index.ets b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/index.ets new file mode 100644 index 00000000..f130ca57 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/index.ets @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import NetworkInfoPlusOhosPlugin from './src/main/ets/components/plugin/NetworkInfoPlusOhosPlugin'; +export default NetworkInfoPlusOhosPlugin; diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/oh-package.json5 b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/oh-package.json5 new file mode 100644 index 00000000..f2161f9b --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "network_info_plus_ohos", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/ets/components/plugin/NetworkInfoPlusOhosPlugin.ets b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/ets/components/plugin/NetworkInfoPlusOhosPlugin.ets new file mode 100644 index 00000000..f4e1f2d5 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/ets/components/plugin/NetworkInfoPlusOhosPlugin.ets @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + FlutterPlugin, + FlutterPluginBinding, + MethodCall, + MethodCallHandler, + MethodChannel, + MethodResult, +} from '@ohos/flutter_ohos'; +import { wifiManager } from '@kit.ConnectivityKit'; +import { connection } from '@kit.NetworkKit'; + +/** NetworkInfoPlusOhosPlugin **/ +export default class NetworkInfoPlusOhosPlugin implements FlutterPlugin, MethodCallHandler { + private channel: MethodChannel | null = null; + private wifiMessage: string | number | null = null; + constructor() { + } + + getUniqueClassName(): string { + return "NetworkInfoPlusOhosPlugin"; + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + this.channel = new MethodChannel(binding.getBinaryMessenger(), "dev.fluttercommunity.plus/network_info"); + this.channel.setMethodCallHandler(this); + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + if (this.channel != null) { + this.channel.setMethodCallHandler(null); + } + } + + async getWifiName() { + let dataSource: string | number = 0; + let wifiMessage = await wifiManager.getLinkedInfo().then(data => { + dataSource = data.ssid; + return dataSource; + }).catch((error: number) => { + console.info("get linked info error"); + }); + return wifiMessage; + } + + async getWifiBSSID() { + let dataSource: string | number = 0; + let wifiMessage = await wifiManager.getLinkedInfo().then(data => { + dataSource = data.bssid; + return dataSource; + }).catch((error: number) => { + console.info("get linked info error"); + }); + return wifiMessage; + } + + getWifiIPAddress() { + const bytes = [wifiManager.getIpInfo().ipAddress >>> 24, (wifiManager.getIpInfo().ipAddress >>> 16) & 0xFF, + (wifiManager.getIpInfo().ipAddress >>> 8) & 0xFF, wifiManager.getIpInfo().ipAddress & 0xFF]; + let ipv4 = wifiManager.getIpInfo().ipAddress; + if (ipv4 === 0) { + return 'null'; + } + let dataSource = bytes.map(byte => byte.toString()).join('.'); + return dataSource; + } + + ipToInt(ip: string): number { + let parts = ip.split('.'); + let num = 0; + for (let i = 0; i < parts.length; i++) { + num |= parseInt(parts[i], 10) << (24 - 8 * i); + } + return num; + } + + intToIp(num: number): string { + let parts:number[] = []; + for (let i = 0; i < 4; i++) { + parts.push((num >> (24 - 8 * i)) & 0xFF); + } + return parts.join('.'); + } + + getBroadcastIP() { + const ipInt:number = this.ipToInt(this.getWifiIPAddress() as string); + const subnetMaskInt = this.ipToInt(this.getWifiSubnetMask() as string); + const broadcastInt = (ipInt & subnetMaskInt) | (~subnetMaskInt + 1); + if (broadcastInt === 0) { + return null; + } + return this.intToIp(broadcastInt); + } + + getWifiSubnetMask() { + try { + const binaryStr = wifiManager.getIpInfo().netmask.toString(2); + const info:number[] = []; + for (let i = 0; i < 4; i++) { + const octet = parseInt(binaryStr.slice(i * 8, (i + 1) * 8), 2); + info.push(octet); + } + if (wifiManager.getIpInfo().netmask ===0) { + return ''; + } + return info.join('.'); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } + return null; + } + + getGatewayIPAddress() { + try { + const parts = [ + (wifiManager.getIpInfo().gateway >> 24) & 0xFF, + (wifiManager.getIpInfo().gateway >> 16) & 0xFF, + (wifiManager.getIpInfo().gateway >> 8) & 0xFF, + wifiManager.getIpInfo().gateway & 0xFF + ]; + if (wifiManager.getIpInfo().gateway === 0) { + return null; + } + return parts.map(part => part.toString()).join('.'); + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } + return null; + } + + getIpV6() { + try { + let info = wifiManager.getIpv6Info().linkIpv6Address; + if (info === '') { + return null; + } + return info; + }catch(error){ + console.error("failed:" + JSON.stringify(error)); + } + return null; + } + + //需要权限 ohos.permission.GET_WIFI_INFO + onMethodCall(call: MethodCall, result: MethodResult): void { + switch (call.method) { + case "wifiName": + this.getWifiName().then(data =>{ + if (!data) { + result.success(null); + return; + } + result.success(data); + }) + break; + case "wifiBSSID": + this.getWifiBSSID().then(data =>{ + if (!data) { + result.success('02:00:00:00:00:00'); + return; + } + result.success(data); + }) + break; + case "wifiIPAddress": + result.success(this.getWifiIPAddress()); + break; + case "wifiBroadcast": + result.success(this.getBroadcastIP()); + break; + case "wifiSubmask": + result.success(this.getWifiSubnetMask()); + break; + case "wifiGatewayAddress": + result.success(this.getGatewayIPAddress()); + break; + case "wifiIPv6Address": + result.success(this.getIpV6()); + break; + default: + result.notImplemented(); + break; + } + } +} \ No newline at end of file diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/module.json5 b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/module.json5 new file mode 100644 index 00000000..92691425 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/ohos/src/main/module.json5 @@ -0,0 +1,10 @@ +{ + "module": { + "name": "network_info_plus_ohos", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/pubspec.yaml b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/pubspec.yaml new file mode 100644 index 00000000..9d6ac4cb --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/pubspec.yaml @@ -0,0 +1,79 @@ +name: network_info_plus_ohos +description: Flutter plugin for discovering information (e.g. WiFi details) of the network. +version: 1.0.0 +homepage: https://gitee.com/openharmony-sig/fluttertpc_network_info_plus + +environment: + sdk: '>=2.19.6 <3.0.0' + flutter: ">=2.5.0" + +dependencies: + collection: ^1.17.0 + nm: ^0.5.0 + flutter: + sdk: flutter + flutter_web_plugins: + sdk: flutter + meta: ^1.8.0 + network_info_plus_platform_interface: ^1.1.3 + # win32 is compatible across v4 and v5 for Win32 only (not COM) + win32: ">=4.0.0 <6.0.0" + ffi: ^2.0.1 + +dev_dependencies: + flutter_test: + sdk: flutter + plugin_platform_interface: ^2.1.4 + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.) + # which should be registered in the plugin registry. This is required for + # using method channels. + # The Android 'package' specifies package in which the registered class is. + # This is required for using method channels on Android. + # The 'ffiPlugin' specifies that native code should be built and bundled. + # This is required for using `dart:ffi`. + # All these are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + platforms: + ohos: + package: dev.fluttercommunity.plus.network_info_plus_ohos + pluginClass: NetworkInfoPlusOhosPlugin + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/network_info_plus/network_info_plus/network_info_plus_ohos/test/network_info_test.dart b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/test/network_info_test.dart new file mode 100644 index 00000000..37392339 --- /dev/null +++ b/packages/network_info_plus/network_info_plus/network_info_plus_ohos/test/network_info_test.dart @@ -0,0 +1,93 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:network_info_plus_ohos/network_info_plus_ohos.dart'; +import 'package:network_info_plus_platform_interface/network_info_plus_platform_interface.dart'; + +class MockNetworkInfoPlatform extends NetworkInfoPlatform { + @override + Future getWifiName() async => 'Test-SSID'; + + @override + Future getWifiBSSID() async => 'AA:BB:CC:DD:EE:FF'; + + @override + Future getWifiIP() async => '192.168.1.100'; + + @override + Future getWifiIPv6() async => 'fe80::1'; + + @override + Future getWifiSubmask() async => '255.255.255.0'; + + @override + Future getWifiGatewayIP() async => '192.168.1.1'; + + @override + Future getWifiBroadcast() async => '192.168.1.255'; + + @override + Future requestLocationServiceAuthorization( + {bool requestAlwaysLocationUsage = false}) async { + return LocationAuthorizationStatus.authorizedAlways; + } + + @override + Future getLocationServiceAuthorization() async { + return LocationAuthorizationStatus.authorizedAlways; + } +} + +void main() { + group('NetworkInfo', () { + late NetworkInfo networkInfo; + + setUp(() { + NetworkInfoPlatform.instance = MockNetworkInfoPlatform(); + networkInfo = NetworkInfo(); + }); + + test('getWifiName should return a String', () async { + final wifiName = await networkInfo.getWifiName(); + expect(wifiName, 'Test-SSID'); + }); + + test('getWifiBSSID should return a String', () async { + final wifiBSSID = await networkInfo.getWifiBSSID(); + expect(wifiBSSID, 'AA:BB:CC:DD:EE:FF'); + }); + + test('getWifiIP should return a String', () async { + final wifiIP = await networkInfo.getWifiIP(); + expect(wifiIP, '192.168.1.100'); + }); + + test('getWifiIPv6 should return a String', () async { + final wifiIPv6 = await networkInfo.getWifiIPv6(); + expect(wifiIPv6, 'fe80::1'); + }); + + test('getWifiSubmask should return a String', () async { + final wifiSubmask = await networkInfo.getWifiSubmask(); + expect(wifiSubmask, '255.255.255.0'); + }); + + test('getWifiGatewayIP should return a String', () async { + final wifiGatewayIP = await networkInfo.getWifiGatewayIP(); + expect(wifiGatewayIP, '192.168.1.1'); + }); + + test('getWifiBroadcast should return a String', () async { + final wifiBroadcast = await networkInfo.getWifiBroadcast(); + expect(wifiBroadcast, '192.168.1.255'); + }); + + test('requestLocationServiceAuthorization should return LocationAuthorizationStatus', () async { + final status = await networkInfo.requestLocationServiceAuthorization(); + expect(status, LocationAuthorizationStatus.authorizedAlways); + }); + + test('getLocationServiceAuthorization should return LocationAuthorizationStatus', () async { + final status = await networkInfo.getLocationServiceAuthorization(); + expect(status, LocationAuthorizationStatus.authorizedAlways); + }); + }); +} \ No newline at end of file -- Gitee