Skip to content

Commit

Permalink
[wifi_info_flutter] Add wifi_info_flutter_tizen package (flutter-tize…
Browse files Browse the repository at this point in the history
…n#34)

* [wifi_info_flutter] Add wifi_info_flutter_tizen package

* Update example app

* Update pubspec and etc.

* Apply coding rules

* Update README

Co-authored-by: Swift Kim <[email protected]>
  • Loading branch information
bwikbs and swift-kim authored Mar 24, 2021
1 parent c40bf67 commit 6342185
Show file tree
Hide file tree
Showing 23 changed files with 659 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**share_tizen**](packages/share) | [share](https://github.com/flutter/plugins/tree/master/packages/share) (1st-party) | [![pub package](https://img.shields.io/pub/v/share_tizen.svg)](https://pub.dev/packages/share_tizen) | No |
| [**shared_preferences_tizen**](packages/path_provider) | [shared_preferences](https://github.com/flutter/plugins/tree/master/packages/shared_preferences) (1st-party) | [![pub package](https://img.shields.io/pub/v/shared_preferences_tizen.svg)](https://pub.dev/packages/shared_preferences_tizen) | No |
| [**url_launcher_tizen**](packages/url_launcher) | [url_launcher](https://github.com/flutter/plugins/tree/master/packages/url_launcher) (1st-party) | [![pub package](https://img.shields.io/pub/v/url_launcher_tizen.svg)](https://pub.dev/packages/url_launcher_tizen) | No |
| [**wifi_info_flutter_tizen**](packages/wifi_info_flutter) | [wifi_info_flutter](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter) (1st-party) | [![pub package](https://img.shields.io/pub/v/wifi_info_flutter_tizen.svg)](https://pub.dev/packages/wifi_info_flutter_tizen) | No |

## Device limitations

Expand All @@ -39,3 +40,4 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**share_tizen**](packages/share) | ⚠️ | ⚠️ ||| No SMS or e-mail app |
| [**shared_preferences_tizen**](packages/path_provider) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**url_launcher_tizen**](packages/url_launcher) | ✔️ || ✔️ || No browser app |
| [**wifi_info_flutter_tizen**](packages/wifi_info_flutter) | ✔️ || ✔️ ||
7 changes: 7 additions & 0 deletions packages/wifi_info_flutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
3 changes: 3 additions & 0 deletions packages/wifi_info_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

* Initial release
26 changes: 26 additions & 0 deletions packages/wifi_info_flutter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2020 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 names of the copyright holders nor the names of the
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.
33 changes: 33 additions & 0 deletions packages/wifi_info_flutter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# wifi_info_flutter_tizen

The Tizen implementation of [`wifi_info_flutter`](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter).

## Usage

This package is not an _endorsed_ implementation of `wifi_info_flutter`. Therefore, you have to include `wifi_info_flutter_tizen` alongside `wifi_info_flutter` as dependencies in your `pubspec.yaml` file.

```yaml
dependencies:
wifi_info_flutter: ^1.0.1
wifi_info_flutter_tizen: ^1.0.0
```
Then you can import `wifi_info_flutter` in your Dart code:

```dart
import 'package:wifi_info_flutter/wifi_info_flutter.dart';
```

For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter#usage.

## Required privileges

To get network information using this plugin, add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,

```xml
<privileges>
<privilege>http://tizen.org/privilege/network.get</privilege>
</privileges>
```

For details, see [Security and API Privileges](https://docs.tizen.org/application/dotnet/tutorials/sec-privileges).
41 changes: 41 additions & 0 deletions packages/wifi_info_flutter/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# 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/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
7 changes: 7 additions & 0 deletions packages/wifi_info_flutter/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# wifi_info_flutter_example

Demonstrates how to use the wifi_info_flutter_tizen plugin.

## Getting Started

To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 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:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wifi_info_flutter/wifi_info_flutter.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('$WifiInfo test driver', () {
WifiInfo _wifiInfo;

setUpAll(() async {
_wifiInfo = WifiInfo();
});

testWidgets('test location methods, iOS only', (WidgetTester tester) async {
expect(
(await _wifiInfo.getLocationServiceAuthorization()),
LocationAuthorizationStatus.notDetermined,
);
}, skip: !Platform.isIOS);
});
}
173 changes: 173 additions & 0 deletions packages/wifi_info_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright 2020 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:io';

import 'package:connectivity/connectivity.dart'
show Connectivity, ConnectivityResult;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:wifi_info_flutter/wifi_info_flutter.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(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
String _connectionStatus = 'Unknown';
final Connectivity _connectivity = Connectivity();
final WifiInfo _wifiInfo = WifiInfo();
StreamSubscription<ConnectivityResult> _connectivitySubscription;

@override
void initState() {
super.initState();
initConnectivity();
_connectivitySubscription =
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
}

@override
void dispose() {
_connectivitySubscription.cancel();
super.dispose();
}

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initConnectivity() async {
ConnectivityResult result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await _connectivity.checkConnectivity();
} on PlatformException catch (e) {
print(e.toString());
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) {
return Future.value(null);
}

return _updateConnectionStatus(result);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Connectivity example app'),
),
body: Center(child: Text('Connection Status: $_connectionStatus')),
);
}

Future<void> _updateConnectionStatus(ConnectivityResult result) async {
switch (result) {
case ConnectivityResult.wifi:
String wifiName, wifiBSSID, wifiIP;

try {
if (!kIsWeb && Platform.isIOS) {
LocationAuthorizationStatus status =
await _wifiInfo.getLocationServiceAuthorization();
if (status == LocationAuthorizationStatus.notDetermined) {
status = await _wifiInfo.requestLocationServiceAuthorization();
}
if (status == LocationAuthorizationStatus.authorizedAlways ||
status == LocationAuthorizationStatus.authorizedWhenInUse) {
wifiName = await _wifiInfo.getWifiName();
} else {
wifiName = await _wifiInfo.getWifiName();
}
} else {
wifiName = await _wifiInfo.getWifiName();
}
} on PlatformException catch (e) {
print(e.toString());
wifiName = "Failed to get Wifi Name";
}

try {
if (!kIsWeb && Platform.isIOS) {
LocationAuthorizationStatus status =
await _wifiInfo.getLocationServiceAuthorization();
if (status == LocationAuthorizationStatus.notDetermined) {
status = await _wifiInfo.requestLocationServiceAuthorization();
}
if (status == LocationAuthorizationStatus.authorizedAlways ||
status == LocationAuthorizationStatus.authorizedWhenInUse) {
wifiBSSID = await _wifiInfo.getWifiBSSID();
} else {
wifiBSSID = await _wifiInfo.getWifiBSSID();
}
} else {
wifiBSSID = await _wifiInfo.getWifiBSSID();
}
} on PlatformException catch (e) {
print(e.toString());
wifiBSSID = "Failed to get Wifi BSSID";
}

try {
wifiIP = await _wifiInfo.getWifiIP();
} on PlatformException catch (e) {
print(e.toString());
wifiIP = "Failed to get Wifi IP";
}

setState(() {
_connectionStatus = '$result\n'
'Wifi Name: $wifiName\n'
'Wifi BSSID: $wifiBSSID\n'
'Wifi IP: $wifiIP\n';
});
break;
case ConnectivityResult.mobile:
case ConnectivityResult.none:
setState(() => _connectionStatus = result.toString());
break;
default:
setState(() => _connectionStatus = 'Failed to get connectivity.');
break;
}
}
}
28 changes: 28 additions & 0 deletions packages/wifi_info_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: wifi_info_flutter_tizen_example
description: Demonstrates how to use the wifi_info_flutter_tizen plugin.
publish_to: 'none'

dependencies:
connectivity: ^2.0.2
connectivity_tizen:
path: ../../connectivity/
cupertino_icons: ^1.0.0
flutter:
sdk: flutter
integration_test: ^1.0.1
integration_test_tizen:
path: ../../integration_test/
wifi_info_flutter: ^1.0.1
wifi_info_flutter_tizen:
path: ../

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.20.0 <2.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
5 changes: 5 additions & 0 deletions packages/wifi_info_flutter/example/tizen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flutter/
.vs/
*.user
bin/
obj/
20 changes: 20 additions & 0 deletions packages/wifi_info_flutter/example/tizen/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Tizen.Flutter.Embedding;

namespace Runner
{
public class App : FlutterApplication
{
protected override void OnCreate()
{
base.OnCreate();

GeneratedPluginRegistrant.RegisterPlugins(this);
}

static void Main(string[] args)
{
var app = new App();
app.Run(args);
}
}
}
Loading

0 comments on commit 6342185

Please sign in to comment.