Skip to content

[path_provider] Add path_provider_tizen package #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/path_provider/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/path_provider/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2019 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.
51 changes: 51 additions & 0 deletions packages/path_provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# path_provider_tizen

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

## Usage

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.

```yaml
dependencies:
path_provider: ^1.6.10
path_provider_tizen: ^1.0.0
```

Then you can import `path_provider` in your Dart code:

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

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

## Required privileges

- To access paths returned by

- `getExternalStoragePaths`
- `getDownloadsPath`

add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,

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

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.

- To access paths returned by

- `getExternalDataPath`
- `getExternalCachePath`

add below lines under the `<manifest>` section in your `tizen-manifest.xml` file.

```xml
<privileges>
<privilege>http://tizen.org/privilege/externalstorage.appdata</privilege>
</privileges>
```
41 changes: 41 additions & 0 deletions packages/path_provider/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/path_provider/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# path_provider_tizen_example

Demonstrates how to use the path_provider_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,108 @@
// Copyright 2019 the Chromium project 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 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart';
import 'package:integration_test/integration_test.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('getTemporaryDirectory', (WidgetTester tester) async {
final Directory result = await getTemporaryDirectory();
_verifySampleFile(result, 'temporaryDirectory');
});

testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async {
final Directory result = await getApplicationDocumentsDirectory();
_verifySampleFile(result, 'applicationDocuments');
});

testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async {
final Directory result = await getApplicationSupportDirectory();
_verifySampleFile(result, 'applicationSupport');
});

testWidgets('getLibraryDirectory', (WidgetTester tester) async {
if (Platform.isIOS) {
final Directory result = await getLibraryDirectory();
_verifySampleFile(result, 'library');
} else if (Platform.isAndroid) {
final Future<Directory> result = getLibraryDirectory();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
}
});

testWidgets('getExternalStorageDirectory', (WidgetTester tester) async {
if (Platform.isIOS) {
final Future<Directory> result = getExternalStorageDirectory();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final Directory result = await getExternalStorageDirectory();
_verifySampleFile(result, 'externalStorage');
}
});

testWidgets('getExternalCacheDirectories', (WidgetTester tester) async {
if (Platform.isIOS) {
final Future<List<Directory>> result = getExternalCacheDirectories();
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final List<Directory> directories = await getExternalCacheDirectories();
for (Directory result in directories) {
_verifySampleFile(result, 'externalCache');
}
}
});

final List<StorageDirectory> _allDirs = <StorageDirectory>[
null,
StorageDirectory.music,
StorageDirectory.podcasts,
StorageDirectory.alarms,
StorageDirectory.notifications,
StorageDirectory.pictures,
StorageDirectory.movies,
];

for (StorageDirectory type in _allDirs) {
test('getExternalStorageDirectories (type: $type)', () async {
if (Platform.isIOS) {
final Future<List<Directory>> result =
getExternalStorageDirectories(type: null);
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else {
// Remove when testing on TV.
if (!await Permission.accessMediaLocation.isGranted) {
await Permission.accessMediaLocation.request();
}
final List<Directory> directories =
await getExternalStorageDirectories(type: type);
for (Directory result in directories) {
_verifySampleFile(result, '$type');
}
}
});
}
}

/// Verify a file called [name] in [directory] by recreating it with test
/// contents when necessary.
void _verifySampleFile(Directory directory, String name) {
final File file = File('${directory.path}/$name');

if (file.existsSync()) {
file.deleteSync();
expect(file.existsSync(), isFalse);
}

file.writeAsStringSync('Hello world!');
expect(file.readAsStringSync(), 'Hello world!');
expect(directory.listSync(), isNotEmpty);
file.deleteSync();
}
Loading