Skip to content

Commit 2ca6750

Browse files
committed
[connectivity] Add connectivity_tizen package
1 parent 64e8d64 commit 2ca6750

23 files changed

+777
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
1313
| Package name | Original package | Pub | Endorsed |
1414
|-|-|:-:|:-:|
1515
| [**battery_tizen**](packages/battery) | [battery](https://github.com/flutter/plugins/tree/master/packages/battery) (1st-party) | [![pub package](https://img.shields.io/pub/v/battery_tizen.svg)](https://pub.dev/packages/battery_tizen) | No |
16+
| [**connectivity_tizen**](packages/connectivity) | [connectivity](https://github.com/flutter/plugins/tree/master/packages/connectivity) (1st-party) | [![pub package](https://img.shields.io/pub/v/connectivity_tizen.svg)](https://pub.dev/packages/connectivity_tizen) | No |
1617
| [**integration_test_tizen**](packages/integration_test) | [integration_test](https://github.com/flutter/plugins/tree/master/packages/integration_test) (1st-party) | [![pub package](https://img.shields.io/pub/v/integration_test_tizen.svg)](https://pub.dev/packages/integration_test_tizen) | No |
1718
| [**path_provider_tizen**](packages/path_provider) | [path_provider](https://github.com/flutter/plugins/tree/master/packages/path_provider) (1st-party) | [![pub package](https://img.shields.io/pub/v/path_provider_tizen.svg)](https://pub.dev/packages/path_provider_tizen) | No |
1819
| [**sensors_tizen**](packages/sensors) | [sensors](https://github.com/flutter/plugins/tree/master/packages/sensors) (1st-party) | [![pub package](https://img.shields.io/pub/v/sensors_tizen.svg)](https://pub.dev/packages/sensors_tizen) | No |
@@ -24,6 +25,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
2425
| Package name | Watch | Watch emulator | TV | TV emulator | Remarks |
2526
|-|:-:|:-:|:-:|:-:|-|
2627
| [**battery_tizen**](packages/battery) | ✔️ | ✔️ ||| No battery |
28+
| [**connectivity_tizen**](packages/connectivity) | ✔️ | ✔️ ||| |
2729
| [**integration_test_tizen**](packages/integration_test) | ✔️ | ✔️ | ✔️ | ✔️ |
2830
| [**path_provider_tizen**](packages/path_provider) | ⚠️ | ⚠️ | ⚠️ | ⚠️ | No external storage |
2931
| [**sensors_tizen**](packages/sensors) | ✔️ | ✔️ ||| No hardware |

packages/connectivity/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.packages
5+
.pub/
6+
7+
build/

packages/connectivity/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release

packages/connectivity/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2017 The Chromium Authors. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the names of the copyright holders nor the names of the
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/connectivity/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# connectivity_tizen
2+
3+
The Tizen implementation of [`connectivity`](https://github.com/flutter/plugins/tree/master/packages/connectivity).
4+
5+
## Usage
6+
7+
This package is not an _endorsed_ implementation of `connectivity`. Therefore, you have to include `connectivity_tizen` alongside `connectivity` as dependencies in your `pubspec.yaml` file.
8+
9+
```yaml
10+
dependencies:
11+
connectivity: ^0.4.9
12+
connectivity_tizen: ^1.0.0
13+
```
14+
15+
Then you can import `connectivity` in your Dart code:
16+
17+
```dart
18+
import 'package:connectivity/connectivity.dart';
19+
```
20+
21+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity#usage.
22+
23+
## Supported devices
24+
25+
This plugin is supported on these types of devices:
26+
27+
- Galaxy Watch (running Tizen 4.0 or later)
28+
29+
## Required privileges
30+
31+
- To get connectivity information using this plugin, add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,
32+
33+
```xml
34+
<privileges>
35+
<privilege>http://tizen.org/privilege/network.get</privilege>
36+
<privilege>http://tizen.org/privilege/network.set</privilege>
37+
<privilege>http://tizen.org/privilege/network.profile</privilege>
38+
</privileges>
39+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# connectiviy example
2+
3+
Demonstrates how to use the connectiviy plugin.
4+
5+
## Getting Started
6+
7+
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// TODO(cyanglaz): Remove once https://github.com/flutter/plugins/pull/3158 is landed.
6+
// @dart = 2.9
7+
8+
import 'package:integration_test/integration_test.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:connectivity/connectivity.dart';
11+
12+
void main() {
13+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
14+
15+
group('Connectivity test driver', () {
16+
Connectivity _connectivity;
17+
18+
setUpAll(() async {
19+
_connectivity = Connectivity();
20+
});
21+
22+
testWidgets('test connectivity result', (WidgetTester tester) async {
23+
final ConnectivityResult result = await _connectivity.checkConnectivity();
24+
expect(result, isNotNull);
25+
});
26+
});
27+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:async';
8+
import 'dart:io';
9+
10+
import 'package:connectivity/connectivity.dart';
11+
import 'package:flutter/foundation.dart';
12+
import 'package:flutter/material.dart';
13+
import 'package:flutter/services.dart';
14+
15+
// Sets a platform override for desktop to avoid exceptions. See
16+
// https://flutter.dev/desktop#target-platform-override for more info.
17+
void _enablePlatformOverrideForDesktop() {
18+
if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
19+
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
20+
}
21+
}
22+
23+
void main() {
24+
_enablePlatformOverrideForDesktop();
25+
runApp(MyApp());
26+
}
27+
28+
class MyApp extends StatelessWidget {
29+
// This widget is the root of your application.
30+
@override
31+
Widget build(BuildContext context) {
32+
return MaterialApp(
33+
title: 'Flutter Demo',
34+
theme: ThemeData(
35+
primarySwatch: Colors.blue,
36+
),
37+
home: MyHomePage(title: 'Flutter Demo Home Page'),
38+
);
39+
}
40+
}
41+
42+
class MyHomePage extends StatefulWidget {
43+
MyHomePage({Key key, this.title}) : super(key: key);
44+
45+
final String title;
46+
47+
@override
48+
_MyHomePageState createState() => _MyHomePageState();
49+
}
50+
51+
class _MyHomePageState extends State<MyHomePage> {
52+
String _connectionStatus = 'Unknown';
53+
final Connectivity _connectivity = Connectivity();
54+
StreamSubscription<ConnectivityResult> _connectivitySubscription;
55+
56+
@override
57+
void initState() {
58+
super.initState();
59+
initConnectivity();
60+
_connectivitySubscription =
61+
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
62+
}
63+
64+
@override
65+
void dispose() {
66+
_connectivitySubscription.cancel();
67+
super.dispose();
68+
}
69+
70+
// Platform messages are asynchronous, so we initialize in an async method.
71+
Future<void> initConnectivity() async {
72+
ConnectivityResult result;
73+
// Platform messages may fail, so we use a try/catch PlatformException.
74+
try {
75+
result = await _connectivity.checkConnectivity();
76+
} on PlatformException catch (e) {
77+
print(e.toString());
78+
}
79+
80+
// If the widget was removed from the tree while the asynchronous platform
81+
// message was in flight, we want to discard the reply rather than calling
82+
// setState to update our non-existent appearance.
83+
if (!mounted) {
84+
return Future.value(null);
85+
}
86+
87+
return _updateConnectionStatus(result);
88+
}
89+
90+
@override
91+
Widget build(BuildContext context) {
92+
return Scaffold(
93+
appBar: AppBar(
94+
title: const Text('Connectivity example app'),
95+
),
96+
body: Center(child: Text('Connection Status: $_connectionStatus')),
97+
);
98+
}
99+
100+
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
101+
switch (result) {
102+
case ConnectivityResult.wifi:
103+
String wifiName, wifiBSSID, wifiIP;
104+
105+
try {
106+
if (!kIsWeb && Platform.isIOS) {
107+
LocationAuthorizationStatus status =
108+
await _connectivity.getLocationServiceAuthorization();
109+
if (status == LocationAuthorizationStatus.notDetermined) {
110+
status =
111+
await _connectivity.requestLocationServiceAuthorization();
112+
}
113+
if (status == LocationAuthorizationStatus.authorizedAlways ||
114+
status == LocationAuthorizationStatus.authorizedWhenInUse) {
115+
wifiName = await _connectivity.getWifiName();
116+
} else {
117+
wifiName = await _connectivity.getWifiName();
118+
}
119+
} else {
120+
wifiName = await _connectivity.getWifiName();
121+
}
122+
} on PlatformException catch (e) {
123+
print(e.toString());
124+
wifiName = "Failed to get Wifi Name";
125+
}
126+
127+
try {
128+
if (!kIsWeb && Platform.isIOS) {
129+
LocationAuthorizationStatus status =
130+
await _connectivity.getLocationServiceAuthorization();
131+
if (status == LocationAuthorizationStatus.notDetermined) {
132+
status =
133+
await _connectivity.requestLocationServiceAuthorization();
134+
}
135+
if (status == LocationAuthorizationStatus.authorizedAlways ||
136+
status == LocationAuthorizationStatus.authorizedWhenInUse) {
137+
wifiBSSID = await _connectivity.getWifiBSSID();
138+
} else {
139+
wifiBSSID = await _connectivity.getWifiBSSID();
140+
}
141+
} else {
142+
wifiBSSID = await _connectivity.getWifiBSSID();
143+
}
144+
} on PlatformException catch (e) {
145+
print(e.toString());
146+
wifiBSSID = "Failed to get Wifi BSSID";
147+
}
148+
149+
try {
150+
wifiIP = await _connectivity.getWifiIP();
151+
} on PlatformException catch (e) {
152+
print(e.toString());
153+
wifiIP = "Failed to get Wifi IP";
154+
}
155+
156+
setState(() {
157+
_connectionStatus = '$result\n'
158+
'Wifi Name: $wifiName\n'
159+
'Wifi BSSID: $wifiBSSID\n'
160+
'Wifi IP: $wifiIP\n';
161+
});
162+
break;
163+
case ConnectivityResult.mobile:
164+
case ConnectivityResult.none:
165+
setState(() => _connectionStatus = result.toString());
166+
break;
167+
default:
168+
setState(() => _connectionStatus = 'Failed to get connectivity.');
169+
break;
170+
}
171+
}
172+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: connectivity_example
2+
description: Demonstrates how to use the connectivity plugin.
3+
publish_to: 'none'
4+
5+
dependencies:
6+
flutter:
7+
sdk: flutter
8+
connectivity: ^2.0.2
9+
connectivity_tizen:
10+
path: ../
11+
12+
dev_dependencies:
13+
flutter_driver:
14+
sdk: flutter
15+
test: any
16+
pedantic: ^1.8.0
17+
integration_test: ^1.0.1
18+
integration_test_tizen:
19+
path: ../../integration_test/
20+
21+
flutter:
22+
uses-material-design: true

0 commit comments

Comments
 (0)