diff --git a/packages/path_provider/path_provider_ohos/.gitignore b/packages/path_provider/path_provider_ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6665baf5ad7de7fd7352c04cfa1b6d9e318a73c9 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/.gitignore @@ -0,0 +1,44 @@ +# 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/ +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Exceptions to above rules. +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +pubspec.lock +GeneratedPluginRegistrant* +ohos/**/oh_modules +ohos/**.har +ohos/**/BuildProfile.ets +ohos/**/oh-package-lock.json5 diff --git a/packages/path_provider/path_provider_ohos/AUTHORS b/packages/path_provider/path_provider_ohos/AUTHORS new file mode 100644 index 0000000000000000000000000000000000000000..fc4d15a6a5ddfeb0896666c68ba8beaeb131932e --- /dev/null +++ b/packages/path_provider/path_provider_ohos/AUTHORS @@ -0,0 +1,79 @@ +# 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. + +# Below is a list of people and organizations that have contributed +# to the Flutter project. Names should be added to the list like so: +# +# Name/Organization + +Google Inc. +The Chromium Authors +German Saprykin +Benjamin Sauer +larsenthomasj@gmail.com +Ali Bitek +Pol Batlló +Anatoly Pulyaevskiy +Hayden Flinner +Stefano Rodriguez +Salvatore Giordano +Brian Armstrong +Paul DeMarco +Fabricio Nogueira +Simon Lightfoot +Ashton Thomas +Thomas Danner +Diego Velásquez +Hajime Nakamura +Tuyển Vũ Xuân +Miguel Ruivo +Sarthak Verma +Mike Diarmid +Invertase +Elliot Hesp +Vince Varga +Aawaz Gyawali +EUI Limited +Katarina Sheremet +Thomas Stockx +Sarbagya Dhaubanjar +Ozkan Eksi +Rishab Nayak +ko2ic +Jonathan Younger +Jose Sanchez +Debkanchan Samadder +Audrius Karosevicius +Lukasz Piliszczuk +SoundReply Solutions GmbH +Rafal Wachol +Pau Picas +Christian Weder +Alexandru Tuca +Christian Weder +Rhodes Davis Jr. +Luigi Agosti +Quentin Le Guennec +Koushik Ravikumar +Nissim Dsilva +Giancarlo Rocha +Ryo Miyake +Théo Champion +Kazuki Yamaguchi +Eitan Schwartz +Chris Rutkowski +Juan Alvarez +Aleksandr Yurkovskiy +Anton Borries +Alex Li +Rahul Raj <64.rahulraj@gmail.com> diff --git a/packages/path_provider/path_provider_ohos/CHANGELOG.md b/packages/path_provider/path_provider_ohos/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..fa33ade004e754f86fba199db9541983bea7b3e2 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/CHANGELOG.md @@ -0,0 +1,153 @@ +## 2.2.9 + +* Updates annotations lib to 1.8.1. + +## 2.2.8 + +* Updates lint checks to ignore NewerVersionAvailable. + +## 2.2.7 + +* Updates AGP version to 8.5.0. + +## 2.2.6 + +* Updates annotations lib to 1.8.0. + +## 2.2.5 + +* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Removes support for apps using the v1 Android embedding. + +## 2.2.4 + +* Updates minSdkVersion version to 19. +* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2. + +## 2.2.3 + +* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. +* Updates compileSdk version to 34. + +## 2.2.2 + +* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. +* Updates annotations lib to 1.7.1. + +## 2.2.1 + +* Updates annotations lib to 1.7.0. + +## 2.2.0 + +* Adds implementation of `getDownloadsDirectory()`. + +## 2.1.1 + +* Adds pub topics to package metadata. +* Updates minimum supported SDK version to Flutter 3.7/Dart 2.19. + +## 2.1.0 + +* Adds getApplicationCachePath() for storing app-specific cache files. +* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18. + +## 2.0.27 + +* Fixes compatibility with AGP versions older than 4.2. + +## 2.0.26 + +* Adds a namespace for compatibility with AGP 8.0. + +## 2.0.25 + +* Fixes Java warnings. + +## 2.0.24 + +* Clarifies explanation of endorsement in README. +* Aligns Dart and Flutter SDK constraints. +* Updates compileSdkVersion to 33. + +## 2.0.23 + +* Updates links for the merge of flutter/plugins into flutter/packages. +* Updates minimum Flutter version to 3.0. + +## 2.0.22 + +* Removes unused Guava dependency. + +## 2.0.21 + +* Updates code for `no_leading_underscores_for_local_identifiers` lint. +* Updates minimum Flutter version to 2.10. +* Upgrades `androidx.annotation` version to 1.5.0. +* Upgrades Android Gradle plugin version to 7.3.1. + +## 2.0.20 + +* Reverts changes in versions 2.0.18 and 2.0.19. + +## 2.0.19 + +* Bumps kotlin to 1.7.10 + +## 2.0.18 + +* Bumps `androidx.annotation:annotation` version to 1.4.0. +* Bumps gradle version to 7.2.2. + +## 2.0.17 + +* Lower minimim version back to 2.8.1. + +## 2.0.16 + +* Fixes bug with `getExternalStoragePaths(null)`. + +## 2.0.15 + +* Switches the medium from MethodChannels to Pigeon. + +## 2.0.14 + +* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors + lint warnings. + +## 2.0.13 + +* Fixes typing build warning. + +## 2.0.12 + +* Returns to using a different platform channel name, undoing the revert in + 2.0.11, but updates the minimum Flutter version to 2.8 to avoid the issue + that caused the revert. + +## 2.0.11 + +* Temporarily reverts the platform channel name change from 2.0.10 in order to + restore compatibility with Flutter versions earlier than 2.8. + +## 2.0.10 + +* Switches to a package-internal implementation of the platform interface. + +## 2.0.9 + +* Updates Android compileSdkVersion to 31. + +## 2.0.8 + +* Updates example app Android compileSdkVersion to 31. +* Fixes typing build warning. + +## 2.0.7 + +* Fixes link in README. + +## 2.0.6 + +* Split from `path_provider` as a federated implementation. diff --git a/packages/path_provider/path_provider_ohos/LICENSE b/packages/path_provider/path_provider_ohos/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..c6823b81eb845db89cee59cbbc7ee0b0b63d86ec --- /dev/null +++ b/packages/path_provider/path_provider_ohos/LICENSE @@ -0,0 +1,25 @@ +Copyright 2013 The Flutter 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. diff --git a/packages/path_provider/path_provider_ohos/README.md b/packages/path_provider/path_provider_ohos/README.md new file mode 100644 index 0000000000000000000000000000000000000000..78f49e4c4eb11a1aa295fa0f329709fae99be5d8 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/README.md @@ -0,0 +1,15 @@ +# path\_provider\_ohos + +The Ohos implementation of [`path_provider`][1]. + +## Usage + +This package is [endorsed][2], which means you can simply use `path_provider` +normally. This package will be automatically included in your app when you do, +so you do not need to add it to your `pubspec.yaml`. + +However, if you `import` this package to use any of its APIs directly, you +should add it to your `pubspec.yaml` as usual. + +[1]: https://pub.dev/packages/path_provider +[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin diff --git a/packages/path_provider/path_provider_ohos/example/.pluginToolsConfig.yaml b/packages/path_provider/path_provider_ohos/example/.pluginToolsConfig.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ee743227bca525ed77efe9f1bcb00d37657d6163 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/.pluginToolsConfig.yaml @@ -0,0 +1,16 @@ +# 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. +buildFlags: + _pluginToolsConfigGlobalKey: + - "--no-tree-shake-icons" + - "--dart-define=buildmode=testing" diff --git a/packages/path_provider/path_provider_ohos/example/README.md b/packages/path_provider/path_provider_ohos/example/README.md new file mode 100644 index 0000000000000000000000000000000000000000..96b8bb17dbff8e7acd9a1dd59c65ff40b96e1228 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/README.md @@ -0,0 +1,9 @@ +# Platform Implementation Test App + +This is a test app for manual testing and automated integration testing +of this platform implementation. It is not intended to demonstrate actual use of +this package, since the intent is that plugin clients use the app-facing +package. + +Unless you are making changes to this implementation package, this example is +very unlikely to be relevant. diff --git a/packages/path_provider/path_provider_ohos/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider_ohos/example/integration_test/path_provider_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..67b3efc4911aaae0c346e14c6994f9caeaf6443b --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/integration_test/path_provider_test.dart @@ -0,0 +1,109 @@ +/* + * 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 'dart:io'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('getTemporaryDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getTemporaryPath(); + _verifySampleFile(result, 'temporaryDirectory'); + }); + + testWidgets('getApplicationDocumentsDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getApplicationDocumentsPath(); + _verifySampleFile(result, 'applicationDocuments'); + }); + + testWidgets('getApplicationSupportDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getApplicationSupportPath(); + _verifySampleFile(result, 'applicationSupport'); + }); + + testWidgets('getLibraryDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + expect(() => provider.getLibraryPath(), + throwsA(isInstanceOf())); + }); + + testWidgets('getExternalStorageDirectory', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final String? result = await provider.getExternalStoragePath(); + _verifySampleFile(result, 'externalStorage'); + }); + + testWidgets('getExternalCacheDirectories', (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + final List? directories = await provider.getExternalCachePaths(); + expect(directories, isNotNull); + for (final String result in directories!) { + _verifySampleFile(result, 'externalCache'); + } + }); + + final List allDirs = [ + null, + StorageDirectory.music, + StorageDirectory.podcasts, + StorageDirectory.ringtones, + StorageDirectory.alarms, + StorageDirectory.notifications, + StorageDirectory.pictures, + StorageDirectory.movies, + ]; + + for (final StorageDirectory? type in allDirs) { + testWidgets('getExternalStorageDirectories (type: $type)', + (WidgetTester tester) async { + final PathProviderPlatform provider = PathProviderPlatform.instance; + + final List? directories = + await provider.getExternalStoragePaths(type: type); + expect(directories, isNotNull); + expect(directories, isNotEmpty); + for (final String result in directories!) { + _verifySampleFile(result, '$type'); + } + }); + } +} + +/// Verify a file called [name] in [directoryPath] by recreating it with test +/// contents when necessary. +void _verifySampleFile(String? directoryPath, String name) { + expect(directoryPath, isNotNull); + if (directoryPath == null) { + return; + } + final Directory directory = Directory(directoryPath); + final File file = File('${directory.path}${Platform.pathSeparator}$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(); +} diff --git a/packages/path_provider/path_provider_ohos/example/lib/main.dart b/packages/path_provider/path_provider_ohos/example/lib/main.dart new file mode 100644 index 0000000000000000000000000000000000000000..c4d6e2a13ff1ee6aa69e0c96b2e15c20e3dc3696 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/lib/main.dart @@ -0,0 +1,234 @@ +/* + * 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. + */ + +// ignore_for_file: public_member_api_docs + +import 'package:flutter/material.dart'; +import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Path Provider', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Path Provider'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + final PathProviderPlatform provider = PathProviderPlatform.instance; + Future? _tempDirectory; + Future? _appSupportDirectory; + Future? _appDocumentsDirectory; + Future? _appCacheDirectory; + Future? _externalDocumentsDirectory; + Future? _externalDownloadsDirectory; + Future?>? _externalStorageDirectories; + Future?>? _externalCacheDirectories; + + void _requestTempDirectory() { + setState(() { + _tempDirectory = provider.getTemporaryPath(); + }); + } + + Widget _buildDirectory( + BuildContext context, AsyncSnapshot snapshot) { + Text text = const Text(''); + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + text = Text('Error: ${snapshot.error}'); + } else if (snapshot.hasData) { + text = Text('path: ${snapshot.data}'); + } else { + text = const Text('path unavailable'); + } + } + return Padding(padding: const EdgeInsets.all(16.0), child: text); + } + + Widget _buildDirectories( + BuildContext context, AsyncSnapshot?> snapshot) { + Text text = const Text(''); + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + text = Text('Error: ${snapshot.error}'); + } else if (snapshot.hasData) { + final String combined = snapshot.data!.join(', '); + text = Text('paths: $combined'); + } else { + text = const Text('path unavailable'); + } + } + return Padding(padding: const EdgeInsets.all(16.0), child: text); + } + + void _requestAppDocumentsDirectory() { + setState(() { + _appDocumentsDirectory = provider.getApplicationDocumentsPath(); + }); + } + + void _requestAppSupportDirectory() { + setState(() { + _appSupportDirectory = provider.getApplicationSupportPath(); + }); + } + + void _requestAppCacheDirectory() { + setState(() { + _appCacheDirectory = provider.getApplicationCachePath(); + }); + } + + void _requestExternalStorageDirectory() { + setState(() { + _externalDocumentsDirectory = provider.getExternalStoragePath(); + }); + } + + void _requestExternalStorageDirectories(StorageDirectory type) { + setState(() { + _externalStorageDirectories = + provider.getExternalStoragePaths(type: type); + }); + } + + void _requestExternalCacheDirectories() { + setState(() { + _externalCacheDirectories = provider.getExternalCachePaths(); + }); + } + + void _requestDownloadsDirectory() { + setState(() { + _externalDownloadsDirectory = provider.getDownloadsPath(); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: ListView( + children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestTempDirectory, + child: const Text('Get Temporary Directory'), + ), + ), + FutureBuilder( + future: _tempDirectory, builder: _buildDirectory), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestAppDocumentsDirectory, + child: const Text('Get Application Documents Directory'), + ), + ), + FutureBuilder( + future: _appDocumentsDirectory, builder: _buildDirectory), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestAppSupportDirectory, + child: const Text('Get Application Support Directory'), + ), + ), + FutureBuilder( + future: _appSupportDirectory, builder: _buildDirectory), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestAppCacheDirectory, + child: const Text('Get Application Cache Directory'), + ), + ), + FutureBuilder( + future: _appCacheDirectory, builder: _buildDirectory), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestExternalStorageDirectory, + child: const Text('Get External Storage Directory'), + ), + ), + FutureBuilder( + future: _externalDocumentsDirectory, builder: _buildDirectory), + Column(children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + child: const Text('Get External Storage Directories'), + onPressed: () { + _requestExternalStorageDirectories( + StorageDirectory.music, + ); + }, + ), + ), + ]), + FutureBuilder?>( + future: _externalStorageDirectories, + builder: _buildDirectories), + Column(children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestExternalCacheDirectories, + child: const Text('Get External Cache Directories'), + ), + ), + ]), + FutureBuilder?>( + future: _externalCacheDirectories, builder: _buildDirectories), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: _requestDownloadsDirectory, + child: const Text('Get Downloads Directory'), + ), + ), + FutureBuilder( + future: _externalDownloadsDirectory, builder: _buildDirectory), + ], + ), + ), + ); + } +} diff --git a/packages/path_provider/path_provider_ohos/example/ohos/.gitignore b/packages/path_provider/path_provider_ohos/example/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9c2e3beb5298da79d035b39643f8a69810133b61 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/.gitignore @@ -0,0 +1,17 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +entry/libs/arm64-v8a/libapp.so +entry/libs/arm64-v8a/libflutter.so +entry/src/main/resources/rawfile/flutter_assets/ +*.har +oh-package-lock.json5 +BuildProfile.ets diff --git a/packages/path_provider/path_provider_ohos/example/ohos/AppScope/app.json5 b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e786fc563e70dbd071ada98ffdfaa7298f148edb --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * 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. + */ +{ + "app": { + "bundleName": "com.example.path_demo", + "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/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/element/string.json b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bc6b31d4a2d337acfa35b422ea3796db402e2c24 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "path_demo" + } + ] +} diff --git a/packages/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/media/app_icon.png b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/path_provider/path_provider_ohos/example/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/packages/path_provider/path_provider_ohos/example/ohos/build-profile.json5 b/packages/path_provider/path_provider_ohos/example/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1d12140d202702d7c73d64f1b291fe5c45a660ce --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/build-profile.json5 @@ -0,0 +1,27 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/.gitignore b/packages/path_provider/path_provider_ohos/example/ohos/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2795a1c5b1fe53659dd1b71d90ba0592eaf7e043 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/.gitignore @@ -0,0 +1,7 @@ + +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/build-profile.json5 b/packages/path_provider/path_provider_ohos/example/ohos/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..633d360fbc91a3186a23b66ab71b27e5618944cb --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/build-profile.json5 @@ -0,0 +1,29 @@ +/* +* 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. +*/ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/hvigorfile.ts b/packages/path_provider/path_provider_ohos/example/ohos/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..894fc15c6b793f085e6c8506e43d719af658e8ff --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/hvigorfile.ts @@ -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. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/libs/arm64-v8a/libc++_shared.so b/packages/path_provider/path_provider_ohos/example/ohos/entry/libs/arm64-v8a/libc++_shared.so new file mode 100644 index 0000000000000000000000000000000000000000..831c9353702073d45889352a4dafb93103d67d20 Binary files /dev/null and b/packages/path_provider/path_provider_ohos/example/ohos/entry/libs/arm64-v8a/libc++_shared.so differ diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/oh-package.json5 b/packages/path_provider/path_provider_ohos/example/ohos/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b5acee18b35dfc242a2ec42090e440d04354da4e --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:../har/flutter.har", + "integration_test": "file:../har/integration_test.har", + "path_provider_ohos": "file:../har/path_provider_ohos.har" + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..483d8221a8cd571c048ec6eba973cd0a97d8cfb9 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,27 @@ +/* +* 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 { FlutterAbility } from '@ohos/flutter_ohos' +import { FlutterPlugin } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; +import List from '@ohos.util.List'; +import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine); + } +} diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/pages/Index.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1125f9fdd95f4310a182c1c9e3680f37f73686c9 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,38 @@ +/* +* 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 common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/module.json5 b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1aeeb2da1b769819c2fdf57c01c550109e20938a --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/module.json5 @@ -0,0 +1,62 @@ +/* +* 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", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name" : "ohos.permission.INTERNET", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } + }, + ] + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/element/color.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/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/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/element/string.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/media/icon.png b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..597ecf95e61d7e30367c22fe2f8638008361b044 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..25d4c71ff3cd584f5d64f6f8c0ac864928c234c4 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* +* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(function () { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(function () { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(function () { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(function () { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain',0, function () { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc' + let b = 'b' + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/List.test.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4140030e65d20df6af30a6bf51e464dea8f8aa6 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* 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 abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ca645e6013cfce8e7dbb728313cb8840c4da660 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,63 @@ +/* +* 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 UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + 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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cef0447cd2f137ef82d223ead2e156808878ab90 --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1def08f2e9dcbfa3454a07b7a3b82b173bb90d02 --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/module.json5 b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fab77ce2e0c61e3ad010bab5b27ccbd15f9a8c96 --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7e7343cacb32ce982a45e76daad86e435e054fe --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/packages/path_provider/path_provider_ohos/example/ohos/hvigor/hvigor-config.json5 b/packages/path_provider/path_provider_ohos/example/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ba720309263e55532a56354c49cdbc813c391ff6 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,8 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "properties": { + "ohos.nativeResolver": false + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/hvigorfile.ts b/packages/path_provider/path_provider_ohos/example/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..5a172b770e3b15f67c12152d00f38f2084d3915b --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/hvigorfile.ts @@ -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. +*/ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/ohos/oh-package.json5 b/packages/path_provider/path_provider_ohos/example/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8f72a6f6c86d7c91b97dd324494dda410ec79c80 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/ohos/oh-package.json5 @@ -0,0 +1,18 @@ +{ + "modelVersion": "5.0.0", + "name": "apptemplate", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "overrides": { + "@ohos/flutter_ohos": "file:./har/flutter.har" + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/example/pubspec.yaml b/packages/path_provider/path_provider_ohos/example/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d3e334ef32960ab1fe71555988d0ed01a3cc1ea9 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/pubspec.yaml @@ -0,0 +1,39 @@ +# 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. +name: path_provider_example +description: Demonstrates how to use the path_provider plugin. +publish_to: none + +environment: + sdk: ^3.4.0 + flutter: ">=3.21.0" + +dependencies: + flutter: + sdk: flutter + path_provider: + path: ../../path_provider + path_provider_platform_interface: ^2.1.0 + +dependency_overrides: + path_provider_ohos: + path: ../../path_provider_ohos + +dev_dependencies: + flutter_test: + sdk: flutter + integration_test: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/packages/path_provider/path_provider_ohos/example/test_driver/integration_test.dart b/packages/path_provider/path_provider_ohos/example/test_driver/integration_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..c20ad8aee123a1893e742c989cdb70daae37cd6a --- /dev/null +++ b/packages/path_provider/path_provider_ohos/example/test_driver/integration_test.dart @@ -0,0 +1,18 @@ +/* + * 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 'package:integration_test/integration_test_driver.dart'; + +Future main() => integrationDriver(); diff --git a/packages/path_provider/path_provider_ohos/lib/messages.g.dart b/packages/path_provider/path_provider_ohos/lib/messages.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..82de2ba3540f837ac1998ceb09d556164c828a52 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/lib/messages.g.dart @@ -0,0 +1,204 @@ +/* + * 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 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; + +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/services.dart'; + +enum StorageDirectory { + root, + music, + podcasts, + ringtones, + alarms, + notifications, + pictures, + movies, + downloads, + dcim, + documents, +} + +class PathProviderApi { + /// Constructor for [PathProviderApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + PathProviderApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = StandardMessageCodec(); + + Future getTemporaryPath() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getTemporaryPath', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future getApplicationSupportPath() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future getApplicationDocumentsPath() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future getApplicationCachePath() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getApplicationCachePath', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future getExternalStoragePath() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePath', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return (replyList[0] as String?); + } + } + + Future> getExternalCachePaths() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalCachePaths', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as List?)!.cast(); + } + } + + Future> getExternalStoragePaths( + StorageDirectory arg_directory) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_directory.index]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as List?)!.cast(); + } + } +} diff --git a/packages/path_provider/path_provider_ohos/lib/path_provider_ohos.dart b/packages/path_provider/path_provider_ohos/lib/path_provider_ohos.dart new file mode 100644 index 0000000000000000000000000000000000000000..9917bb8585bc1e5be154424c516ba66466347814 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/lib/path_provider_ohos.dart @@ -0,0 +1,111 @@ +/* + * 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 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; +import 'messages.g.dart' as messages; + +messages.StorageDirectory _convertStorageDirectory( + StorageDirectory? directory) { + switch (directory) { + case null: + return messages.StorageDirectory.root; + case StorageDirectory.music: + return messages.StorageDirectory.music; + case StorageDirectory.podcasts: + return messages.StorageDirectory.podcasts; + case StorageDirectory.ringtones: + return messages.StorageDirectory.ringtones; + case StorageDirectory.alarms: + return messages.StorageDirectory.alarms; + case StorageDirectory.notifications: + return messages.StorageDirectory.notifications; + case StorageDirectory.pictures: + return messages.StorageDirectory.pictures; + case StorageDirectory.movies: + return messages.StorageDirectory.movies; + case StorageDirectory.downloads: + return messages.StorageDirectory.downloads; + case StorageDirectory.dcim: + return messages.StorageDirectory.dcim; + case StorageDirectory.documents: + return messages.StorageDirectory.documents; + } +} + +/// The OHOS implementation of [PathProviderPlatform]. +class PathProviderOhos extends PathProviderPlatform { + final messages.PathProviderApi _api = messages.PathProviderApi(); + + /// Registers this class as the default instance of [PathProviderPlatform]. + static void registerWith() { + PathProviderPlatform.instance = PathProviderOhos(); + } + + @override + Future getTemporaryPath() { + return _api.getTemporaryPath(); + } + + @override + Future getApplicationSupportPath() { + return _api.getApplicationSupportPath(); + } + + @override + Future getLibraryPath() { + throw UnsupportedError('getLibraryPath is not supported on OHOS'); + } + + @override + Future getApplicationDocumentsPath() { + return _api.getApplicationDocumentsPath(); + } + + @override + Future getApplicationCachePath() { + return _api.getApplicationCachePath(); + } + + @override + Future getExternalStoragePath() { + return _api.getExternalStoragePath(); + } + + @override + Future?> getExternalCachePaths() async { + return (await _api.getExternalCachePaths()).cast(); + } + + @override + Future?> getExternalStoragePaths({ + StorageDirectory? type, + }) async { + return _getExternalStoragePaths(type: type); + } + + @override + Future getDownloadsPath() async { + final List paths = + await _getExternalStoragePaths(type: StorageDirectory.downloads); + return paths.isEmpty ? null : paths.first; + } + + Future> _getExternalStoragePaths({ + StorageDirectory? type, + }) async { + return (await _api.getExternalStoragePaths(_convertStorageDirectory(type))) + .cast(); + } +} diff --git a/packages/path_provider/path_provider_ohos/ohos/.gitignore b/packages/path_provider/path_provider_ohos/ohos/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f7b4f89c49a6abadc383d9665d3b4c171d466bc --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/.gitignore @@ -0,0 +1,17 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test + +/entry/libs/arm64-v8a/libflutter.so +/entry/src/main/resources/rawfile/flutter_assets +**.har +**/oh-package-lock.json5 +BuildProfile.ets diff --git a/packages/path_provider/path_provider_ohos/ohos/build-profile.json5 b/packages/path_provider/path_provider_ohos/ohos/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d5a27749b92674777c50631deea098b3bb2620b --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/build-profile.json5 @@ -0,0 +1,24 @@ +/* + * 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/packages/path_provider/path_provider_ohos/ohos/hvigorfile.ts b/packages/path_provider/path_provider_ohos/ohos/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47e6e1f81d365872f101585f5dbf816bcad65864 --- /dev/null +++ b/packages/path_provider/path_provider_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/path_provider/path_provider_ohos/ohos/index.ets b/packages/path_provider/path_provider_ohos/ohos/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d5475f8dad953d201ecead309f5176e92561b5f --- /dev/null +++ b/packages/path_provider/path_provider_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 PathProviderPlugin from './src/main/ets/io/flutter/plugins/pathprovider/PathProviderPlugin' + +export default PathProviderPlugin \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/ohos/oh-package.json5 b/packages/path_provider/path_provider_ohos/ohos/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..36cc052aa7ef22c29c206246d5540954162396ca --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ +{ + "name": "path_provider_ohos", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/flutter_ohos": "file:libs/flutter.har" + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/Messages.ets b/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/Messages.ets new file mode 100644 index 0000000000000000000000000000000000000000..6dc5b93074c063f4783b47813310eb11621fb1a4 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/Messages.ets @@ -0,0 +1,263 @@ +/* + * 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 Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import BasicMessageChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel'; +import { BinaryMessenger } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger'; +import MessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/MessageCodec'; +import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec'; + +export enum StorageDirectory { + ROOT = 0, + MUSIC = 1, + PODCASTS = 2, + RINGTONES = 3, + ALARMS = 4, + NOTIFICATIONS = 5, + PICTURES = 6, + MOVIES = 7, + DOWNLOADS = 8, + DCIM = 9, + DOCUMENTS = 10 +} + +const TAG: string = "Message"; + +export default class Messages { + static wrapError(exception: Error): Array { + const errorList: Array = new Array(); + if (exception instanceof FlutterError) { + const error = exception; + errorList.push(error.code); + errorList.push(error.message); + errorList.push(error.details); + } else { + errorList.push(exception.name); + errorList.push(exception.message); + errorList.push(exception.stack); + } + return errorList; + } +} + +export class FlutterError extends Error { + code: string; + details: ESObject; + + constructor(code: string, message: string, details: ESObject) { + super(message); + this.code = code; + this.details = details; + } +} + +export abstract class PathProviderApi { + abstract getTemporaryPath(): string; + + abstract getApplicationSupportPath(): string; + + abstract getApplicationDocumentsPath(): string; + + abstract getApplicationCachePath(): string; + + abstract getExternalStoragePath(): string; + + abstract getExternalCachePaths(): Array; + + abstract getExternalStoragePaths(directory: StorageDirectory): Array; + + static getCodec(): MessageCodec { + return new StandardMessageCodec(); + } + + static setup(binaryMessenger: BinaryMessenger, api: PathProviderApi) { + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getTemporaryPath", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getTemporaryPath(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getApplicationSupportPath(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getApplicationDocumentsPath(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getApplicationCachePath", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getApplicationCachePath(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getExternalStoragePath", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getExternalStoragePath(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getExternalCachePaths", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + try { + const output = api.getExternalCachePaths(); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + { + const channel: BasicMessageChannel = + new BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths", + PathProviderApi.getCodec()); + if (api != null) { + channel.setMessageHandler({ + onMessage: (message: ESObject, reply: ESObject) => { + Log.i(TAG, "setup on message : " + message); + let wrapped: Array = new Array(); + let args: Array = message; + const directoryArg: StorageDirectory = args[0] == null ? null : args[0]; + try { + const output = api.getExternalStoragePaths(directoryArg); + wrapped.push(output); + } catch (err) { + const wrappedError: Array = Messages.wrapError(err); + wrapped = wrappedError; + } + reply.reply(wrapped); + } + } as ESObject) + } else { + channel.setMessageHandler(null); + } + } + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/PathProviderPlugin.ets b/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/PathProviderPlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..50fa4555e281bf413373a762e04814e77181a66a --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/src/main/ets/io/flutter/plugins/pathprovider/PathProviderPlugin.ets @@ -0,0 +1,187 @@ +/* + * 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 common from '@ohos.app.ability.common'; +import AbilityAware from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityAware'; +import { + AbilityPluginBinding +} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding'; +import { + FlutterPlugin, + FlutterPluginBinding +} from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; +import PathUtils from '@ohos/flutter_ohos/src/main/ets/util/PathUtils'; +import { BinaryMessenger } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger'; +import { PathProviderApi, StorageDirectory } from './Messages'; +import fs from '@ohos.file.fs'; + +const TAG: string = "PathProviderPlugin"; + +export default class PathProviderPlugin extends PathProviderApi implements FlutterPlugin, AbilityAware { + private pluginBinding: FlutterPluginBinding | null = null; + private context: common.Context | null = null; + + constructor(context?: common.Context) { + super(); + if (context) { + this.context = context; + } + } + + getUniqueClassName(): string { + return TAG; + } + + onAttachedToEngine(binding: FlutterPluginBinding): void { + this.pluginBinding = binding; + if (this.pluginBinding) { + this.setup(this.pluginBinding.getBinaryMessenger(), this.pluginBinding.getApplicationContext()); + } + } + + onDetachedFromEngine(binding: FlutterPluginBinding): void { + this.pluginBinding = null; + } + + onAttachedToAbility(binding: AbilityPluginBinding): void { + Log.i(TAG, "onAttachedToAbility"); + } + + onDetachedFromAbility(): void { + } + + static registerWith(): void { + } + + setup(messenger: BinaryMessenger, context: common.Context) { + try { + PathProviderApi.setup(messenger, this); + } catch (err) { + Log.e(TAG, "Received exception while setting up PathProviderPlugin", err); + } + this.context = context; + } + + getTemporaryPath(): string { + return this.getPathProviderTemporaryDirectory(); + } + + getApplicationSupportPath(): string { + return this.getApplicationSupportDirectory(); + } + + getApplicationDocumentsPath(): string { + return this.getPathProviderApplicationDocumentsDirectory(); + } + + getApplicationCachePath(): string { + if (this.context) { + return this.context.cacheDir; + } + return ""; + } + + getExternalStoragePath(): string { + return this.getPathProviderStorageDirectory(); + } + + getExternalCachePaths(): Array { + return this.getPathProviderExternalCacheDirectories(); + } + + getExternalStoragePaths(directory: StorageDirectory): Array { + return this.getPathProviderExternalStorageDirectories(directory); + } + + private getPathProviderTemporaryDirectory(): string { + if (this.context) { + return this.context.cacheDir; + } + return ""; + } + + private getApplicationSupportDirectory(): string { + return PathUtils.getFilesDir(this.context); + } + + private getPathProviderApplicationDocumentsDirectory(): string { + return PathUtils.getDataDirectory(this.context) ?? ""; + } + + private getPathProviderStorageDirectory(): string { + if (this.context) { + return this.context.filesDir; + } + return ""; + } + + private getPathProviderExternalCacheDirectories(): Array { + const paths = new Array(); + if (this.context) { + paths.push(this.context.cacheDir); + } + return paths; + } + + private getStorageDirectoryString(directory: StorageDirectory): string { + switch (directory) { + case StorageDirectory.ROOT: + return ""; + case StorageDirectory.MUSIC: + return "music"; + case StorageDirectory.PODCASTS: + return "podcasts"; + case StorageDirectory.RINGTONES: + return "ringtones"; + case StorageDirectory.ALARMS: + return "alarms"; + case StorageDirectory.NOTIFICATIONS: + return "notifications"; + case StorageDirectory.PICTURES: + return "pictures"; + case StorageDirectory.MOVIES: + return "movies"; + case StorageDirectory.DOWNLOADS: + return "downloads"; + case StorageDirectory.DCIM: + return "dcim"; + case StorageDirectory.DOCUMENTS: + return "documents"; + default: + throw new Error("Unrecognized directory: " + directory); + } + } + + private getPathProviderExternalStorageDirectories(directory: StorageDirectory): Array { + const paths = new Array(); + if (!this.context) { + return paths; + } + const filePath = this.context.filesDir + "/" + this.getStorageDirectoryString(directory); + if (!fs.accessSync(filePath)) { + try { + fs.mkdirSync(filePath); + paths.push(filePath); + Log.i(TAG, "no directory " + filePath + " create success"); + } catch (err) { + Log.e(TAG, "mkdirSync failed err:" + err); + } + } else { + paths.push(filePath); + } + + return paths; + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/ohos/src/main/module.json5 b/packages/path_provider/path_provider_ohos/ohos/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..86cc60e7b92ef18e85b4e7e35f8b178c65e5a9d6 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/ohos/src/main/module.json5 @@ -0,0 +1,24 @@ +/* + * 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": "path_provider_ohos", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} \ No newline at end of file diff --git a/packages/path_provider/path_provider_ohos/pubspec.yaml b/packages/path_provider/path_provider_ohos/pubspec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..12a67e8e58380b1443926c190de2a5225e935a23 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/pubspec.yaml @@ -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. + +name: path_provider_ohos +description: Ohos implementation of the path_provider plugin. +repository: https://gitee.com/openharmony-sig/flutter_packages/tree/master/packages/path_provider/path_provider_ohos +issue_tracker: https://gitee.com/openharmony-sig/flutter_packages/issues +version: 2.2.9 + +environment: + sdk: ^3.4.0 + flutter: ">=3.21.0" + +flutter: + plugin: + implements: path_provider + platforms: + ohos: + package: io.flutter.plugins.pathprovider + pluginClass: PathProviderPlugin + dartPluginClass: PathProviderOhos + +dependencies: + flutter: + sdk: flutter + path_provider_platform_interface: ^2.1.0 + +dev_dependencies: + flutter_test: + sdk: flutter + integration_test: + sdk: flutter + pigeon: ^9.2.4 + test: ^1.16.0 + +topics: + - files + - path-provider + - paths diff --git a/packages/path_provider/path_provider_ohos/test/messages_test.g.dart b/packages/path_provider/path_provider_ohos/test/messages_test.g.dart new file mode 100644 index 0000000000000000000000000000000000000000..a29825e1b6ed9bba00d2591e141ce9786501927f --- /dev/null +++ b/packages/path_provider/path_provider_ohos/test/messages_test.g.dart @@ -0,0 +1,153 @@ +/* + * 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 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:path_provider_ohos/messages.g.dart'; + +abstract class TestPathProviderApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = StandardMessageCodec(); + + String? getTemporaryPath(); + + String? getApplicationSupportPath(); + + String? getApplicationDocumentsPath(); + + String? getExternalStoragePath(); + + List getExternalCachePaths(); + + List getExternalStoragePaths(StorageDirectory directory); + + static void setup(TestPathProviderApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getTemporaryPath', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + // ignore message + final String? output = api.getTemporaryPath(); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getApplicationSupportPath', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + // ignore message + final String? output = api.getApplicationSupportPath(); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getApplicationDocumentsPath', + codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + // ignore message + final String? output = api.getApplicationDocumentsPath(); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePath', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + // ignore message + final String? output = api.getExternalStoragePath(); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalCachePaths', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + // ignore message + final List output = api.getExternalCachePaths(); + return [output]; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null.'); + final List args = (message as List?)!; + final StorageDirectory? arg_directory = + args[0] == null ? null : StorageDirectory.values[args[0] as int]; + assert(arg_directory != null, + 'Argument for dev.flutter.pigeon.PathProviderApi.getExternalStoragePaths was null, expected non-null StorageDirectory.'); + final List output = + api.getExternalStoragePaths(arg_directory!); + return [output]; + }); + } + } + } +} diff --git a/packages/path_provider/path_provider_ohos/test/path_provider_ohos_test.dart b/packages/path_provider/path_provider_ohos/test/path_provider_ohos_test.dart new file mode 100644 index 0000000000000000000000000000000000000000..86f8b687294ab748d28455d7ff1fd6c6fa5aa176 --- /dev/null +++ b/packages/path_provider/path_provider_ohos/test/path_provider_ohos_test.dart @@ -0,0 +1,112 @@ +/* + * 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 'package:flutter_test/flutter_test.dart'; +import 'package:path_provider_ohos/messages.g.dart' as messages; +import 'package:path_provider_ohos/path_provider_ohos.dart'; +import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; +import 'messages_test.g.dart'; + +const String kTemporaryPath = 'temporaryPath'; +const String kApplicationSupportPath = 'applicationSupportPath'; +const String kLibraryPath = 'libraryPath'; +const String kApplicationDocumentsPath = 'applicationDocumentsPath'; +const String kExternalCachePaths = 'externalCachePaths'; +const String kExternalStoragePaths = 'externalStoragePaths'; +const String kDownloadsPath = 'downloadsPath'; + +class _Api implements TestPathProviderApi { + @override + String? getApplicationDocumentsPath() => kApplicationDocumentsPath; + + @override + String? getApplicationSupportPath() => kApplicationSupportPath; + + @override + List getExternalCachePaths() => [kExternalCachePaths]; + + @override + String? getExternalStoragePath() => kExternalStoragePaths; + + @override + List getExternalStoragePaths(messages.StorageDirectory directory) => + [kExternalStoragePaths]; + + @override + String? getTemporaryPath() => kTemporaryPath; +} + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('PathProviderOhos', () { + late PathProviderOhos pathProvider; + + setUp(() async { + pathProvider = PathProviderOhos(); + TestPathProviderApi.setup(_Api()); + }); + + test('getTemporaryPath', () async { + final String? path = await pathProvider.getTemporaryPath(); + expect(path, kTemporaryPath); + }); + + test('getApplicationSupportPath', () async { + final String? path = await pathProvider.getApplicationSupportPath(); + expect(path, kApplicationSupportPath); + }); + + test('getLibraryPath fails', () async { + try { + await pathProvider.getLibraryPath(); + fail('should throw UnsupportedError'); + } catch (e) { + expect(e, isUnsupportedError); + } + }); + + test('getApplicationDocumentsPath', () async { + final String? path = await pathProvider.getApplicationDocumentsPath(); + expect(path, kApplicationDocumentsPath); + }); + + test('getExternalCachePaths succeeds', () async { + final List? result = await pathProvider.getExternalCachePaths(); + expect(result!.length, 1); + expect(result.first, kExternalCachePaths); + }); + + for (final StorageDirectory? type in [ + ...StorageDirectory.values + ]) { + test('getExternalStoragePaths (type: $type) ohos succeeds', () async { + final List? result = + await pathProvider.getExternalStoragePaths(type: type); + expect(result!.length, 1); + expect(result.first, kExternalStoragePaths); + }); + } // end of for-loop + + test('getDownloadsPath fails', () async { + try { + await pathProvider.getDownloadsPath(); + fail('should throw UnsupportedError'); + } catch (e) { + expect(e, isUnsupportedError); + } + }); + }); +}