Skip to content

Commit b107f18

Browse files
[path_provider] Add path_provider_tizen package (#3)
* [path_provider] Add path_provider_tizen package * Fix ambiguous variable name * Fix copyright notice * Enable test cases for media storage Co-authored-by: Seungsoo Lee <[email protected]>
1 parent df2774f commit b107f18

19 files changed

+870
-0
lines changed

packages/path_provider/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release

packages/path_provider/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2019 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/path_provider/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# path_provider_tizen
2+
3+
The Tizen implementation of [`path_provider`](https://github.com/flutter/plugins/tree/master/packages/path_provider).
4+
5+
## Usage
6+
7+
This package is not an _endorsed_ implementation of `path_provider`. Therefore, you have to include `path_provider_tizen` alongside `path_provider` as dependencies in your `pubspec.yaml` file.
8+
9+
```yaml
10+
dependencies:
11+
path_provider: ^1.6.10
12+
path_provider_tizen: ^1.0.0
13+
```
14+
15+
Then you can import `path_provider` in your Dart code:
16+
17+
```dart
18+
import 'package:path_provider/path_provider.dart';
19+
```
20+
21+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider#usage.
22+
23+
## Required privileges
24+
25+
- To access paths returned by
26+
27+
- `getExternalStoragePaths`
28+
- `getDownloadsPath`
29+
30+
add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,
31+
32+
```xml
33+
<privileges>
34+
<privilege>http://tizen.org/privilege/mediastorage</privilege>
35+
</privileges>
36+
```
37+
38+
and also acquire `Permission.accessMediaLocation` using the [`permission_handler`](https://pub.dev/packages/permission_handler_tizen) plugin (to be available soon). The permission is already granted on TV devices by default.
39+
40+
- To access paths returned by
41+
42+
- `getExternalDataPath`
43+
- `getExternalCachePath`
44+
45+
add below lines under the `<manifest>` section in your `tizen-manifest.xml` file.
46+
47+
```xml
48+
<privileges>
49+
<privilege>http://tizen.org/privilege/externalstorage.appdata</privilege>
50+
</privileges>
51+
```
+41
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
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# path_provider_tizen_example
2+
3+
Demonstrates how to use the path_provider_tizen 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).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright 2019 the Chromium project 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+
import 'dart:async';
6+
7+
import 'dart:io';
8+
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:path_provider/path_provider.dart';
10+
import 'package:integration_test/integration_test.dart';
11+
import 'package:permission_handler/permission_handler.dart';
12+
13+
void main() {
14+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
15+
16+
testWidgets('getTemporaryDirectory', (WidgetTester tester) async {
17+
final Directory result = await getTemporaryDirectory();
18+
_verifySampleFile(result, 'temporaryDirectory');
19+
});
20+
21+
testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async {
22+
final Directory result = await getApplicationDocumentsDirectory();
23+
_verifySampleFile(result, 'applicationDocuments');
24+
});
25+
26+
testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async {
27+
final Directory result = await getApplicationSupportDirectory();
28+
_verifySampleFile(result, 'applicationSupport');
29+
});
30+
31+
testWidgets('getLibraryDirectory', (WidgetTester tester) async {
32+
if (Platform.isIOS) {
33+
final Directory result = await getLibraryDirectory();
34+
_verifySampleFile(result, 'library');
35+
} else if (Platform.isAndroid) {
36+
final Future<Directory> result = getLibraryDirectory();
37+
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
38+
}
39+
});
40+
41+
testWidgets('getExternalStorageDirectory', (WidgetTester tester) async {
42+
if (Platform.isIOS) {
43+
final Future<Directory> result = getExternalStorageDirectory();
44+
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
45+
} else if (Platform.isAndroid) {
46+
final Directory result = await getExternalStorageDirectory();
47+
_verifySampleFile(result, 'externalStorage');
48+
}
49+
});
50+
51+
testWidgets('getExternalCacheDirectories', (WidgetTester tester) async {
52+
if (Platform.isIOS) {
53+
final Future<List<Directory>> result = getExternalCacheDirectories();
54+
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
55+
} else if (Platform.isAndroid) {
56+
final List<Directory> directories = await getExternalCacheDirectories();
57+
for (Directory result in directories) {
58+
_verifySampleFile(result, 'externalCache');
59+
}
60+
}
61+
});
62+
63+
final List<StorageDirectory> _allDirs = <StorageDirectory>[
64+
null,
65+
StorageDirectory.music,
66+
StorageDirectory.podcasts,
67+
StorageDirectory.alarms,
68+
StorageDirectory.notifications,
69+
StorageDirectory.pictures,
70+
StorageDirectory.movies,
71+
];
72+
73+
for (StorageDirectory type in _allDirs) {
74+
test('getExternalStorageDirectories (type: $type)', () async {
75+
if (Platform.isIOS) {
76+
final Future<List<Directory>> result =
77+
getExternalStorageDirectories(type: null);
78+
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
79+
} else {
80+
// Remove when testing on TV.
81+
if (!await Permission.accessMediaLocation.isGranted) {
82+
await Permission.accessMediaLocation.request();
83+
}
84+
final List<Directory> directories =
85+
await getExternalStorageDirectories(type: type);
86+
for (Directory result in directories) {
87+
_verifySampleFile(result, '$type');
88+
}
89+
}
90+
});
91+
}
92+
}
93+
94+
/// Verify a file called [name] in [directory] by recreating it with test
95+
/// contents when necessary.
96+
void _verifySampleFile(Directory directory, String name) {
97+
final File file = File('${directory.path}/$name');
98+
99+
if (file.existsSync()) {
100+
file.deleteSync();
101+
expect(file.existsSync(), isFalse);
102+
}
103+
104+
file.writeAsStringSync('Hello world!');
105+
expect(file.readAsStringSync(), 'Hello world!');
106+
expect(directory.listSync(), isNotEmpty);
107+
file.deleteSync();
108+
}

0 commit comments

Comments
 (0)