From efa2d982f4ce4d7ad3e962bfae732b0a518475f3 Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Fri, 6 May 2022 15:27:38 +0800 Subject: [PATCH 01/22] add file extension frameworks code Signed-off-by: linjun9528 --- LICENSE | 177 -- README.md | 36 - README_zh.md | 39 - bundle.json | 7 +- figures/user_file_manager.png | Bin 15402 -> 0 bytes .../kits/js => frameworks/innerkits}/BUILD.gn | 70 +- .../innerkits/file_extension}/BUILD.gn | 138 +- .../include/file_access_helper.h | 96 + .../file_extension/include/file_ext_ability.h | 64 +- .../include/file_ext_ability_module_loader.h | 64 +- .../include/file_ext_connection.h | 64 +- .../file_extension/include/file_ext_proxy.h | 33 +- .../file_extension/include/file_ext_stub.h | 37 +- .../include/file_ext_stub_impl.h | 49 +- .../file_extension/include/ifile_ext_base.h | 54 +- .../include/js_file_ext_ability.h | 56 +- .../file_extension/src/file_access_helper.cpp | 354 ++++ .../file_extension/src/file_ext_ability.cpp | 66 + .../src/file_ext_ability_module_loader.cpp | 34 + .../src/file_ext_connection.cpp | 96 + .../file_extension/src/file_ext_proxy.cpp | 73 + .../file_extension/src/file_ext_stub.cpp | 89 + .../file_extension/src/file_ext_stub_impl.cpp | 72 +- .../src/js_file_ext_ability.cpp | 224 +++ .../innerkits/file_extension_hap/.gitignore | 4 + .../file_extension_hap/AppScope/app.json | 13 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes .../file_extension_hap/build-profile.json5 | 26 + .../file_extension_hap/entry/.gitignore | 3 + .../entry/build-profile.json5 | 13 + .../file_extension_hap/entry/hvigorfile.js | 2 + .../entry/package-lock.json | 5 + .../file_extension_hap/entry/package.json | 14 + .../src/main/ets/Application/AbilityStage.ts | 7 + .../ets/FileService/FileExtensionAbility.ts | 13 + .../src/main/ets/MainAbility/MainAbility.ts | 34 + .../entry/src/main/ets/pages/index.ets | 17 + .../entry/src/main/module.json | 37 + .../main/resources/base/element/string.json | 20 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../ohosTest/ets/TestAbility/TestAbility.ts | 39 + .../ohosTest/ets/TestAbility/pages/index.ets | 34 + .../ets/TestRunner/OpenHarmonyTestRunner.ts | 58 + .../src/ohosTest/ets/test/Ability.test.ets | 13 + .../entry/src/ohosTest/ets/test/List.test.ets | 5 + .../entry/src/ohosTest/module.json5 | 37 + .../resources/base/element/string.json | 16 + .../ohosTest/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + .../file_extension_hap/hvigorfile.js | 2 + .../file_extension_hap/package-lock.json | 1652 +++++++++++++++++ .../innerkits/file_extension_hap/package.json | 18 + frameworks/innerkits/signature/medialib.p7b | Bin 0 -> 3528 bytes .../innerkits/signature/openharmony_sx.p7b | Bin 0 -> 3544 bytes interfaces/kits/js/src/file_manager_napi.cpp | 412 ---- .../kits/napi/file_access_module/BUILD.gn | 69 + .../file_access_module/file_access_common.h | 45 + .../napi_fileaccess_helper.cpp | 385 ++++ .../napi_fileaccess_helper.h} | 41 +- .../native_fileaccess_module.cpp} | 54 +- .../kits/napi/file_ext_ability}/BUILD.gn | 38 +- .../napi/file_ext_ability/file_ext_ability.js | 25 +- .../file_ext_ability_module.cpp | 57 + services/etc/fms_service.cfg | 9 - services/etc/fms_service.rc | 20 - services/include/file_manager_service_def.h | 99 - services/include/log.h | 36 - services/include/storage_manager_inf.h | 37 - services/sa_profile/5010.xml | 28 - services/src/client/file_manager_proxy.cpp | 164 -- services/src/client/ifms_client.h | 34 - services/src/fileoper/cmd_options.h | 131 -- services/src/fileoper/cmd_response.h | 102 - .../fileoper/ext_storage/ext_storage_status.h | 112 -- .../ext_storage/ext_storage_subscriber.cpp | 96 - .../ext_storage/storage_manager_inf.cpp | 117 -- .../src/fileoper/external_storage_oper.cpp | 108 -- services/src/fileoper/external_storage_oper.h | 36 - .../src/fileoper/external_storage_utils.cpp | 206 -- services/src/fileoper/file_info.cpp | 48 - services/src/fileoper/file_info.h | 91 - services/src/fileoper/media_file_oper.cpp | 133 -- services/src/fileoper/media_file_utils.cpp | 444 ----- services/src/fileoper/media_file_utils.h | 58 - services/src/fileoper/oper_factory.cpp | 48 - services/src/server/file_manager_service.cpp | 46 - .../src/server/file_manager_service_stub.cpp | 98 - services/test/BUILD.gn | 125 -- .../test/client/file_manager_proxy_test.cpp | 89 - services/test/client/fms_manager_proxy_mock.h | 61 - services/test/fileoper/oper_factory_test.cpp | 113 -- .../test/server/file_manager_service_test.cpp | 111 -- utils/hilog_wrapper.h | 83 + 95 files changed, 4277 insertions(+), 3824 deletions(-) delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 README_zh.md delete mode 100644 figures/user_file_manager.png rename {interfaces/kits/js => frameworks/innerkits}/BUILD.gn (32%) rename {services => frameworks/innerkits/file_extension}/BUILD.gn (32%) create mode 100644 frameworks/innerkits/file_extension/include/file_access_helper.h rename services/src/fileoper/ext_storage/ext_storage_subscriber.h => frameworks/innerkits/file_extension/include/file_ext_ability.h (34%) rename services/include/file_manager_service_errno.h => frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h (42%) rename services/src/client/file_manager_proxy.h => frameworks/innerkits/file_extension/include/file_ext_connection.h (32%) rename services/src/fileoper/file_oper.h => frameworks/innerkits/file_extension/include/file_ext_proxy.h (50%) rename services/src/server/file_manager_service.h => frameworks/innerkits/file_extension/include/file_ext_stub.h (45%) rename services/src/fileoper/external_storage_utils.h => frameworks/innerkits/file_extension/include/file_ext_stub_impl.h (39%) rename services/src/server/file_manager_service_stub.h => frameworks/innerkits/file_extension/include/ifile_ext_base.h (39%) rename services/src/fileoper/media_file_oper.h => frameworks/innerkits/file_extension/include/js_file_ext_ability.h (30%) create mode 100644 frameworks/innerkits/file_extension/src/file_access_helper.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_connection.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_proxy.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_stub.cpp rename interfaces/kits/js/src/file_manager_napi_def.h => frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp (34%) create mode 100644 frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp create mode 100644 frameworks/innerkits/file_extension_hap/.gitignore create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/app.json create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png create mode 100644 frameworks/innerkits/file_extension_hap/build-profile.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/.gitignore create mode 100644 frameworks/innerkits/file_extension_hap/entry/build-profile.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/hvigorfile.js create mode 100644 frameworks/innerkits/file_extension_hap/entry/package-lock.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/package.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/module.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/media/icon.png create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 frameworks/innerkits/file_extension_hap/hvigorfile.js create mode 100644 frameworks/innerkits/file_extension_hap/package-lock.json create mode 100644 frameworks/innerkits/file_extension_hap/package.json create mode 100644 frameworks/innerkits/signature/medialib.p7b create mode 100644 frameworks/innerkits/signature/openharmony_sx.p7b delete mode 100644 interfaces/kits/js/src/file_manager_napi.cpp create mode 100644 interfaces/kits/napi/file_access_module/BUILD.gn create mode 100644 interfaces/kits/napi/file_access_module/file_access_common.h create mode 100644 interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp rename interfaces/kits/{js/src/file_manager_napi.h => napi/file_access_module/napi_fileaccess_helper.h} (39%) rename interfaces/kits/{js/src/module.cpp => napi/file_access_module/native_fileaccess_module.cpp} (47%) rename {services/sa_profile => interfaces/kits/napi/file_ext_ability}/BUILD.gn (35%) rename services/src/fileoper/oper_factory.h => interfaces/kits/napi/file_ext_ability/file_ext_ability.js (57%) create mode 100644 interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp delete mode 100644 services/etc/fms_service.cfg delete mode 100644 services/etc/fms_service.rc delete mode 100644 services/include/file_manager_service_def.h delete mode 100644 services/include/log.h delete mode 100644 services/include/storage_manager_inf.h delete mode 100644 services/sa_profile/5010.xml delete mode 100644 services/src/client/file_manager_proxy.cpp delete mode 100644 services/src/client/ifms_client.h delete mode 100644 services/src/fileoper/cmd_options.h delete mode 100644 services/src/fileoper/cmd_response.h delete mode 100644 services/src/fileoper/ext_storage/ext_storage_status.h delete mode 100644 services/src/fileoper/ext_storage/ext_storage_subscriber.cpp delete mode 100644 services/src/fileoper/ext_storage/storage_manager_inf.cpp delete mode 100644 services/src/fileoper/external_storage_oper.cpp delete mode 100644 services/src/fileoper/external_storage_oper.h delete mode 100644 services/src/fileoper/external_storage_utils.cpp delete mode 100644 services/src/fileoper/file_info.cpp delete mode 100644 services/src/fileoper/file_info.h delete mode 100644 services/src/fileoper/media_file_oper.cpp delete mode 100644 services/src/fileoper/media_file_utils.cpp delete mode 100644 services/src/fileoper/media_file_utils.h delete mode 100644 services/src/fileoper/oper_factory.cpp delete mode 100644 services/src/server/file_manager_service.cpp delete mode 100644 services/src/server/file_manager_service_stub.cpp delete mode 100644 services/test/BUILD.gn delete mode 100644 services/test/client/file_manager_proxy_test.cpp delete mode 100644 services/test/client/fms_manager_proxy_mock.h delete mode 100644 services/test/fileoper/oper_factory_test.cpp delete mode 100644 services/test/server/file_manager_service_test.cpp create mode 100644 utils/hilog_wrapper.h diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4947287f..00000000 --- a/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 1d37300c..00000000 --- a/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# storage_user_file_manger - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README_zh.md b/README_zh.md deleted file mode 100644 index 6b659a73..00000000 --- a/README_zh.md +++ /dev/null @@ -1,39 +0,0 @@ -# 公共文件服务 - -## 简介 - -公共文件服务提供公共文件访问和管理的服务接口。 - -公共文件服务中File Manager Service服务向下对接底层文件管理服务,如媒体库、外卡管理。File Manager Service服务向上对接应用提供公共文件查询、创建的能力,如图1。 File Manager Service接口能力当前只对系统应用如文件选择器提供。 - -支持能力列举如下: -- 查询、创建公共文件路径下媒体文件。媒体文件包括图片、音频、视频。媒体文件通过相册方式呈现。 - -- 查询、创建公共文件路径下文档文件。文档文件包括其他文件、外部存储卡内的文件。文件以目录树方式呈现。 - -**图 1** 公共文件管理架构图 -![](figures/user_file_manager.png "公共文件管理架构图") - -## 目录 - -仓目录结构如下: -``` -/foundation/storage/user_file_service -├── figures # 插图文件 -├── serivce # 服务实现 -│   ├── etc # 内部接口实现 -│   ├── src # 内部接口实现 -├── interfaces # 接口代码 -│   ├── innerkits # 内部 Native 接口 -│   └── kits # 外部 JS 接口 -├── BUILD.gn # 编译入口 -└── bundle.json # 部件描述文件 -``` -## 说明 -### 使用说明 -1. 创建文件 - - 提供createFile接口,传入文件名与相册uri进行文件创建。 - - 文件创建成功后,可获得文件uri。应用可通过uri进行文件打开并进行读写操作。 -2. 查询文件 - - 提供listFile接口,传入文件类型、相册uri进行文件查询。 - - 获得相册下文件信息的集合,包括文件名、文件类型、文件大小、文件创建时间等信息。 \ No newline at end of file diff --git a/bundle.json b/bundle.json index 95dbc537..3ba13c4e 100644 --- a/bundle.json +++ b/bundle.json @@ -33,12 +33,11 @@ }, "build": { "sub_component": [ - "//foundation/filemanagement/user_file_service/services:fms", - "//foundation/filemanagement/user_file_service/services/sa_profile:filemanager_service_sa_profile", - "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + "//foundation/filemanagement/user_file_service/frameworks/innerkits:frameworks_innerkits", + "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_access_module:fileaccess", + "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_ext_ability:fileextensionability_napi" ], "test": [ - "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" ] } } diff --git a/figures/user_file_manager.png b/figures/user_file_manager.png deleted file mode 100644 index 597ec2aa841410c412dbe7517a95eed5fe9377f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15402 zcmdVB2UJtv^Dhc0pnxEv0s>+~ItWPb3L-^7dJBkvG--hlYCw^q2uKUP_b$B$6{UqD zp_dR^2tASzdf)}Wzu$k|x87TC{r_*>^}qMB7VB`%;q2Kndpc~a}_-@G74QXGIHBXRHP@^1xg#zh1^q5?Fm`sAp08W=Aymw3uQ90>KNJ+Yf94n zW%uW%o@8X#yv~2g=iYGokdeuDsH-R&_*iabIJ@2N4Xhdp$5Z!~1=<{ty|eo1_CB3V z{R+_QwoEqd2gckbz3KU5q` zT4yVp0vN=L#br|ac&pihYfU#RPpeB?4mvK9W0Mm{St#k9 z11~uZ>D{p2-(hkK{vRLis5jS{$G@p9Dev8m^G*3SpdU2#cmoKj<4*h)=Rq9MACY0) zzyRxvV}BtIS|SdbNK_V?Y6LKir@fV{?82y3Irt?cH^ zjGT=mY5_9PpwTuuxao+4;&YPm9<>lmCI(pxC~3aDuDzbNVg~?GtWVe?ciT2< zXf*ccfMC$nXF29d*lkmV1>Cz2Wp1fS%0Jb(Ndm}ZiLIq^o*Pt=hEF3YIpMo_i>r~ynmG_nry+H zZLKpM=9@0l{*JDFGasj;v0OZ?7A{y@L7pDEw9fUu>E5iZ5w+Y=-a3$&KLGjqg4O<(B9K>aZ zzSgB5W8A3F@Ccp1QhrUC)w%D;QPsCzI@QUBrEjnPzD!~+{ak4kEE_A^)+iqi5SE)v zncbps2Xfly?~Kmh>2)?|JsgzSE;TQ`rdafZ#0~Gct}NB7|F>Jb|H1w& zhGcM)gsq|yaBVO?=Alx%&kn`8H8CSe^WMGx7i;pL<@oQQf9;n^a2jy>t%g_G@5Xb}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-G0%(B?ulhvEfWvhd%Cud9M*#bBVuCmi4flEXi_EX z!SHz}PKxQyv-d?GxC=6Cl(x}+U?6<-N1ErF%!`+-6((X=bcOqXEB)z?$sK%q0nhly zaMp0PrBV5K@agILO`iS0x$%%zavKt}inmBrSyE4v(AiV5E!Dqx(i!+XTPU`EuuY}? zK3bNVAtOA|Xq|9P%5}_2DwW*!G>vy^VX{A}P1+zv(cjY{6n=E(#yKP*84sU$N*lP`z~9g6^p!$Fm=^xOYC1ta}AeLah*5ta-1@NSfNtg(e~9ZFb80Ynh2lLy1PVm=lXRyU@~~cQ${lPCPuz zuF9j=Y>}-th{adV@Jjm5@rCS=6*O#|igVRz-5q>!t`SI_=>&(#_Gfa9Imf+$*20M^ z<7MhxOVOet~+uD62tg~Ms9bn-3z zo$161`f}1Y^R@aN?bQ3YIjS@Va;%ah^)D)r;JI|(5`?cch)qq)ytWh`w?gbq5@B8@ zsLy2KUOi~EuUZ@m!fU5m*2dDwh)`eo!5?uP6xKSD~7=*H-u&sH6t1sn$0 z?h8uyi1f78)!Y~F;2*ebiA=az96F%}^u#I_ z5+EBEdwsNFgl-bd{$a(R*%GeqKOgNMr>w7yQVn`Fv7i4iY7$^~4fMb4HjZjiXC8Q>q>0xKn=W?!9q)kA4?c`9e09?7f zq@hC)9lBc60JW{I;l_l|bQ$sgdv*UOl#e6q+5VO~aIUxAIq%^jwJBPXJnwmT>YvH~ gEqhjP+&km64PXpJBY~uDU@|gwRc)2ZC$HZBUzUwp(*OVf diff --git a/interfaces/kits/js/BUILD.gn b/frameworks/innerkits/BUILD.gn similarity index 32% rename from interfaces/kits/js/BUILD.gn rename to frameworks/innerkits/BUILD.gn index bc9b9e5c..08487cc6 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/frameworks/innerkits/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device 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 @@ -12,49 +12,47 @@ # limitations under the License. import("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -ohos_shared_library("filemanager") { +group("frameworks_innerkits") { + deps = [ + ":file_extension_hap", + "file_extension:file_extension_ability_kit", + "file_extension:file_extension_ability_module", + ] +} + +#### file extension hap +ohos_hap("file_extension_hap") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + deps = [ + ":file_extension_js_assets", + ":file_extension_resources", + ] + certificate_profile = "signature/medialib.p7b" + hap_name = "file_extension" subsystem_name = "filemanagement" part_name = "user_file_service" + module_install_dir = "app/com.ohos.FileExtension" +} - relative_install_dir = "module" +ohos_js_assets("file_extension_js_assets") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + ets2abc = true + source_dir = "file_extension_hap/entry/src/main/ets" +} - include_dirs = [ - "//third_party/node/src", - "//foundation/arkui/napi/interfaces/kits", - "//utils/native/base/include", - "//third_party/libuv/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi/n_async", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - ] +ohos_app_scope("file_extension_app_profile") { + app_profile = "file_extension_hap/AppScope/app.json" + sources = [ "file_extension_hap/AppScope/resources" ] +} +ohos_resources("file_extension_resources") { sources = [ - "src/file_manager_napi.cpp", - "src/module.cpp", + "file_extension_hap/entry/src/main/resources", ] - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/arkui/napi:ace_napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js:fileio", - "//foundation/multimedia/medialibrary_standard/frameworks/services/media_library:medialibrary_data_ability", - "//utils/native/base:utils", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", + ":file_extension_app_profile", ] + hap_profile = "file_extension_hap/entry/src/main/module.json" } +#### file extension hap \ No newline at end of file diff --git a/services/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn similarity index 32% rename from services/BUILD.gn rename to frameworks/innerkits/file_extension/BUILD.gn index 20af4663..6ccbd0c6 100644 --- a/services/BUILD.gn +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device 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 @@ -12,80 +12,110 @@ # limitations under the License. import("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -group("fms") { - deps = [ - ":fms_server", - ":fms_service.cfg", +BASE_DIR = "//foundation/filemanagement/user_file_service" + +config("ability_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${BASE_DIR}/utils", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/aafwk/standard/services/common/include", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", ] -} -ohos_prebuilt_etc("fms_service.cfg") { - source = "etc/fms_service.cfg" - relative_install_dir = "init" - subsystem_name = "filemanagement" - part_name = "user_file_service" + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } } -ohos_shared_library("fms_server") { - subsystem_name = "filemanagement" - part_name = "user_file_service" - +config("ability_public_config") { + visibility = [ ":*" ] include_dirs = [ - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "$FMS_BASE_DIR/include/fileoper", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog", - "//foundation/filemanagement/storage_service/services/storage_manager/include", - "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", - "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "include", + "${BASE_DIR}/utils", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/app", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context", ] +} + +ohos_shared_library("file_extension_ability_kit") { + include_dirs = [] sources = [ - "src/client/file_manager_proxy.cpp", - "src/fileoper/ext_storage/ext_storage_subscriber.cpp", - "src/fileoper/ext_storage/storage_manager_inf.cpp", - "src/fileoper/external_storage_oper.cpp", - "src/fileoper/external_storage_utils.cpp", - "src/fileoper/file_info.cpp", - "src/fileoper/media_file_oper.cpp", - "src/fileoper/media_file_utils.cpp", - "src/fileoper/oper_factory.cpp", - "src/server/file_manager_service.cpp", - "src/server/file_manager_service_stub.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_access_helper.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_connection.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp", + ] + configs = [ ":ability_config" ] + public_configs = [ + ":ability_public_config", + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_public_config", ] deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native:storage_manager_sa_proxy", - "//foundation/filemanagement/storage_service/services/storage_manager:storage_manager", - "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/media_library_helper:media_library", - "//foundation/multimedia/medialibrary_standard/frameworks/services/media_library:medialibrary_data_ability", - "//utils/native/base:utils", + "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } + external_deps = [ "ability_base:want", "ability_base:zuri", + "ability_runtime:ability_context_native", "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", - "common_event_service:cesfwk_innerkits", - "hiviewdfx_hilog_native:libhilog", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "bytrace_standard:bytrace_core", "ipc:ipc_core", - "native_appdatamgr:native_appdatafwk", + "ipc_js:rpc", "native_appdatamgr:native_dataability", - "native_appdatamgr:native_rdb", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", + "permission_standard:libpermissionsdk_standard", + "utils_base:utils", + ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/arkui/napi:ace_napi", ] + + subsystem_name = "filemanagement" + part_name = "user_file_service" +} + +ohos_shared_library("file_extension_ability_module") { + sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp", ] + + configs = [ ":ability_config" ] + public_configs = [ ":ability_public_config" ] + + deps = [ + ":file_extension_ability_kit", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/appexecfwk/standard/common:libappexecfwk_common", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:runtime", + "hiviewdfx_hilog_native:libhilog", + "native_appdatamgr:native_appdatafwk", + "utils_base:utils", + ] + + subsystem_name = "filemanagement" + part_name = "user_file_service" } diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h new file mode 100644 index 00000000..8ea8784e --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#ifndef FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H +#define FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H + +#include +#include +#include + +#include "context.h" +#include "file_ext_connection.h" +#include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" +#include "ifile_ext_base.h" +#include "uri.h" +#include "want.h" + +using Uri = OHOS::Uri; + +namespace OHOS { +namespace NativeRdb { +class AbsSharedResultSet; +class DataAbilityPredicates; +class ValuesBucket; +} // namespace NativeRdb +namespace AppExecFwk { +using string = std::string; +class DataAbilityResult; +class DataAbilityOperation; +class PacMap; +class FileAccessHelper final : public std::enable_shared_from_this { +public: + ~FileAccessHelper() = default; + + static std::shared_ptr Creator(const std::shared_ptr &context, + const AAFwk::Want &want); + + static std::shared_ptr Creator(const std::shared_ptr &context, + const AAFwk::Want &want, const std::shared_ptr &uri); + + static std::shared_ptr Creator(const std::shared_ptr &context, + const AAFwk::Want &want, const std::shared_ptr &uri); + + bool Release(); + + int OpenFile(Uri &uri, const std::string &mode); +private: + FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want); + FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, + const std::shared_ptr &uri, const sptr &fileExtProxy); + FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, + const std::shared_ptr &uri, const sptr &fileExtProxy); + void AddFileAccessDeathRecipient(const sptr &token); + void OnSchedulerDied(const wptr &remote); + bool CheckUriParam(const Uri &uri); + bool CheckOhosUri(const Uri &uri); + + sptr token_ = {}; + std::shared_ptr context_ = nullptr; + AAFwk::Want want_ = {}; + std::shared_ptr uri_ = nullptr; + sptr fileExtProxy_ = nullptr; + bool isSystemCaller_ = false; + static std::mutex oplock_; + sptr callerDeathRecipient_ = nullptr; + sptr fileExtConnection_ = nullptr; +}; + +class FileAccessDeathRecipient : public IRemoteObject::DeathRecipient { +public: + using RemoteDiedHandler = std::function &)>; + + explicit FileAccessDeathRecipient(RemoteDiedHandler handler); + + virtual ~FileAccessDeathRecipient(); + + virtual void OnRemoteDied(const wptr &remote); + +private: + RemoteDiedHandler handler_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h similarity index 34% rename from services/src/fileoper/ext_storage/ext_storage_subscriber.h rename to frameworks/innerkits/file_extension/include/file_ext_ability.h index 18a34b77..f47168e0 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,42 +12,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_SYS_EVENT_RECEIVER_H -#define STORAGE_FILE_SYS_EVENT_RECEIVER_H -#include -#include +#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H +#define FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H -#include "common_event_manager.h" -#include "common_event_subscribe_info.h" -#include "common_event_subscriber.h" -#include "common_event_support.h" -#include "ext_storage_status.h" -#include "matching_skills.h" +#include "extension_base.h" namespace OHOS { -namespace FileManagerService { -/** - * @class ExtStorageSubscriber - * Receive system common event. - */ -class ExtStorageSubscriber : public EventFwk::CommonEventSubscriber { +namespace NativeRdb { +class AbsSharedResultSet; +class DataAbilityPredicates; +class ValuesBucket; +} +namespace AAFwk { +class IDataAbilityObserver; +} +namespace AppExecFwk { +class DataAbilityOperation; +class DataAbilityResult; +} +namespace AbilityRuntime { +//class DataShareExtAbilityContext; +class Runtime; +//class FileExtAbility : public ExtensionBase { +class FileExtAbility : public ExtensionBase<> { public: - ExtStorageSubscriber() = default; - explicit ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); - static bool Subscriber(void); - virtual ~ExtStorageSubscriber() = default; - /** - * @brief System common event receiver. - * @param eventData Common event data. - */ - virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; + FileExtAbility() = default; + virtual ~FileExtAbility() = default; + + virtual void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; - bool CheckMountPoint(const std::string &path); + static FileExtAbility* Create(const std::unique_ptr& runtime); - std::unordered_map mountStatus; + + virtual int OpenFile(const Uri &uri, const std::string &mode); }; -} // namespace FileManagerService +} // namespace AbilityRuntime } // namespace OHOS - -#endif // STORAGE_FILE_SYS_EVENT_RECEIVER_H \ No newline at end of file +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H \ No newline at end of file diff --git a/services/include/file_manager_service_errno.h b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h similarity index 42% rename from services/include/file_manager_service_errno.h rename to frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h index dcc22b5f..81cd27ac 100644 --- a/services/include/file_manager_service_errno.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h @@ -1,28 +1,36 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERVICES_INCLUDE_ERRNO_H -#define STORAGE_SERVICES_INCLUDE_ERRNO_H -namespace OHOS { -namespace FileManagerService { -constexpr int32_t SUCCESS = 0; -constexpr int32_t FAIL = -1; // internal Error -constexpr int32_t E_NOEXIST = -2; // file not exist -constexpr int32_t E_EMPTYFOLDER = -3; // folder empty -constexpr int32_t E_INVALID_OPERCODE = -4; // not valid oper code -constexpr int32_t E_CREATE_FAIL = -5; // create file fail -constexpr int32_t E_INVALID_FILE_NUMBER = -6; // file count or offset invalid -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_INCLUDE_ERRNO_H +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#ifndef FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H +#define FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H + +#include "extension_module_loader.h" + +namespace OHOS::AbilityRuntime { +class FileExtAbilityModuleLoader : public ExtensionModuleLoader, + public Singleton { + DECLARE_SINGLETON(FileExtAbilityModuleLoader); + +public: + /** + * @brief Create Extension. + * + * @param runtime The runtime. + * @return The Extension instance. + */ + virtual Extension *Create(const std::unique_ptr& runtime) const override; +}; +} +#endif // FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H \ No newline at end of file diff --git a/services/src/client/file_manager_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_connection.h similarity index 32% rename from services/src/client/file_manager_proxy.h rename to frameworks/innerkits/file_extension/include/file_ext_connection.h index 494648ed..292a9130 100644 --- a/services/src/client/file_manager_proxy.h +++ b/frameworks/innerkits/file_extension/include/file_ext_connection.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,30 +12,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_PROXY_H -#define STORAGE_FILE_MANAGER_PROXY_H -#include "file_manager_service_stub.h" -#include "ifms_client.h" -#include "iremote_proxy.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" +#ifndef FOUNDATION_APPEXECFWK_OHOS_FILEEXT_CONNECTION_H +#define FOUNDATION_APPEXECFWK_OHOS_FILEEXT_CONNECTION_H + +#include + +#include "ability_connect_callback_stub.h" +#include "event_handler.h" +#include "ifile_ext_base.h" +#include "want.h" namespace OHOS { -namespace FileManagerService { -class FileManagerProxy : public IRemoteProxy, public IFmsClient { +namespace AppExecFwk { +class FileExtConnection : public AAFwk::AbilityConnectionStub { public: - explicit FileManagerProxy(const sptr &impl); - virtual ~FileManagerProxy() = default; - int Mkdir(const std::string &name, const std::string &path) override; - int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) override; - int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override; - int GetRoot(const CmdOptions &option, std::vector> &fileRes) override; + FileExtConnection() = default; + virtual ~FileExtConnection() = default; + + + static sptr GetInstance(); + + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + + + void ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token); + + + void DisconnectFileExtAbility(); + + + bool IsExtAbilityConnected(); + + + sptr GetFileExtProxy(); + private: - static inline BrokerDelegator delegator_; + static sptr instance_; + static std::mutex mutex_; + std::atomic isConnected_ = {false}; + sptr fileExtProxy_; }; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_PROXY_H \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_OHOS_DATASHARE_CONNECTION_H diff --git a/services/src/fileoper/file_oper.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h similarity index 50% rename from services/src/fileoper/file_oper.h rename to frameworks/innerkits/file_extension/include/file_ext_proxy.h index 57839af3..07dbc99b 100644 --- a/services/src/fileoper/file_oper.h +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,23 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_FILE_OPER_H -#define STORAGE_SERVICES_FILE_OPER_H -#include -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" +#ifndef OHOS_APPEXECFWK_FILEEXT_PROXY_H +#define OHOS_APPEXECFWK_FILEEXT_PROXY_H + +#include +#include "ifile_ext_base.h" namespace OHOS { -namespace FileManagerService { -class FileOper { +namespace AppExecFwk { +class FileExtProxy : public IRemoteProxy { public: - FileOper() = default; - virtual ~FileOper() = default; - virtual int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const = 0; + explicit FileExtProxy(const sptr& remote) : IRemoteProxy(remote) {} + + virtual ~FileExtProxy() {} + + virtual int OpenFile(const Uri &uri, const std::string &mode) override; +private: + static inline BrokerDelegator delegator_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_SERVICES_FILE_OPER_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_DATASHARE_PROXY_H + diff --git a/services/src/server/file_manager_service.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h similarity index 45% rename from services/src/server/file_manager_service.h rename to frameworks/innerkits/file_extension/include/file_ext_stub.h index 3410c409..b8fe2e16 100644 --- a/services/src/server/file_manager_service.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,25 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_SERVICE_H -#define STORAGE_FILE_MANAGER_SERVICE_H -#include "file_manager_service_stub.h" -#include "iremote_stub.h" -#include "system_ability.h" +#ifndef OHOS_APPEXECFWK_FILEEXT_STUB_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_H + +#include +#include + +#include "ifile_ext_base.h" namespace OHOS { -namespace FileManagerService { -class FileManagerService : public SystemAbility, public FileManagerServiceStub { - DECLARE_SYSTEM_ABILITY(FileManagerService); +namespace AppExecFwk { +class FileExtStub : public IRemoteStub { public: - DISALLOW_COPY_AND_MOVE(FileManagerService); - explicit FileManagerService(int32_t systemAbilityId, bool runOnCreate = true); - virtual ~FileManagerService() = default; - void OnDump() override; - void OnStart() override; - void OnStop() override; + FileExtStub(); + ~FileExtStub(); + int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; +private: + ErrCode CmdOpenFile(MessageParcel &data, MessageParcel &reply); + using RequestFuncType = int (FileExtStub::*)(MessageParcel &data, MessageParcel &reply); + std::map stubFuncMap_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_H + diff --git a/services/src/fileoper/external_storage_utils.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h similarity index 39% rename from services/src/fileoper/external_storage_utils.h rename to frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index a975ba17..e5320017 100644 --- a/services/src/fileoper/external_storage_utils.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,29 +12,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H -#define STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H -#include -#include -#include +#ifndef OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H -#include "cmd_options.h" -#include "file_info.h" -#include "file_oper.h" +#include +#include "file_ext_stub.h" +//#include "datashare_uv_queue.h" +#include "js_file_ext_ability.h" +#include "native_engine/native_value.h" namespace OHOS { -namespace FileManagerService { -class ExternalStorageUtils { +namespace AppExecFwk { +using AbilityRuntime::JsFileExtAbility; +class FileExtStubImpl : public FileExtStub { public: - ExternalStorageUtils(); - ~ExternalStorageUtils(); - static int DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList); - static int DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); + explicit FileExtStubImpl(const std::shared_ptr& extension, napi_env env) + : extension_(extension) + { + //uvQueue_ = std::make_shared(env); + } + + virtual ~FileExtStubImpl() {} + + int OpenFile(const Uri &uri, const std::string &mode) override; +private: + std::shared_ptr GetOwner(); + +private: + std::shared_ptr extension_; + //std::shared_ptr uvQueue_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H + diff --git a/services/src/server/file_manager_service_stub.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h similarity index 39% rename from services/src/server/file_manager_service_stub.h rename to frameworks/innerkits/file_extension/include/ifile_ext_base.h index e00697a9..eaaf4974 100644 --- a/services/src/server/file_manager_service_stub.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,30 +12,42 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_SERVICE_STUB_H -#define STORAGE_FILE_MANAGER_SERVICE_STUB_H -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "oper_factory.h" +#ifndef OHOS_APPEXECFWK_I_FILEEXTBASE_H +#define OHOS_APPEXECFWK_I_FILEEXTBASE_H + +#include +#include +#include "uri.h" namespace OHOS { -namespace FileManagerService { -class IFileManagerService : public IRemoteBroker { +namespace AppExecFwk { +class IFileExtBase : public IRemoteBroker { public: - DECLARE_INTERFACE_DESCRIPTOR(u"IFileManagerService"); -}; + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IFileExtBase"); -class FileManagerServiceStub : public IRemoteStub { -public: - FileManagerServiceStub() = default; - virtual ~FileManagerServiceStub() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; + enum { + CMD_GET_FILE_TYPES = 1, + CMD_OPEN_FILE = 2, + CMD_OPEN_RAW_FILE = 3, + CMD_INSERT = 4, + CMD_UPDATE = 5, + CMD_DELETE = 6, + CMD_QUERY = 7, + CMD_GET_TYPE = 8, + CMD_BATCH_INSERT = 9, + CMD_REGISTER_OBSERVER = 10, + CMD_UNREGISTER_OBSERVER = 11, + CMD_NOTIFY_CHANGE = 12, + CMD_NORMALIZE_URI = 13, + CMD_DENORMALIZE_URI = 14, + CMD_EXECUTE_BATCH = 15, + }; + + + virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_STUB_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_I_FILEEXTBASE_H + diff --git a/services/src/fileoper/media_file_oper.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h similarity index 30% rename from services/src/fileoper/media_file_oper.h rename to frameworks/innerkits/file_extension/include/js_file_ext_ability.h index bc4374b2..02e4403a 100644 --- a/services/src/fileoper/media_file_oper.h +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,24 +12,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_MEDIA_FILE_OPER_H -#define STORAGE_SERVICES_MEDIA_FILE_OPER_H -#include -#include "file_oper.h" +#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_JS_FILE_EXT_ABILITY_H +#define FOUNDATION_ABILITYRUNTIME_OHOS_JS_FILE_EXT_ABILITY_H + +#include "file_ext_ability.h" + +#include "abs_shared_result_set.h" +#include "data_ability_predicates.h" +#include "js_runtime.h" +#include "native_engine/native_reference.h" +#include "native_engine/native_value.h" +#include "values_bucket.h" + namespace OHOS { -namespace FileManagerService { -class MediaFileOper : public FileOper { +namespace AbilityRuntime { + +class JsFileExtAbility : public FileExtAbility { public: - MediaFileOper() = default; - virtual ~MediaFileOper() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; + JsFileExtAbility(JsRuntime& jsRuntime); + virtual ~JsFileExtAbility() override; + + static JsFileExtAbility* Create(const std::unique_ptr& runtime); + + void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + + void OnStart(const AAFwk::Want &want) override; + + sptr OnConnect(const AAFwk::Want &want) override; + + int OpenFile(const Uri &uri, const std::string &mode) override; + private: - int CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const; - int ListFile(const std::string &type, const std::string &path, int offset, int count, MessageParcel &data) const; - int GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const; - int Mkdir(const std::string &name, const std::string &path) const; + NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0); + void GetSrcPath(std::string &srcPath); + + JsRuntime& jsRuntime_; + std::unique_ptr jsObj_; }; -} // namespace FileManagerService +} // namespace AbilityRuntime } // namespace OHOS -#endif // STORAGE_SERVICES_MEDIA_FILE_OPER_H \ No newline at end of file +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_DATASHARE_EXT_ABILITY_H \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp new file mode 100644 index 00000000..0be3aae8 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_access_helper.h" + +#include "ability_scheduler_interface.h" +#include "ability_thread.h" +#include "abs_shared_result_set.h" +#include "data_ability_observer_interface.h" +#include "data_ability_operation.h" +#include "data_ability_predicates.h" +#include "data_ability_result.h" +#include "hilog_wrapper.h" +#include "ifile_ext_base.h" +#include "values_bucket.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +//const std::string SCHEME_DATASHARE = "datashare"; +constexpr int INVALID_VALUE = -1; +} // namespace + +std::mutex FileAccessHelper::oplock_; +FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, + const AAFwk::Want &want) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + token_ = context->GetToken(); + want_ = want; + uri_ = nullptr; + fileExtProxy_ = nullptr; + fileExtConnection_ = FileExtConnection::GetInstance(); + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, + const std::shared_ptr &uri, const sptr &fileExtProxy) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + //token_ = context->GetToken(); + context_ = std::shared_ptr(context); + want_ = want; + uri_ = uri; + fileExtProxy_ = fileExtProxy; + fileExtConnection_ = FileExtConnection::GetInstance(); + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, + const AAFwk::Want &want, const std::shared_ptr &uri, const sptr &fileExtProxy) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + token_ = context->GetToken(); + want_ = want; + uri_ = uri; + fileExtProxy_ = fileExtProxy; + fileExtConnection_ = FileExtConnection::GetInstance(); + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +void FileAccessHelper::AddFileAccessDeathRecipient(const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (token != nullptr && callerDeathRecipient_ != nullptr) { + HILOG_INFO("tag dsa token RemoveDeathRecipient."); + token->RemoveDeathRecipient(callerDeathRecipient_); + } + if (callerDeathRecipient_ == nullptr) { + callerDeathRecipient_ = + new FileAccessDeathRecipient(std::bind(&FileAccessHelper::OnSchedulerDied, this, std::placeholders::_1)); + } + if (token != nullptr) { + HILOG_INFO("tag dsa token AddDeathRecipient."); + token->AddDeathRecipient(callerDeathRecipient_); + } + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +void FileAccessHelper::OnSchedulerDied(const wptr &remote) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + auto object = remote.promote(); + object = nullptr; + fileExtProxy_ = nullptr; + uri_ = nullptr; + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +std::shared_ptr FileAccessHelper::Creator( + const std::shared_ptr &context, const AAFwk::Want &want) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (context == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator (context) failed, context == nullptr"); + return nullptr; + } + + HILOG_INFO("tag dsa FileAccessHelper::Creator before ConnectFileExtAbility."); + sptr fileExtConnection = FileExtConnection::GetInstance(); + if (!fileExtConnection->IsExtAbilityConnected()) { + fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); + } + HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); + + FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want); + if (ptrDataShareHelper == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator (context) failed, create FileAccessHelper failed"); + return nullptr; + } + + HILOG_INFO("tag dsa %{public}s called end", __func__); + return std::shared_ptr(ptrDataShareHelper); +} + +std::shared_ptr FileAccessHelper::Creator( + const std::shared_ptr &context, const AAFwk::Want &want, const std::shared_ptr &uri) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (context == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, context == nullptr"); + return nullptr; + } + + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, uri == nullptr"); + return nullptr; + } +/* + if (uri->GetScheme() != SCHEME_DATASHARE) { + HILOG_ERROR("FileAccessHelper::Creator failed, the Scheme is not datashare, Scheme: %{public}s", + uri->GetScheme().c_str()); + return nullptr; + } +*/ + HILOG_INFO("tag dsa FileAccessHelper::Creator before ConnectFileExtAbility."); + sptr fileExtProxy = nullptr; + + sptr fileExtConnection = FileExtConnection::GetInstance(); + if (!fileExtConnection->IsExtAbilityConnected()) { + //fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); + } + fileExtProxy = fileExtConnection->GetFileExtProxy(); + if (fileExtProxy == nullptr) { + HILOG_WARN("tag dsa FileAccessHelper::Creator get invalid fileExtProxy"); + } + HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); + + FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, uri, fileExtProxy); + if (ptrDataShareHelper == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, create FileAccessHelper failed"); + return nullptr; + } + + HILOG_INFO("tag dsa %{public}s called end", __func__); + return std::shared_ptr(ptrDataShareHelper); +} + +std::shared_ptr FileAccessHelper::Creator( + const std::shared_ptr &context, const AAFwk::Want &want, + const std::shared_ptr &uri) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (context == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, context == nullptr"); + return nullptr; + } + + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, uri == nullptr"); + return nullptr; + } +/* + if (uri->GetScheme() != SCHEME_DATASHARE) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, the Scheme is not datashare, Scheme: %{public}s", + uri->GetScheme().c_str()); + return nullptr; + } +*/ + HILOG_INFO("FileAccessHelper::Creator before ConnectFileExtAbility."); + sptr fileExtProxy = nullptr; + + sptr fileExtConnection = FileExtConnection::GetInstance(); + if (!fileExtConnection->IsExtAbilityConnected()) { + fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); + } + fileExtProxy = fileExtConnection->GetFileExtProxy(); + if (fileExtProxy == nullptr) { + HILOG_WARN("tag dsa FileAccessHelper::Creator get invalid fileExtProxy"); + } + HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); + + FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, uri, fileExtProxy); + if (ptrDataShareHelper == nullptr) { + HILOG_ERROR("FileAccessHelper::Creator failed, create FileAccessHelper failed"); + return nullptr; + } + + HILOG_INFO("tag dsa %{public}s called end", __func__); + return std::shared_ptr(ptrDataShareHelper); +} + +bool FileAccessHelper::Release() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (uri_ == nullptr) { + HILOG_ERROR("FileAccessHelper::Release failed, uri_ is nullptr"); + return false; + } + + HILOG_INFO("tag dsa FileAccessHelper::Release before DisconnectFileExtAbility."); + if (fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->DisconnectFileExtAbility(); + } + HILOG_INFO("tag dsa FileAccessHelper::Release after DisconnectFileExtAbility."); + fileExtProxy_ = nullptr; + uri_.reset(); + HILOG_INFO("tag dsa %{public}s called end", __func__); + return true; +} + +int FileAccessHelper::OpenFile(Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = INVALID_VALUE; + if (!CheckUriParam(uri)) { + HILOG_ERROR("tag dsa %{public}s called. CheckUriParam uri failed", __func__); + return fd; + } + + if (uri_ == nullptr) { + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::OpenFile after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + } else { + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return fd; + } + + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + fd = fileExtProxy_->OpenFile(uri, mode); + HILOG_INFO("tag dsa FileAccessHelper::OpenFile after fileExtProxy_->OpenFile."); + if (uri_ == nullptr) { + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before DisconnectFileExtAbility."); + if (fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->DisconnectFileExtAbility(); + } + HILOG_INFO("tag dsa FileAccessHelper::OpenFile after DisconnectFileExtAbility."); + fileExtProxy_ = nullptr; + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return fd; +} + +bool FileAccessHelper::CheckUriParam(const Uri &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + Uri checkUri(uri.ToString()); + if (!CheckOhosUri(checkUri)) { + HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. CheckOhosUri uri failed"); + return false; + } + + if (uri_ != nullptr) { + if (!CheckOhosUri(*uri_)) { + HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. CheckOhosUri uri_ failed"); + return false; + } + + std::vector checkSegments; + checkUri.GetPathSegments(checkSegments); + + std::vector segments; + uri_->GetPathSegments(segments); + + // if (checkSegments[0] != segments[0]) { + // HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. the datashare in uri doesn't equal the one in uri_."); + // return false; + // } + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return true; +} + +bool FileAccessHelper::CheckOhosUri(const Uri &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + + return true; + + Uri checkUri(uri.ToString()); +/* + if (checkUri.GetScheme() != SCHEME_DATASHARE) { + HILOG_ERROR("FileAccessHelper::CheckOhosUri failed. uri is not a datashare one."); + return false; + } +*/ + std::vector segments; + checkUri.GetPathSegments(segments); + if (segments.empty()) { + HILOG_ERROR("tag dsa FileAccessHelper::CheckOhosUri failed. There is no segments in the uri."); + return false; + } + + if (checkUri.GetPath() == "") { + HILOG_ERROR("tag dsa FileAccessHelper::CheckOhosUri failed. The path in the uri is empty."); + return false; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return true; +} + +void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (handler_) { + handler_(remote); + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +FileAccessDeathRecipient::FileAccessDeathRecipient(RemoteDiedHandler handler) : handler_(handler) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +FileAccessDeathRecipient::~FileAccessDeathRecipient() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp new file mode 100644 index 00000000..a9785710 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_ability.h" + +#include "extension_context.h" +#include "ability_loader.h" +#include "connection_manager.h" +#include "hilog_wrapper.h" +#include "js_file_ext_ability.h" +#include "runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; +FileExtAbility* FileExtAbility::Create(const std::unique_ptr& runtime) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (!runtime) { + return new FileExtAbility(); + } + HILOG_INFO("tag dsa FileExtAbility::Create runtime"); + switch (runtime->GetLanguage()) { + case Runtime::Language::JS: + HILOG_INFO("tag dsa Runtime::Language::JS --> JsFileExtAbility"); + return JsFileExtAbility::Create(runtime); + + default: + HILOG_INFO("tag dsa default --> FileExtAbility"); + return new FileExtAbility(); + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +void FileExtAbility::Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + //ExtensionBase::Init(record, application, handler, token); + ExtensionBase<>::Init(record, application, handler, token); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +int FileExtAbility::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp new file mode 100644 index 00000000..96ae5c4a --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_ability_module_loader.h" +#include "file_ext_ability.h" + +namespace OHOS::AbilityRuntime { +FileExtAbilityModuleLoader::FileExtAbilityModuleLoader() = default; +FileExtAbilityModuleLoader::~FileExtAbilityModuleLoader() = default; + +Extension *FileExtAbilityModuleLoader::Create(const std::unique_ptr& runtime) const +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return FileExtAbility::Create(runtime); +} + +extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtensionModule() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return &FileExtAbilityModuleLoader::GetInstance(); +} +} // namespace OHOS::AbilityRuntime \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_connection.cpp b/frameworks/innerkits/file_extension/src/file_ext_connection.cpp new file mode 100644 index 00000000..08893233 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_connection.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_connection.h" + +#include "ability_manager_client.h" +#include "bytrace.h" +#include "file_ext_proxy.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +sptr FileExtConnection::instance_ = nullptr; +std::mutex FileExtConnection::mutex_; + +sptr FileExtConnection::GetInstance() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (instance_ == nullptr) { + std::lock_guard lock(mutex_); + if (instance_ == nullptr) { + instance_ = sptr(new (std::nothrow) FileExtConnection()); + } + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return instance_; +} + +void FileExtConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + if (remoteObject == nullptr) { + HILOG_ERROR("tag dsa FileExtConnection::OnAbilityConnectDone failed, remote is nullptr"); + return; + } + fileExtProxy_ = iface_cast(remoteObject); + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa FileExtConnection::OnAbilityConnectDone failed, fileExtProxy_ is nullptr"); + return; + } + isConnected_.store(true); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +void FileExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + fileExtProxy_ = nullptr; + isConnected_.store(false); + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +void FileExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token); + HILOG_INFO("tag dsa %{public}s called end, ret=%{public}d", __func__, ret); +} + +void FileExtConnection::DisconnectFileExtAbility() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + fileExtProxy_ = nullptr; + isConnected_.store(false); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this); + HILOG_INFO("tag dsa %{public}s called end, ret=%{public}d", __func__, ret); +} + +bool FileExtConnection::IsExtAbilityConnected() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + return isConnected_.load(); +} + +sptr FileExtConnection::GetFileExtProxy() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + return fileExtProxy_; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp new file mode 100644 index 00000000..bbcf51ef --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_proxy.h" + +#include +#include + +#include "abs_shared_result_set.h" +#include "data_ability_observer_interface.h" +#include "data_ability_operation.h" +#include "data_ability_predicates.h" +#include "data_ability_result.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "ishared_result_set.h" +#include "pac_map.h" +#include "values_bucket.h" + +namespace OHOS { +namespace AppExecFwk { +int FileExtProxy::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return fd; + } + + if (!data.WriteParcelable(&uri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable uri"); + return fd; + } + + if (!data.WriteString(mode)) { + HILOG_ERROR("tag dsa fail to WriteString mode"); + return fd; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_OPEN_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return fd; + } + + // fd = reply.ReadFileDescriptor(); + fd = reply.ReadInt32(); + if (fd == -1) { + HILOG_ERROR("tag dsa fail to ReadFileDescriptor fd"); + return fd; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return fd=%{public}d", __func__, fd); + return fd; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp new file mode 100644 index 00000000..138c8bd5 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_stub.h" + +#include "data_ability_observer_interface.h" +#include "data_ability_operation.h" +#include "data_ability_predicates.h" +#include "data_ability_result.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "ishared_result_set.h" +#include "values_bucket.h" + +namespace OHOS { +namespace AppExecFwk { +FileExtStub::FileExtStub() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + stubFuncMap_[CMD_OPEN_FILE] = &FileExtStub::CmdOpenFile; +} + +FileExtStub::~FileExtStub() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + stubFuncMap_.clear(); +} + +int FileExtStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) +{ + HILOG_INFO("tag dsa %{public}s Received stub message: %{public}d", __func__, code); + std::u16string descriptor = FileExtStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("tag dsa local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + const auto &itFunc = stubFuncMap_.find(code); + if (itFunc != stubFuncMap_.end()) { + return (this->*(itFunc->second))(data, reply); + } + + HILOG_INFO("tag dsa %{public}s remote request unhandled: %{public}d", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string mode = data.ReadString(); + if (mode.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + int fd = OpenFile(*uri, mode); + if (fd < 0) { + HILOG_ERROR("tag dsa OpenFile fail, fd is %{pubilc}d", fd); + return ERR_INVALID_VALUE; + } + + // if (!reply.WriteFileDescriptor(fd)) { + if (!reply.WriteInt32(fd)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/interfaces/kits/js/src/file_manager_napi_def.h b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp similarity index 34% rename from interfaces/kits/js/src/file_manager_napi_def.h rename to frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp index 05d75348..01915b80 100644 --- a/interfaces/kits/js/src/file_manager_napi_def.h +++ b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,43 +12,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_NAPI_DEF_H -#define STORAGE_FILE_MANAGER_NAPI_DEF_H -#include "n_async_work_callback.h" -#include "n_async_work_promise.h" -#include "n_func_arg.h" -#include "uni_error.h" -namespace OHOS { -namespace FileManagerService { -enum CreateFileArgs { - CF_PATH = 0, - CF_FILENAME = 1, - CF_OPTION = 2, - CF_CALLBACK_WITHOUT_OP = 2, - CF_CALLBACK_WITH_OP = 3, -}; +#include "file_ext_stub_impl.h" + +#include "hilog_wrapper.h" -enum GetRootArgs { - GR_OPTION = 0, - GR_CALLBACK_WITHOUT_OP = 0, - GR_CALLBACK_WITH_OP = 1, -}; +namespace OHOS { +namespace AppExecFwk { +std::shared_ptr FileExtStubImpl::GetOwner() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return extension_; +} -enum ListFileArgs { - LF_PATH = 0, - LF_TYPE = 1, - LF_OPTION = 2, - LF_CALLBACK_WITHOUT_OP = 2, - LF_CALLBACK_WITH_OP = 3, -}; +int FileExtStubImpl::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + /* + std::function syncTaskFunc = [=, &ret, client = sptr(this)]() { + auto extension = client->GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return; + } + ret = extension->OpenFile(uri, mode); + }; + uvQueue_->SyncCall(syncTaskFunc); + */ + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->OpenFile(uri, mode); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} -constexpr int CREATE_FILE_PARA_MAX = 4; -constexpr int CREATE_FILE_PARA_MIN = 2; -constexpr int GET_ROOT_PARA_MAX = 2; -constexpr int GET_ROOT_PARA_MIN = 0; -constexpr int LIST_FILE_PARA_MAX = 4; -constexpr int LIST_FILE_PARA_MIN = 2; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_FILE_MANAGER_NAPI_DEF_H diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp new file mode 100644 index 00000000..2ed3b3d2 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "js_file_ext_ability.h" + +#include "extension_context.h" +#include "ability_info.h" +#include "accesstoken_kit.h" +#include "bytrace.h" +#include "dataobs_mgr_client.h" +#include "file_ext_stub_impl.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_common_util.h" +#include "napi_common_want.h" +#include "napi_remote_object.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr size_t ARGC_ONE = 1; +constexpr size_t ARGC_TWO = 2; +} + +using namespace OHOS::AppExecFwk; +using OHOS::Security::AccessToken::AccessTokenKit; +using DataObsMgrClient = OHOS::AAFwk::DataObsMgrClient; + +JsFileExtAbility* JsFileExtAbility::Create(const std::unique_ptr& runtime) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return new JsFileExtAbility(static_cast(*runtime)); +} + +JsFileExtAbility::JsFileExtAbility(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {} +JsFileExtAbility::~JsFileExtAbility() = default; + +void JsFileExtAbility::Init(const std::shared_ptr &record, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + FileExtAbility::Init(record, application, handler, token); + std::string srcPath = ""; + GetSrcPath(srcPath); + if (srcPath.empty()) { + HILOG_ERROR("tag dsa Failed to get srcPath"); + return; + } + + std::string moduleName(Extension::abilityInfo_->moduleName); + moduleName.append("::").append(abilityInfo_->name); + HILOG_INFO("tag dsa %{public}s module:%{public}s, srcPath:%{public}s.", __func__, moduleName.c_str(), srcPath.c_str()); + HandleScope handleScope(jsRuntime_); + //auto& engine = jsRuntime_.GetNativeEngine(); + + jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath); + if (jsObj_ == nullptr) { + HILOG_ERROR("tag dsa Failed to get jsObj_"); + return; + } + HILOG_INFO("tag dsa JsFileExtAbility::Init ConvertNativeValueTo."); + NativeObject* obj = ConvertNativeValueTo(jsObj_->Get()); + if (obj == nullptr) { + HILOG_ERROR("tag dsa Failed to get JsFileExtAbility object"); + return; + } + + /* + auto context = GetContext(); + if (context == nullptr) { + HILOG_ERROR("tag dsa Failed to get context"); + return; + } + + HILOG_INFO("tag dsa JsFileExtAbility::Init CreateJsDataShareExtAbilityContext."); + NativeValue* contextObj = CreateJsDataShareExtAbilityContext(engine, context); + auto contextRef = jsRuntime_.LoadSystemModule("application.DataShareExtensionAbilityContext", + &contextObj, ARGC_ONE); + contextObj = contextRef->Get(); + HILOG_INFO("tag dsa JsFileExtAbility::Init Bind."); + context->Bind(jsRuntime_, contextRef.release()); + HILOG_INFO("tag dsa JsFileExtAbility::SetProperty."); + obj->SetProperty("context", contextObj); + + auto nativeObj = ConvertNativeValueTo(contextObj); + if (nativeObj == nullptr) { + HILOG_ERROR("tag dsa Failed to get datashare extension ability native object"); + return; + } + + HILOG_INFO("tag dsa Set datashare extension ability context"); + + nativeObj->SetNativePointer(new std::weak_ptr(context), + [](NativeEngine*, void* data, void*) { + HILOG_INFO("tag dsa Finalizer for weak_ptr datashare extension ability context is called"); + delete static_cast*>(data); + }, nullptr); + */ + HILOG_INFO("tag dsa JsFileExtAbility::Init end."); +} + +void JsFileExtAbility::OnStart(const AAFwk::Want &want) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + Extension::OnStart(want); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); + NativeValue* nativeWant = reinterpret_cast(napiWant); + NativeValue* argv[] = {nativeWant}; + CallObjectMethod("onCreate", argv, ARGC_ONE); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +sptr JsFileExtAbility::OnConnect(const AAFwk::Want &want) +{ + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + Extension::OnConnect(want); + sptr remoteObject = new (std::nothrow) FileExtStubImpl( + std::static_pointer_cast(shared_from_this()), + reinterpret_cast(&jsRuntime_.GetNativeEngine())); + if (remoteObject == nullptr) { + HILOG_ERROR("tag dsa %{public}s No memory allocated for FileExtStubImpl", __func__); + return nullptr; + } + HILOG_INFO("tag dsa %{public}s end. ", __func__); + return remoteObject->AsObject(); +} + +NativeValue* JsFileExtAbility::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc) +{ + HILOG_INFO("tag dsa JsFileExtAbility::CallObjectMethod(%{public}s), begin", name); + + if (!jsObj_) { + HILOG_WARN("Not found FileExtAbility.js"); + return nullptr; + } + + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + + NativeValue* value = jsObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("tag dsa Failed to get FileExtAbility object"); + return nullptr; + } + + NativeValue* method = obj->GetProperty(name); + if (method == nullptr) { + HILOG_ERROR("tag dsa Failed to get '%{public}s' from FileExtAbility object", name); + return nullptr; + } + HILOG_INFO("tag dsa JsFileExtAbility::CallFunction(%{public}s), success", name); + return handleScope.Escape(nativeEngine.CallFunction(value, method, argv, argc)); +} + +void JsFileExtAbility::GetSrcPath(std::string &srcPath) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (!Extension::abilityInfo_->isStageBasedModel) { + /* temporary compatibility api8 + config.json */ + srcPath.append(Extension::abilityInfo_->package); + srcPath.append("/assets/js/"); + if (!Extension::abilityInfo_->srcPath.empty()) { + srcPath.append(Extension::abilityInfo_->srcPath); + } + srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc"); + return; + } + + if (!Extension::abilityInfo_->srcEntrance.empty()) { + srcPath.append(Extension::abilityInfo_->moduleName + "/"); + srcPath.append(Extension::abilityInfo_->srcEntrance); + srcPath.erase(srcPath.rfind('.')); + srcPath.append(".abc"); + } +} + +int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + auto ret = FileExtAbility::OpenFile(uri, mode); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiUri = nullptr; + napi_create_string_utf8(env, uri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiUri); + napi_value napiMode = nullptr; + napi_create_string_utf8(env, mode.c_str(), NAPI_AUTO_LENGTH, &napiMode); + + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* nativeMode = reinterpret_cast(napiMode); + NativeValue* argv[] = {nativeUri, nativeMode}; + NativeValue* nativeResult = CallObjectMethod("openFile", argv, ARGC_TWO); + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call openFile with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/.gitignore b/frameworks/innerkits/file_extension_hap/.gitignore new file mode 100644 index 00000000..39187ebe --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/local.properties +/.idea +**/build \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/AppScope/app.json b/frameworks/innerkits/file_extension_hap/AppScope/app.json new file mode 100644 index 00000000..f86c4521 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/AppScope/app.json @@ -0,0 +1,13 @@ +{ + "app": { + "bundleName": "com.ohos.FileExtension.FileExtensionData", + "vendor": "FileExtension", + "versionCode": 1000000, + "versionName": "1.0.0", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json new file mode 100644 index 00000000..7863972b --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FileExtension" + } + ] +} diff --git a/frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?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!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 00000000..7a0024d4 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,58 @@ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('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 + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 00000000..1236e0ce --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,13 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + it('assertContain',0, function () { + console.info("it begin") + let a = 'abc' + let b = 'b' + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 00000000..d766fe24 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 new file mode 100644 index 00000000..5d696c10 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 00000000..84078007 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "i am an entry for tv" + }, + { + "name": "TestAbility_desc", + "value": "the tv entry test ability" + }, + { + "name": "TestAbility_label", + "value": "tvBase" + } + ] +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb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512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "ini": { + "version": "1.3.8", + "resolved": "https://repo.huaweicloud.com/repository/npm/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" + }, + "interpret": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, + "invert-kv": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" + }, + "is-absolute": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-absolute/-/is-absolute-1.0.0.tgz", + "integrity": "sha512-dOWoqflvcydARa360Gvv18DZ/gRuHKi2NU/wU5X1ZFzdYfH29nkiNZsF3mp4OJ3H4yo9Mx8A/uAGNzpzPN3yBA==", + "requires": { + "is-relative": "^1.0.0", + "is-windows": "^1.0.1" + } + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + }, + "is-core-module": { + "version": "2.9.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-core-module/-/is-core-module-2.9.0.tgz", + "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", + "requires": { + "has": "^1.0.3" + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "is-glob": { + "version": "4.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "4.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==" + }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, + "is-relative": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-relative/-/is-relative-1.0.0.tgz", + "integrity": "sha512-Kw/ReK0iqwKeu0MITLFuj0jbPAmEiOsIwyIXvvbfa6QfmN9pkD1M+8pdk7Rl/dTKbH34/XBFMbgD4iMJhLQbGA==", + "requires": { + "is-unc-path": "^1.0.0" + } + }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" + }, + "is-unc-path": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-unc-path/-/is-unc-path-1.0.0.tgz", + "integrity": "sha512-mrGpVd0fs7WWLfVsStvgF6iEJnbjDFZh9/emhRDcGWTduTfNHd9CHeUwH3gYIjdbwo4On6hunkztwOaAw0yllQ==", + "requires": { + "unc-path-regex": "^0.1.2" + } + }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=" + }, + "is-windows": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-windows/-/is-windows-1.0.2.tgz", + "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=" + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "json5": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/json5/-/json5-2.2.0.tgz", + "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "requires": { + "minimist": "^1.2.5" + } + }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "kind-of": { + "version": "6.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" + }, + "last-run": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/last-run/-/last-run-1.1.1.tgz", + "integrity": "sha1-RblpQsF7HHnHchmCWbqUO+v4yls=", + "requires": { + "default-resolution": "^2.0.0", + "es6-weak-map": "^2.0.1" + } + }, + "lazystream": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/lazystream/-/lazystream-1.0.1.tgz", + "integrity": "sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==", + "requires": { + "readable-stream": "^2.0.5" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, + "lcid": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", + "requires": { + "invert-kv": "^1.0.0" + } + }, + "liftoff": { + "version": "4.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/liftoff/-/liftoff-4.0.0.tgz", + "integrity": "sha512-rMGwYF8q7g2XhG2ulBmmJgWv25qBsqRbDn5gH0+wnuyeFt7QBJlHJmtg5qEdn4pN6WVAUMgXnIxytMFRX9c1aA==", + "requires": { + "extend": "^3.0.2", + "findup-sync": "^5.0.0", + "fined": "^2.0.0", + "flagged-respawn": "^2.0.0", + "is-plain-object": "^5.0.0", + "object.map": "^1.0.1", + "rechoir": "^0.8.0", + "resolve": "^1.20.0" + } + }, + "load-json-file": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "strip-bom": "^2.0.0" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lodash.defaults": { + "version": "4.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.defaults/-/lodash.defaults-4.2.0.tgz", + "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" + }, + "lodash.difference": { + "version": "4.5.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.difference/-/lodash.difference-4.5.0.tgz", + "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=" + }, + "lodash.flatten": { + "version": "4.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.union": { + "version": "4.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.union/-/lodash.union-4.6.0.tgz", + "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=" + }, + "log4js": { + "version": "6.4.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/log4js/-/log4js-6.4.1.tgz", + "integrity": "sha512-iUiYnXqAmNKiIZ1XSAitQ4TmNs8CdZYTAWINARF3LjnsLN8tY5m0vRwd6uuWj/yNY0YHxeZodnbmxKFUOM2rMg==", + "requires": { + "date-format": "^4.0.3", + "debug": "^4.3.3", + "flatted": "^3.2.4", + "rfdc": "^1.3.0", + "streamroller": "^3.0.2" + } + }, + "make-iterator": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/make-iterator/-/make-iterator-1.0.1.tgz", + "integrity": "sha512-pxiuXh0iVEq7VM7KMIhs5gxsfxCux2URptUQaXo4iZZJxBAzTPOLE2BumO5dbfVYq/hBJFBR/a1mFDmOx5AGmw==", + "requires": { + "kind-of": "^6.0.2" + } + }, + "map-cache": { + "version": "0.2.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/map-cache/-/map-cache-0.2.2.tgz", + "integrity": "sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8=" + }, + "merge-stream": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://repo.huaweicloud.com/repository/npm/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "mute-stdout": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/mute-stdout/-/mute-stdout-1.0.0.tgz", + "integrity": "sha1-WzLqB+tDyd7WEwQ0z5JvRrKn/U0=" + }, + "next-tick": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, + "now-and-later": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/now-and-later/-/now-and-later-2.0.1.tgz", + "integrity": "sha512-KGvQ0cB70AQfg107Xvs/Fbu+dGmZoTRJp2TaPwcwQm3/7PteUyN2BCgk8KBMPGBUXZdVwyWS8fDCGFygBm19UQ==", + "requires": { + "once": "^1.3.2" + } + }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "requires": { + "path-key": "^3.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + }, + "object.defaults": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.defaults/-/object.defaults-1.1.0.tgz", + "integrity": "sha1-On+GgzS0B96gbaFtiNXNKeQ1/s8=", + "requires": { + "array-each": "^1.0.1", + "array-slice": "^1.0.0", + "for-own": "^1.0.0", + "isobject": "^3.0.0" + } + }, + "object.map": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.map/-/object.map-1.0.1.tgz", + "integrity": "sha1-z4Plncj8wK1fQlDh94s7gb2AHTc=", + "requires": { + "for-own": "^1.0.0", + "make-iterator": "^1.0.0" + } + }, + "object.pick": { + "version": "1.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.pick/-/object.pick-1.3.0.tgz", + "integrity": "sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c=", + "requires": { + "isobject": "^3.0.1" + } + }, + "object.reduce": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.reduce/-/object.reduce-1.0.1.tgz", + "integrity": "sha1-b+NI8qx/oPlcpiEiZZkJaCW7A60=", + "requires": { + "for-own": "^1.0.0", + "make-iterator": "^1.0.0" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "onetime": { + "version": "5.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "requires": { + "mimic-fn": "^2.1.0" + } + }, + "os-locale": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", + "requires": { + "lcid": "^1.0.0" + } + }, + "parse-filepath": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-filepath/-/parse-filepath-1.0.2.tgz", + "integrity": "sha1-pjISf1Oq89FYdvWHLz/6x2PWyJE=", + "requires": { + "is-absolute": "^1.0.0", + "map-cache": "^0.2.0", + "path-root": "^0.1.1" + } + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "requires": { + "error-ex": "^1.2.0" + } + }, + "parse-passwd": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=" + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "requires": { + "pinkie-promise": "^2.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" + }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "path-root": { + "version": "0.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-root/-/path-root-0.1.1.tgz", + "integrity": "sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc=", + "requires": { + "path-root-regex": "^0.1.0" + } + }, + "path-root-regex": { + "version": "0.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-root-regex/-/path-root-regex-0.1.2.tgz", + "integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=" + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "requires": { + "graceful-fs": "^4.1.2", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" + }, + "pify": { + "version": "2.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "requires": { + "pinkie": "^2.0.0" + } + }, + "pretty-hrtime": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz", + "integrity": "sha1-9ualItPmBwRSK/Db5oVu0g515Nw=" + }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "requires": { + "load-json-file": "^1.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^1.0.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "requires": { + "find-up": "^1.0.0", + "read-pkg": "^1.0.0" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "readdir-glob": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/readdir-glob/-/readdir-glob-1.1.1.tgz", + "integrity": "sha512-91/k1EzZwDx6HbERR+zucygRFfiPl2zkIYZtv3Jjr6Mn7SkKcVct8aVO+sSRiGMc6fLf72du3d92/uY63YPdEA==", + "requires": { + "minimatch": "^3.0.4" + } + }, + "rechoir": { + "version": "0.8.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/rechoir/-/rechoir-0.8.0.tgz", + "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==", + "requires": { + "resolve": "^1.20.0" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, + "require-main-filename": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-main-filename/-/require-main-filename-1.0.1.tgz", + "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + }, + "resolve": { + "version": "1.22.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve/-/resolve-1.22.0.tgz", + "integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==", + "requires": { + "is-core-module": "^2.8.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, + "resolve-dir": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-dir/-/resolve-dir-1.0.1.tgz", + "integrity": "sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=", + "requires": { + "expand-tilde": "^2.0.0", + "global-modules": "^1.0.0" + } + }, + "resolve-package-path": { + "version": "4.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-package-path/-/resolve-package-path-4.0.3.tgz", + "integrity": "sha512-SRpNAPW4kewOaNUt8VPqhJ0UMxawMwzJD8V7m1cJfdSTK9ieZwS6K7Dabsm4bmLFM96Z5Y/UznrpG5kt1im8yA==", + "requires": { + "path-root": "^0.1.1" + } + }, + "rfdc": { + "version": "1.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/rfdc/-/rfdc-1.3.0.tgz", + "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" + }, + "signal-exit": { + "version": "3.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, + "spdx-correct": { + "version": "3.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-correct/-/spdx-correct-3.1.1.tgz", + "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==", + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==" + }, + "spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.11", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz", + "integrity": "sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==" + }, + "stream-exhaust": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/stream-exhaust/-/stream-exhaust-1.0.2.tgz", + "integrity": "sha512-b/qaq/GlBK5xaq1yrK9/zFcyRSTNxmcZwFLGSTG0mXgZl/4Z6GgiyYOXOvY7N3eEvFRAG1bkDRz5EPGSvPYQlw==" + }, + "streamroller": { + "version": "3.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/streamroller/-/streamroller-3.0.7.tgz", + "integrity": "sha512-kh68kwiDGuIPiPDWwRbEC5us+kfARP1e9AsQiaLaSqGrctOvMn0mtL8iNY3r4/o5nIoYi3gPI1jexguZsXDlxw==", + "requires": { + "date-format": "^4.0.7", + "debug": "^4.3.4", + "fs-extra": "^10.0.1" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "requires": { + "is-utf8": "^0.2.0" + } + }, + "strip-final-newline": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" + }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" + }, + "tar-stream": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + }, + "dependencies": { + "is-number": { + "version": "7.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + } + } + }, + "type": { + "version": "1.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, + "unc-path-regex": { + "version": "0.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/unc-path-regex/-/unc-path-regex-0.1.2.tgz", + "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=" + }, + "undertaker": { + "version": "1.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker/-/undertaker-1.2.1.tgz", + "integrity": "sha512-71WxIzDkgYk9ZS+spIB8iZXchFhAdEo2YU8xYqBYJ39DIUIqziK78ftm26eecoIY49X0J2MLhG4hr18Yp6/CMA==", + "requires": { + "arr-flatten": "^1.0.1", + "arr-map": "^2.0.0", + "bach": "^1.0.0", + "collection-map": "^1.0.0", + "es6-weak-map": "^2.0.1", + "last-run": "^1.1.0", + "object.defaults": "^1.0.0", + "object.reduce": "^1.0.0", + "undertaker-registry": "^1.0.0" + } + }, + "undertaker-registry": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker-registry/-/undertaker-registry-1.0.1.tgz", + "integrity": "sha1-XkvaMI5KiirlhPm5pDWaSZglzFA=" + }, + "universalify": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, + "uri-js": { + "version": "4.4.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "requires": { + "punycode": "^2.1.0" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "v8flags": { + "version": "3.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/v8flags/-/v8flags-3.2.0.tgz", + "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", + "requires": { + "homedir-polyfill": "^1.0.1" + } + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "requires": { + "isexe": "^2.0.0" + } + }, + "which-module": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/which-module/-/which-module-1.0.0.tgz", + "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=" + }, + "wrap-ansi": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "y18n": { + "version": "3.2.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/y18n/-/y18n-3.2.2.tgz", + "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" + }, + "yargs": { + "version": "7.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/yargs/-/yargs-7.1.0.tgz", + "integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=", + "requires": { + "camelcase": "^3.0.0", + "cliui": "^3.2.0", + "decamelize": "^1.1.1", + "get-caller-file": "^1.0.1", + "os-locale": "^1.4.0", + "read-pkg-up": "^1.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^1.0.2", + "which-module": "^1.0.0", + "y18n": "^3.2.1", + "yargs-parser": "^5.0.0" + } + }, + "yargs-parser": { + "version": "5.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/yargs-parser/-/yargs-parser-5.0.1.tgz", + "integrity": "sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA==", + "requires": { + "camelcase": "^3.0.0", + "object.assign": "^4.1.0" + } + }, + "zip-stream": { + "version": "4.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/zip-stream/-/zip-stream-4.1.0.tgz", + "integrity": "sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==", + "requires": { + "archiver-utils": "^2.1.0", + "compress-commons": "^4.1.0", + "readable-stream": "^3.6.0" + } + } + } +} diff --git a/frameworks/innerkits/file_extension_hap/package.json b/frameworks/innerkits/file_extension_hap/package.json new file mode 100644 index 00000000..15be3afb --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/package.json @@ -0,0 +1,18 @@ +{ + "license":"ISC", + "devDependencies":{}, + "name":"fileextension", + "ohos":{ + "org":"huawei", + "directoryLevel":"project", + "buildTool":"hvigor" + }, + "description":"FileExtension", + "repository":{}, + "version":"1.0.0", + "dependencies":{ + "@ohos/hvigor-ohos-plugin":"1.0.6", + "hypium":"^1.0.0", + "@ohos/hvigor":"1.0.6" + } +} \ No newline at end of file diff --git a/frameworks/innerkits/signature/medialib.p7b b/frameworks/innerkits/signature/medialib.p7b new file mode 100644 index 0000000000000000000000000000000000000000..664fa352718693e853f035d6afc3b443e8211b09 GIT binary patch literal 3528 zcmcgvYj6|S6}BEW7!VlDD{cTI2qu8cU0JdvCxq-utJMmxUP!iOOw3AJJ?z!4EUmn< zD36N9;Sr#e1ZXhCybLskw7d+R2}#ocO-Nt}gvq2h3873HN}*{;LPMe5l^w7d_|eG> z`k|e3?z!iF_ulV(XD&!9-pR?G(qeA;ULolxZA&W-g0$lIQi%jofPp!=^IFUjN+y>| zKsuYc7bs~mB*K2d)B<&x zSFfj3+JNwNka;@AVF&-0()F=gViQva5{K2=rLA09J5fKv-_~h#B9ve?5)x#C>L5o zAU+I++^8W*I9w$N?QIB!d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y2Ilb-5~tyf0x-k{A+Yh2w*Azqf?ca>_`aX_?4B%;27FS$ z*YE|<=Xdz6udZx4Q@v-|&VtRomYnRfuXO*2H|CDlCTlmX8>U)&`Uoo@6>=AFtEFJ{ z`=j4vXKWvp=@_ta$*tD6fMrUv@n3PYJ+iT>Wz8+HveCA@`OKEw(-StIzy{Ax7kESp zJZkUa(Fp3`D?O1s$L@6#BS>4M?#?68d_Ic!3<`~0d;M6;2f5lEi$2*{_m?a1m;(9b zq3_-NlACAPxi#bVjvEC-KRxrd;@A61HqMDuFFZEqrO2+P%^!Z|09AXwSvjt_d~e$a zhgT0>v+3r-h1oYxts1%T?rSsmOvt-?_4vi5_f)P8UO@H`r>An{|KQkD#jVE)BMYVh zN(#bff2^DL4tL|VU)?PY)@?ghy!P^e>|ryURkpG{;&m~y>sdHeb>ruEeag;dUTRY z -#include -#include -#include - -#include "file_manager_napi_def.h" -#include "file_manager_proxy.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ifms_client.h" -#include "log.h" -namespace OHOS { -namespace FileManagerService { -using namespace std; -using namespace DistributedFS; -struct AsyncFileInfoArg { - NRef ref_; - vector> fileRes_; - explicit AsyncFileInfoArg(NVal ref) : ref_(ref), fileRes_() {}; - ~AsyncFileInfoArg() = default; -}; - -struct AsyncUriArg { - NRef ref_; - string uri_; - explicit AsyncUriArg(NVal ref) : ref_(ref), uri_() {}; - ~AsyncUriArg() = default; -}; - -tuple FileManagerNapi::GetFmsClient() -{ - if (fmsClient_ == nullptr) { - fmsClient_ = IFmsClient::GetFmsInstance(); - } - if (fmsClient_ == nullptr) { - ERR_LOG("fms get instance fails"); - return make_tuple(false, nullptr); - } else { - return make_tuple(true, fmsClient_); - } -} - -UniError DealWithErrno(int err) -{ - unordered_map errMap = { - {FAIL, ESRCH}, - {E_CREATE_FAIL, EPERM}, - {E_NOEXIST, ENOENT}, - {E_EMPTYFOLDER, ENOTDIR}, - {SUCCESS, ERRNO_NOERR}, - }; - if (errMap.count(err) == 0) { - ERR_LOG("unhandler err number %{public}d", err); - return UniError(EACCES); - } else { - return UniError(errMap[err]); - } -} - -bool GetDevInfoArg(const NVal &prop, DevInfo &dev) -{ - if (prop.HasProp("name")) { - bool ret = false; - unique_ptr name; - tie(ret, name, ignore) = prop.GetProp("name").ToUTF8String(); - if (!ret) { - return false; - } - dev.SetName(std::string(name.get())); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetCreateFileArgs(napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[CreateFileArgs::CF_PATH]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - tie(succ, fileName, ignore) = NVal(env, funcArg[CreateFileArgs::CF_FILENAME]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - - if (funcArg.GetArgc() < CreateFileArgs::CF_OPTION) { - return {false, nullptr, nullptr, option}; - } - - NVal op(env, NVal(env, funcArg[CreateFileArgs::CF_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return {true, move(path), move(fileName), option}; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return {true, move(path), move(fileName), option}; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - ERR_LOG("CreateFile func get dev para fails"); - option.SetDevInfo(dev); - return {false, nullptr, nullptr, option}; - } - - option.SetDevInfo(dev); - return {true, move(path), move(fileName), option}; -} - -napi_value FileManagerNapi::CreateFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(CREATE_FILE_PARA_MIN, CREATE_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option; - tie(succ, path, fileName, option) = GetCreateFileArgs(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "CreateFile func get args fails"); - return nullptr; - } - auto arg = make_shared(NVal(env, funcArg.GetThisVar())); - auto cbExec = [arg, path = string(path.get()), fileName = string(fileName.get()), option = option] - (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - string uri = ""; - int err = client->CreateFile(path, fileName, option, arg->uri_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal::CreateUTF8String(env, arg->uri_); - } - }; - string procedureName = "CreateFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == CREATE_FILE_PARA_MIN || (argc != CREATE_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? - CreateFileArgs::CF_CALLBACK_WITHOUT_OP : CreateFileArgs::CF_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -static bool CreateFileArray(napi_env env, shared_ptr arg) -{ - for (size_t i = 0; i < arg->fileRes_.size(); i++) { - NVal obj = NVal::CreateObject(env); - shared_ptr res = arg->fileRes_[i]; - if (res == nullptr) { - ERR_LOG("inner error, lack of memory, file count %{public}zu", arg->fileRes_.size()); - return false; - } - obj.AddProp("name", NVal::CreateUTF8String(env, res->GetName()).val_); - obj.AddProp("path", NVal::CreateUTF8String(env, res->GetPath()).val_); - obj.AddProp("type", NVal::CreateUTF8String(env, res->GetType()).val_); - obj.AddProp("size", NVal::CreateInt64(env, res->GetSize()).val_); - obj.AddProp("added_time", NVal::CreateInt64(env, res->GetAddedTime()).val_); - obj.AddProp("modified_time", NVal::CreateInt64(env, res->GetModifiedTime()).val_); - napi_set_property(env, arg->ref_.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); - } - return true; -} - -bool GetRootArgs(napi_env env, NFuncArg &funcArg, CmdOptions &option) -{ - NVal op(env, NVal(env, funcArg[GetRootArgs::GR_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return true; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return true; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - - option.SetDevInfo(dev); - return true; -} - -napi_value FileManagerNapi::GetRoot(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(GET_ROOT_PARA_MIN, GET_ROOT_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); - return nullptr; - } - - CmdOptions option("local", "", 0, MAX_NUM, false); - if (funcArg.GetArgc() != 0) { - if (!GetRootArgs(env, funcArg, option)) { - UniError(EINVAL).ThrowErr(env, "GetRoot func get dev para fails"); - return nullptr; - } - } - - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [option = option, arg] (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->GetRoot(option, arg->fileRes_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "GetRoot"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == GET_ROOT_PARA_MIN || (argc != GET_ROOT_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? GetRootArgs::GR_CALLBACK_WITHOUT_OP : GetRootArgs::GR_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -bool GetListFileOption(const NVal &argv, CmdOptions &option) -{ - bool ret = false; - if (argv.HasProp("dev")) { - NVal prop(argv.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - option.SetDevInfo(dev); - } - if (argv.HasProp("offset")) { - int64_t offset; - tie(ret, offset) = argv.GetProp("offset").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION offset para fails"); - return false; - } - option.SetOffset(offset); - } - if (argv.HasProp("count")) { - int64_t count; - tie(ret, count) = argv.GetProp("count").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION count para fails"); - return false; - } - option.setCount(count); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetListFileArg( - napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr type; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[ListFileArgs::LF_PATH]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_PATH para fails"); - return {false, nullptr, nullptr, option}; - } - tie(succ, type, ignore) = NVal(env, funcArg[ListFileArgs::LF_TYPE]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_TYPE para fails"); - return {false, nullptr, nullptr, option}; - } - - NVal op(env, NVal(env, funcArg[ListFileArgs::LF_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return {true, move(type), move(path), option}; - } - option.SetHasOpt(true); - if (!GetListFileOption(op, option)) { - return {false, nullptr, nullptr, option}; - } - return {true, move(type), move(path), option}; -} - -napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(LIST_FILE_PARA_MIN, LIST_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr type; - unique_ptr path; - CmdOptions option; - tie(succ, type, path, option) = GetListFileArg(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Get argments fails"); - return nullptr; - } - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [type = string(type.get()), path = string(path.get()), option, arg](napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->ListFile(type, path, option, arg->fileRes_); - return DealWithErrno(err); - }; - - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "ListFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == LIST_FILE_PARA_MIN || (argc != LIST_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = ((!option.GetHasOpt()) ? ListFileArgs::LF_CALLBACK_WITHOUT_OP : ListFileArgs::LF_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -napi_value FileManagerNapi::Mkdir(napi_env env, napi_callback_info info) -{ - return NVal::CreateUndefined(env).val_; -} - -bool FileManagerNapi::Export() -{ - return exports_.AddProp( { - NVal::DeclareNapiFunction("listFile", ListFile), - NVal::DeclareNapiFunction("createFile", CreateFile), - NVal::DeclareNapiFunction("getRoot", GetRoot), - }); -} - -string FileManagerNapi::GetClassName() -{ - return FileManagerNapi::className_; -} - -FileManagerNapi::FileManagerNapi(napi_env env, napi_value exports) : NExporter(env, exports) {} - -FileManagerNapi::~FileManagerNapi() {} -} // namespace FileManagerService -} // namespace OHOS diff --git a/interfaces/kits/napi/file_access_module/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn new file mode 100644 index 00000000..37fd8a82 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2022 Huawei Device 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("//build/ohos.gni") + +ohos_shared_library("fileaccess") { + subsystem_name = "filemanagement" + part_name = "user_file_service" + + relative_install_dir = "module/data" + + include_dirs = [ + "./", + "//foundation/filemanagement/user_file_service/utils", + "//foundation/filemanagement/user_file_service/frameworks/innerkits/file_extension/include", + "//third_party/node/src", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/include", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/common/include", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/dataability/include", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/include", + ] + + sources = [ + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/common/src/js_utils.cpp", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp", + "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/src/napi_result_set.cpp", + "napi_fileaccess_helper.cpp", + "native_fileaccess_module.cpp", + ] + + deps = [ + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", + "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager", + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", + "//third_party/libuv:uv", + "//foundation/filemanagement/user_file_service/frameworks/innerkits/file_extension:file_extension_ability_kit", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:napi_base_context", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + "native_appdatamgr:native_appdatafwk", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + "utils_base:utils", + ] +} \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h new file mode 100644 index 00000000..562fbf55 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -0,0 +1,45 @@ +#ifndef OHOS_APPEXECFWK_FILEACCESS_COMMON_H +#define OHOS_APPEXECFWK_FILEACCESS_COMMON_H + +#include "ability.h" +#include "file_access_helper.h" +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi_common.h" +#include "napi_common_util.h" +#include "want.h" + +using Want = OHOS::AAFwk::Want; +using Ability = OHOS::AppExecFwk::Ability; +using AbilityStartSetting = OHOS::AppExecFwk::AbilityStartSetting; + +namespace OHOS { +namespace AppExecFwk { + +struct CBBase { + CallbackInfo cbInfo; + napi_async_work asyncWork; + napi_deferred deferred; + Ability *ability = nullptr; + AbilityType abilityType = AbilityType::UNKNOWN; + int errCode = 0; +}; + +struct FileAccessHelperCB { + CBBase cbBase; + napi_ref uri = nullptr; + napi_value result = nullptr; +}; + +struct FileAccessHelperOpenFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string uri; + std::string mode; + int result = 0; + int execResult; +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp new file mode 100644 index 00000000..46c975c6 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2021-2022 Huawei Device 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. + */ + +#include "napi_fileaccess_helper.h" + +#include +#include +#include + +#include "data_ability_observer_interface.h" +#include "uri.h" + +#include "hilog_wrapper.h" +#include "message_parcel.h" +#include "napi_base_context.h" +#include "napi_data_ability_predicates.h" +#include "napi_rdb_predicates.h" +#include "napi_result_set.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AppExecFwk { +namespace { +const std::string FILEACCESS_CLASS_NAME = "FileAccessHelper"; +constexpr int NO_ERROR = 0; +constexpr int INVALID_PARAMETER = -1; + +std::string NapiValueToStringUtf8(napi_env env, napi_value value) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + std::string result = ""; + return UnwrapStringFromJS(env, value, result); +} + +/* +bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector &result) +{ + return UnwrapArrayStringFromJS(env, param, result); +} +*/ +} + +std::list> g_fileAccessHelperList; +static napi_ref g_constructorRef = nullptr; + +napi_value AcquireFileAccessHelperWrap(napi_env env, napi_callback_info info, FileAccessHelperCB *fileAccessHelperCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + if (fileAccessHelperCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s,fileAccessHelperCB == nullptr", __func__); + return nullptr; + } + + size_t requireArgc = ARGS_THREE; + size_t argc = ARGS_THREE; + napi_value args[ARGS_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + if (argc > requireArgc) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count %{public}zu.", __func__, argc); + return nullptr; + } + + napi_value result = nullptr; + napi_value cons = nullptr; + if (napi_get_reference_value(env, g_constructorRef, &cons) != napi_ok) { + return nullptr; + } + NAPI_CALL(env, napi_new_instance(env, cons, ARGS_THREE, args, &result)); + + if (!IsTypeForNapiValue(env, result, napi_object)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue isn`t object", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_null)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue is null", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_undefined)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue is undefined", __func__); + return nullptr; + } + + delete fileAccessHelperCB; + fileAccessHelperCB = nullptr; + HILOG_INFO("tag dsa %{public}s,end", __func__); + return result; +} + +napi_value NAPI_AcquireFileAccessHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCB *fileAccessHelperCB = new (std::nothrow) FileAccessHelperCB; + if (fileAccessHelperCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, FileAccessHelperCB == nullptr", __func__); + return WrapVoidToJS(env); + } + + fileAccessHelperCB->cbBase.cbInfo.env = env; + fileAccessHelperCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + fileAccessHelperCB->cbBase.abilityType = abilityType; + napi_value ret = AcquireFileAccessHelperWrap(env, info, fileAccessHelperCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s, ret == nullptr", __func__); + if (fileAccessHelperCB != nullptr) { + delete fileAccessHelperCB; + fileAccessHelperCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value NAPI_CreateFileAccessHelper(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s, called", __func__); + return NAPI_AcquireFileAccessHelperCommon(env, info, AbilityType::EXTENSION); +} + +napi_value FileAccessHelperInit(napi_env env, napi_value exports) +{ + HILOG_INFO("tag dsa %{public}s,called start ", __func__); + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("openFile", NAPI_OpenFile), + }; + napi_value cons = nullptr; + NAPI_CALL(env, + napi_define_class(env, + FILEACCESS_CLASS_NAME.c_str(), + NAPI_AUTO_LENGTH, + FileAccessHelperConstructor, + nullptr, + sizeof(properties) / sizeof(*properties), + properties, + &cons)); + g_fileAccessHelperList.clear(); + NAPI_CALL(env, napi_create_reference(env, cons, 1, &g_constructorRef)); + NAPI_CALL(env, napi_set_named_property(env, exports, FILEACCESS_CLASS_NAME.c_str(), cons)); + + napi_property_descriptor export_properties[] = { + DECLARE_NAPI_FUNCTION("createFileAccessHelper", NAPI_CreateFileAccessHelper), + }; + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(export_properties) / sizeof(export_properties[0]), + export_properties)); + return exports; +} + +napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s, called", __func__); + size_t argc = ARGS_THREE; + napi_value argv[ARGS_THREE] = {nullptr}; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); + NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); + AAFwk::Want want; + OHOS::AppExecFwk::UnwrapWant(env, argv[PARAM1], want); + std::string strUri = NapiValueToStringUtf8(env, argv[PARAM2]); + std::shared_ptr fileAccessHelper = nullptr; + bool isStageMode = false; + napi_status status = AbilityRuntime::IsStageContext(env, argv[PARAM0], isStageMode); + if (status != napi_ok || !isStageMode) { + auto ability = OHOS::AbilityRuntime::GetCurrentAbility(env); + NAPI_ASSERT(env, ability != nullptr, "FileAccessHelperConstructor: failed to get native ability"); + HILOG_INFO("tag dsa FA Model: strUri = %{public}s", strUri.c_str()); + fileAccessHelper = FileAccessHelper::Creator(ability->GetContext(), want, std::make_shared(strUri)); + } else { + auto context = OHOS::AbilityRuntime::GetStageModeContext(env, argv[PARAM0]); + NAPI_ASSERT(env, context != nullptr, "FileAccessHelperConstructor: failed to get native context"); + HILOG_INFO("tag dsa Stage Model: strUri = %{public}s", strUri.c_str()); + fileAccessHelper = FileAccessHelper::Creator(context, want, std::make_shared(strUri)); + } + NAPI_ASSERT(env, fileAccessHelper != nullptr, "FileAccessHelperConstructor: fileAccessHelper is nullptr"); + g_fileAccessHelperList.emplace_back(fileAccessHelper); + napi_wrap(env, thisVar, fileAccessHelper.get(), [](napi_env env, void *data, void *hint) { + FileAccessHelper *objectInfo = static_cast(data); + g_fileAccessHelperList.remove_if([objectInfo](const std::shared_ptr &fileAccessHelper) { + return objectInfo == fileAccessHelper.get(); + }); + }, nullptr, nullptr); + HILOG_INFO("tag dsa %{public}s,called end", __func__); + return thisVar; +} + +napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperOpenFileCB *openFileCB = new (std::nothrow) FileAccessHelperOpenFileCB; + if (openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, openFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + openFileCB->cbBase.cbInfo.env = env; + openFileCB->cbBase.asyncWork = nullptr; + openFileCB->cbBase.deferred = nullptr; + openFileCB->cbBase.ability = nullptr; + + napi_value ret = OpenFileWrap(env, info, openFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (openFileCB != nullptr) { + delete openFileCB; + openFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + openFileCB->uri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, openFileCB->uri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + openFileCB->mode = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, openFileCB->mode.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,DataShareHelper objectInfo", __func__); + openFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = OpenFileAsync(env, args, ARGS_TWO, openFileCB); + } else { + ret = OpenFilePromise(env, openFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value OpenFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &openFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + OpenFileExecuteCB, + OpenFileAsyncCompleteCB, + (void *)openFileCB, + &openFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, openFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value OpenFilePromise(napi_env env, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + openFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + OpenFileExecuteCB, + OpenFilePromiseCompleteCB, + (void *)openFileCB, + &openFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, openFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void OpenFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFile, worker pool thread execute."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + if (OpenFileCB->fileAccessHelper != nullptr) { + OpenFileCB->execResult = INVALID_PARAMETER; + if (!OpenFileCB->uri.empty()) { + OHOS::Uri uri(OpenFileCB->uri); + OpenFileCB->result = OpenFileCB->fileAccessHelper->OpenFile(uri, OpenFileCB->mode); + OpenFileCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_OpenFile, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_OpenFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_OpenFile, worker pool thread execute end."); +} + +void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, OpenFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, OpenFileCB->execResult); + napi_create_int32(env, OpenFileCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (OpenFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, OpenFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); + delete OpenFileCB; + OpenFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete end."); +} + +void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, OpenFileCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, OpenFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); + delete OpenFileCB; + OpenFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete end."); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/file_manager_napi.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h similarity index 39% rename from interfaces/kits/js/src/file_manager_napi.h rename to interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 8b06b57a..7d5045a6 100644 --- a/interfaces/kits/js/src/file_manager_napi.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -12,29 +12,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_NAPI_H -#define STORAGE_FILE_MANAGER_NAPI_H -#include "ifms_client.h" -#include "n_exporter.h" +#ifndef FILE_ACCESS_NAPI_H +#define FILE_ACCESS_NAPI_H + +//#include "n_exporter.h" +#include "file_access_common.h" namespace OHOS { -namespace FileManagerService { -class FileManagerNapi final : public DistributedFS::NExporter { -public: - static napi_value CreateFile(napi_env env, napi_callback_info info); - static napi_value ListFile(napi_env env, napi_callback_info info); - static napi_value Mkdir(napi_env env, napi_callback_info info); - static napi_value GetRoot(napi_env env, napi_callback_info info); - bool Export() override; - std::string GetClassName() override; - static std::tuple GetFmsClient(); - FileManagerNapi(napi_env env, napi_value exports); - ~FileManagerNapi() override; -private: - inline static const std::string className_ = "__properities__"; - inline static IFmsClient* fmsClient_ = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_NAPI_H \ No newline at end of file +namespace AppExecFwk { + napi_value FileAccessHelperInit(napi_env env, napi_value exports); + napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info); + napi_value NAPI_OpenFile(napi_env env, napi_callback_info info); + napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperOpenFileCB *openFileCB); + napi_value OpenFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperOpenFileCB *openFileCB); + napi_value OpenFilePromise(napi_env env, FileAccessHelperOpenFileCB *openFileCB); + void OpenFileExecuteCB(napi_env env, void *data); + void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data); +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/js/src/module.cpp b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp similarity index 47% rename from interfaces/kits/js/src/module.cpp rename to interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp index 5c5b7a2c..8889db96 100644 --- a/interfaces/kits/js/src/module.cpp +++ b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp @@ -16,29 +16,47 @@ #include #include -#include "file_manager_napi.h" -#include "log.h" - +#include "napi_fileaccess_helper.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "hilog_wrapper.h" using namespace std; namespace OHOS { -namespace FileManagerService { -using namespace DistributedFS; -static napi_value Export(napi_env env, napi_value exports) -{ - std::vector> products; - products.emplace_back(make_unique(env, exports)); - for (auto &&product : products) { - if (!product->Export()) { - ERR_LOG("INNER BUG. Failed to export class %{public}s for module filemanager", - product->GetClassName().c_str()); - return nullptr; - } - } +namespace AppExecFwk { +EXTERN_C_START +/* + * The module initialization. + */ +static napi_value Init(napi_env env, napi_value exports) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperInit(env, exports); return exports; } +EXTERN_C_END -NAPI_MODULE(filemanager, Export) -} // namespace FileManagerService +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "data.fileAccess", + .nm_priv = ((void *)0), + .reserved = {0} +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + napi_module_register(&_module); +} +} } // namespace OHOS \ No newline at end of file diff --git a/services/sa_profile/BUILD.gn b/interfaces/kits/napi/file_ext_ability/BUILD.gn similarity index 35% rename from services/sa_profile/BUILD.gn rename to interfaces/kits/napi/file_ext_ability/BUILD.gn index 16b9a8ba..b0e794e8 100644 --- a/services/sa_profile/BUILD.gn +++ b/interfaces/kits/napi/file_ext_ability/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 Huawei Device 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 @@ -11,10 +11,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos/sa_profile/sa_profile.gni") +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") -ohos_sa_profile("filemanager_service_sa_profile") { - sources = [ "5010.xml" ] +ts2abc_gen_abc("gen_file_ext_ability_abc") { + src_js = rebase_path("file_ext_ability.js") + dst_file = rebase_path(target_out_dir + "/file_ext_ability.abc") + in_puts = [ "file_ext_ability.js" ] + out_puts = [ target_out_dir + "/file_ext_ability.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("file_ext_ability_js") { + input = "file_ext_ability.js" + output = target_out_dir + "/file_ext_ability.o" +} + +gen_js_obj("file_ext_ability_abc") { + input = get_label_info(":gen_file_ext_ability_abc", "target_out_dir") + + "/file_ext_ability.abc" + output = target_out_dir + "/file_ext_ability_abc.o" + dep = ":gen_file_ext_ability_abc" +} + +ohos_shared_library("fileextensionability_napi") { + sources = [ "file_ext_ability_module.cpp" ] + + deps = [ + ":file_ext_ability_abc", + ":file_ext_ability_js", + ] + + external_deps = [ "napi:ace_napi" ] + relative_install_dir = "module/application" + subsystem_name = "filemanagement" part_name = "user_file_service" } diff --git a/services/src/fileoper/oper_factory.h b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js similarity index 57% rename from services/src/fileoper/oper_factory.h rename to interfaces/kits/napi/file_ext_ability/file_ext_ability.js index 90443b05..b966cb34 100644 --- a/services/src/fileoper/oper_factory.h +++ b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device 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 @@ -12,20 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_OPER_FACTORY_H -#define STORAGE_SERVICES_OPER_FACTORY_H -#pragma once -#include +class FileExtensionAbility { + onCreate(want) { + console.log('js c++ tag dsa onCreate, want:' + want.abilityName); + } -#include "file_oper.h" + openFile(uri, mode) { + console.log('js c++ tag dsa openFile, uri:' + uri); + } +} -namespace OHOS { -namespace FileManagerService { -class OperFactory { -public: - std::unique_ptr GetFileOper(int equipmentId); -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_OPER_FACTORY_H \ No newline at end of file +export default FileExtensionAbility \ No newline at end of file diff --git a/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp b/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp new file mode 100644 index 00000000..6dca96b5 --- /dev/null +++ b/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "native_engine/native_engine.h" + +extern const char _binary_file_ext_ability_js_start[]; +extern const char _binary_file_ext_ability_js_end[]; +extern const char _binary_file_ext_ability_abc_start[]; +extern const char _binary_file_ext_ability_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_FileExtensionAbility_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.FileExtensionAbility", + .fileName = "application/libfileextensionability_napi.so/FileExtensionAbility.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_FileExtensionAbility_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_file_ext_ability_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_file_ext_ability_js_end - _binary_file_ext_ability_js_start; + } +} + +// file extension ability JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_FileExtensionAbility_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_file_ext_ability_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_file_ext_ability_abc_end - _binary_file_ext_ability_abc_start; + } +} \ No newline at end of file diff --git a/services/etc/fms_service.cfg b/services/etc/fms_service.cfg deleted file mode 100644 index a271b415..00000000 --- a/services/etc/fms_service.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "services" : [{ - "name" : "fms_service", - "path" : ["/system/bin/sa_main", "/system/profile/fms_service.xml"], - "uid" : "1006", - "gid" : ["system", "shell"] - } - ] -} diff --git a/services/etc/fms_service.rc b/services/etc/fms_service.rc deleted file mode 100644 index 41f1e4d1..00000000 --- a/services/etc/fms_service.rc +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2021 Huawei Device 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. - -service fms_service /system/bin/sa_main /system/profile/fms_service.xml - class z_core - seclabel u:r:audiodistributedservice:s0 - -on boot - start fms_service - diff --git a/services/include/file_manager_service_def.h b/services/include/file_manager_service_def.h deleted file mode 100644 index 1cd2f168..00000000 --- a/services/include/file_manager_service_def.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_FILE_MANAGER_SERVICE_DEF_H -#define STORAGE_FILE_MANAGER_SERVICE_DEF_H - -#include -#include -#include -#include "media_data_ability_const.h" -#include "media_lib_service_const.h" - -namespace OHOS { -namespace FileManagerService { -enum Operation { - GET_ROOT, - MAKE_DIR, - LIST_FILE, - CREATE_FILE -}; - -enum Equipment { - INTERNAL_STORAGE, - EXTERNAL_STORAGE -}; - -enum VolumeState { - UNMOUNTED = 0, - CHECKING, - MOUNTED, - EJECTING -}; -constexpr int64_t MAX_NUM = 200; -constexpr int32_t CODE_MASK = 0xff; -constexpr int32_t EQUIPMENT_SHIFT = 16; - -const std::string FISRT_LEVEL_ALBUM = "dataability:///album"; -// use to find out album in the root dir -const std::string RELATIVE_ROOT_PATH = ""; - -const std::string MEDIA_ROOT_PATH = "/storage/media/local/files"; -const std::string IMAGE_ROOT_NAME = "image_album"; -const std::string VIDEO_ROOT_NAME = "video_album"; -const std::string AUDIO_ROOT_NAME = "audio_album"; -const std::string FILE_ROOT_NAME = "file_folder"; - -const std::string ALBUM_TYPE = "album"; -const std::string FILE_MIME_TYPE = "file/*"; - -const std::string EXTERNAL_STORAGE_URI = "dataability:///external_storage"; -const std::string MOUNT_POINT_ROOT = "/mnt/"; - -constexpr int FILE_MEDIA_TYPE = Media::MediaType::MEDIA_TYPE_FILE; -constexpr int RESULTSET_EMPTY = 0; -constexpr int RESULTSET_ONE = 1; - -const std::unordered_map FILE_MIME_TYPE_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "image/*"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "audio/*"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "video/*"}, - {Media::MediaType::MEDIA_TYPE_FILE, "file/*"}, - {Media::MediaType::MEDIA_TYPE_ALBUM, "file/*"}, -}; - -const std::unordered_map MEDIA_TYPE_FOLDER_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "image/"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "audio/"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "video/"}, - {Media::MediaType::MEDIA_TYPE_FILE, "document/"}, -}; - -const std::unordered_map MEDIA_TYPE_URI_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, Media::MEDIALIBRARY_IMAGE_URI}, - {Media::MediaType::MEDIA_TYPE_AUDIO, Media::MEDIALIBRARY_AUDIO_URI}, - {Media::MediaType::MEDIA_TYPE_VIDEO, Media::MEDIALIBRARY_VIDEO_URI}, - {Media::MediaType::MEDIA_TYPE_FILE, Media::MEDIALIBRARY_FILE_URI}, -}; - -#define GET_COLUMN_INDEX_FROM_NAME(result, name, index) \ - do { \ - if (result->GetColumnIndex(name, index) != NativeRdb::E_OK) { \ - ERR_LOG("NativeRdb gets %{public}s index fail", name.c_str()); \ - return false; \ - } \ - } while (0) -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_DEF_H diff --git a/services/include/log.h b/services/include/log.h deleted file mode 100644 index db1322ef..00000000 --- a/services/include/log.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERIVCE_INCLUDE_LOG_H -#define STORAGE_SERIVCE_INCLUDE_LOG_H - -#include -#include "hilog/log.h" - -#undef LOG_DOMAIN -#undef LOG_TAG -#define LOG_DOMAIN 0xD00430A -#define LOG_TAG "FileManagerment:FMS" - -#define DEBUG_LOG(fmt, args...) \ - HILOG_DEBUG(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define ERR_LOG(fmt, args...) \ - HILOG_ERROR(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define WARNING_LOG(fmt, args...) \ - HILOG_WARN(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define INFO_LOG(fmt, args...) \ - HILOG_INFO(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define FATAL_LOG(fmt, args...) \ - HILOG_FATAL(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#endif // STORAGE_SERIVCE_INCLUDE_LOG_H diff --git a/services/include/storage_manager_inf.h b/services/include/storage_manager_inf.h deleted file mode 100644 index 4f294f16..00000000 --- a/services/include/storage_manager_inf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device 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. - */ -#ifndef STORAGE_MANAGER_INTERFACE_H -#define STORAGE_MANAGER_INTERFACE_H -#include -#include -#include "ipc/storage_manager_proxy.h" -#include "ipc/storage_manager.h" -#include "istorage_manager.h" -namespace OHOS { -namespace FileManagerService { -class StorageManagerInf { -public: - StorageManagerInf() = default; - ~StorageManagerInf() = default; - static int Connect(); - static std::vector GetAllVolumes(); - static bool GetMountedVolumes(std::vector &vecRootPath); - static bool StoragePathValidCheck(const std::string &path); -private: - inline static sptr storageManager_; -}; -} // FileManagerService -} // OHOS -#endif // STORAGE_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/services/sa_profile/5010.xml b/services/sa_profile/5010.xml deleted file mode 100644 index 49e52242..00000000 --- a/services/sa_profile/5010.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - fms_service - - libfms_server.z.so - - - 5010 - libfms_server.z.so - true - false - 1 - - diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp deleted file mode 100644 index 0c15b609..00000000 --- a/services/src/client/file_manager_proxy.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#include "file_manager_proxy.h" - -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "file_manager_service_stub.h" -#include "log.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -static int GetCmdResponse(MessageParcel &reply, sptr &cmdResponse) -{ - cmdResponse = reply.ReadParcelable(); - if (cmdResponse == nullptr) { - ERR_LOG("Unmarshalling cmdResponse fail"); - return FAIL; - } - return cmdResponse->GetErr(); -} - -FileManagerProxy::FileManagerProxy(const sptr &impl) - : IRemoteProxy(impl) {} -int FileManagerProxy::GetRoot(const CmdOptions &option, vector> &fileRes) -{ - CmdOptions op(option); - int code = Operation::GET_ROOT; - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::GET_ROOT; - } - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(op.GetDevInfo().GetName()); - MessageParcel reply; - MessageOption messageOption; - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("GetRoot inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(fileName); - data.WriteString(path); - MessageParcel reply; - MessageOption messageOption; - int code = Operation::CREATE_FILE; - CmdOptions op(option); - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::CREATE_FILE; - } - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - uri = cmdResponse->GetUri(); - return err; -} - -IFmsClient *IFmsClient::GetFmsInstance() -{ - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - ERR_LOG("samgr object is NULL."); - return nullptr; - } - sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); - if (object == nullptr) { - ERR_LOG("FileManager Service object is NULL."); - return nullptr; - } - static FileManagerProxy proxy = FileManagerProxy(object); - return &proxy; -} - -int FileManagerProxy::ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) -{ - CmdOptions op(option); - std::string devName(op.GetDevInfo().GetName()); - std::string devPath(op.GetDevInfo().GetPath()); - int64_t offset = op.GetOffset(); - int64_t count = op.GetCount(); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(devName); - data.WriteString(devPath); - data.WriteString(type); - data.WriteString(path); - data.WriteInt64(offset); - data.WriteInt64(count); - MessageParcel reply; - MessageOption messageOption; - uint32_t code = Operation::LIST_FILE; - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::LIST_FILE; - } - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::Mkdir(const string &name, const string &path) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(name); - data.WriteString(path); - MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(Operation::MAKE_DIR, data, reply, option); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - reply.ReadInt32(err); - return err; -} -} // FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h deleted file mode 100644 index ba0ce14a..00000000 --- a/services/src/client/ifms_client.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_IFILE_MANAGER_CLIENT_H -#define STORAGE_IFILE_MANAGER_CLIENT_H -#include "cmd_options.h" -#include "file_info.h" -namespace OHOS { -namespace FileManagerService { -class IFmsClient { -public: - virtual ~IFmsClient() {} - static IFmsClient *GetFmsInstance(); - virtual int Mkdir(const std::string &name, const std::string &path) = 0; - virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) = 0; - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) = 0; - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) = 0; -}; -} // namespace FileManagerService { -} // namespace OHOS -#endif // STORAGE_IFILE_MANAGER_CLIENT_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_options.h b/services/src/fileoper/cmd_options.h deleted file mode 100644 index b119ead8..00000000 --- a/services/src/fileoper/cmd_options.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERVICES_DEV_INFO_H -#define STORAGE_SERVICES_DEV_INFO_H - -#include -#include "file_manager_service_def.h" -namespace OHOS { -namespace FileManagerService { -class DevInfo { -public: - DevInfo() = default; - ~DevInfo() = default; - DevInfo(const std::string &nameIn, const std::string &pathIn) : name_(nameIn), path_(pathIn) - {} - - DevInfo(const DevInfo &dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - } - - DevInfo& operator=(const DevInfo& dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - return *this; - } - - std::string GetName() const - { - return name_; - } - - void SetName(const std::string& name) - { - name_ = name; - } - - std::string GetPath() const - { - return path_; - } - - void SetPath(const std::string& path) - { - path_ = path; - } - -private: - std::string name_ {""}; - std::string path_ {""}; -}; - -class CmdOptions { -public: - CmdOptions() = default; - ~CmdOptions() = default; - - CmdOptions(DevInfo devIn, int64_t offsetIn, int64_t countIn, bool hasOptIn) - : dev_(devIn), offset_(offsetIn), count_(countIn), hasOpt_(hasOptIn) - {} - CmdOptions(const std::string &nameIn, const std::string &pathIn, - int64_t offsetIn, int64_t countIn, bool hasOptIn) - : dev_(nameIn, pathIn), offset_(offsetIn), count_(countIn), hasOpt_(hasOptIn) - {} - - CmdOptions(const CmdOptions &option) = default; - CmdOptions& operator=(const CmdOptions& option) = default; - - DevInfo GetDevInfo() const - { - return dev_; - } - - void SetDevInfo(const DevInfo& dev) - { - dev_ = dev; - } - - int64_t GetOffset() const - { - return offset_; - } - - void SetOffset(int64_t offset) - { - offset_ = offset; - } - - int64_t GetCount() const - { - return count_; - } - - void setCount(int64_t count) - { - count_ = count; - } - - bool GetHasOpt() const - { - return hasOpt_; - } - - void SetHasOpt(bool hasOpt) - { - hasOpt_ = hasOpt; - } - -private: - DevInfo dev_; - int64_t offset_ {0}; - int64_t count_ {MAX_NUM}; - bool hasOpt_ {false}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_DEV_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_response.h b/services/src/fileoper/cmd_response.h deleted file mode 100644 index f4a3b445..00000000 --- a/services/src/fileoper/cmd_response.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERVICES_CMD_RESPONSE_H -#define STORAGE_SERVICES_CMD_RESPONSE_H - -#include -#include -#include - -#include "file_info.h" -#include "log.h" -#include "parcel.h" -namespace OHOS { -namespace FileManagerService { -class CmdResponse : public Parcelable { -public: - CmdResponse() = default; - CmdResponse(int &err, std::string &uri, std::vector> &fileInfoList) - : err_(err), uri_(uri), vecFileInfo_(fileInfoList) - {} - ~CmdResponse() = default; - - void SetErr(const int err) - { - err_ = err; - } - - int GetErr() const - { - return err_; - } - - void SetUri(const std::string &uri) - { - uri_ = uri; - } - - std::string GetUri() const - { - return uri_; - } - - void SetFileInfoList(std::vector> &fileInfoList) - { - vecFileInfo_ = fileInfoList; - } - - std::vector> GetFileInfoList() - { - return vecFileInfo_; - } - - virtual bool Marshalling(Parcel &parcel) const override - { - parcel.WriteInt32(err_); - parcel.WriteString(uri_); - size_t fileCount = vecFileInfo_.size(); - parcel.WriteUint64(fileCount); - for (size_t i = 0; i < fileCount; i++) { - if (parcel.WriteParcelable(vecFileInfo_[i].get()) != true) { - ERR_LOG("Marshalling FileInfo fails!"); - return false; - } - } - return true; - } - - static CmdResponse* Unmarshalling(Parcel &parcel) - { - auto *obj = new (std::nothrow) CmdResponse(); - if (obj == nullptr) { - return nullptr; - } - obj->err_ = parcel.ReadInt32(); - obj->uri_ = parcel.ReadString(); - size_t fileCount = parcel.ReadUint64(); - for (size_t i = 0; i < fileCount; i++) { - std::shared_ptr file(parcel.ReadParcelable()); - obj->vecFileInfo_.emplace_back(file); - } - return obj; - } -private: - int err_; - std::string uri_; - std::vector> vecFileInfo_; -}; -} // FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_CMD_RESPONSE_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h deleted file mode 100644 index a2b27b0e..00000000 --- a/services/src/fileoper/ext_storage/ext_storage_status.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_EXT_STORAGE_STATUS_H -#define STORAGE_EXT_STORAGE_STATUS_H - -#include - -#include "file_manager_service_def.h" - -namespace OHOS { -namespace FileManagerService { -class ExtStorageStatus { -public: - ExtStorageStatus() = default; - ~ExtStorageStatus() = default; - ExtStorageStatus(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const VolumeState &volumeState) - : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), volumeState_(volumeState) {} - - ExtStorageStatus(const ExtStorageStatus &extStatus) - { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - - ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) - { - if (this != &extStatus) { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - return *this; - } - - std::string GetId() - { - return id_; - } - - void SetId(const std::string &id) - { - id_ = id; - } - - std::string GetDiskId() - { - return diskId_; - } - - void SetDiskId(const std::string &diskId) - { - diskId_ = diskId; - } - - std::string GetFsUuid() - { - return fsUuid_; - } - - void SetFsUuid(const std::string &fsUuid) - { - fsUuid_ = fsUuid; - } - - std::string GetPath() - { - return path_; - } - - void SetPath(const std::string &path) - { - path_ = path; - } - - VolumeState GetVolumeState() - { - return volumeState_; - } - - void SetVolumeState(const VolumeState &volumeState) - { - volumeState_ = volumeState; - } - -private: - std::string id_; - std::string diskId_; - std::string fsUuid_; - std::string path_; - VolumeState volumeState_; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_EXT_STORAGE_STATUS_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp deleted file mode 100644 index 7211fc70..00000000 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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. - */ -#include "ext_storage_subscriber.h" - -#include - -#include "appexecfwk_errors.h" -#include "bundle_info.h" -#include "common_event_manager.h" -#include "common_event_support.h" -#include "log.h" -#include "string_wrapper.h" -#include "int_wrapper.h" -#include "want.h" - -using namespace OHOS::AAFwk; -namespace OHOS { -namespace FileManagerService { -/** - * @brief Receiver Constructor. - * @param subscriberInfo Subscriber info. - */ -ExtStorageSubscriber::ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) - : EventFwk::CommonEventSubscriber(subscriberInfo) -{} - -std::shared_ptr ExtStorageSubscriber_ = nullptr; -bool ExtStorageSubscriber::Subscriber(void) -{ - if (ExtStorageSubscriber_ == nullptr) { - EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); - - EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); - ExtStorageSubscriber_ = std::make_shared(subscribeInfo); - EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); - } - return true; -} - -/** - * @brief Receive common event. - * @param eventData Common event data. - */ -void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) -{ - const AAFwk::Want& want = eventData.GetWant(); - std::string action = want.GetAction(); - DEBUG_LOG("%{public}s, action:%{public}s.", __func__, action.c_str()); - - const AAFwk::WantParams wantParams = want.GetParams(); - std::string id = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("id"))); - std::string diskId = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("diskId"))); - DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); - DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - std::string fsUuid = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("fsUuid"))); - std::string path = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("path"))); - DEBUG_LOG("%{public}s, volumeState:%{public}d.", __func__, volumeState); - DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", - __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); - } -} - -bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) -{ - auto extStorageStatus = mountStatus.find(path); - if (extStorageStatus == mountStatus.end()) { - return false; - } else { - if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { - return true; - } - return false; - } -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/storage_manager_inf.cpp b/services/src/fileoper/ext_storage/storage_manager_inf.cpp deleted file mode 100644 index 02481edf..00000000 --- a/services/src/fileoper/ext_storage/storage_manager_inf.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device 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. - */ - -#include "storage_manager_inf.h" - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -static bool GetMountPointFromPath(const string &path, string &mountPoint) -{ - size_t len = MOUNT_POINT_ROOT.size(); - std::string head = path.substr(0, len); - std::string body = path.substr(len); - if (head != MOUNT_POINT_ROOT || body.size() == 0) { - ERR_LOG("invalid mountPoint %{public}s, head check fail", path.c_str()); - return false; - } - - size_t index = body.find("/"); - if (index != std::string::npos) { - mountPoint = MOUNT_POINT_ROOT + body.substr(0, index); - } else { - mountPoint = path; - } - return true; -} - -int StorageManagerInf::Connect() -{ - DEBUG_LOG("StorageManagerConnect::Connect start"); - auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (sam == nullptr) { - ERR_LOG("StorageManagerConnect::Connect samgr == nullptr"); - return FAIL; - } - auto object = sam->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); - if (object == nullptr) { - ERR_LOG("StorageManagerConnect::Connect object == nullptr"); - return FAIL; - } - storageManager_ = iface_cast(object); - if (storageManager_ == nullptr) { - ERR_LOG("StorageManagerConnect::Connect service == nullptr"); - return FAIL; - } - DEBUG_LOG("StorageManagerConnect::Connect end"); - return SUCCESS; -} - -std::vector StorageManagerInf::GetAllVolumes() -{ - vector result = {}; - if (Connect() != SUCCESS) { - ERR_LOG("GetTotalSizeOfVolume:Connect error"); - return result; - } - return storageManager_->GetAllVolumes(); -} - -bool StorageManagerInf::GetMountedVolumes(vector &vecRootPath) -{ - bool succ = false; - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return succ; - } - for (auto vol : result) { - DEBUG_LOG("find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - if (vol.GetState() == VolumeState::MOUNTED) { - DEBUG_LOG("mounted find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - vecRootPath.emplace_back(EXTERNAL_STORAGE_URI + vol.GetPath()); - succ = true; - } - } - return succ; -} - -bool StorageManagerInf::StoragePathValidCheck(const string &path) -{ - string mountPoint; - if (!GetMountPointFromPath(path, mountPoint)) { - ERR_LOG("uri path is invalid"); - return false; - } - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return false; - } - bool succ = false; - for (auto vol : result) { - if (vol.GetPath() == mountPoint && vol.GetState() == VolumeState::MOUNTED) { - succ = true; - break; - } - } - return succ; -} -} // FileManagerService -} // OHOS diff --git a/services/src/fileoper/external_storage_oper.cpp b/services/src/fileoper/external_storage_oper.cpp deleted file mode 100644 index af9c01d6..00000000 --- a/services/src/fileoper/external_storage_oper.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "external_storage_oper.h" - -#include - -#include "cmd_response.h" -#include "external_storage_utils.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -int ExternalStorageOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const -{ - DEBUG_LOG("ExternalStorageOper::OperProcess"); - int errCode = SUCCESS; - switch (code) { - case Operation::LIST_FILE: { - std::string devName = data.ReadString(); - std::string devPath = data.ReadString(); - std::string type = data.ReadString(); - std::string path = data.ReadString(); - int64_t offset = data.ReadInt64(); - int64_t count = data.ReadInt64(); - - CmdOptions option(devName, devPath, offset, count, true); - errCode = this->ListFile(type, path, option, reply); - break; - } - case Operation::CREATE_FILE: { - std::string name = data.ReadString(); - std::string uri = data.ReadString(); - errCode = this->CreateFile(uri, name, reply); - break; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}d.", code); - break; - } - } - return errCode; -} - -int ExternalStorageOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const -{ - std::string resultUir; - int ret = ExternalStorageUtils::DoCreateFile(uri, name, resultUir); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(resultUir); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::ListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoListFile(type, uri, option, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/external_storage_oper.h b/services/src/fileoper/external_storage_oper.h deleted file mode 100644 index af5ee57a..00000000 --- a/services/src/fileoper/external_storage_oper.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H -#define STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H - -#include -#include "cmd_options.h" -#include "file_oper.h" -namespace OHOS { -namespace FileManagerService { -class ExternalStorageOper : public FileOper { -public: - ExternalStorageOper() = default; - virtual ~ExternalStorageOper() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; -private: - int CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const; - int ListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - MessageParcel &reply) const; - int GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H \ No newline at end of file diff --git a/services/src/fileoper/external_storage_utils.cpp b/services/src/fileoper/external_storage_utils.cpp deleted file mode 100644 index 1cff272a..00000000 --- a/services/src/fileoper/external_storage_utils.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "external_storage_utils.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "storage_manager_inf.h" -using namespace std; -using namespace OHOS::StorageManager; -namespace OHOS { -namespace FileManagerService { -static bool GetPathFromUri(const string &uri, string &path) -{ - uint len = EXTERNAL_STORAGE_URI.size(); - string head = uri.substr(0, len); - if (head != EXTERNAL_STORAGE_URI) { - ERR_LOG("invalid format uri %{private}s, head check fail", uri.c_str()); - return false; - } - if (uri.size() == len) { - ERR_LOG("uri content is invalid %{private}s", uri.c_str()); - return false; - } - path = uri.substr(len); - return true; -} - -static bool GetRealPath(string &path) -{ - char filePath[PATH_MAX + 1] = { 0 }; - if (realpath(path.c_str(), filePath) == nullptr) { - ERR_LOG("untrustPath invalid %{public}d\n", errno); - return false; - } - path = string(filePath); - return true; -} - -static bool GetFileInfo(const std::string &path, const std::string &name, shared_ptr &fileInfo) -{ - std::string fullPath(path); - size_t len = fullPath.size(); - if (fullPath.at(len - 1) != '/') { - fullPath.append("/").append(name); - } else { - fullPath.append(name); - } - struct stat st; - if (lstat(fullPath.c_str(), &st) != 0) { - ERR_LOG("check file info fail."); - return false; - } - std::string uri(EXTERNAL_STORAGE_URI); - std::string fName(name.c_str()); - - uri.append(fullPath); - fileInfo->SetPath(uri); - std::string type = S_ISDIR(st.st_mode) ? "album" : "file"; - fileInfo->SetType(type); - fileInfo->SetName(fName); - fileInfo->SetSize(st.st_size); - fileInfo->SetAddedTime(static_cast(st.st_ctim.tv_sec)); - fileInfo->SetModifiedTime(static_cast(st.st_mtim.tv_sec)); - return true; -} - -static bool ConvertUriToAbsolutePath(const std::string &uri, std::string &path) -{ - if (!GetPathFromUri(uri, path)) { - ERR_LOG("GetPathFromUri fail"); - return false; - } - if (!GetRealPath(path)) { - ERR_LOG("get real path fail"); - return false; - } - if (!StorageManagerInf::StoragePathValidCheck(path)) { - ERR_LOG("external uri path was ejected"); - return false; - } - return true; -} - -int ExternalStorageUtils::DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList) -{ - int64_t count = option.GetCount(); - int64_t offset = option.GetOffset(); - if (count < 0 || count > MAX_NUM || offset < 0) { - ERR_LOG("invalid file count or offset."); - return E_INVALID_FILE_NUMBER; - } - DEBUG_LOG("limit %{public}lld, offset %{public}lld", (long long)count, (long long)offset); - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{private}s].", uri.c_str()); - return E_NOEXIST; - } - - DIR *dir = opendir(path.c_str()); - if (!dir) { - ERR_LOG("opendir path[%{private}s] fail.", path.c_str()); - return E_NOEXIST; - } - if (offset != 0) { - int64_t index = 0; - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (index == offset - 1) { - break; - } - index++; - } - } - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (count > 0) { - shared_ptr fileInfo = make_shared(); - if (!GetFileInfo(path, ent->d_name, fileInfo)) { - continue; - } - fileList.push_back(fileInfo); - count--; - if (count == 0) { - break; - } - } - } - closedir(dir); - if (option.GetCount() == MAX_NUM && count == 0) { - DEBUG_LOG("get files with MAX_NUM:[%{public}lld].", (long long)MAX_NUM); - } - return SUCCESS; -} - -int ExternalStorageUtils::DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri) -{ - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{public}s].", uri.c_str()); - return E_NOEXIST; - } - size_t len = path.size(); - if (path.at(len - 1) != '/') { - path.append("/").append(name); - } else { - path.append(name); - } - if (access(path.c_str(), F_OK) == 0) { - ERR_LOG("target file[%{public}s] exist.", path.c_str()); - return E_CREATE_FAIL; - } - - int fd = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0771); - if (fd == -1) { - ERR_LOG("create file[%{public}s] fail.", path.c_str()); - return E_CREATE_FAIL; - } - close(fd); - resultUri = EXTERNAL_STORAGE_URI + path; - return SUCCESS; -} - -int ExternalStorageUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - vector vecRootPath; - if (!StorageManagerInf::GetMountedVolumes(vecRootPath)) { - ERR_LOG("none valid extorage storage"); - return FAIL; - } - for (auto rootPath : vecRootPath) { - shared_ptr fileInfo = make_shared(FILE_ROOT_NAME, rootPath, ALBUM_TYPE); - fileList.push_back(fileInfo); - } - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/file_info.cpp b/services/src/fileoper/file_info.cpp deleted file mode 100644 index 3eaf9006..00000000 --- a/services/src/fileoper/file_info.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#include "file_info.h" -#include "log.h" -using namespace std; - -namespace OHOS { -namespace FileManagerService { -bool FileInfo::Marshalling(Parcel &parcel) const -{ - parcel.WriteString(path_); - parcel.WriteString(name_); - parcel.WriteString(type_); - parcel.WriteInt64(size_); - parcel.WriteInt64(addedTime_); - parcel.WriteInt64(modifiedTime_); - return true; -} - -FileInfo* FileInfo::Unmarshalling(Parcel &parcel) -{ - auto *obj = new (std::nothrow) FileInfo(); - if (obj == nullptr) { - ERR_LOG("Unmarshalling fail"); - return nullptr; - } - obj->path_ = parcel.ReadString(); - obj->name_ = parcel.ReadString(); - obj->type_ = parcel.ReadString(); - obj->size_ = parcel.ReadInt64(); - obj->addedTime_ = parcel.ReadInt64(); - obj->modifiedTime_ = parcel.ReadInt64(); - return obj; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/file_info.h b/services/src/fileoper/file_info.h deleted file mode 100644 index 8a8742b6..00000000 --- a/services/src/fileoper/file_info.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERVICES_FILE_INFO_H -#define STORAGE_SERVICES_FILE_INFO_H - -#include -#include -#include "parcel.h" - -namespace OHOS { -namespace FileManagerService { -class FileInfo : public Parcelable { -public: - FileInfo(const std::string &name, const std::string &path, const std::string &type) : path_(path), - name_(name), type_(type) {} - FileInfo() = default; - ~FileInfo() = default; - - void SetName(std::string &name) - { - name_ = name; - } - void SetPath(std::string &path) - { - path_ = path; - } - void SetType(std::string &type) - { - type_ = type; - } - void SetSize(int64_t size) - { - size_ = size; - } - void SetAddedTime(int64_t time) - { - addedTime_ = time; - } - void SetModifiedTime(int64_t time) - { - modifiedTime_ = time; - } - std::string GetName() const - { - return name_; - } - std::string GetPath() const - { - return path_; - } - std::string GetType() const - { - return type_; - } - int64_t GetSize() const - { - return size_; - } - int64_t GetAddedTime() const - { - return addedTime_; - } - int64_t GetModifiedTime() const - { - return modifiedTime_; - } - bool Marshalling(Parcel &parcel) const override; - static FileInfo* Unmarshalling(Parcel &parcel); -private: - std::string path_; - std::string name_; - std::string type_; - int64_t size_ {0}; - int64_t addedTime_ {0}; - int64_t modifiedTime_ {0}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_FILE_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp deleted file mode 100644 index 3d5e69ee..00000000 --- a/services/src/fileoper/media_file_oper.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "media_file_oper.h" - -#include - -#include "cmd_options.h" -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "log.h" -#include "media_data_ability_const.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const -{ - int errCode = SUCCESS; - // media process - switch (code) { - case Operation::MAKE_DIR: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = Mkdir(name, path); - break; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - case Operation::LIST_FILE: { - string devName = data.ReadString(); - string devPath = data.ReadString(); - string type = data.ReadString(); - string path = data.ReadString(); - int off = data.ReadInt64(); - int count = data.ReadInt64(); - // put fileInfo into reply - errCode = ListFile(type, path, off, count, reply); - break; - } - case Operation::CREATE_FILE: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = CreateFile(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}u.", code); - break; - } - } - return errCode; -} - -int MediaFileOper::CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - string type = "file"; - std::string uri; - int ret = MediaFileUtils::DoInsert(name, path, type, uri); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(uri); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = MediaFileUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::ListFile(const string &type, const string &path, int offset, int count, MessageParcel &reply) const -{ - shared_ptr result; - int res = MediaFileUtils::DoListFile(type, path, offset, count, result); - if (res != SUCCESS) { - return res; - } - - std::vector> fileList; - res = MediaFileUtils::GetFileInfoFromResult(result, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(res); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return res; -} - -int MediaFileOper::Mkdir(const string &name, const string &path) const -{ - (void)name; - DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/media_file_utils.cpp b/services/src/fileoper/media_file_utils.cpp deleted file mode 100644 index dcdd31e4..00000000 --- a/services/src/fileoper/media_file_utils.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (C) 2021-2022 Huawei Device 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. - */ - -#include "media_file_utils.h" - -#include - -#include "data_ability_predicates.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "media_asset.h" -#include "media_data_ability_const.h" -#include "rdb_errno.h" -#include "values_bucket.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -bool GetPathFromResult(shared_ptr result, string &path) -{ - int count = 0; - result->GetRowCount(count); - if (count == RESULTSET_EMPTY) { - ERR_LOG("AbsSharedResultSet null"); - return false; - } - int32_t columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_FILE_PATH, columnIndex); - result->GoToFirstRow(); - int ret = result->GetString(columnIndex, path); - if (ret != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path index fail"); - return false; - } - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - string relativePath; - ret = result->GetString(columnIndex, relativePath); - if (ret != NativeRdb::E_OK) { - relativePath = ""; - DEBUG_LOG("NativeRdb gets relative path is null %{public}d", columnIndex); - } - // get relative path from absolute path - string::size_type pos = path.find_last_of('/'); - if (pos != string::npos) { - path = relativePath + path.substr(pos + 1) + "/"; - } - return true; -} - -bool IsNumber(const string &str) -{ - if (str.length() == 0) { - ERR_LOG("IsNumber input is empty "); - return false; - } - - for (char const &c : str) { - if (isdigit(c) == 0) { - ERR_LOG("Index is not a number"); - return false; - } - } - - return true; -} - -bool GetPathID(const string &uriPath, string &index) -{ - string::size_type pos = uriPath.find_last_of('/'); - if (pos == string::npos) { - ERR_LOG("invalid uri %{private}s", uriPath.c_str()); - return false; - } - index = uriPath.substr(pos + 1); - if (!IsNumber(index)) { - ERR_LOG("invalid uri %{private}s invalid id %{public}s", uriPath.c_str(), index.c_str()); - return false; - } - return true; -} - -int GetMediaType(const string &name) -{ - int mediaType = Media::MediaAsset::GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MEDIA_TYPE; - } - return mediaType; -} - -string GetMimeType(const string &name) -{ - int mediaType = GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MIME_TYPE; - } - return FILE_MIME_TYPE_MAPS.at(mediaType); -} - -bool GetPathFromAlbumPath(const string &albumUri, string &path) -{ - string id; - if (!GetPathID(albumUri, id)) { - ERR_LOG("GetPathID fails"); - return false; - } - string selection = Media::MEDIA_DATA_DB_ID + " LIKE ? "; - vector selectionArgs = {id}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - if (result == nullptr) { - ERR_LOG("AbsSharedResultSet null"); - return false; - } - return GetPathFromResult(result, path); -} - -string GetType(string type) -{ - unordered_map typeMap = { - {"image", Media::MediaType::MEDIA_TYPE_IMAGE}, - {"video", Media::MediaType::MEDIA_TYPE_VIDEO}, - {"audio", Media::MediaType::MEDIA_TYPE_AUDIO} - }; - if (typeMap.count(type) == 0) { - // type is wrong - ERR_LOG("Type %{public}s", type.c_str()); - return ""; - } - return ToString(typeMap[type]); -} - -bool IsFirstLevelUriPath(const string &path) -{ - // check whether path is first level uri - return path == FISRT_LEVEL_ALBUM; -} - -bool GetAlbumFromResult(shared_ptr &result, vector &album) -{ - int count = 0; - result->GetRowCount(count); - result->GoToFirstRow(); - int32_t columnIndex; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - for (int i = 0; i < count; i++) { - string path; - if (result->GetString(columnIndex, path) != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path columnIndex fail"); - return false; - } - path = MEDIA_ROOT_PATH + "/" + path.substr(0, path.size() - 1); - // add into ablum if not in album - if (find(album.begin(), album.end(), path) == album.end()) { - DEBUG_LOG(" // add into ablum path %{public}s", path.c_str()); - album.emplace_back(path); - } - result->GoToNextRow(); - } - return true; -} - -vector FindAlbumByType(string type) -{ - // find out the first level Album - // first find out file by type - // then get the album - string selection = Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - vector selectionArgs = {type}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - vector album; - if (result == nullptr) { - ERR_LOG("query album type returns fail"); - return album; - } - GetAlbumFromResult(result, album); - return album; -} - -/* listfile - * ----find "file" type - * --------first level view---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == root_path && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * --------other level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * - * ----find "image"/"audio"/"video" type - * --------first level view---- - * --------find out all album with type file - * --------selection MEDIA_DATA_DB_MEDIA_TYPE == type - * --------Get the relative path ----> Album path - * --------selection MEDIA_DATA_DB_FILE_PATH == Album path1 || selection MEDIA_DATA_DB_FILE_PATH == Album path2 || ... - * --------second level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && MEDIA_DATA_DB_MEDIA_TYPE == type - */ -int CreateSelectionAndArgsFirstLevel(const string &type, string &selection, vector &selectionArgs) -{ - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - RELATIVE_ROOT_PATH, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selectionArgs = FindAlbumByType(GetType(type)); - selection = Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - if (selectionArgs.size() > 1) { - for (uint32_t i = 1; i < selectionArgs.size(); i++) { - selection += " OR " + Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - } - } - } - return SUCCESS; -} - -int CreateSelectionAndArgsOtherLevel(const string &type, const string &albumUri, string &selection, - vector &selectionArgs) -{ - // get the album path from the album uri - string albumPath; - if (!GetPathFromAlbumPath(albumUri, albumPath)) { - ERR_LOG("path not exsit"); - return E_NOEXIST; - } - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - albumPath, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - selectionArgs = { albumPath, GetType(type) }; - } - return SUCCESS; -} - -bool GetAlbumPath(const string &name, const string &path, string &albumPath) -{ - if (IsFirstLevelUriPath(path)) { - int mediaType = GetMediaType(name); - albumPath = (MEDIA_TYPE_FOLDER_MAPS.count(mediaType) == 0) ? MEDIA_TYPE_FOLDER_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_FOLDER_MAPS.at(mediaType); - return true; - } - return GetPathFromAlbumPath(path, albumPath); -} - -static void ShowSelecArgs(const string &selection, const vector &selectionArgs) -{ - DEBUG_LOG("selection %{public}s ", selection.c_str()); - for (auto s : selectionArgs) { - DEBUG_LOG("selectionArgs %{public}s", s.c_str()); - } -} - -int MediaFileUtils::DoListFile(const string &type, const string &path, int offset, int count, - shared_ptr &result) -{ - string selection; - vector selectionArgs; - if (IsFirstLevelUriPath(path)) { - DEBUG_LOG("IsFirstLevelUriPath"); - CreateSelectionAndArgsFirstLevel(type, selection, selectionArgs); - } else { - int err = CreateSelectionAndArgsOtherLevel(type, path, selection, selectionArgs); - if (err) { - ERR_LOG("CreateSelectionAndArgsOtherLevel returns fail"); - return err; - } - } - result = DoQuery(selection, selectionArgs, offset, count); - if (result == nullptr) { - ERR_LOG("ListFile folder is empty"); - return E_EMPTYFOLDER; - } - return SUCCESS; -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs) -{ - return DoQuery(selection, selectionArgs, 0, MAX_NUM); -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs, int offset, int count) -{ - ShowSelecArgs(selection, selectionArgs); - NativeRdb::DataAbilityPredicates predicates; - predicates.SetWhereClause(selection); - predicates.SetWhereArgs(selectionArgs); - predicates.SetOrder("date_taken DESC LIMIT " + ToString(offset) + "," + ToString(count)); - DEBUG_LOG("limit %{public}d, offset %{public}d", count, offset); - Uri uri = Uri(Media::MEDIALIBRARY_DATA_URI); - vector columns; - return abilityHelper->Query(uri, columns, predicates); -} - -int MediaFileUtils::DoInsert(const string &name, const string &path, const string &type, string &uri) -{ - NativeRdb::ValuesBucket values; - string albumPath; - if (!GetAlbumPath(name, path, albumPath)) { - ERR_LOG("path not exsit"); - return E_NOEXIST; - } - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, albumPath); - values.PutString(Media::MEDIA_DATA_DB_NAME, name); - values.PutString(Media::MEDIA_DATA_DB_MIME_TYPE, GetMimeType(name)); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, GetMediaType(name)); - Uri createAsset(Media::MEDIALIBRARY_DATA_URI + "/" + Media::MEDIA_FILEOPRN + "/" + - Media::MEDIA_FILEOPRN_CREATEASSET); - int index = abilityHelper->Insert(createAsset, values); - if (index < 0) { - ERR_LOG("Fail to create fail file %{public}s uri %{private}s album %{public}s", name.c_str(), - path.c_str(), albumPath.c_str()); - return E_CREATE_FAIL; - } - // use file id concatenate head as uri - uri = (MEDIA_TYPE_URI_MAPS.count(GetMediaType(name)) == 0) ? MEDIA_TYPE_URI_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_URI_MAPS.at(GetMediaType(name)); - uri += "/" + to_string(index); - - return SUCCESS; -} - -bool MediaFileUtils::InitMediaTableColIndexMap(shared_ptr result) -{ - if (mediaTableMap.size() == 0) { - DEBUG_LOG("init mediaTableMap"); - vector> mediaData = { - {Media::MEDIA_DATA_DB_ID, "string"}, - {Media::MEDIA_DATA_DB_URI, "string"}, - {Media::MEDIA_DATA_DB_MEDIA_TYPE, "string"}, - {Media::MEDIA_DATA_DB_NAME, "string"}, - {Media::MEDIA_DATA_DB_SIZE, "int"}, - {Media::MEDIA_DATA_DB_DATE_ADDED, "int"}, - {Media::MEDIA_DATA_DB_DATE_MODIFIED, "int"} - }; - for (auto i : mediaData) { - int columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, i.first, columnIndex); - mediaTableMap.emplace_back(columnIndex, i.second); - } - } - return true; -} - -bool MediaFileUtils::GetFileInfo(shared_ptr result, - shared_ptr &fileInfo) -{ - if (!InitMediaTableColIndexMap(result)) { - ERR_LOG("InitMediaTableColIndexMap returns fail"); - return false; - } - int index = 0; - string id; - result->GetString(mediaTableMap[index++].first, id); - string uri; - result->GetString(mediaTableMap[index++].first, uri); - - string path = uri + "/" + id; - fileInfo->SetPath(path); - string type; - result->GetString(mediaTableMap[index++].first, type); - fileInfo->SetType(type); - string name; - result->GetString(mediaTableMap[index++].first, name); - fileInfo->SetName(name); - int64_t value; - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetSize(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetAddedTime(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetModifiedTime(value); - return true; -} - -int MediaFileUtils::GetFileInfoFromResult(shared_ptr result, - std::vector> &fileList) -{ - int count = 0; - result->GetRowCount(count); - if (count == 0) { - ERR_LOG("AbsSharedResultSet null"); - return E_EMPTYFOLDER; - } - result->GoToFirstRow(); - for (int i = 0; i < count; i++) { - shared_ptr fileInfo = make_shared(); - GetFileInfo(result, fileInfo); - fileList.push_back(fileInfo); - result->GoToNextRow(); - } - return SUCCESS; -} - -bool MediaFileUtils::InitHelper(sptr obj) -{ - if (abilityHelper == nullptr) { - abilityHelper = AppExecFwk::DataAbilityHelper::Creator(obj, make_shared(Media::MEDIALIBRARY_DATA_URI)); - if (abilityHelper == nullptr) { - DEBUG_LOG("get %{private}s helper fail", Media::MEDIALIBRARY_DATA_URI.c_str()); - return false; - } - } - return true; -} - -int MediaFileUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - shared_ptr image = make_shared(IMAGE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(image); - shared_ptr video = make_shared(VIDEO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(video); - shared_ptr audio = make_shared(AUDIO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(audio); - shared_ptr file = make_shared(FILE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(file); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/media_file_utils.h b/services/src/fileoper/media_file_utils.h deleted file mode 100644 index 0a3b923f..00000000 --- a/services/src/fileoper/media_file_utils.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ -#ifndef STORAGE_SERIVCES_MEDIA_FILE_UTILS_H -#define STORAGE_SERIVCES_MEDIA_FILE_UTILS_H - -#include -#include - -#include "abs_shared_result_set.h" -#include "file_info.h" -#include "file_oper.h" - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -#include "data_ability_helper.h" - -namespace OHOS { -namespace FileManagerService { -class MediaFileUtils { -public: - MediaFileUtils(); - ~MediaFileUtils(); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); - static int DoListFile(const std::string &type, const std::string &path, int offset, int count, - std::shared_ptr &result); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs, int offset, int count); - static int DoInsert(const std::string &name, const std::string &path, const std::string &type, std::string &uri); - static bool GetFileInfo(std::shared_ptr result, std::shared_ptr &fileInfo); - static int GetFileInfoFromResult(std::shared_ptr result, - std::vector> &fileList); - static bool InitMediaTableColIndexMap(std::shared_ptr result); - static bool InitHelper(sptr obj); -private: - inline static std::vector> mediaTableMap = {}; - inline static std::shared_ptr abilityHelper = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_MEDIA_FILE_UTILS_H \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.cpp b/services/src/fileoper/oper_factory.cpp deleted file mode 100644 index e0b8ea24..00000000 --- a/services/src/fileoper/oper_factory.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "oper_factory.h" - -#include "external_storage_oper.h" -#include "file_manager_service_def.h" -#include "file_oper.h" -#include "log.h" -#include "media_file_oper.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -unique_ptr OperFactory::GetFileOper(int equipmentId) -{ - unique_ptr fp; - DEBUG_LOG("FileOper %{public}d.", equipmentId); - switch (equipmentId) { - case Equipment::INTERNAL_STORAGE: { - fp = make_unique(); - break; - } - case Equipment::EXTERNAL_STORAGE: { - fp = make_unique(); - break; - } - default: { - DEBUG_LOG("default FileOper %{public}d.", equipmentId); - break; - } - } - return fp; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/server/file_manager_service.cpp b/services/src/server/file_manager_service.cpp deleted file mode 100644 index f1471a25..00000000 --- a/services/src/server/file_manager_service.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "file_manager_service.h" - -#include "iservice_registry.h" -#include "log.h" -#include "system_ability_definition.h" -#include "ext_storage/ext_storage_subscriber.h" - -namespace OHOS { -namespace FileManagerService { -REGISTER_SYSTEM_ABILITY_BY_ID(FileManagerService, FILE_MANAGER_SERVICE_ID, true); - -FileManagerService::FileManagerService(int32_t systemAbilityId, bool runOnCreate) - : SystemAbility(systemAbilityId, runOnCreate) {} -void FileManagerService::OnDump() {} - -void FileManagerService::OnStart() -{ - DEBUG_LOG("FileManagerService OnStart"); - ExtStorageSubscriber::Subscriber(); - bool res = Publish(this); - if (!res) { - ERR_LOG("FileManagerService OnStart invalid"); - } -} - -void FileManagerService::OnStop() -{ - DEBUG_LOG("FileManagerService OnStop"); -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/server/file_manager_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp deleted file mode 100644 index 2cfc3d65..00000000 --- a/services/src/server/file_manager_service_stub.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device 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. - */ - -#include "file_manager_service_stub.h" - -#include "accesstoken_kit.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "file_manager_service.h" -#include "ipc_singleton.h" -#include "ipc_skeleton.h" -#include "log.h" -#include "media_file_utils.h" -#include "oper_factory.h" -#include "sa_mgr_client.h" -#include "string_ex.h" -#include "system_ability_definition.h" -using namespace std; -namespace OHOS { -namespace FileManagerService { -static int GetEquipmentCode(uint32_t code) -{ - return (code >> EQUIPMENT_SHIFT) & CODE_MASK; -} - -static int GetOperCode(uint32_t code) -{ - return code & CODE_MASK; -} - -int FileManagerServiceStub::OperProcess(uint32_t code, MessageParcel &data, - MessageParcel &reply) -{ - int equipmentId = GetEquipmentCode(code); - int operCode = GetOperCode(code); - OperFactory factory = OperFactory(); - auto fp = factory.GetFileOper(equipmentId); - if (fp == nullptr) { - ERR_LOG("OnRemoteRequest inner error %{public}d", code); - return FAIL; - } - int errCode = fp->OperProcess(operCode, data, reply); - return errCode; -} - -bool CheckClientPermission(const std::string& permissionStr) -{ - Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); - int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, - permissionStr); - if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - ERR_LOG("Have no media permission"); - return false; - } - ERR_LOG("permission check success"); - return true; -} - -int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - // check whether request from fms proxy - if (data.ReadInterfaceToken() != GetDescriptor()) { - ERR_LOG("reject error remote request"); - reply.WriteInt32(FAIL); - return FAIL; - } - // change permission string after finishing accessToken - string permission = "ohos.permission.READ_MEDIA"; - if (!CheckClientPermission(permission)) { - ERR_LOG("checkpermission error FAIL"); - reply.WriteInt32(FAIL); - return FAIL; - } - if (!MediaFileUtils::InitHelper(AsObject())) { - ERR_LOG("Init MediaLibraryDataAbility Helper error"); - reply.WriteInt32(FAIL); - return FAIL; - } - // do request process - int32_t errCode = OperProcess(code, data, reply); - reply.WriteInt32(errCode); - return errCode; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn deleted file mode 100644 index 92b1ac6c..00000000 --- a/services/test/BUILD.gn +++ /dev/null @@ -1,125 +0,0 @@ -# Copyright (c) 2021 Huawei Device 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("//build/test.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -ohos_unittest("file_manager_proxy_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "client/file_manager_proxy_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//third_party/googletest/googlemock/include/gmock", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/googletest:gmock_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -ohos_unittest("oper_factory_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "fileoper/oper_factory_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk:native_appdatafwk", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb:native_rdb", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -ohos_unittest("file_manager_service_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "server/file_manager_service_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk:native_appdatafwk", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb:native_rdb", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -group("user_file_manager_test") { - testonly = true - - deps = [ - ":file_manager_proxy_test", - ":file_manager_service_test", - ":oper_factory_test", - ] -} diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp deleted file mode 100644 index 501a1ec9..00000000 --- a/services/test/client/file_manager_proxy_test.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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. - */ - -#include - -#include - -#include "ifms_client.h" -#include "file_manager_proxy.h" -#include "fms_manager_proxy_mock.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerProxyTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp(); - void TearDown() {}; - std::shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; -}; - -void FileManagerProxyTest::SetUp() -{ - mock_ = new OHOS::FileManagerService::FmsManagerProxyMock(); - proxy_ = std::make_shared(mock_); -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000 - * @tc.name: File_Manager_Proxy_GetFmsInstance_0000 - * @tc.desc: Test function of GetFmsInstance interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000"; - try { - IFmsClient* result = IFmsClient::GetFmsInstance(); - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000"; -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000 - * @tc.name: File_Manager_Proxy_Mkdir_0000 - * @tc.desc: Test function of Mkdir interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000"; - std::string name = "File_Manager_Proxy_Mkdir_0000"; - std::string path = "dataability:///album"; - EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) - .Times(1) - .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); - int ret = proxy_->Mkdir(name, path); - EXPECT_EQ(ret, 1); - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; -} -} // namespace \ No newline at end of file diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h deleted file mode 100644 index 811807ed..00000000 --- a/services/test/client/fms_manager_proxy_mock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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. - */ - -#ifndef FMS_MANAGER_PROXY_MOCK_H -#define FMS_MANAGER_PROXY_MOCK_H -#include -#include "gmock/gmock.h" -#include "iremote_stub.h" -#include "iremote_proxy.h" -#include "ifms_client.h" -#include "cmd_response.h" - -namespace OHOS { -namespace FileManagerService { -class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); - FmsManagerProxyMock() {} - virtual ~FmsManagerProxyMock() {} - MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); - int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) - { - sptr cmdResponse = new CmdResponse(); - reply.WriteParcelable(cmdResponse); - return ERR_NONE; - } - virtual int Mkdir(const std::string &name, const std::string &path) override - { - return ERR_NONE; - } - virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override - { - return ERR_NONE; - } -}; -} // namespace FileManagerService -} // namespace OHOS - -#endif // FMS_MANAGER_PROXY_MOCK_H \ No newline at end of file diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp deleted file mode 100644 index 9a2eebbc..00000000 --- a/services/test/fileoper/oper_factory_test.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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. - */ - -#include -#include - -#include "file_manager_service_def.h" -#include "file_manager_service_stub.h" -#include "media_data_ability_const.h" -#include "abs_shared_result_set.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class OperFactoryTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "OperFactoryTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0000 - * @tc.name: oper_factory_GetFileOper_0000 - * @tc.desc: Test function of GetFileOper interface for SUCCESS which INTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0000"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0000"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0001 - * @tc.name: oper_factory_GetFileOper_0001 - * @tc.desc: Test function of GetFileOper for SUCCESS which EXTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0001"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 - * @tc.name: oper_factory_GetFileOper_0002 - * @tc.desc: Test function of GetFileOper interface for SUCCESS wich default. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0002"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(3); - } - EXPECT_EQ(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0002"; -} -} // namespace \ No newline at end of file diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp deleted file mode 100644 index 3d0ea852..00000000 --- a/services/test/server/file_manager_service_test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device 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. - */ - -#include -#include - -#include "ifms_client.h" -#include "file_info.h" -#include "media_file_oper.h" -#include "file_manager_service_stub.h" -#include "media_data_ability_const.h" -#include "file_manager_service_def.h" -#include "abs_shared_result_set.h" -#include "file_manager_service.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerServiceTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerServiceTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 - * @tc.name: file_Manager_Service_OnDump_0000 - * @tc.desc: Test function of OnDump interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnDump(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnDump_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStart_0000 - * @tc.name: file_Manager_Service_OnStart_0000 - * @tc.desc: Test function of OnStart interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStart_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStart(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStart_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStop_0000 - * @tc.name: file_Manager_Service_OnStop_0000 - * @tc.desc: Test function of OnStop interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStop(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStop_0000"; -} -} // namespace \ No newline at end of file diff --git a/utils/hilog_wrapper.h b/utils/hilog_wrapper.h new file mode 100644 index 00000000..a070b12e --- /dev/null +++ b/utils/hilog_wrapper.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#ifndef HILOG_WRAPPER_H +#define HILOG_WRAPPER_H + +#define CONFIG_HILOG +#ifdef CONFIG_HILOG +#include "hilog/log.h" + +#ifdef HILOG_FATAL +#undef HILOG_FATAL +#endif + +#ifdef HILOG_ERROR +#undef HILOG_ERROR +#endif + +#ifdef HILOG_WARN +#undef HILOG_WARN +#endif + +#ifdef HILOG_INFO +#undef HILOG_INFO +#endif + +#ifdef HILOG_DEBUG +#undef HILOG_DEBUG +#endif + +#ifndef AMS_LOG_DOMAIN +#define AMS_LOG_DOMAIN 0xD00430A +#endif + +#ifndef AMS_LOG_TAG +#define AMS_LOG_TAG "FileAccessFrameworks" +#endif + +#ifdef LOG_LABEL +#undef LOG_LABEL +#endif + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, AMS_LOG_DOMAIN, AMS_LOG_TAG}; + +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#define HILOG_FATAL(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Fatal( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_ERROR(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Error( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_WARN(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Warn( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_INFO(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Info( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_DEBUG(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Debug( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#else + +#define HILOG_FATAL(...) +#define HILOG_ERROR(...) +#define HILOG_WARN(...) +#define HILOG_INFO(...) +#define HILOG_DEBUG(...) +#endif // CONFIG_HILOG + +#endif // HILOG_WRAPPER_H \ No newline at end of file -- Gitee From c4603dadef114e9aef78029593a5496642752d04 Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Fri, 6 May 2022 17:47:56 +0800 Subject: [PATCH 02/22] clean useless comde Signed-off-by: linjun9528 --- frameworks/innerkits/file_extension/BUILD.gn | 7 +---- .../include/file_access_helper.h | 8 ------ .../file_extension/include/file_ext_ability.h | 14 ---------- .../include/file_ext_stub_impl.h | 1 - .../include/js_file_ext_ability.h | 3 --- .../file_extension/src/file_access_helper.cpp | 9 ------- .../file_extension/src/file_ext_ability.cpp | 2 +- .../file_extension/src/file_ext_proxy.cpp | 12 --------- .../file_extension/src/file_ext_stub.cpp | 7 ----- .../src/js_file_ext_ability.cpp | 2 -- .../kits/napi/file_access_module/BUILD.gn | 27 +++---------------- .../napi_fileaccess_helper.cpp | 6 ----- 12 files changed, 5 insertions(+), 93 deletions(-) diff --git a/frameworks/innerkits/file_extension/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn index 6ccbd0c6..aba44d06 100644 --- a/frameworks/innerkits/file_extension/BUILD.gn +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -77,12 +77,9 @@ ohos_shared_library("file_extension_ability_kit") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", "ipc:ipc_core", "ipc_js:rpc", - "native_appdatamgr:native_dataability", "permission_standard:libpermissionsdk_standard", "utils_base:utils", ] @@ -97,7 +94,7 @@ ohos_shared_library("file_extension_ability_kit") { } ohos_shared_library("file_extension_ability_module") { - sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp", ] + sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp" ] configs = [ ":ability_config" ] public_configs = [ ":ability_public_config" ] @@ -105,14 +102,12 @@ ohos_shared_library("file_extension_ability_module") { deps = [ ":file_extension_ability_kit", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/appexecfwk/standard/common:libappexecfwk_common", ] external_deps = [ "ability_base:want", "ability_runtime:runtime", "hiviewdfx_hilog_native:libhilog", - "native_appdatamgr:native_appdatafwk", "utils_base:utils", ] diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 8ea8784e..437ad01c 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -30,16 +30,8 @@ using Uri = OHOS::Uri; namespace OHOS { -namespace NativeRdb { -class AbsSharedResultSet; -class DataAbilityPredicates; -class ValuesBucket; -} // namespace NativeRdb namespace AppExecFwk { using string = std::string; -class DataAbilityResult; -class DataAbilityOperation; -class PacMap; class FileAccessHelper final : public std::enable_shared_from_this { public: ~FileAccessHelper() = default; diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index f47168e0..7f72431c 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -19,22 +19,8 @@ #include "extension_base.h" namespace OHOS { -namespace NativeRdb { -class AbsSharedResultSet; -class DataAbilityPredicates; -class ValuesBucket; -} -namespace AAFwk { -class IDataAbilityObserver; -} -namespace AppExecFwk { -class DataAbilityOperation; -class DataAbilityResult; -} namespace AbilityRuntime { -//class DataShareExtAbilityContext; class Runtime; -//class FileExtAbility : public ExtensionBase { class FileExtAbility : public ExtensionBase<> { public: FileExtAbility() = default; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index e5320017..ec5afd0b 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -18,7 +18,6 @@ #include #include "file_ext_stub.h" -//#include "datashare_uv_queue.h" #include "js_file_ext_ability.h" #include "native_engine/native_value.h" diff --git a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h index 02e4403a..5302c57f 100644 --- a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -18,12 +18,9 @@ #include "file_ext_ability.h" -#include "abs_shared_result_set.h" -#include "data_ability_predicates.h" #include "js_runtime.h" #include "native_engine/native_reference.h" #include "native_engine/native_value.h" -#include "values_bucket.h" namespace OHOS { namespace AbilityRuntime { diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index 0be3aae8..9453cd9b 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -15,21 +15,12 @@ #include "file_access_helper.h" -#include "ability_scheduler_interface.h" -#include "ability_thread.h" -#include "abs_shared_result_set.h" -#include "data_ability_observer_interface.h" -#include "data_ability_operation.h" -#include "data_ability_predicates.h" -#include "data_ability_result.h" #include "hilog_wrapper.h" #include "ifile_ext_base.h" -#include "values_bucket.h" namespace OHOS { namespace AppExecFwk { namespace { -//const std::string SCHEME_DATASHARE = "datashare"; constexpr int INVALID_VALUE = -1; } // namespace diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index a9785710..a703b2c2 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -15,9 +15,9 @@ #include "file_ext_ability.h" -#include "extension_context.h" #include "ability_loader.h" #include "connection_manager.h" +#include "extension_context.h" #include "hilog_wrapper.h" #include "js_file_ext_ability.h" #include "runtime.h" diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index bbcf51ef..4a1d24de 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -15,19 +15,7 @@ #include "file_ext_proxy.h" -#include -#include - -#include "abs_shared_result_set.h" -#include "data_ability_observer_interface.h" -#include "data_ability_operation.h" -#include "data_ability_predicates.h" -#include "data_ability_result.h" #include "hilog_wrapper.h" -#include "ipc_types.h" -#include "ishared_result_set.h" -#include "pac_map.h" -#include "values_bucket.h" namespace OHOS { namespace AppExecFwk { diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index 138c8bd5..e23df7e7 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -15,14 +15,7 @@ #include "file_ext_stub.h" -#include "data_ability_observer_interface.h" -#include "data_ability_operation.h" -#include "data_ability_predicates.h" -#include "data_ability_result.h" #include "hilog_wrapper.h" -#include "ipc_types.h" -#include "ishared_result_set.h" -#include "values_bucket.h" namespace OHOS { namespace AppExecFwk { diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index 2ed3b3d2..1eefab5c 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -19,7 +19,6 @@ #include "ability_info.h" #include "accesstoken_kit.h" #include "bytrace.h" -#include "dataobs_mgr_client.h" #include "file_ext_stub_impl.h" #include "hilog_wrapper.h" #include "ipc_skeleton.h" @@ -40,7 +39,6 @@ constexpr size_t ARGC_TWO = 2; using namespace OHOS::AppExecFwk; using OHOS::Security::AccessToken::AccessTokenKit; -using DataObsMgrClient = OHOS::AAFwk::DataObsMgrClient; JsFileExtAbility* JsFileExtAbility::Create(const std::unique_ptr& runtime) { diff --git a/interfaces/kits/napi/file_access_module/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn index 37fd8a82..cb6a0605 100644 --- a/interfaces/kits/napi/file_access_module/BUILD.gn +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +BASE_DIR = "//foundation/filemanagement/user_file_service" ohos_shared_library("fileaccess") { subsystem_name = "filemanagement" @@ -21,49 +22,27 @@ ohos_shared_library("fileaccess") { include_dirs = [ "./", - "//foundation/filemanagement/user_file_service/utils", - "//foundation/filemanagement/user_file_service/frameworks/innerkits/file_extension/include", - "//third_party/node/src", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/include", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/common/include", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/dataability/include", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/include", + "${BASE_DIR}/utils", ] sources = [ - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/common/src/js_utils.cpp", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/dataability/src/napi_data_ability_predicates.cpp", - "//foundation/distributeddatamgr/appdatamgr/frameworks/js/napi/rdb/src/napi_result_set.cpp", "napi_fileaccess_helper.cpp", "native_fileaccess_module.cpp", ] deps = [ + "${BASE_DIR}/frameworks/innerkits/file_extension:file_extension_ability_kit", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", - "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//third_party/libuv:uv", - "//foundation/filemanagement/user_file_service/frameworks/innerkits/file_extension:file_extension_ability_kit", ] external_deps = [ "ability_base:base", "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", "ability_runtime:napi_base_context", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", "napi:ace_napi", - "native_appdatamgr:native_appdatafwk", - "native_appdatamgr:native_dataability", - "native_appdatamgr:native_rdb", "utils_base:utils", ] } \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 46c975c6..2a165ab2 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -16,18 +16,12 @@ #include "napi_fileaccess_helper.h" #include -#include #include -#include "data_ability_observer_interface.h" #include "uri.h" #include "hilog_wrapper.h" -#include "message_parcel.h" #include "napi_base_context.h" -#include "napi_data_ability_predicates.h" -#include "napi_rdb_predicates.h" -#include "napi_result_set.h" #include "securec.h" using namespace OHOS::AAFwk; -- Gitee From d2bf3f08a6908d6febfa711787778326f812d417 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Sat, 7 May 2022 10:57:25 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- frameworks/innerkits/file_extension/include/ifile_ext_base.h | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index eaaf4974..66adb6e3 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -46,6 +46,7 @@ public: virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; + virtual int Mkdir(const Uri &uri, const std::string &displayName, const Uri &newDirUri) = 0; }; } // namespace AppExecFwk } // namespace OHOS -- Gitee From 1231586b3d40b78cb25f5b3840d6fbafc51692ce Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Sat, 7 May 2022 11:09:40 +0800 Subject: [PATCH 04/22] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- frameworks/innerkits/file_extension/include/ifile_ext_base.h | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index 66adb6e3..eaaf4974 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -46,7 +46,6 @@ public: virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; - virtual int Mkdir(const Uri &uri, const std::string &displayName, const Uri &newDirUri) = 0; }; } // namespace AppExecFwk } // namespace OHOS -- Gitee From 19bc9f9374606455b1c8e20a0a835ac7c8f76fd6 Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Sat, 7 May 2022 16:56:23 +0800 Subject: [PATCH 05/22] fix file_extension hap code bug Signed-off-by: linjun9528 --- frameworks/innerkits/file_extension/include/ifile_ext_base.h | 1 - .../FileExtensionAbility.ts | 0 2 files changed, 1 deletion(-) rename frameworks/innerkits/file_extension_hap/entry/src/main/ets/{FileService => FileExtensionAbility}/FileExtensionAbility.ts (100%) diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index 66adb6e3..eaaf4974 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -46,7 +46,6 @@ public: virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; - virtual int Mkdir(const Uri &uri, const std::string &displayName, const Uri &newDirUri) = 0; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts similarity index 100% rename from frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts rename to frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts -- Gitee From abf2fde192548f5fd6f3093611284bcee81a0928 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Mon, 9 May 2022 20:38:17 +0800 Subject: [PATCH 06/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0createFile=E5=92=8Cmkdi?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../file_extension/include/file_ext_ability.h | 2 + .../file_extension/include/file_ext_proxy.h | 5 + .../file_extension/include/file_ext_stub.h | 2 + .../include/file_ext_stub_impl.h | 2 + .../file_extension/include/ifile_ext_base.h | 8 +- .../include/js_file_ext_ability.h | 2 + .../file_extension/src/file_ext_ability.cpp | 14 +++ .../file_extension/src/file_ext_proxy.cpp | 105 ++++++++++++++++++ .../file_extension/src/file_ext_stub.cpp | 82 ++++++++++++++ .../file_extension/src/file_ext_stub_impl.cpp | 28 +++++ .../src/js_file_ext_ability.cpp | 74 +++++++++++- .../FileExtensionAbility.ts | 12 ++ 12 files changed, 334 insertions(+), 2 deletions(-) rename frameworks/innerkits/file_extension_hap/entry/src/main/ets/{FileService => FileExtensionAbility}/FileExtensionAbility.ts (44%) diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index 7f72431c..afca031c 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -35,6 +35,8 @@ public: virtual int OpenFile(const Uri &uri, const std::string &mode); + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/include/file_ext_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h index 07dbc99b..5c4997cb 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_proxy.h +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -28,6 +28,11 @@ public: virtual ~FileExtProxy() {} virtual int OpenFile(const Uri &uri, const std::string &mode) override; + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + // virtual int Delete(const Uri &sourceFileUri) override; + // virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + // virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h index b8fe2e16..4aa94680 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -30,6 +30,8 @@ public: int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: ErrCode CmdOpenFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdCreateFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdMkdir(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (FileExtStub::*)(MessageParcel &data, MessageParcel &reply); std::map stubFuncMap_; }; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index ec5afd0b..fb837012 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -35,6 +35,8 @@ public: virtual ~FileExtStubImpl() {} int OpenFile(const Uri &uri, const std::string &mode) override; + int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; private: std::shared_ptr GetOwner(); diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index eaaf4974..fbcdc11d 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -42,10 +42,16 @@ public: CMD_NORMALIZE_URI = 13, CMD_DENORMALIZE_URI = 14, CMD_EXECUTE_BATCH = 15, + CMD_CREATE_FILE = 16, + CMD_MKDIR = 17 }; - virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; + // virtual int Delete(const Uri &sourceFileUri) = 0; + // virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) = 0; + // virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) = 0; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h index 5302c57f..815a23ab 100644 --- a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -43,6 +43,8 @@ public: sptr OnConnect(const AAFwk::Want &want) override; int OpenFile(const Uri &uri, const std::string &mode) override; + int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; private: NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0); diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index a703b2c2..011ea8a7 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -62,5 +62,19 @@ int FileExtAbility::OpenFile(const Uri &uri, const std::string &mode) return 0; } +int FileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 123; +} + +int FileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 124; +} + } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index 4a1d24de..05583518 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -57,5 +57,110 @@ int FileExtProxy::OpenFile(const Uri &uri, const std::string &mode) HILOG_INFO("tag dsa %{public}s end successfully, return fd=%{public}d", __func__, fd); return fd; } + +int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return -1; + } + + if (!data.WriteParcelable(&parentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); + return -1; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString mode"); + return -1; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return -1; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_CREATE_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return -2; + } + + // fd = reply.ReadFileDescriptor(); + int ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + +int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return -1; + } + + if (!data.WriteParcelable(&parentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); + return -1; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString mode"); + return -1; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return -1; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MKDIR, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return -2; + } + + // fd = reply.ReadFileDescriptor(); + int ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + } // namespace AAFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index e23df7e7..c10124fd 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -23,6 +23,8 @@ FileExtStub::FileExtStub() { HILOG_INFO("tag dsa %{public}s begin.", __func__); stubFuncMap_[CMD_OPEN_FILE] = &FileExtStub::CmdOpenFile; + stubFuncMap_[CMD_CREATE_FILE] = &FileExtStub::CmdCreateFile; + stubFuncMap_[CMD_MKDIR] = &FileExtStub::CmdMkdir; } FileExtStub::~FileExtStub() @@ -78,5 +80,85 @@ ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) HILOG_INFO("tag dsa %{public}s end.", __func__); return NO_ERROR; } + +ErrCode FileExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr parentUri(data.ReadParcelable()); + if (parentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub parentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = CreateFile(*parentUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa CreateFile fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr parentUri(data.ReadParcelable()); + if (parentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub parentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Mkdir(*parentUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Mkdir fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} + } // namespace AAFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp index 01915b80..00fc3e59 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp @@ -50,5 +50,33 @@ int FileExtStubImpl::OpenFile(const Uri &uri, const std::string &mode) return ret; } +int FileExtStubImpl::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->CreateFile(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} + +int FileExtStubImpl::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Mkdir(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index 1eefab5c..f0cdf053 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -35,6 +35,7 @@ namespace AbilityRuntime { namespace { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; +constexpr size_t ARGC_THREE = 3; } using namespace OHOS::AppExecFwk; @@ -196,7 +197,7 @@ void JsFileExtAbility::GetSrcPath(std::string &srcPath) int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - auto ret = FileExtAbility::OpenFile(uri, mode); + // auto ret = FileExtAbility::OpenFile(uri, mode); HandleScope handleScope(jsRuntime_); napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); @@ -209,6 +210,7 @@ int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) NativeValue* nativeMode = reinterpret_cast(napiMode); NativeValue* argv[] = {nativeUri, nativeMode}; NativeValue* nativeResult = CallObjectMethod("openFile", argv, ARGC_TWO); + int ret = -1; if (nativeResult == nullptr) { HILOG_ERROR("tag dsa %{public}s call openFile with return null.", __func__); return ret; @@ -218,5 +220,75 @@ int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) return ret; } +int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiParentUri = nullptr; + napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + napi_value napiNewFileUri = nullptr; + napi_create_string_utf8(env, newFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiNewFileUri); + + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* nativeNewFileUri = reinterpret_cast(napiNewFileUri); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName, nativeNewFileUri}; + NativeValue* nativeResult = CallObjectMethod("createFile", argv, ARGC_THREE); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call createFile with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); + return ret; + } else { + ret = 1112; //测试用值 + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiParentUri = nullptr; + napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + napi_value napiNewFileUri = nullptr; + napi_create_string_utf8(env, newFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiNewFileUri); + + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* nativeNewFileUri = reinterpret_cast(napiNewFileUri); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName, nativeNewFileUri}; + NativeValue* nativeResult = CallObjectMethod("mkdir", argv, ARGC_THREE); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); + return ret; + } else { + ret = 110; //测试用值 + } + newFileUri = Uri(uriStr); + // ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts similarity index 44% rename from frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts rename to frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index 0c075da2..cac2015c 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileService/FileExtensionAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -10,4 +10,16 @@ export default class FileExtAbility extends Extension { console.log('js server tag dsa openFile, uri:' + uri + ',mode:' + mode); return 50; } + + createFile(parentUri, displayName, newFileUri) { + console.log('js server tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName + ',newFileUri:' + newFileUri); + return "filetest://fileext.share/temp/test/CreateFile001.txt"; + // return 112; + } + + mkdir(parentUri, displayName, newFileUri) { + console.log('js server tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName + ',newFileUri:' + newFileUri); + return "filetest://fileext.share/temp/test/Mkdir001"; + // return 110; + } }; \ No newline at end of file -- Gitee From a48663fb88dfd615b07675aaee53789db32988a3 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 10 May 2022 10:00:59 +0800 Subject: [PATCH 07/22] add mkdir and createfile Signed-off-by: wangjianqiang --- .../include/file_access_helper.h | 15 +- .../file_extension/src/file_access_helper.cpp | 243 ++++------- .../file_access_module/file_access_common.h | 20 + .../napi_fileaccess_helper.cpp | 403 +++++++++++++++++- .../napi_fileaccess_helper.h | 16 + 5 files changed, 513 insertions(+), 184 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 437ad01c..44860630 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -39,21 +39,14 @@ public: static std::shared_ptr Creator(const std::shared_ptr &context, const AAFwk::Want &want); - static std::shared_ptr Creator(const std::shared_ptr &context, - const AAFwk::Want &want, const std::shared_ptr &uri); - - static std::shared_ptr Creator(const std::shared_ptr &context, - const AAFwk::Want &want, const std::shared_ptr &uri); - bool Release(); int OpenFile(Uri &uri, const std::string &mode); + int CreateFile(Uri &parentUri, const std::string &displayName, Uri &newFileUri); + int Mkdir(Uri &parentUri, const std::string &displayName, Uri &newDirUri); private: - FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want); - FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, - const std::shared_ptr &uri, const sptr &fileExtProxy); FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, - const std::shared_ptr &uri, const sptr &fileExtProxy); + const sptr &fileExtProxy); void AddFileAccessDeathRecipient(const sptr &token); void OnSchedulerDied(const wptr &remote); bool CheckUriParam(const Uri &uri); @@ -62,7 +55,7 @@ private: sptr token_ = {}; std::shared_ptr context_ = nullptr; AAFwk::Want want_ = {}; - std::shared_ptr uri_ = nullptr; + // std::shared_ptr uri_ = nullptr; sptr fileExtProxy_ = nullptr; bool isSystemCaller_ = false; static std::mutex oplock_; diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index 9453cd9b..c1f1a058 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -25,41 +25,16 @@ constexpr int INVALID_VALUE = -1; } // namespace std::mutex FileAccessHelper::oplock_; -FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, - const AAFwk::Want &want) -{ - HILOG_INFO("tag dsa %{public}s called begin", __func__); - token_ = context->GetToken(); - want_ = want; - uri_ = nullptr; - fileExtProxy_ = nullptr; - fileExtConnection_ = FileExtConnection::GetInstance(); - HILOG_INFO("tag dsa %{public}s called end", __func__); -} - -FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, - const std::shared_ptr &uri, const sptr &fileExtProxy) -{ - HILOG_INFO("tag dsa %{public}s called begin", __func__); - //token_ = context->GetToken(); - context_ = std::shared_ptr(context); - want_ = want; - uri_ = uri; - fileExtProxy_ = fileExtProxy; - fileExtConnection_ = FileExtConnection::GetInstance(); - HILOG_INFO("tag dsa %{public}s called end", __func__); -} FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, - const AAFwk::Want &want, const std::shared_ptr &uri, const sptr &fileExtProxy) + const AAFwk::Want &want, const sptr &fileExtProxy) { - HILOG_INFO("tag dsa %{public}s called begin", __func__); + HILOG_INFO("tag dsa FileAccessHelper::FileAccessHelper start"); token_ = context->GetToken(); want_ = want; - uri_ = uri; fileExtProxy_ = fileExtProxy; fileExtConnection_ = FileExtConnection::GetInstance(); - HILOG_INFO("tag dsa %{public}s called end", __func__); + HILOG_INFO("tag dsa FileAccessHelper::FileAccessHelper end"); } void FileAccessHelper::AddFileAccessDeathRecipient(const sptr &token) @@ -86,103 +61,21 @@ void FileAccessHelper::OnSchedulerDied(const wptr &remote) auto object = remote.promote(); object = nullptr; fileExtProxy_ = nullptr; - uri_ = nullptr; HILOG_INFO("tag dsa %{public}s called end", __func__); } std::shared_ptr FileAccessHelper::Creator( const std::shared_ptr &context, const AAFwk::Want &want) { - HILOG_INFO("tag dsa %{public}s called begin", __func__); - if (context == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator (context) failed, context == nullptr"); - return nullptr; - } - - HILOG_INFO("tag dsa FileAccessHelper::Creator before ConnectFileExtAbility."); - sptr fileExtConnection = FileExtConnection::GetInstance(); - if (!fileExtConnection->IsExtAbilityConnected()) { - fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); - } - HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); - - FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want); - if (ptrDataShareHelper == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator (context) failed, create FileAccessHelper failed"); - return nullptr; - } - - HILOG_INFO("tag dsa %{public}s called end", __func__); - return std::shared_ptr(ptrDataShareHelper); -} - -std::shared_ptr FileAccessHelper::Creator( - const std::shared_ptr &context, const AAFwk::Want &want, const std::shared_ptr &uri) -{ - HILOG_INFO("tag dsa %{public}s called begin", __func__); + HILOG_INFO("tag dsa FileAccessHelper::Creator with runtime context, want and uri called start."); if (context == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, context == nullptr"); + HILOG_ERROR("tag dsa ileAccessHelper::Creator failed, context == nullptr"); return nullptr; } - if (uri == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, uri == nullptr"); - return nullptr; - } -/* - if (uri->GetScheme() != SCHEME_DATASHARE) { - HILOG_ERROR("FileAccessHelper::Creator failed, the Scheme is not datashare, Scheme: %{public}s", - uri->GetScheme().c_str()); - return nullptr; - } -*/ HILOG_INFO("tag dsa FileAccessHelper::Creator before ConnectFileExtAbility."); sptr fileExtProxy = nullptr; - sptr fileExtConnection = FileExtConnection::GetInstance(); - if (!fileExtConnection->IsExtAbilityConnected()) { - //fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); - } - fileExtProxy = fileExtConnection->GetFileExtProxy(); - if (fileExtProxy == nullptr) { - HILOG_WARN("tag dsa FileAccessHelper::Creator get invalid fileExtProxy"); - } - HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); - - FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, uri, fileExtProxy); - if (ptrDataShareHelper == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, create FileAccessHelper failed"); - return nullptr; - } - - HILOG_INFO("tag dsa %{public}s called end", __func__); - return std::shared_ptr(ptrDataShareHelper); -} - -std::shared_ptr FileAccessHelper::Creator( - const std::shared_ptr &context, const AAFwk::Want &want, - const std::shared_ptr &uri) -{ - HILOG_INFO("tag dsa %{public}s called begin", __func__); - if (context == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, context == nullptr"); - return nullptr; - } - - if (uri == nullptr) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, uri == nullptr"); - return nullptr; - } -/* - if (uri->GetScheme() != SCHEME_DATASHARE) { - HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, the Scheme is not datashare, Scheme: %{public}s", - uri->GetScheme().c_str()); - return nullptr; - } -*/ - HILOG_INFO("FileAccessHelper::Creator before ConnectFileExtAbility."); - sptr fileExtProxy = nullptr; - sptr fileExtConnection = FileExtConnection::GetInstance(); if (!fileExtConnection->IsExtAbilityConnected()) { fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); @@ -193,23 +86,19 @@ std::shared_ptr FileAccessHelper::Creator( } HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); - FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, uri, fileExtProxy); + FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, fileExtProxy); if (ptrDataShareHelper == nullptr) { - HILOG_ERROR("FileAccessHelper::Creator failed, create FileAccessHelper failed"); + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, create FileAccessHelper failed"); return nullptr; } - HILOG_INFO("tag dsa %{public}s called end", __func__); + HILOG_INFO("tag dsa FileAccessHelper::Creator with runtime context, want and uri called end."); return std::shared_ptr(ptrDataShareHelper); } bool FileAccessHelper::Release() { HILOG_INFO("tag dsa %{public}s called begin", __func__); - if (uri_ == nullptr) { - HILOG_ERROR("FileAccessHelper::Release failed, uri_ is nullptr"); - return false; - } HILOG_INFO("tag dsa FileAccessHelper::Release before DisconnectFileExtAbility."); if (fileExtConnection_->IsExtAbilityConnected()) { @@ -217,7 +106,7 @@ bool FileAccessHelper::Release() } HILOG_INFO("tag dsa FileAccessHelper::Release after DisconnectFileExtAbility."); fileExtProxy_ = nullptr; - uri_.reset(); + // uri_.reset(); HILOG_INFO("tag dsa %{public}s called end", __func__); return true; } @@ -231,18 +120,14 @@ int FileAccessHelper::OpenFile(Uri &uri, const std::string &mode) return fd; } - if (uri_ == nullptr) { - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before ConnectFileExtAbility."); - if (!fileExtConnection_->IsExtAbilityConnected()) { - fileExtConnection_->ConnectFileExtAbility(want_, token_); - } - fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); - HILOG_INFO("tag dsa FileAccessHelper::OpenFile after ConnectFileExtAbility."); - if (isSystemCaller_ && fileExtProxy_) { - AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); - } - } else { - fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::OpenFile after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); } if (fileExtProxy_ == nullptr) { @@ -252,19 +137,72 @@ int FileAccessHelper::OpenFile(Uri &uri, const std::string &mode) HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); fd = fileExtProxy_->OpenFile(uri, mode); - HILOG_INFO("tag dsa FileAccessHelper::OpenFile after fileExtProxy_->OpenFile."); - if (uri_ == nullptr) { - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before DisconnectFileExtAbility."); - if (fileExtConnection_->IsExtAbilityConnected()) { - fileExtConnection_->DisconnectFileExtAbility(); - } - HILOG_INFO("tag dsa FileAccessHelper::OpenFile after DisconnectFileExtAbility."); - fileExtProxy_ = nullptr; - } HILOG_INFO("tag dsa %{public}s begin.", __func__); return fd; } +int FileAccessHelper::CreateFile(Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::CreateFile start."); + int index = INVALID_VALUE; + if (!CheckUriParam(parentUri)) { + HILOG_ERROR("tag dsa%{public}s called. CheckUriParam uri failed", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::CreateFile before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::CreateFile before fileExtProxy_->Mkdir."); + index = fileExtProxy_->CreateFile(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. newDirUri = %{public}s", newFileUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::Mkdir(Uri &parentUri, const std::string &displayName, Uri &newDirUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::Mkdir start."); + int index = INVALID_VALUE; + if (!CheckUriParam(parentUri)) { + HILOG_ERROR("tag dsa%{public}s called. CheckUriParam uri failed", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Mkdir before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Mkdir before fileExtProxy_->Mkdir."); + index = fileExtProxy_->Mkdir(parentUri, displayName, newDirUri); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. newDirUri = %{public}s", newDirUri.ToString().c_str()); + return index; +} + bool FileAccessHelper::CheckUriParam(const Uri &uri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); @@ -274,23 +212,6 @@ bool FileAccessHelper::CheckUriParam(const Uri &uri) return false; } - if (uri_ != nullptr) { - if (!CheckOhosUri(*uri_)) { - HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. CheckOhosUri uri_ failed"); - return false; - } - - std::vector checkSegments; - checkUri.GetPathSegments(checkSegments); - - std::vector segments; - uri_->GetPathSegments(segments); - - // if (checkSegments[0] != segments[0]) { - // HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. the datashare in uri doesn't equal the one in uri_."); - // return false; - // } - } HILOG_INFO("tag dsa %{public}s begin.", __func__); return true; } @@ -302,12 +223,6 @@ bool FileAccessHelper::CheckOhosUri(const Uri &uri) return true; Uri checkUri(uri.ToString()); -/* - if (checkUri.GetScheme() != SCHEME_DATASHARE) { - HILOG_ERROR("FileAccessHelper::CheckOhosUri failed. uri is not a datashare one."); - return false; - } -*/ std::vector segments; checkUri.GetPathSegments(segments); if (segments.empty()) { diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h index 562fbf55..2ae8bc15 100644 --- a/interfaces/kits/napi/file_access_module/file_access_common.h +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -40,6 +40,26 @@ struct FileAccessHelperOpenFileCB { int result = 0; int execResult; }; + +struct FileAccessHelperCreateFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string parentUri; + std::string name; + std::string newFileUri; + std::string result; + int execResult; +}; + +struct FileAccessHelperMkdirCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string parentUri; + std::string name; + std::string newDirUri; + std::string result; + int execResult; +}; } } #endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 2a165ab2..ef8fe930 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -133,6 +133,8 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) HILOG_INFO("tag dsa %{public}s,called start ", __func__); napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("openFile", NAPI_OpenFile), + DECLARE_NAPI_FUNCTION("mkdir", NAPI_Mkdir), + DECLARE_NAPI_FUNCTION("createFile", NAPI_CreateFile), }; napi_value cons = nullptr; NAPI_CALL(env, @@ -159,27 +161,24 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info) { HILOG_INFO("tag dsa %{public}s, called", __func__); - size_t argc = ARGS_THREE; - napi_value argv[ARGS_THREE] = {nullptr}; + size_t argc = ARGS_TWO; + napi_value argv[ARGS_TWO] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); AAFwk::Want want; OHOS::AppExecFwk::UnwrapWant(env, argv[PARAM1], want); - std::string strUri = NapiValueToStringUtf8(env, argv[PARAM2]); std::shared_ptr fileAccessHelper = nullptr; bool isStageMode = false; napi_status status = AbilityRuntime::IsStageContext(env, argv[PARAM0], isStageMode); if (status != napi_ok || !isStageMode) { - auto ability = OHOS::AbilityRuntime::GetCurrentAbility(env); - NAPI_ASSERT(env, ability != nullptr, "FileAccessHelperConstructor: failed to get native ability"); - HILOG_INFO("tag dsa FA Model: strUri = %{public}s", strUri.c_str()); - fileAccessHelper = FileAccessHelper::Creator(ability->GetContext(), want, std::make_shared(strUri)); + HILOG_INFO("tag dsa FA Model"); + return thisVar; } else { auto context = OHOS::AbilityRuntime::GetStageModeContext(env, argv[PARAM0]); NAPI_ASSERT(env, context != nullptr, "FileAccessHelperConstructor: failed to get native context"); - HILOG_INFO("tag dsa Stage Model: strUri = %{public}s", strUri.c_str()); - fileAccessHelper = FileAccessHelper::Creator(context, want, std::make_shared(strUri)); + HILOG_INFO("tag dsa Stage Model"); + fileAccessHelper = FileAccessHelper::Creator(context, want); } NAPI_ASSERT(env, fileAccessHelper != nullptr, "FileAccessHelperConstructor: fileAccessHelper is nullptr"); g_fileAccessHelperList.emplace_back(fileAccessHelper); @@ -375,5 +374,391 @@ void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) OpenFileCB = nullptr; HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete end."); } + +napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCreateFileCB *createFileCB = new (std::nothrow) FileAccessHelperCreateFileCB; + if (createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, openFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + createFileCB->cbBase.cbInfo.env = env; + createFileCB->cbBase.asyncWork = nullptr; + createFileCB->cbBase.deferred = nullptr; + createFileCB->cbBase.ability = nullptr; + + napi_value ret = CreateFileWrap(env, info, createFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (createFileCB != nullptr) { + delete createFileCB; + createFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_FOUR; + const size_t argcPromise = ARGS_THREE; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + createFileCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, createFileCB->parentUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + createFileCB->name = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, createFileCB->name.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); + if (valuetype == napi_string) { + createFileCB->newFileUri = NapiValueToStringUtf8(env, args[PARAM2]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, createFileCB->newFileUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + createFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = CreateFileAsync(env, args, ARGS_THREE, createFileCB); + } else { + ret = CreateFilePromise(env, createFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CreateFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &createFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CreateFileExecuteCB, + CreateFileAsyncCompleteCB, + (void *)createFileCB, + &createFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, createFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value CreateFilePromise(napi_env env, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + createFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CreateFileExecuteCB, + CreateFilePromiseCompleteCB, + (void *)createFileCB, + &createFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, createFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void CreateFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, worker pool thread execute."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + if (CreateFileCB->fileAccessHelper != nullptr) { + CreateFileCB->execResult = INVALID_PARAMETER; + if (!CreateFileCB->parentUri.empty()) { + OHOS::Uri parentUri(CreateFileCB->parentUri); + OHOS::Uri newFileUri(CreateFileCB->newFileUri); + int err = CreateFileCB->fileAccessHelper->CreateFile(parentUri, CreateFileCB->name, newFileUri); + CreateFileCB->result = newFileUri.ToString(); + CreateFileCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_CreateFile, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_CreateFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_CreateFile, worker pool thread execute end."); +} + +void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CreateFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, CreateFileCB->execResult); + // napi_create_int32(env, CreateFileCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (CreateFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, CreateFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CreateFileCB->cbBase.asyncWork)); + delete CreateFileCB; + CreateFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete end."); +} + +void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + napi_value result = nullptr; + // napi_create_int32(env, CreateFileCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, CreateFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CreateFileCB->cbBase.asyncWork)); + delete CreateFileCB; + CreateFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete end."); +} + +napi_value NAPI_Mkdir(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa%{public}s,called", __func__); + FileAccessHelperMkdirCB *mkdirCB = new (std::nothrow) FileAccessHelperMkdirCB; + if (mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, mkdirCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + mkdirCB->cbBase.cbInfo.env = env; + mkdirCB->cbBase.asyncWork = nullptr; + mkdirCB->cbBase.deferred = nullptr; + mkdirCB->cbBase.ability = nullptr; + + napi_value ret = MkdirWrap(env, info, mkdirCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa%{public}s,ret == nullptr", __func__); + if (mkdirCB != nullptr) { + delete mkdirCB; + mkdirCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa%{public}s,end", __func__); + return ret; +} + +napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s,called", __func__); + size_t argcAsync = ARGS_FOUR; + const size_t argcPromise = ARGS_THREE; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + mkdirCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa%{public}s,uri=%{public}s", __func__, mkdirCB->parentUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + mkdirCB->name = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa%{public}s,mode=%{public}s", __func__, mkdirCB->name.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); + if (valuetype == napi_string) { + mkdirCB->newDirUri = NapiValueToStringUtf8(env, args[PARAM2]); + HILOG_INFO("tag dsa%{public}s,mode=%{public}s", __func__, mkdirCB->newDirUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa%{public}s,FileAccessHelper objectInfo", __func__); + mkdirCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = MkdirAsync(env, args, ARGS_THREE, mkdirCB); + } else { + ret = MkdirPromise(env, mkdirCB); + } + HILOG_INFO("tag dsa%{public}s,end", __func__); + return ret; +} + +napi_value MkdirAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s, asyncCallback.", __func__); + if (args == nullptr || mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &mkdirCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MkdirExecuteCB, + MkdirAsyncCompleteCB, + (void *)mkdirCB, + &mkdirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, mkdirCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa%{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value MkdirPromise(napi_env env, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s, promise.", __func__); + if (mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + mkdirCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MkdirExecuteCB, + MkdirPromiseCompleteCB, + (void *)mkdirCB, + &mkdirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, mkdirCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa%{public}s, promise end.", __func__); + return promise; +} + +void MkdirExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, worker pool thread execute."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + if (MkdirCB->fileAccessHelper != nullptr) { + MkdirCB->execResult = INVALID_PARAMETER; + if (!MkdirCB->parentUri.empty()) { + OHOS::Uri parentUri(MkdirCB->parentUri); + OHOS::Uri newDirUri(MkdirCB->newDirUri); + int err = MkdirCB->fileAccessHelper->Mkdir(parentUri, MkdirCB->name, newDirUri); + MkdirCB->result = newDirUri.ToString(); + MkdirCB->execResult = err; + } else { + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsaNAPI_Mkdir, worker pool thread execute end."); +} + +void MkdirAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, MkdirCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, MkdirCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, MkdirCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (MkdirCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, MkdirCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MkdirCB->cbBase.asyncWork)); + delete MkdirCB; + MkdirCB = nullptr; + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete end."); +} + +void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, MkdirCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, MkdirCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MkdirCB->cbBase.asyncWork)); + delete MkdirCB; + MkdirCB = nullptr; + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete end."); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 7d5045a6..bec4dfc3 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -30,6 +30,22 @@ namespace AppExecFwk { void OpenFileExecuteCB(napi_env env, void *data); void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data); void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_CreateFile(napi_env env, napi_callback_info info); + napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCreateFileCB *createFileCB); + napi_value CreateFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCreateFileCB *createFileCB); + napi_value CreateFilePromise(napi_env env, FileAccessHelperCreateFileCB *createFileCB); + void CreateFileExecuteCB(napi_env env, void *data); + void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Mkdir(napi_env env, napi_callback_info info); + napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB); + napi_value MkdirAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMkdirCB *mkdirCB); + napi_value MkdirPromise(napi_env env, FileAccessHelperMkdirCB *mkdirCB); + void MkdirExecuteCB(napi_env env, void *data); + void MkdirAsyncCompleteCB(napi_env env, napi_status status, void *data); + void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data); } } #endif \ No newline at end of file -- Gitee From 240bbdcd40154f37dbdf1ee033815f8ebda97eed Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Tue, 10 May 2022 18:09:24 +0800 Subject: [PATCH 08/22] add delete and move and rename Signed-off-by: wangjianqiang --- .../include/file_access_helper.h | 9 +- .../file_extension/src/file_access_helper.cpp | 98 ++- .../file_access_module/file_access_common.h | 28 +- .../napi_fileaccess_helper.cpp | 591 +++++++++++++++++- .../napi_fileaccess_helper.h | 26 +- 5 files changed, 690 insertions(+), 62 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 44860630..18bb32b1 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -44,21 +44,20 @@ public: int OpenFile(Uri &uri, const std::string &mode); int CreateFile(Uri &parentUri, const std::string &displayName, Uri &newFileUri); int Mkdir(Uri &parentUri, const std::string &displayName, Uri &newDirUri); + int Delete(Uri &selectFileUri); + int Move(Uri &sourceFileUri, Uri &targetParentUri, Uri &newFileUri); + int Rename(Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); private: FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, const sptr &fileExtProxy); void AddFileAccessDeathRecipient(const sptr &token); void OnSchedulerDied(const wptr &remote); - bool CheckUriParam(const Uri &uri); - bool CheckOhosUri(const Uri &uri); sptr token_ = {}; - std::shared_ptr context_ = nullptr; AAFwk::Want want_ = {}; - // std::shared_ptr uri_ = nullptr; sptr fileExtProxy_ = nullptr; - bool isSystemCaller_ = false; static std::mutex oplock_; + bool isSystemCaller_ = false; sptr callerDeathRecipient_ = nullptr; sptr fileExtConnection_ = nullptr; }; diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index c1f1a058..a8c77c7d 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -106,7 +106,6 @@ bool FileAccessHelper::Release() } HILOG_INFO("tag dsa FileAccessHelper::Release after DisconnectFileExtAbility."); fileExtProxy_ = nullptr; - // uri_.reset(); HILOG_INFO("tag dsa %{public}s called end", __func__); return true; } @@ -115,10 +114,6 @@ int FileAccessHelper::OpenFile(Uri &uri, const std::string &mode) { HILOG_INFO("tag dsa %{public}s begin.", __func__); int fd = INVALID_VALUE; - if (!CheckUriParam(uri)) { - HILOG_ERROR("tag dsa %{public}s called. CheckUriParam uri failed", __func__); - return fd; - } HILOG_INFO("tag dsa FileAccessHelper::OpenFile before ConnectFileExtAbility."); if (!fileExtConnection_->IsExtAbilityConnected()) { @@ -145,10 +140,6 @@ int FileAccessHelper::CreateFile(Uri &parentUri, const std::string &displayName, { HILOG_INFO("tag dsa FileAccessHelper::CreateFile start."); int index = INVALID_VALUE; - if (!CheckUriParam(parentUri)) { - HILOG_ERROR("tag dsa%{public}s called. CheckUriParam uri failed", __func__); - return index; - } HILOG_INFO("tag dsa FileAccessHelper::CreateFile before ConnectDataShareExtAbility."); if (!fileExtConnection_->IsExtAbilityConnected()) { @@ -176,10 +167,6 @@ int FileAccessHelper::Mkdir(Uri &parentUri, const std::string &displayName, Uri { HILOG_INFO("tag dsa FileAccessHelper::Mkdir start."); int index = INVALID_VALUE; - if (!CheckUriParam(parentUri)) { - HILOG_ERROR("tag dsa%{public}s called. CheckUriParam uri failed", __func__); - return index; - } HILOG_INFO("tag dsa FileAccessHelper::Mkdir before ConnectDataShareExtAbility."); if (!fileExtConnection_->IsExtAbilityConnected()) { @@ -203,39 +190,84 @@ int FileAccessHelper::Mkdir(Uri &parentUri, const std::string &displayName, Uri return index; } -bool FileAccessHelper::CheckUriParam(const Uri &uri) +int FileAccessHelper::Delete(Uri &selectFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - Uri checkUri(uri.ToString()); - if (!CheckOhosUri(checkUri)) { - HILOG_ERROR("tag dsa FileAccessHelper::CheckUriParam failed. CheckOhosUri uri failed"); - return false; + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Delete before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Delete after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); } + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + index = fileExtProxy_->Delete(selectFileUri); HILOG_INFO("tag dsa %{public}s begin.", __func__); - return true; + return index; } -bool FileAccessHelper::CheckOhosUri(const Uri &uri) +int FileAccessHelper::Move(Uri &sourceFileUri, Uri &targetParentUri, Uri &newFileUri) { - HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa FileAccessHelper::Move start."); + int index = INVALID_VALUE; - return true; + HILOG_INFO("tag dsa FileAccessHelper::Move before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Move after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } - Uri checkUri(uri.ToString()); - std::vector segments; - checkUri.GetPathSegments(segments); - if (segments.empty()) { - HILOG_ERROR("tag dsa FileAccessHelper::CheckOhosUri failed. There is no segments in the uri."); - return false; + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; } - if (checkUri.GetPath() == "") { - HILOG_ERROR("tag dsa FileAccessHelper::CheckOhosUri failed. The path in the uri is empty."); - return false; + HILOG_INFO("tag dsa FileAccessHelper::Move before fileExtProxy_->Move."); + index = fileExtProxy_->Move(sourceFileUri, targetParentUri, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::Move end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Move end. newFileUri = %{public}s", newFileUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::Rename(Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::Rename start."); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Rename before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); } - HILOG_INFO("tag dsa %{public}s end.", __func__); - return true; + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Rename after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Rename before fileExtProxy_->Rename."); + index = fileExtProxy_->Rename(sourceFileUri, displayName, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::Rename end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Rename end. newFileUri = %{public}s", newFileUri.ToString().c_str()); + return index; } void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h index 2ae8bc15..0f1b371a 100644 --- a/interfaces/kits/napi/file_access_module/file_access_common.h +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -46,7 +46,6 @@ struct FileAccessHelperCreateFileCB { FileAccessHelper *fileAccessHelper = nullptr; std::string parentUri; std::string name; - std::string newFileUri; std::string result; int execResult; }; @@ -56,7 +55,32 @@ struct FileAccessHelperMkdirCB { FileAccessHelper *fileAccessHelper = nullptr; std::string parentUri; std::string name; - std::string newDirUri; + std::string result; + int execResult; +}; + +struct FileAccessHelperDeleteCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string selectFileUri; + int result = 0; + int execResult; +}; + +struct FileAccessHelperMoveCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string sourceFileUri; + std::string targetParentUri; + std::string result; + int execResult; +}; + +struct FileAccessHelperRenameCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string sourceFileUri; + std::string displayName; std::string result; int execResult; }; diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index ef8fe930..caa05bc2 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -135,6 +135,9 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("openFile", NAPI_OpenFile), DECLARE_NAPI_FUNCTION("mkdir", NAPI_Mkdir), DECLARE_NAPI_FUNCTION("createFile", NAPI_CreateFile), + DECLARE_NAPI_FUNCTION("delete", NAPI_Delete), + DECLARE_NAPI_FUNCTION("move", NAPI_Move), + DECLARE_NAPI_FUNCTION("rename", NAPI_Rename), }; napi_value cons = nullptr; NAPI_CALL(env, @@ -173,7 +176,7 @@ napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info) napi_status status = AbilityRuntime::IsStageContext(env, argv[PARAM0], isStageMode); if (status != napi_ok || !isStageMode) { HILOG_INFO("tag dsa FA Model"); - return thisVar; + return nullptr; } else { auto context = OHOS::AbilityRuntime::GetStageModeContext(env, argv[PARAM0]); NAPI_ASSERT(env, context != nullptr, "FileAccessHelperConstructor: failed to get native context"); @@ -404,8 +407,8 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCreateFileCB *createFileCB) { HILOG_INFO("tag dsa %{public}s,called", __func__); - size_t argcAsync = ARGS_FOUR; - const size_t argcPromise = ARGS_THREE; + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; napi_value args[ARGS_MAX_COUNT] = {nullptr}; napi_value ret = 0; @@ -430,19 +433,13 @@ napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelpe HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, createFileCB->name.c_str()); } - NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); - if (valuetype == napi_string) { - createFileCB->newFileUri = NapiValueToStringUtf8(env, args[PARAM2]); - HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, createFileCB->newFileUri.c_str()); - } - FileAccessHelper *objectInfo = nullptr; napi_unwrap(env, thisVar, (void **)&objectInfo); HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); createFileCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { - ret = CreateFileAsync(env, args, ARGS_THREE, createFileCB); + ret = CreateFileAsync(env, args, ARGS_TWO, createFileCB); } else { ret = CreateFilePromise(env, createFileCB); } @@ -516,7 +513,8 @@ void CreateFileExecuteCB(napi_env env, void *data) CreateFileCB->execResult = INVALID_PARAMETER; if (!CreateFileCB->parentUri.empty()) { OHOS::Uri parentUri(CreateFileCB->parentUri); - OHOS::Uri newFileUri(CreateFileCB->newFileUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); int err = CreateFileCB->fileAccessHelper->CreateFile(parentUri, CreateFileCB->name, newFileUri); CreateFileCB->result = newFileUri.ToString(); CreateFileCB->execResult = err; @@ -598,8 +596,8 @@ napi_value NAPI_Mkdir(napi_env env, napi_callback_info info) napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB) { HILOG_INFO("tag dsa%{public}s,called", __func__); - size_t argcAsync = ARGS_FOUR; - const size_t argcPromise = ARGS_THREE; + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; napi_value args[ARGS_MAX_COUNT] = {nullptr}; napi_value ret = 0; @@ -624,19 +622,13 @@ napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdi HILOG_INFO("tag dsa%{public}s,mode=%{public}s", __func__, mkdirCB->name.c_str()); } - NAPI_CALL(env, napi_typeof(env, args[PARAM2], &valuetype)); - if (valuetype == napi_string) { - mkdirCB->newDirUri = NapiValueToStringUtf8(env, args[PARAM2]); - HILOG_INFO("tag dsa%{public}s,mode=%{public}s", __func__, mkdirCB->newDirUri.c_str()); - } - FileAccessHelper *objectInfo = nullptr; napi_unwrap(env, thisVar, (void **)&objectInfo); HILOG_INFO("tag dsa%{public}s,FileAccessHelper objectInfo", __func__); mkdirCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { - ret = MkdirAsync(env, args, ARGS_THREE, mkdirCB); + ret = MkdirAsync(env, args, ARGS_TWO, mkdirCB); } else { ret = MkdirPromise(env, mkdirCB); } @@ -710,7 +702,8 @@ void MkdirExecuteCB(napi_env env, void *data) MkdirCB->execResult = INVALID_PARAMETER; if (!MkdirCB->parentUri.empty()) { OHOS::Uri parentUri(MkdirCB->parentUri); - OHOS::Uri newDirUri(MkdirCB->newDirUri); + std::string newDir = ""; + OHOS::Uri newDirUri(newDir); int err = MkdirCB->fileAccessHelper->Mkdir(parentUri, MkdirCB->name, newDirUri); MkdirCB->result = newDirUri.ToString(); MkdirCB->execResult = err; @@ -760,5 +753,561 @@ void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data) MkdirCB = nullptr; HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete end."); } + +napi_value NAPI_Delete(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperDeleteCB *deleteCB = new (std::nothrow) FileAccessHelperDeleteCB; + if (deleteCB == nullptr) { + HILOG_ERROR("%{public}s, deleteCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + deleteCB->cbBase.cbInfo.env = env; + deleteCB->cbBase.asyncWork = nullptr; + deleteCB->cbBase.deferred = nullptr; + deleteCB->cbBase.ability = nullptr; + + napi_value ret = DeleteWrap(env, info, deleteCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (deleteCB != nullptr) { + delete deleteCB; + deleteCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_TWO; + const size_t argcPromise = ARGS_ONE; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + deleteCB->selectFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + deleteCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + HILOG_INFO("tag dsa DeleteWrap_DeleteAsync start"); + ret = DeleteAsync(env, args, ARGS_ONE, deleteCB); + HILOG_INFO("tag dsa DeleteWrap_DeleteAsync ,end"); + } else { + HILOG_INFO("tag dsa DeleteWrap_DeletePromise start"); + ret = DeletePromise(env, deleteCB); + HILOG_INFO("tag dsa DeleteWrap_DeletePromise,end"); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value DeleteAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || deleteCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &deleteCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + DeleteExecuteCB, + DeleteAsyncCompleteCB, + (void *)deleteCB, + &deleteCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, deleteCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value DeletePromise(napi_env env, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (deleteCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + deleteCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + DeleteExecuteCB, + DeletePromiseCompleteCB, + (void *)deleteCB, + &deleteCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, deleteCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void DeleteExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, worker pool thread execute."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + if (DeleteCB->fileAccessHelper != nullptr) { + DeleteCB->execResult = INVALID_PARAMETER; + if (!DeleteCB->selectFileUri.empty()) { + OHOS::Uri selectFileUri(DeleteCB->selectFileUri); + DeleteCB->result = DeleteCB->fileAccessHelper->Delete(selectFileUri); + DeleteCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Delete, worker pool thread execute end."); +} + +void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, DeleteCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, DeleteCB->execResult); + napi_create_int32(env, DeleteCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (DeleteCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, DeleteCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, DeleteCB->cbBase.asyncWork)); + delete DeleteCB; + DeleteCB = nullptr; + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete end."); +} + +void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, DeleteCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, DeleteCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, DeleteCB->cbBase.asyncWork)); + delete DeleteCB; + DeleteCB = nullptr; + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete end."); +} + +napi_value NAPI_Move(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperMoveCB *moveCB = new (std::nothrow) FileAccessHelperMoveCB; + if (moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, moveCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + moveCB->cbBase.cbInfo.env = env; + moveCB->cbBase.asyncWork = nullptr; + moveCB->cbBase.deferred = nullptr; + moveCB->cbBase.ability = nullptr; + + napi_value ret = MoveWrap(env, info, moveCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (moveCB != nullptr) { + delete moveCB; + moveCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + moveCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, moveCB->sourceFileUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + moveCB->targetParentUri = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, moveCB->targetParentUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + moveCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = MoveAsync(env, args, ARGS_TWO, moveCB); + } else { + ret = MovePromise(env, moveCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value MoveAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &moveCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MoveExecuteCB, + MoveAsyncCompleteCB, + (void *)moveCB, + &moveCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, moveCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value MovePromise(napi_env env, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + moveCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MoveExecuteCB, + MovePromiseCompleteCB, + (void *)moveCB, + &moveCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, moveCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void MoveExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, worker pool thread execute."); + FileAccessHelperMoveCB *MoveCB = static_cast(data); + if (MoveCB->fileAccessHelper != nullptr) { + MoveCB->execResult = INVALID_PARAMETER; + if (!MoveCB->sourceFileUri.empty()) { + OHOS::Uri sourceFileUri(MoveCB->sourceFileUri); + OHOS::Uri targetParentUri(MoveCB->targetParentUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = MoveCB->fileAccessHelper->Move(sourceFileUri, targetParentUri, newFileUri); + MoveCB->result = newFileUri.ToString(); + MoveCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Move, worker pool thread execute end."); +} + +void MoveAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, main event thread complete."); + FileAccessHelperCreateFileCB *MoveCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, MoveCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, MoveCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, MoveCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (MoveCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, MoveCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MoveCB->cbBase.asyncWork)); + delete MoveCB; + MoveCB = nullptr; + HILOG_INFO("tag dsa NAPI_Move, main event thread complete end."); +} + +void MovePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, main event thread complete."); + FileAccessHelperCreateFileCB *MoveCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, MoveCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, MoveCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MoveCB->cbBase.asyncWork)); + delete MoveCB; + MoveCB = nullptr; + HILOG_INFO("tag dsa NAPI_Move, main event thread complete end."); +} + +napi_value NAPI_Rename(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperRenameCB *renameCB = new (std::nothrow) FileAccessHelperRenameCB; + if (renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, renameCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + renameCB->cbBase.cbInfo.env = env; + renameCB->cbBase.asyncWork = nullptr; + renameCB->cbBase.deferred = nullptr; + renameCB->cbBase.ability = nullptr; + + napi_value ret = RenameWrap(env, info, renameCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (renameCB != nullptr) { + delete renameCB; + renameCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + renameCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, renameCB->sourceFileUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + renameCB->displayName = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, renameCB->displayName.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + renameCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = RenameAsync(env, args, ARGS_TWO, renameCB); + } else { + ret = RenamePromise(env, renameCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value RenameAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &renameCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenameAsyncCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value RenamePromise(napi_env env, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + renameCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenamePromiseCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void RenameExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, worker pool thread execute."); + FileAccessHelperRenameCB *renameCB = static_cast(data); + if (renameCB->fileAccessHelper != nullptr) { + renameCB->execResult = INVALID_PARAMETER; + if (!renameCB->sourceFileUri.empty()) { + OHOS::Uri sourceFileUri(renameCB->sourceFileUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = renameCB->fileAccessHelper->Rename(sourceFileUri, renameCB->displayName, newFileUri); + renameCB->result = newFileUri.ToString(); + renameCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Rename, worker pool thread execute end."); +} + +void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete."); + FileAccessHelperRenameCB *RenameCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, RenameCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, RenameCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, RenameCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (RenameCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, RenameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, RenameCB->cbBase.asyncWork)); + delete RenameCB; + RenameCB = nullptr; + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete end."); +} + +void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete."); + FileAccessHelperRenameCB *RenameCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, RenameCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, RenameCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, RenameCB->cbBase.asyncWork)); + delete RenameCB; + RenameCB = nullptr; + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete end."); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index bec4dfc3..67ab39da 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -38,7 +38,7 @@ namespace AppExecFwk { void CreateFileExecuteCB(napi_env env, void *data); void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data); void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data); - + napi_value NAPI_Mkdir(napi_env env, napi_callback_info info); napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB); napi_value MkdirAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMkdirCB *mkdirCB); @@ -46,6 +46,30 @@ namespace AppExecFwk { void MkdirExecuteCB(napi_env env, void *data); void MkdirAsyncCompleteCB(napi_env env, napi_status status, void *data); void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Delete(napi_env env, napi_callback_info info); + napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDeleteCB *deleteCB); + napi_value DeleteAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperDeleteCB *deleteCB); + napi_value DeletePromise(napi_env env, FileAccessHelperDeleteCB *deleteCB); + void DeleteExecuteCB(napi_env env, void *data); + void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data); + void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Move(napi_env env, napi_callback_info info); + napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveCB *moveCB); + napi_value MoveAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMoveCB *moveCB); + napi_value MovePromise(napi_env env, FileAccessHelperMoveCB *moveCB); + void MoveExecuteCB(napi_env env, void *data); + void MoveAsyncCompleteCB(napi_env env, napi_status status, void *data); + void MovePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Rename(napi_env env, napi_callback_info info); + napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRenameCB *renameCB); + napi_value RenameAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperRenameCB *renameCB); + napi_value RenamePromise(napi_env env, FileAccessHelperRenameCB *renameCB); + void RenameExecuteCB(napi_env env, void *data); + void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data); + void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data); } } #endif \ No newline at end of file -- Gitee From 859c159804db2fafb0b2c981e5d0e8d537146046 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Tue, 10 May 2022 18:54:39 +0800 Subject: [PATCH 09/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0delete,move,rename?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../file_extension/include/file_ext_ability.h | 4 +- .../file_extension/include/file_ext_proxy.h | 6 +- .../file_extension/include/file_ext_stub.h | 3 + .../include/file_ext_stub_impl.h | 3 + .../file_extension/include/ifile_ext_base.h | 29 ++-- .../include/js_file_ext_ability.h | 3 + .../file_extension/src/file_ext_ability.cpp | 24 ++- .../file_extension/src/file_ext_proxy.cpp | 137 +++++++++++++++++- .../file_extension/src/file_ext_stub.cpp | 103 +++++++++++++ .../file_extension/src/file_ext_stub_impl.cpp | 50 +++++-- .../src/js_file_ext_ability.cpp | 106 ++++++++++++-- .../FileExtensionAbility.ts | 25 +++- .../napi/file_ext_ability/file_ext_ability.js | 28 +++- 13 files changed, 462 insertions(+), 59 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index afca031c..8b360087 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -33,10 +33,12 @@ public: static FileExtAbility* Create(const std::unique_ptr& runtime); - virtual int OpenFile(const Uri &uri, const std::string &mode); virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); + virtual int Delete(const Uri &sourceFileUri); + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri); + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/include/file_ext_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h index 5c4997cb..235c2d8f 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_proxy.h +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -30,9 +30,9 @@ public: virtual int OpenFile(const Uri &uri, const std::string &mode) override; virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; - // virtual int Delete(const Uri &sourceFileUri) override; - // virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; - // virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; + virtual int Delete(const Uri &sourceFileUri) override; + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h index 4aa94680..25653f2f 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -32,6 +32,9 @@ private: ErrCode CmdOpenFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdCreateFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdMkdir(MessageParcel &data, MessageParcel &reply); + ErrCode CmdDelete(MessageParcel &data, MessageParcel &reply); + ErrCode CmdMove(MessageParcel &data, MessageParcel &reply); + ErrCode CmdRename(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (FileExtStub::*)(MessageParcel &data, MessageParcel &reply); std::map stubFuncMap_; }; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index fb837012..1259ef32 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -37,6 +37,9 @@ public: int OpenFile(const Uri &uri, const std::string &mode) override; int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Delete(const Uri &sourceFileUri) override; + int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; private: std::shared_ptr GetOwner(); diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index fbcdc11d..b9462c0b 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -27,31 +27,20 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IFileExtBase"); enum { - CMD_GET_FILE_TYPES = 1, - CMD_OPEN_FILE = 2, - CMD_OPEN_RAW_FILE = 3, - CMD_INSERT = 4, - CMD_UPDATE = 5, - CMD_DELETE = 6, - CMD_QUERY = 7, - CMD_GET_TYPE = 8, - CMD_BATCH_INSERT = 9, - CMD_REGISTER_OBSERVER = 10, - CMD_UNREGISTER_OBSERVER = 11, - CMD_NOTIFY_CHANGE = 12, - CMD_NORMALIZE_URI = 13, - CMD_DENORMALIZE_URI = 14, - CMD_EXECUTE_BATCH = 15, - CMD_CREATE_FILE = 16, - CMD_MKDIR = 17 + CMD_OPEN_FILE = 1, + CMD_CREATE_FILE = 2, + CMD_MKDIR = 3, + CMD_DELETE = 4, + CMD_MOVE = 5, + CMD_RENAME = 6 }; virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; - // virtual int Delete(const Uri &sourceFileUri) = 0; - // virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) = 0; - // virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) = 0; + virtual int Delete(const Uri &sourceFileUri) = 0; + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) = 0; + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) = 0; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h index 815a23ab..0d3d04e3 100644 --- a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -45,6 +45,9 @@ public: int OpenFile(const Uri &uri, const std::string &mode) override; int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Delete(const Uri &sourceFileUri) override; + int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; private: NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0); diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index 011ea8a7..d30fea55 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -66,15 +66,35 @@ int FileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayN { HILOG_INFO("tag dsa %{public}s begin.", __func__); HILOG_INFO("tag dsa %{public}s end.", __func__); - return 123; + return 0; } int FileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); HILOG_INFO("tag dsa %{public}s end.", __func__); - return 124; + return 0; +} + +int FileExtAbility::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; } +int FileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index 05583518..35addda7 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -125,7 +125,7 @@ int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Ur } if (!data.WriteString(displayName)) { - HILOG_ERROR("tag dsa fail to WriteString mode"); + HILOG_ERROR("tag dsa fail to WriteString displayName"); return -1; } @@ -162,5 +162,140 @@ int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Ur return ret; } +int FileExtProxy::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_DELETE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret == -1) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d", __func__, ret); + return ret; +} + +int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return -1; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return -1; + } + + if (!data.WriteParcelable(&targetParentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable targetParentUri"); + return -1; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return -1; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MOVE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return -2; + } + + int ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + +int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return -1; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return -1; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString displayName"); + return -1; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return -1; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_RENAME, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return -2; + } + + // fd = reply.ReadFileDescriptor(); + int ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} } // namespace AAFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index c10124fd..cbbb5afb 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -25,6 +25,9 @@ FileExtStub::FileExtStub() stubFuncMap_[CMD_OPEN_FILE] = &FileExtStub::CmdOpenFile; stubFuncMap_[CMD_CREATE_FILE] = &FileExtStub::CmdCreateFile; stubFuncMap_[CMD_MKDIR] = &FileExtStub::CmdMkdir; + stubFuncMap_[CMD_DELETE] = &FileExtStub::CmdDelete; + stubFuncMap_[CMD_MOVE] = &FileExtStub::CmdMove; + stubFuncMap_[CMD_RENAME] = &FileExtStub::CmdRename; } FileExtStub::~FileExtStub() @@ -160,5 +163,105 @@ ErrCode FileExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply) return NO_ERROR; } +ErrCode FileExtStub::CmdDelete(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Delete(*uri); + if (ret < 0) { + HILOG_ERROR("tag dsa Delete fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor ret"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} +ErrCode FileExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr sourceFileUri(data.ReadParcelable()); + if (sourceFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub sourceFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr targetParentUri(data.ReadParcelable()); + if (targetParentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub targetParentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Move(*sourceFileUri, *targetParentUri, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Move fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} +ErrCode FileExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr sourceFileUri(data.ReadParcelable()); + if (sourceFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub sourceFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Rename(*sourceFileUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Rename fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp index 00fc3e59..4826ea06 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp @@ -29,17 +29,6 @@ int FileExtStubImpl::OpenFile(const Uri &uri, const std::string &mode) { HILOG_INFO("tag dsa %{public}s begin.", __func__); int ret = -1; - /* - std::function syncTaskFunc = [=, &ret, client = sptr(this)]() { - auto extension = client->GetOwner(); - if (extension == nullptr) { - HILOG_ERROR("tag dsa %{public}s end failed.", __func__); - return; - } - ret = extension->OpenFile(uri, mode); - }; - uvQueue_->SyncCall(syncTaskFunc); - */ auto extension = GetOwner(); if (extension == nullptr) { HILOG_ERROR("tag dsa %{public}s end failed.", __func__); @@ -78,5 +67,44 @@ int FileExtStubImpl::Mkdir(const Uri &parentUri, const std::string &displayName, return ret; } +int FileExtStubImpl::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Delete(sourceFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} +int FileExtStubImpl::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Move(sourceFileUri, targetParentUri, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} +int FileExtStubImpl::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Rename(sourceFileUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index f0cdf053..ff28249d 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -35,7 +35,6 @@ namespace AbilityRuntime { namespace { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; -constexpr size_t ARGC_THREE = 3; } using namespace OHOS::AppExecFwk; @@ -197,7 +196,6 @@ void JsFileExtAbility::GetSrcPath(std::string &srcPath) int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - // auto ret = FileExtAbility::OpenFile(uri, mode); HandleScope handleScope(jsRuntime_); napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); @@ -230,14 +228,11 @@ int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displa napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); napi_value napiDisplayName = nullptr; napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); - napi_value napiNewFileUri = nullptr; - napi_create_string_utf8(env, newFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiNewFileUri); - + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); - NativeValue* nativeNewFileUri = reinterpret_cast(napiNewFileUri); - NativeValue* argv[] = {nativeParentUri, nativeDisplayName, nativeNewFileUri}; - NativeValue* nativeResult = CallObjectMethod("createFile", argv, ARGC_THREE); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("createFile", argv, ARGC_TWO); int ret = -1; if (nativeResult == nullptr) { HILOG_ERROR("tag dsa %{public}s call createFile with return null.", __func__); @@ -265,14 +260,12 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); napi_value napiDisplayName = nullptr; napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); - napi_value napiNewFileUri = nullptr; - napi_create_string_utf8(env, newFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiNewFileUri); + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); - NativeValue* nativeNewFileUri = reinterpret_cast(napiNewFileUri); - NativeValue* argv[] = {nativeParentUri, nativeDisplayName, nativeNewFileUri}; - NativeValue* nativeResult = CallObjectMethod("mkdir", argv, ARGC_THREE); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("mkdir", argv, ARGC_TWO); int ret = -1; if (nativeResult == nullptr) { HILOG_ERROR("tag dsa %{public}s call Mkdir with return null.", __func__); @@ -286,7 +279,92 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName ret = 110; //测试用值 } newFileUri = Uri(uriStr); - // ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiUri); + + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* argv[] = {nativeUri}; + NativeValue* nativeResult = CallObjectMethod("delete", argv, ARGC_ONE); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call delete with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + +int JsFileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiSourceFileUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiSourceFileUri); + napi_value napiTargetParentUri = nullptr; + napi_create_string_utf8(env, targetParentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiTargetParentUri); + + NativeValue* nativeSourceFileUri = reinterpret_cast(napiSourceFileUri); + NativeValue* nativeTargetParentUri = reinterpret_cast(napiTargetParentUri); + NativeValue* argv[] = {nativeSourceFileUri, nativeTargetParentUri}; + NativeValue* nativeResult = CallObjectMethod("move", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call move with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call move with return empty.", __func__); + return ret; + } else { + ret = 118; //测试用值 + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiSourceFileUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiSourceFileUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + + NativeValue* nativeSourceFileUri = reinterpret_cast(napiSourceFileUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* argv[] = {nativeSourceFileUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("rename", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call rename with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call rename with return empty.", __func__); + return ret; + } else { + ret = 119; //测试用值 + } + newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); return ret; } diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index cac2015c..dd23fecc 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -11,15 +11,28 @@ export default class FileExtAbility extends Extension { return 50; } - createFile(parentUri, displayName, newFileUri) { - console.log('js server tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName + ',newFileUri:' + newFileUri); + createFile(parentUri, displayName) { + console.log('js server tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName ); return "filetest://fileext.share/temp/test/CreateFile001.txt"; - // return 112; } - mkdir(parentUri, displayName, newFileUri) { - console.log('js server tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName + ',newFileUri:' + newFileUri); + mkdir(parentUri, displayName) { + console.log('js server tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName); return "filetest://fileext.share/temp/test/Mkdir001"; - // return 110; + } + + delete(sourceFileUri) { + console.log('js server tag dsa delete, sourceFileUri:' + sourceFileUri); + return 132; + } + + move(sourceFileUri, targetParentUri) { + console.log('js server tag dsa move, sourceFileUri:' + sourceFileUri + ',targetParentUri:' + targetParentUri); + return "filetest://fileext.share/temp/test/move001.xl"; + } + + rename(sourceFileUri, displayName) { + console.log('js server tag dsa rename, sourceFileUri:' + sourceFileUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/rename001.ttt"; } }; \ No newline at end of file diff --git a/interfaces/kits/napi/file_ext_ability/file_ext_ability.js b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js index b966cb34..7ecdc1bc 100644 --- a/interfaces/kits/napi/file_ext_ability/file_ext_ability.js +++ b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js @@ -19,7 +19,33 @@ class FileExtensionAbility { } openFile(uri, mode) { - console.log('js c++ tag dsa openFile, uri:' + uri); + console.log('js c++ tag dsa openFile, uri:' + uri + ',mode: ' + mode); + return 0; + } + + createFile(parentUri, displayName) { + console.log('js c++ tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName ); + return "filetest://fileext.share/temp/test/CreateFile000.txt"; + } + + mkdir(parentUri, displayName) { + console.log('js c++ tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/Mkdir000"; + } + + delete(sourceFileUri) { + console.log('js c++ tag dsa delete, sourceFileUri:' + sourceFileUri); + return 0; + } + + move(sourceFileUri, targetParentUri) { + console.log('js c++ tag dsa move, sourceFileUri:' + sourceFileUri + ',targetParentUri:' + targetParentUri); + return "filetest://fileext.share/temp/test/move000.xl"; + } + + rename(sourceFileUri, displayName) { + console.log('js c++ tag dsa rename, sourceFileUri:' + sourceFileUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/rename000.ttt"; } } -- Gitee From 36a96b8aa48d939ce15710df84579abb05839e8f Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Wed, 11 May 2022 17:16:06 +0800 Subject: [PATCH 10/22] add closeFile Signed-off-by: wangjianqiang --- .../include/file_access_helper.h | 1 + .../file_extension/src/file_access_helper.cpp | 26 +++ .../file_access_module/file_access_common.h | 9 + .../napi_fileaccess_helper.cpp | 190 ++++++++++++++++++ .../napi_fileaccess_helper.h | 8 + 5 files changed, 234 insertions(+) diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 18bb32b1..9cdfc593 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -47,6 +47,7 @@ public: int Delete(Uri &selectFileUri); int Move(Uri &sourceFileUri, Uri &targetParentUri, Uri &newFileUri); int Rename(Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); + int CloseFile(int fd, const std::string &uri); private: FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, const sptr &fileExtProxy); diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index a8c77c7d..eababd69 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -270,6 +270,32 @@ int FileAccessHelper::Rename(Uri &sourceFileUri, const std::string &displayName, return index; } +int FileAccessHelper::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Delete before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Delete after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + index = fileExtProxy_->CloseFile(fd, uri); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return index; +} + void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) { HILOG_INFO("tag dsa %{public}s begin.", __func__); diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h index 0f1b371a..ffe83648 100644 --- a/interfaces/kits/napi/file_access_module/file_access_common.h +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -84,6 +84,15 @@ struct FileAccessHelperRenameCB { std::string result; int execResult; }; + +struct FileAccessHelperCloseFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + int fd; + std::string uri; + int result; + int execResult; +}; } } #endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index caa05bc2..2ab5b8e5 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -41,6 +41,12 @@ std::string NapiValueToStringUtf8(napi_env env, napi_value value) return UnwrapStringFromJS(env, value, result); } +int NapiValueToInt32Utf8(napi_env env, napi_value value) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + int result = 0; + return UnwrapInt32FromJS(env, value, result); +} /* bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector &result) { @@ -138,6 +144,7 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("delete", NAPI_Delete), DECLARE_NAPI_FUNCTION("move", NAPI_Move), DECLARE_NAPI_FUNCTION("rename", NAPI_Rename), + DECLARE_NAPI_FUNCTION("closeFile", NAPI_CloseFile), }; napi_value cons = nullptr; NAPI_CALL(env, @@ -1309,5 +1316,188 @@ void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data) RenameCB = nullptr; HILOG_INFO("tag dsa NAPI_Rename, main event thread complete end."); } + +napi_value NAPI_CloseFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCloseFileCB *closeFileCB = new (std::nothrow) FileAccessHelperCloseFileCB; + if (closeFileCB == nullptr) { + HILOG_ERROR("%{public}s, closeFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + closeFileCB->cbBase.cbInfo.env = env; + closeFileCB->cbBase.asyncWork = nullptr; + closeFileCB->cbBase.deferred = nullptr; + closeFileCB->cbBase.ability = nullptr; + + napi_value ret = CloseFileWrap(env, info, closeFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (closeFileCB != nullptr) { + delete closeFileCB; + closeFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CloseFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_number) { + closeFileCB->fd = NapiValueToInt32Utf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,fd=%d", __func__, closeFileCB->fd); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + closeFileCB->uri = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, closeFileCB->uri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + closeFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = CloseFileAsync(env, args, ARGS_TWO, closeFileCB); + } else { + ret = CloseFilePromise(env, closeFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CloseFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || closeFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &closeFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CloseFileExecuteCB, + CloseFileAsyncCompleteCB, + (void *)closeFileCB, + &closeFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, closeFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value CloseFilePromise(napi_env env, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (closeFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + closeFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CloseFileExecuteCB, + CloseFilePromiseCompleteCB, + (void *)closeFileCB, + &closeFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, closeFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void CloseFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, worker pool thread execute."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + if (CloseFileCB->fileAccessHelper != nullptr) { + CloseFileCB->execResult = INVALID_PARAMETER; + if (CloseFileCB->fd!=NO_ERROR) { + CloseFileCB->result = CloseFileCB->fileAccessHelper->CloseFile(CloseFileCB->fd, CloseFileCB->uri); + CloseFileCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_CloseFile, worker pool thread execute end."); +} + +void CloseFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CloseFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, CloseFileCB->execResult); + napi_create_int32(env, CloseFileCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (CloseFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, CloseFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CloseFileCB->cbBase.asyncWork)); + delete CloseFileCB; + CloseFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete end."); +} + +void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, CloseFileCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, CloseFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CloseFileCB->cbBase.asyncWork)); + delete CloseFileCB; + CloseFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete end."); +} + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 67ab39da..196398d5 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -70,6 +70,14 @@ namespace AppExecFwk { void RenameExecuteCB(napi_env env, void *data); void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data); void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_CloseFile(napi_env env, napi_callback_info info); + napi_value CloseFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCloseFileCB *closeFileCB); + napi_value CloseFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCloseFileCB *closeFileCB); + napi_value CloseFilePromise(napi_env env, FileAccessHelperCloseFileCB *closeFileCB); + void CloseFileExecuteCB(napi_env env, void *data); + void CloseFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data); } } #endif \ No newline at end of file -- Gitee From 27014925299eb36295f90a97626f180c9b2276de Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 11 May 2022 17:18:35 +0800 Subject: [PATCH 11/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0closeFile=E4=BF=AE?= =?UTF-8?q?=E6=94=B9openFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../file_extension/include/file_ext_ability.h | 1 + .../file_extension/include/file_ext_proxy.h | 1 + .../file_extension/include/file_ext_stub.h | 1 + .../include/file_ext_stub_impl.h | 2 + .../file_extension/include/ifile_ext_base.h | 12 +- .../include/js_file_ext_ability.h | 1 + .../file_extension/src/file_ext_ability.cpp | 7 ++ .../file_extension/src/file_ext_proxy.cpp | 103 ++++++++++++------ .../file_extension/src/file_ext_stub.cpp | 35 +++++- .../file_extension/src/file_ext_stub_impl.cpp | 14 +++ .../src/js_file_ext_ability.cpp | 33 +++++- .../FileExtensionAbility.ts | 7 +- 12 files changed, 174 insertions(+), 43 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index 8b360087..c98a352a 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -34,6 +34,7 @@ public: static FileExtAbility* Create(const std::unique_ptr& runtime); virtual int OpenFile(const Uri &uri, const std::string &mode); + virtual int CloseFile(int fd, const std::string &uri); virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); virtual int Delete(const Uri &sourceFileUri); diff --git a/frameworks/innerkits/file_extension/include/file_ext_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h index 235c2d8f..1a3d2126 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_proxy.h +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -28,6 +28,7 @@ public: virtual ~FileExtProxy() {} virtual int OpenFile(const Uri &uri, const std::string &mode) override; + virtual int CloseFile(int fd, const std::string &uri) override; virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; virtual int Delete(const Uri &sourceFileUri) override; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h index 25653f2f..356e4cff 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -30,6 +30,7 @@ public: int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: ErrCode CmdOpenFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdCloseFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdCreateFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdMkdir(MessageParcel &data, MessageParcel &reply); ErrCode CmdDelete(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index 1259ef32..f8db689c 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -35,7 +35,9 @@ public: virtual ~FileExtStubImpl() {} int OpenFile(const Uri &uri, const std::string &mode) override; + int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int CloseFile(int fd, const std::string &uri) override; int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int Delete(const Uri &sourceFileUri) override; int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index b9462c0b..7720a484 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -28,14 +28,16 @@ public: enum { CMD_OPEN_FILE = 1, - CMD_CREATE_FILE = 2, - CMD_MKDIR = 3, - CMD_DELETE = 4, - CMD_MOVE = 5, - CMD_RENAME = 6 + CMD_CLOSE_FILE = 2, + CMD_CREATE_FILE = 3, + CMD_MKDIR = 4, + CMD_DELETE = 5, + CMD_MOVE = 6, + CMD_RENAME = 7 }; virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; + virtual int CloseFile(int fd, const std::string &uri) = 0; virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; virtual int Delete(const Uri &sourceFileUri) = 0; diff --git a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h index 0d3d04e3..ae17d3e4 100644 --- a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -43,6 +43,7 @@ public: sptr OnConnect(const AAFwk::Want &want) override; int OpenFile(const Uri &uri, const std::string &mode) override; + int CloseFile(int fd, const std::string &uri) override; int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int Delete(const Uri &sourceFileUri) override; diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index d30fea55..f5fcdb9a 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -62,6 +62,13 @@ int FileExtAbility::OpenFile(const Uri &uri, const std::string &mode) return 0; } +int FileExtAbility::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + int FileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index 35addda7..3224b86f 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -47,8 +47,7 @@ int FileExtProxy::OpenFile(const Uri &uri, const std::string &mode) return fd; } - // fd = reply.ReadFileDescriptor(); - fd = reply.ReadInt32(); + fd = reply.ReadFileDescriptor(); if (fd == -1) { HILOG_ERROR("tag dsa fail to ReadFileDescriptor fd"); return fd; @@ -58,28 +57,67 @@ int FileExtProxy::OpenFile(const Uri &uri, const std::string &mode) return fd; } +int FileExtProxy::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteInt32(fd)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return ret; + } + + if (!data.WriteString(uri)) { + HILOG_ERROR("tag dsa fail to WriteString uri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_CLOSE_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa CloseFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d", __func__, ret); + return ret; +} + int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; MessageParcel data; if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); - return -1; + return ret; } if (!data.WriteParcelable(&parentUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); - return -1; + return ret; } if (!data.WriteString(displayName)) { HILOG_ERROR("tag dsa fail to WriteString mode"); - return -1; + return ret; } if (!data.WriteParcelable(&newFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); - return -1; + return ret; } MessageParcel reply; @@ -87,11 +125,10 @@ int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayNam int32_t err = Remote()->SendRequest(CMD_CREATE_FILE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); - return -2; + return ret; } - // fd = reply.ReadFileDescriptor(); - int ret = reply.ReadInt32(); + ret = reply.ReadInt32(); if (ret < 0) { HILOG_ERROR("tag dsa fail to ReadInt32 ret"); return ret; @@ -101,6 +138,7 @@ int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayNam if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); ret = -1; + return ret; } HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); @@ -113,25 +151,26 @@ int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayNam int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; MessageParcel data; if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); - return -1; + return ret; } if (!data.WriteParcelable(&parentUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); - return -1; + return ret; } if (!data.WriteString(displayName)) { HILOG_ERROR("tag dsa fail to WriteString displayName"); - return -1; + return ret; } if (!data.WriteParcelable(&newFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); - return -1; + return ret; } MessageParcel reply; @@ -139,11 +178,10 @@ int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Ur int32_t err = Remote()->SendRequest(CMD_MKDIR, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); - return -2; + return ret; } - // fd = reply.ReadFileDescriptor(); - int ret = reply.ReadInt32(); + ret = reply.ReadInt32(); if (ret < 0) { HILOG_ERROR("tag dsa fail to ReadInt32 ret"); return ret; @@ -153,6 +191,7 @@ int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Ur if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); ret = -1; + return ret; } HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); @@ -186,7 +225,7 @@ int FileExtProxy::Delete(const Uri &sourceFileUri) } ret = reply.ReadInt32(); - if (ret == -1) { + if (ret < 0) { HILOG_ERROR("tag dsa fail to ReadInt32 ret"); return ret; } @@ -198,25 +237,26 @@ int FileExtProxy::Delete(const Uri &sourceFileUri) int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; MessageParcel data; if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); - return -1; + return ret; } if (!data.WriteParcelable(&sourceFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); - return -1; + return ret; } if (!data.WriteParcelable(&targetParentUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable targetParentUri"); - return -1; + return ret; } if (!data.WriteParcelable(&newFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); - return -1; + return ret; } MessageParcel reply; @@ -224,10 +264,10 @@ int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri int32_t err = Remote()->SendRequest(CMD_MOVE, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); - return -2; + return ret; } - int ret = reply.ReadInt32(); + ret = reply.ReadInt32(); if (ret < 0) { HILOG_ERROR("tag dsa fail to ReadInt32 ret"); return ret; @@ -237,6 +277,7 @@ int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); ret = -1; + return ret; } HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); @@ -249,25 +290,26 @@ int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; MessageParcel data; if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); - return -1; + return ret; } if (!data.WriteParcelable(&sourceFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); - return -1; + return ret; } if (!data.WriteString(displayName)) { HILOG_ERROR("tag dsa fail to WriteString displayName"); - return -1; + return ret; } if (!data.WriteParcelable(&newFileUri)) { HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); - return -1; + return ret; } MessageParcel reply; @@ -275,11 +317,10 @@ int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayNam int32_t err = Remote()->SendRequest(CMD_RENAME, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); - return -2; + return ret; } - // fd = reply.ReadFileDescriptor(); - int ret = reply.ReadInt32(); + ret = reply.ReadInt32(); if (ret < 0) { HILOG_ERROR("tag dsa fail to ReadInt32 ret"); return ret; @@ -288,7 +329,7 @@ int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayNam std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); - ret = -1; + return ret; } HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index cbbb5afb..336cbad5 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -23,6 +23,7 @@ FileExtStub::FileExtStub() { HILOG_INFO("tag dsa %{public}s begin.", __func__); stubFuncMap_[CMD_OPEN_FILE] = &FileExtStub::CmdOpenFile; + stubFuncMap_[CMD_CLOSE_FILE] = &FileExtStub::CmdCloseFile; stubFuncMap_[CMD_CREATE_FILE] = &FileExtStub::CmdCreateFile; stubFuncMap_[CMD_MKDIR] = &FileExtStub::CmdMkdir; stubFuncMap_[CMD_DELETE] = &FileExtStub::CmdDelete; @@ -74,9 +75,9 @@ ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) HILOG_ERROR("tag dsa OpenFile fail, fd is %{pubilc}d", fd); return ERR_INVALID_VALUE; } + HILOG_INFO("tag dsa %{public}s retutn fd: %{public}d.", __func__, fd); - // if (!reply.WriteFileDescriptor(fd)) { - if (!reply.WriteInt32(fd)) { + if (!reply.WriteFileDescriptor(fd)) { HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); return ERR_INVALID_VALUE; } @@ -84,6 +85,34 @@ ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) return NO_ERROR; } +ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = data.ReadInt32(); + if (fd < 0) { + HILOG_ERROR("tag dsa FileExtStub fd is invalid"); + return ERR_INVALID_VALUE; + } + std::string uri = data.ReadString(); + if (uri.empty()) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = CloseFile(fd, uri); + if (ret < 0) { + HILOG_ERROR("tag dsa CloseFile fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor ret"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} + ErrCode FileExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("tag dsa %{public}s begin.", __func__); @@ -185,6 +214,7 @@ ErrCode FileExtStub::CmdDelete(MessageParcel &data, MessageParcel &reply) HILOG_INFO("tag dsa %{public}s end.", __func__); return NO_ERROR; } + ErrCode FileExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("tag dsa %{public}s begin.", __func__); @@ -224,6 +254,7 @@ ErrCode FileExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); return NO_ERROR; } + ErrCode FileExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("tag dsa %{public}s begin.", __func__); diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp index 4826ea06..ced9fe21 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp @@ -39,6 +39,20 @@ int FileExtStubImpl::OpenFile(const Uri &uri, const std::string &mode) return ret; } +int FileExtStubImpl::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->CloseFile(fd, uri); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} + int FileExtStubImpl::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index ff28249d..cb338721 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -218,6 +218,31 @@ int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) return ret; } +int JsFileExtAbility::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiFd = nullptr; + napi_create_int32(env, fd, &napiFd); + napi_value napiUri = nullptr; + napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &napiUri); + + NativeValue* nativeFd = reinterpret_cast(napiFd); + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* argv[] = {nativeFd, nativeUri}; + NativeValue* nativeResult = CallObjectMethod("closeFile", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call closeFile with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) { HILOG_INFO("tag dsa %{public}s begin.", __func__); @@ -243,7 +268,7 @@ int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 1112; //测试用值 + ret = 0; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -276,7 +301,7 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 110; //测试用值 + ret = 0; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -330,7 +355,7 @@ int JsFileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, HILOG_ERROR("tag dsa %{public}s call move with return empty.", __func__); return ret; } else { - ret = 118; //测试用值 + ret = 0; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -362,7 +387,7 @@ int JsFileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call rename with return empty.", __func__); return ret; } else { - ret = 119; //测试用值 + ret = 0; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index dd23fecc..ee98988e 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -8,7 +8,12 @@ export default class FileExtAbility extends Extension { openFile(uri, mode) { console.log('js server tag dsa openFile, uri:' + uri + ',mode:' + mode); - return 50; + return 2; + } + + closeFile(fd, uri) { + console.log('js server tag dsa delete, fd:' + fd + ",uri: " + uri); + return 268; } createFile(parentUri, displayName) { -- Gitee From c601398f1931dd6cb48733f6c967d3f8017f268b Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Wed, 11 May 2022 17:23:44 +0800 Subject: [PATCH 12/22] delete space line Signed-off-by: chenkai008 --- frameworks/innerkits/file_extension/include/file_ext_stub_impl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index f8db689c..3caf1ca0 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -35,7 +35,6 @@ public: virtual ~FileExtStubImpl() {} int OpenFile(const Uri &uri, const std::string &mode) override; - int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; int CloseFile(int fd, const std::string &uri) override; int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; -- Gitee From 7b09d524594be9a2aff9f519951c019922d541d4 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 13 May 2022 15:03:28 +0800 Subject: [PATCH 13/22] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- LICENSE | 176 ++++++++++++++++++ .../file_extension/src/file_ext_ability.cpp | 1 - .../file_extension/src/file_ext_proxy.cpp | 5 +- .../file_extension/src/file_ext_stub.cpp | 4 +- .../src/js_file_ext_ability.cpp | 41 +--- .../FileExtensionAbility.ts | 4 +- 6 files changed, 187 insertions(+), 44 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..2bb9ad24 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index f5fcdb9a..e137a15f 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -50,7 +50,6 @@ void FileExtAbility::Init(const std::shared_ptr &record, const sptr &token) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - //ExtensionBase::Init(record, application, handler, token); ExtensionBase<>::Init(record, application, handler, token); HILOG_INFO("tag dsa %{public}s end.", __func__); } diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index 3224b86f..085c7b41 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -67,8 +67,8 @@ int FileExtProxy::CloseFile(int fd, const std::string &uri) return ret; } - if (!data.WriteInt32(fd)) { - HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + if (!data.WriteFileDescriptor(fd)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); return ret; } @@ -329,6 +329,7 @@ int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayNam std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; return ret; } diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index 336cbad5..e81ddb29 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -88,7 +88,7 @@ ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - int fd = data.ReadInt32(); + int fd = data.ReadFileDescriptor(); if (fd < 0) { HILOG_ERROR("tag dsa FileExtStub fd is invalid"); return ERR_INVALID_VALUE; @@ -106,7 +106,7 @@ ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) } if (!reply.WriteInt32(ret)) { - HILOG_ERROR("tag dsa fail to WriteFileDescriptor ret"); + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); return ERR_INVALID_VALUE; } HILOG_INFO("tag dsa %{public}s end.", __func__); diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index cb338721..f564f016 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -66,7 +66,6 @@ void JsFileExtAbility::Init(const std::shared_ptr &record, moduleName.append("::").append(abilityInfo_->name); HILOG_INFO("tag dsa %{public}s module:%{public}s, srcPath:%{public}s.", __func__, moduleName.c_str(), srcPath.c_str()); HandleScope handleScope(jsRuntime_); - //auto& engine = jsRuntime_.GetNativeEngine(); jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath); if (jsObj_ == nullptr) { @@ -79,38 +78,6 @@ void JsFileExtAbility::Init(const std::shared_ptr &record, HILOG_ERROR("tag dsa Failed to get JsFileExtAbility object"); return; } - - /* - auto context = GetContext(); - if (context == nullptr) { - HILOG_ERROR("tag dsa Failed to get context"); - return; - } - - HILOG_INFO("tag dsa JsFileExtAbility::Init CreateJsDataShareExtAbilityContext."); - NativeValue* contextObj = CreateJsDataShareExtAbilityContext(engine, context); - auto contextRef = jsRuntime_.LoadSystemModule("application.DataShareExtensionAbilityContext", - &contextObj, ARGC_ONE); - contextObj = contextRef->Get(); - HILOG_INFO("tag dsa JsFileExtAbility::Init Bind."); - context->Bind(jsRuntime_, contextRef.release()); - HILOG_INFO("tag dsa JsFileExtAbility::SetProperty."); - obj->SetProperty("context", contextObj); - - auto nativeObj = ConvertNativeValueTo(contextObj); - if (nativeObj == nullptr) { - HILOG_ERROR("tag dsa Failed to get datashare extension ability native object"); - return; - } - - HILOG_INFO("tag dsa Set datashare extension ability context"); - - nativeObj->SetNativePointer(new std::weak_ptr(context), - [](NativeEngine*, void* data, void*) { - HILOG_INFO("tag dsa Finalizer for weak_ptr datashare extension ability context is called"); - delete static_cast*>(data); - }, nullptr); - */ HILOG_INFO("tag dsa JsFileExtAbility::Init end."); } @@ -268,7 +235,7 @@ int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 0; + ret = NO_ERROR; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -301,7 +268,7 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 0; + ret = NO_ERROR; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -355,7 +322,7 @@ int JsFileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, HILOG_ERROR("tag dsa %{public}s call move with return empty.", __func__); return ret; } else { - ret = 0; + ret = NO_ERROR; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); @@ -387,7 +354,7 @@ int JsFileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call rename with return empty.", __func__); return ret; } else { - ret = 0; + ret = NO_ERROR; } newFileUri = Uri(uriStr); HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index ee98988e..2555e833 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -13,7 +13,7 @@ export default class FileExtAbility extends Extension { closeFile(fd, uri) { console.log('js server tag dsa delete, fd:' + fd + ",uri: " + uri); - return 268; + return 0; } createFile(parentUri, displayName) { @@ -28,7 +28,7 @@ export default class FileExtAbility extends Extension { delete(sourceFileUri) { console.log('js server tag dsa delete, sourceFileUri:' + sourceFileUri); - return 132; + return 0; } move(sourceFileUri, targetParentUri) { -- Gitee From cfd8f0bd1fbe9f5f6a69d93566b3c909f083e667 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 13 May 2022 15:39:18 +0800 Subject: [PATCH 14/22] =?UTF-8?q?=E6=B7=BB=E5=8A=A0context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- frameworks/innerkits/file_extension/BUILD.gn | 1 + .../file_extension/include/file_ext_ability.h | 15 ++++++- .../include/file_ext_ability_context.h | 44 +++++++++++++++++++ .../file_extension/src/file_ext_ability.cpp | 12 ++++- .../src/file_ext_ability_context.cpp | 25 +++++++++++ .../src/file_ext_ability_module_loader.cpp | 5 +++ 6 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 frameworks/innerkits/file_extension/include/file_ext_ability_context.h create mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp diff --git a/frameworks/innerkits/file_extension/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn index aba44d06..7f951331 100644 --- a/frameworks/innerkits/file_extension/BUILD.gn +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("file_extension_ability_kit") { sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_access_helper.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_connection.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp", diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index c98a352a..7387a637 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -17,11 +17,14 @@ #define FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H #include "extension_base.h" +#include "file_ext_ability_context.h" namespace OHOS { namespace AbilityRuntime { class Runtime; -class FileExtAbility : public ExtensionBase<> { +class FileExtAbility; +using CreatorFunc = std::function& runtime)>; +class FileExtAbility : public ExtensionBase { public: FileExtAbility() = default; virtual ~FileExtAbility() = default; @@ -40,6 +43,16 @@ public: virtual int Delete(const Uri &sourceFileUri); virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri); virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); + + + /** + * @brief Set a creator function. + * + * @param creator The function for create a file extension ability. + */ + static void SetCreator(const CreatorFunc& creator); +private: + static CreatorFunc creator_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability_context.h b/frameworks/innerkits/file_extension/include/file_ext_ability_context.h new file mode 100644 index 00000000..e2ad5d1c --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_ability_context.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#ifndef FILE_EXT_ABILITY_CONTEXT_H +#define FILE_EXT_ABILITY_CONTEXT_H + +#include "extension_context.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace AbilityRuntime; +/** + * @brief context supply for file + * + */ +class FileExtAbilityContext : public ExtensionContext { +public: + FileExtAbilityContext(); + virtual ~FileExtAbilityContext() = default; + + using SelfType = FileExtAbilityContext; + static const size_t CONTEXT_TYPE_ID; + +protected: + bool IsContext(size_t contextTypeId) override + { + return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); + } +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FILE_EXT_ABILITY_CONTEXT_H \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index e137a15f..faa58242 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -25,12 +25,21 @@ namespace OHOS { namespace AbilityRuntime { using namespace OHOS::AppExecFwk; + +CreatorFunc FileExtAbility::creator_ = nullptr; +void FileExtAbility::SetCreator(const CreatorFunc& creator) +{ + creator_ = creator; +} FileExtAbility* FileExtAbility::Create(const std::unique_ptr& runtime) { HILOG_INFO("tag dsa %{public}s begin.", __func__); if (!runtime) { return new FileExtAbility(); } + if (creator_) { + return creator_(runtime); + } HILOG_INFO("tag dsa FileExtAbility::Create runtime"); switch (runtime->GetLanguage()) { case Runtime::Language::JS: @@ -50,7 +59,7 @@ void FileExtAbility::Init(const std::shared_ptr &record, const sptr &token) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - ExtensionBase<>::Init(record, application, handler, token); + ExtensionBase::Init(record, application, handler, token); HILOG_INFO("tag dsa %{public}s end.", __func__); } @@ -102,5 +111,6 @@ int FileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displayN HILOG_INFO("tag dsa %{public}s end.", __func__); return 0; } + } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp new file mode 100644 index 00000000..68b83294 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ + +#include "file_ext_ability_context.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace AbilityRuntime; +const size_t FileExtAbilityContext::CONTEXT_TYPE_ID(std::hash {} ("FileExtAbilityContext")); + +FileExtAbilityContext::FileExtAbilityContext() {} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp index 96ae5c4a..99be2507 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp @@ -31,4 +31,9 @@ extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtens HILOG_INFO("tag dsa %{public}s begin.", __func__); return &FileExtAbilityModuleLoader::GetInstance(); } + +extern "C" __attribute__((visibility("default"))) void SetCreator(const CreatorFunc& creator) +{ + return FileExtAbility::SetCreator(creator); +} } // namespace OHOS::AbilityRuntime \ No newline at end of file -- Gitee From 8fb34d37b444eb996ad515d08a7af5453380a5d6 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 13 May 2022 16:02:10 +0800 Subject: [PATCH 15/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../innerkits/file_extension/include/file_ext_stub_impl.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index 3caf1ca0..9f964953 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -27,10 +27,7 @@ using AbilityRuntime::JsFileExtAbility; class FileExtStubImpl : public FileExtStub { public: explicit FileExtStubImpl(const std::shared_ptr& extension, napi_env env) - : extension_(extension) - { - //uvQueue_ = std::make_shared(env); - } + : extension_(extension) {} virtual ~FileExtStubImpl() {} @@ -46,9 +43,8 @@ private: private: std::shared_ptr extension_; - //std::shared_ptr uvQueue_; }; } // namespace AppExecFwk } // namespace OHOS -#endif // OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H -- Gitee From 593378f61112a84908b9868fd0a88b5b77e29d89 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Fri, 13 May 2022 16:30:04 +0800 Subject: [PATCH 16/22] add release Signed-off-by: wangjianqiang --- .../file_access_module/file_access_common.h | 6 + .../napi_fileaccess_helper.cpp | 160 ++++++++++++++++++ .../napi_fileaccess_helper.h | 8 + 3 files changed, 174 insertions(+) diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h index ffe83648..a00c843d 100644 --- a/interfaces/kits/napi/file_access_module/file_access_common.h +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -93,6 +93,12 @@ struct FileAccessHelperCloseFileCB { int result; int execResult; }; + +struct FileAccessHelperReleaseCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + bool result = false; +}; } } #endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 2ab5b8e5..5ea94ced 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -145,6 +145,7 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("move", NAPI_Move), DECLARE_NAPI_FUNCTION("rename", NAPI_Rename), DECLARE_NAPI_FUNCTION("closeFile", NAPI_CloseFile), + DECLARE_NAPI_FUNCTION("release", NAPI_Release), }; napi_value cons = nullptr; NAPI_CALL(env, @@ -1499,5 +1500,164 @@ void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data) HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete end."); } +napi_value NAPI_Release(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperReleaseCB *releaseCB = new (std::nothrow) FileAccessHelperReleaseCB; + if (releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, releaseCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + releaseCB->cbBase.cbInfo.env = env; + releaseCB->cbBase.asyncWork = nullptr; + releaseCB->cbBase.deferred = nullptr; + + napi_value ret = ReleaseWrap(env, info, releaseCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + delete releaseCB; + releaseCB = nullptr; + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value ReleaseWrap(napi_env env, napi_callback_info info, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_ONE; + const size_t argcPromise = ARGS_ZERO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa FileAccessHelper ReleaseWrap objectInfo = %{public}p", objectInfo); + releaseCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = ReleaseAsync(env, args, PARAM0, releaseCB); + } else { + ret = ReleasePromise(env, releaseCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value ReleaseAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &releaseCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ReleaseExecuteCB, + ReleaseAsyncCompleteCB, + (void *)releaseCB, + &releaseCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, releaseCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value ReleasePromise(napi_env env, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + releaseCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ReleaseExecuteCB, + ReleasePromiseCompleteCB, + (void *)releaseCB, + &releaseCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, releaseCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void ReleaseExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, worker pool thread execute."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + if (releaseCB->fileAccessHelper != nullptr) { + releaseCB->result = releaseCB->fileAccessHelper->Release(); + } else { + HILOG_ERROR("tag dsa NAPI_Release, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Release, worker pool thread execute end."); +} + +void ReleaseAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, main event thread complete."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, releaseCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + napi_get_boolean(env, releaseCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (releaseCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, releaseCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, releaseCB->cbBase.asyncWork)); + delete releaseCB; + releaseCB = nullptr; + HILOG_INFO("tag dsa NAPI_Release, main event thread complete end."); +} + +void ReleasePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, main event thread complete."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + napi_value result = nullptr; + napi_get_boolean(env, releaseCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, releaseCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, releaseCB->cbBase.asyncWork)); + delete releaseCB; + releaseCB = nullptr; + HILOG_INFO("tag dsa NAPI_Release, main event thread complete end."); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 196398d5..ef7d1faa 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -78,6 +78,14 @@ namespace AppExecFwk { void CloseFileExecuteCB(napi_env env, void *data); void CloseFileAsyncCompleteCB(napi_env env, napi_status status, void *data); void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Release(napi_env env, napi_callback_info info); + napi_value ReleaseWrap(napi_env env, napi_callback_info info, FileAccessHelperReleaseCB *releaseCB); + napi_value ReleaseAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperReleaseCB *releaseCB); + napi_value ReleasePromise(napi_env env, FileAccessHelperReleaseCB *releaseCB); + void ReleaseExecuteCB(napi_env env, void *data); + void ReleaseAsyncCompleteCB(napi_env env, napi_status status, void *data); + void ReleasePromiseCompleteCB(napi_env env, napi_status status, void *data); } } #endif \ No newline at end of file -- Gitee From ebb40c74259fee5f5043bd7f2293980724984e74 Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 13 May 2022 16:58:45 +0800 Subject: [PATCH 17/22] =?UTF-8?q?=E4=BF=AE=E6=94=B9context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- frameworks/innerkits/file_extension/BUILD.gn | 1 - .../innerkits/file_extension/include/file_ext_ability.h | 4 +--- frameworks/innerkits/file_extension/src/file_ext_ability.cpp | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/frameworks/innerkits/file_extension/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn index 7f951331..aba44d06 100644 --- a/frameworks/innerkits/file_extension/BUILD.gn +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -51,7 +51,6 @@ ohos_shared_library("file_extension_ability_kit") { sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_access_helper.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability.cpp", - "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_connection.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp", "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp", diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h index 7387a637..8c9aaa70 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_ability.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -17,14 +17,13 @@ #define FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H #include "extension_base.h" -#include "file_ext_ability_context.h" namespace OHOS { namespace AbilityRuntime { class Runtime; class FileExtAbility; using CreatorFunc = std::function& runtime)>; -class FileExtAbility : public ExtensionBase { +class FileExtAbility : public ExtensionBase<> { public: FileExtAbility() = default; virtual ~FileExtAbility() = default; @@ -44,7 +43,6 @@ public: virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri); virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); - /** * @brief Set a creator function. * diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index faa58242..0610ef52 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -59,7 +59,7 @@ void FileExtAbility::Init(const std::shared_ptr &record, const sptr &token) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - ExtensionBase::Init(record, application, handler, token); + ExtensionBase<>::Init(record, application, handler, token); HILOG_INFO("tag dsa %{public}s end.", __func__); } -- Gitee From 930d10eeb069598697c808b0a92cfc1ec7a22538 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Fri, 13 May 2022 16:58:47 +0800 Subject: [PATCH 18/22] delete exegesis Signed-off-by: wangjianqiang --- .../include/file_access_helper.h | 2 -- .../file_extension/src/file_access_helper.cpp | 1 - .../napi_fileaccess_helper.cpp | 34 ++++++------------- .../napi_fileaccess_helper.h | 1 - 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 9cdfc593..a3f7e3ca 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -20,7 +20,6 @@ #include #include -#include "context.h" #include "file_ext_connection.h" #include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" #include "ifile_ext_base.h" @@ -57,7 +56,6 @@ private: sptr token_ = {}; AAFwk::Want want_ = {}; sptr fileExtProxy_ = nullptr; - static std::mutex oplock_; bool isSystemCaller_ = false; sptr callerDeathRecipient_ = nullptr; sptr fileExtConnection_ = nullptr; diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index eababd69..579490f3 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -24,7 +24,6 @@ namespace { constexpr int INVALID_VALUE = -1; } // namespace -std::mutex FileAccessHelper::oplock_; FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, const sptr &fileExtProxy) diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index 2ab5b8e5..afc7c913 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -47,12 +47,6 @@ int NapiValueToInt32Utf8(napi_env env, napi_value value) int result = 0; return UnwrapInt32FromJS(env, value, result); } -/* -bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector &result) -{ - return UnwrapArrayStringFromJS(env, param, result); -} -*/ } std::list> g_fileAccessHelperList; @@ -374,7 +368,7 @@ void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data) void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) { - HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete."); + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete."); FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); napi_value result = nullptr; napi_create_int32(env, OpenFileCB->result, &result); @@ -382,7 +376,7 @@ void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); delete OpenFileCB; OpenFileCB = nullptr; - HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete end."); + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete end."); } napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) @@ -431,13 +425,13 @@ napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelpe NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { createFileCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); - HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, createFileCB->parentUri.c_str()); + HILOG_INFO("tag dsa %{public}s,parentUri=%{public}s", __func__, createFileCB->parentUri.c_str()); } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); if (valuetype == napi_string) { createFileCB->name = NapiValueToStringUtf8(env, args[PARAM1]); - HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, createFileCB->name.c_str()); + HILOG_INFO("tag dsa %{public}s,name=%{public}s", __func__, createFileCB->name.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -546,7 +540,6 @@ void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CreateFileCB->cbBase.cbInfo.callback, &callback)); result[PARAM0] = GetCallbackErrorValue(env, CreateFileCB->execResult); - // napi_create_int32(env, CreateFileCB->result, &result[PARAM1]); NAPI_CALL_RETURN_VOID( env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); @@ -565,7 +558,6 @@ void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data) HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete."); FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); napi_value result = nullptr; - // napi_create_int32(env, CreateFileCB->result, &result); NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, CreateFileCB->cbBase.deferred, result)); NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CreateFileCB->cbBase.asyncWork)); @@ -620,13 +612,13 @@ napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdi NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { mkdirCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); - HILOG_INFO("tag dsa%{public}s,uri=%{public}s", __func__, mkdirCB->parentUri.c_str()); + HILOG_INFO("tag dsa%{public}s,parentUri=%{public}s", __func__, mkdirCB->parentUri.c_str()); } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); if (valuetype == napi_string) { mkdirCB->name = NapiValueToStringUtf8(env, args[PARAM1]); - HILOG_INFO("tag dsa%{public}s,mode=%{public}s", __func__, mkdirCB->name.c_str()); + HILOG_INFO("tag dsa%{public}s,name=%{public}s", __func__, mkdirCB->name.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -807,7 +799,7 @@ napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDel NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { deleteCB->selectFileUri = NapiValueToStringUtf8(env, args[PARAM0]); - HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); + HILOG_INFO("tag dsa %{public}s,selectFileUri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -816,13 +808,9 @@ napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDel deleteCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { - HILOG_INFO("tag dsa DeleteWrap_DeleteAsync start"); ret = DeleteAsync(env, args, ARGS_ONE, deleteCB); - HILOG_INFO("tag dsa DeleteWrap_DeleteAsync ,end"); } else { - HILOG_INFO("tag dsa DeleteWrap_DeletePromise start"); ret = DeletePromise(env, deleteCB); - HILOG_INFO("tag dsa DeleteWrap_DeletePromise,end"); } HILOG_INFO("tag dsa %{public}s,end", __func__); return ret; @@ -988,13 +976,13 @@ napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveC NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { moveCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); - HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, moveCB->sourceFileUri.c_str()); + HILOG_INFO("tag dsa %{public}s,sourceFileUri=%{public}s", __func__, moveCB->sourceFileUri.c_str()); } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); if (valuetype == napi_string) { moveCB->targetParentUri = NapiValueToStringUtf8(env, args[PARAM1]); - HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, moveCB->targetParentUri.c_str()); + HILOG_INFO("tag dsa %{public}s,targetParentUri=%{public}s", __func__, moveCB->targetParentUri.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -1176,13 +1164,13 @@ napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRen NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); if (valuetype == napi_string) { renameCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); - HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, renameCB->sourceFileUri.c_str()); + HILOG_INFO("tag dsa %{public}s,sourceFileUri=%{public}s", __func__, renameCB->sourceFileUri.c_str()); } NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); if (valuetype == napi_string) { renameCB->displayName = NapiValueToStringUtf8(env, args[PARAM1]); - HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, renameCB->displayName.c_str()); + HILOG_INFO("tag dsa %{public}s,displayName=%{public}s", __func__, renameCB->displayName.c_str()); } FileAccessHelper *objectInfo = nullptr; diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index 196398d5..823ee774 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -16,7 +16,6 @@ #ifndef FILE_ACCESS_NAPI_H #define FILE_ACCESS_NAPI_H -//#include "n_exporter.h" #include "file_access_common.h" namespace OHOS { -- Gitee From e1d075207019a38e7d8ca334aaf3ece297a65aac Mon Sep 17 00:00:00 2001 From: chenkai008 Date: Fri, 13 May 2022 17:00:21 +0800 Subject: [PATCH 19/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenkai008 --- .../include/file_ext_ability_context.h | 44 ------------------- .../src/file_ext_ability_context.cpp | 25 ----------- 2 files changed, 69 deletions(-) delete mode 100644 frameworks/innerkits/file_extension/include/file_ext_ability_context.h delete mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability_context.h b/frameworks/innerkits/file_extension/include/file_ext_ability_context.h deleted file mode 100644 index e2ad5d1c..00000000 --- a/frameworks/innerkits/file_extension/include/file_ext_ability_context.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device 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. - */ - -#ifndef FILE_EXT_ABILITY_CONTEXT_H -#define FILE_EXT_ABILITY_CONTEXT_H - -#include "extension_context.h" - -namespace OHOS { -namespace AppExecFwk { -using namespace AbilityRuntime; -/** - * @brief context supply for file - * - */ -class FileExtAbilityContext : public ExtensionContext { -public: - FileExtAbilityContext(); - virtual ~FileExtAbilityContext() = default; - - using SelfType = FileExtAbilityContext; - static const size_t CONTEXT_TYPE_ID; - -protected: - bool IsContext(size_t contextTypeId) override - { - return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); - } -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FILE_EXT_ABILITY_CONTEXT_H \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp deleted file mode 100644 index 68b83294..00000000 --- a/frameworks/innerkits/file_extension/src/file_ext_ability_context.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device 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. - */ - -#include "file_ext_ability_context.h" - -namespace OHOS { -namespace AppExecFwk { -using namespace AbilityRuntime; -const size_t FileExtAbilityContext::CONTEXT_TYPE_ID(std::hash {} ("FileExtAbilityContext")); - -FileExtAbilityContext::FileExtAbilityContext() {} -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file -- Gitee From 9c2a0a34c201952a16e162eb1dcee79e23e87cb9 Mon Sep 17 00:00:00 2001 From: wangjianqiang Date: Fri, 13 May 2022 17:16:21 +0800 Subject: [PATCH 20/22] delete exegesis Signed-off-by: wangjianqiang --- .../file_extension/src/file_access_helper.cpp | 12 ++++++------ .../file_access_module/napi_fileaccess_helper.cpp | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index 579490f3..6a62e048 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -155,10 +155,10 @@ int FileAccessHelper::CreateFile(Uri &parentUri, const std::string &displayName, return index; } - HILOG_INFO("tag dsa FileAccessHelper::CreateFile before fileExtProxy_->Mkdir."); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile before fileExtProxy_->CreateFile."); index = fileExtProxy_->CreateFile(parentUri, displayName, newFileUri); HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. index = %{public}d", index); - HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. newDirUri = %{public}s", newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. newDirUri = %{public}s", newFileUri.ToString().c_str()); return index; } @@ -209,7 +209,7 @@ int FileAccessHelper::Delete(Uri &selectFileUri) return index; } - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + HILOG_INFO("tag dsa FileAccessHelper::Delete before fileExtProxy_->Delete."); index = fileExtProxy_->Delete(selectFileUri); HILOG_INFO("tag dsa %{public}s begin.", __func__); return index; @@ -274,12 +274,12 @@ int FileAccessHelper::CloseFile(int fd, const std::string &uri) HILOG_INFO("tag dsa %{public}s begin.", __func__); int index = INVALID_VALUE; - HILOG_INFO("tag dsa FileAccessHelper::Delete before ConnectFileExtAbility."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before ConnectFileExtAbility."); if (!fileExtConnection_->IsExtAbilityConnected()) { fileExtConnection_->ConnectFileExtAbility(want_, token_); } fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); - HILOG_INFO("tag dsa FileAccessHelper::Delete after ConnectFileExtAbility."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile after ConnectFileExtAbility."); if (isSystemCaller_ && fileExtProxy_) { AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); } @@ -289,7 +289,7 @@ int FileAccessHelper::CloseFile(int fd, const std::string &uri) return index; } - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before fileExtProxy_->CloseFile."); index = fileExtProxy_->CloseFile(fd, uri); HILOG_INFO("tag dsa %{public}s begin.", __func__); return index; diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp index afc7c913..3db9f1b5 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -253,7 +253,7 @@ napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperO FileAccessHelper *objectInfo = nullptr; napi_unwrap(env, thisVar, (void **)&objectInfo); - HILOG_INFO("tag dsa %{public}s,DataShareHelper objectInfo", __func__); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); openFileCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { @@ -384,7 +384,7 @@ napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) HILOG_INFO("tag dsa %{public}s,called", __func__); FileAccessHelperCreateFileCB *createFileCB = new (std::nothrow) FileAccessHelperCreateFileCB; if (createFileCB == nullptr) { - HILOG_ERROR("tag dsa %{public}s, openFileCB == nullptr.", __func__); + HILOG_ERROR("tag dsa %{public}s, createFileCB == nullptr.", __func__); return WrapVoidToJS(env); } createFileCB->cbBase.cbInfo.env = env; @@ -707,7 +707,7 @@ void MkdirExecuteCB(napi_env env, void *data) MkdirCB->result = newDirUri.ToString(); MkdirCB->execResult = err; } else { - HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper parentUri is empty"); } } else { HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper == nullptr"); @@ -885,7 +885,7 @@ void DeleteExecuteCB(napi_env env, void *data) DeleteCB->result = DeleteCB->fileAccessHelper->Delete(selectFileUri); DeleteCB->execResult = NO_ERROR; } else { - HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper selectFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper == nullptr"); @@ -1072,7 +1072,7 @@ void MoveExecuteCB(napi_env env, void *data) MoveCB->result = newFileUri.ToString(); MoveCB->execResult = err; } else { - HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper sourceFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper == nullptr"); @@ -1259,7 +1259,7 @@ void RenameExecuteCB(napi_env env, void *data) renameCB->result = newFileUri.ToString(); renameCB->execResult = err; } else { - HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper sourceFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper == nullptr"); @@ -1442,7 +1442,7 @@ void CloseFileExecuteCB(napi_env env, void *data) CloseFileCB->result = CloseFileCB->fileAccessHelper->CloseFile(CloseFileCB->fd, CloseFileCB->uri); CloseFileCB->execResult = NO_ERROR; } else { - HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper fd != NO_ERROR"); } } else { HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper == nullptr"); -- Gitee From 50447f4ec82b18ecbd839c0d30e515ecddd9a28f Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Mon, 16 May 2022 09:43:43 +0800 Subject: [PATCH 21/22] add file attribute Signed-off-by: linjun9528 --- frameworks/innerkits/BUILD.gn | 2 +- .../file_extension/include/ifile_ext_base.h | 37 +++++++++++++++++- .../src/js_file_ext_ability.cpp | 5 ++- .../src/main/ets/Application/AbilityStage.ts | 14 +++++++ .../FileExtensionAbility.ts | 14 +++++++ .../src/main/ets/MainAbility/MainAbility.ts | 14 +++++++ .../entry/src/main/ets/pages/index.ets | 14 +++++++ .../{medialib.p7b => fileextension.p7b} | Bin 3528 -> 3400 bytes .../innerkits/signature/openharmony_sx.p7b | Bin 3544 -> 0 bytes .../file_access_module/file_access_common.h | 14 +++++++ .../napi_fileaccess_helper.cpp | 8 ++-- .../napi_fileaccess_helper.h | 4 +- .../native_fileaccess_module.cpp | 4 +- 13 files changed, 118 insertions(+), 12 deletions(-) rename frameworks/innerkits/signature/{medialib.p7b => fileextension.p7b} (49%) delete mode 100644 frameworks/innerkits/signature/openharmony_sx.p7b diff --git a/frameworks/innerkits/BUILD.gn b/frameworks/innerkits/BUILD.gn index 08487cc6..0c10968c 100644 --- a/frameworks/innerkits/BUILD.gn +++ b/frameworks/innerkits/BUILD.gn @@ -28,7 +28,7 @@ ohos_hap("file_extension_hap") { ":file_extension_js_assets", ":file_extension_resources", ] - certificate_profile = "signature/medialib.p7b" + certificate_profile = "signature/fileextension.p7b" hap_name = "file_extension" subsystem_name = "filemanagement" part_name = "user_file_service" diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h index 7720a484..ad7399cf 100644 --- a/frameworks/innerkits/file_extension/include/ifile_ext_base.h +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -16,12 +16,48 @@ #ifndef OHOS_APPEXECFWK_I_FILEEXTBASE_H #define OHOS_APPEXECFWK_I_FILEEXTBASE_H +#include #include #include #include "uri.h" namespace OHOS { namespace AppExecFwk { +struct FileInfo +{ + Uri uri; + std::string fileName; + std::string mode; + size_t size; + int64_t mtime; + std::string mimiType; + std::bitset<32> flags; +}; + +struct DeviceInfo +{ + Uri uri; + std::string displayname; + std::string deviceId; + std::bitset<32> flags; +}; + +const std::string ATTRIBUTE_COLUMN_SUMMARY = "summary"; +const std::string ATTRIBUTE_COLUMN_LAST_MODIFIED = "last_modified"; +const std::string ATTRIBUTE_COLUMN_ICON = "icon"; +const std::string ATTRIBUTE_COLUMN_FLAGS = "flags"; +const std::string ATTRIBUTE_COLUMN_SIZE = "size"; + +const std::bitset<32> FLAG_SUPPORTS_THUMBNAIL = 1; +const std::bitset<32> FLAG_SUPPORTS_WRITE = 1 << 1; +const std::bitset<32> FLAG_SUPPORTS_DELETE = 1 << 2; +const std::bitset<32> FLAG_DIR_SUPPORTS_CREATE = 1 << 3; +const std::bitset<32> FLAG_DIR_PREFERS_LAST_MODIFIED = 1 << 4; +const std::bitset<32> FLAG_SUPPORTS_RENAME = 1 << 5; +const std::bitset<32> FLAG_SUPPORTS_COPY = 1 << 6; +const std::bitset<32> FLAG_SUPPORTS_MOVE = 1 << 7; +const std::bitset<32> FLAG_SUPPORTS_REMOVE = 1 << 8; + class IFileExtBase : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IFileExtBase"); @@ -47,4 +83,3 @@ public: } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_APPEXECFWK_I_FILEEXTBASE_H - diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index f564f016..cc650974 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -149,6 +149,7 @@ void JsFileExtAbility::GetSrcPath(std::string &srcPath) srcPath.append(Extension::abilityInfo_->srcPath); } srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc"); + HILOG_INFO("tag dsa %{public}s end1, srcPath:%{public}s", __func__, srcPath.c_str()); return; } @@ -158,6 +159,7 @@ void JsFileExtAbility::GetSrcPath(std::string &srcPath) srcPath.erase(srcPath.rfind('.')); srcPath.append(".abc"); } + HILOG_INFO("tag dsa %{public}s end2, srcPath:%{public}s", __func__, srcPath.c_str()); } int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) @@ -220,7 +222,7 @@ int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displa napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); napi_value napiDisplayName = nullptr; napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); - + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); NativeValue* argv[] = {nativeParentUri, nativeDisplayName}; @@ -252,7 +254,6 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); napi_value napiDisplayName = nullptr; napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); - NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts index 9eb79930..21eabd6a 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device 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 AbilityStage from "@ohos.application.AbilityStage" export default class MyAbilityStage extends AbilityStage { diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts index 2555e833..ef8d617a 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device 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 Extension from '@ohos.application.FileExtensionAbility' export default class FileExtAbility extends Extension { diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts index a1988f56..2f102204 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device 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 Ability from '@ohos.application.Ability' export default class MainAbility extends Ability { diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets index d6ca48cf..a3361dc3 100644 --- a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device 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. + */ @Entry @Component struct Index { diff --git a/frameworks/innerkits/signature/medialib.p7b b/frameworks/innerkits/signature/fileextension.p7b similarity index 49% rename from frameworks/innerkits/signature/medialib.p7b rename to frameworks/innerkits/signature/fileextension.p7b index 664fa352718693e853f035d6afc3b443e8211b09..5b1328605f9fda63b5b61fa317f25bcff26028fa 100644 GIT binary patch delta 1008 zcmY+DO=u%!9LAe;+TH5LrGhIet8EG%wrw&W`7G4(&b%|3N%AJ0e0D-WCz&^suTIj* zB$H%a16k<7J(b{|Jgl%T9u_=!ReBP7aghbZ%i;k{&@Zme;(fF z?6tF3C*;%vmsf5ai^qR>T$kMUrko9#Z1x%*W7|*-8#qBj^}l+}SPu|Su2IWC53vpcQ_lObwK;b4Lj?Y(PFz&?=4ymM=N~N? zP7qWMSQ`l~yKL~bA|^T|Y1||^AS=?pGX!!K$~xewNRe#Ext76p_hrZ)(h45f822MJ zF&U6I+hrqGuQ$!)p(deBHUODg3l0zbgHkc4(Sukxud7s|P$-#Lq(PKdSqO8EOQOJ;KmQ{FxXLBjtuu}e(A5|kJ7tc~GQ_;*Qt0EAX->*TNXZ^O!JF$v7 z1hsi0Wkbv&J_bQiXLFUhS#1bbKH16l875l@_iMaRQza`i28h-5qe;EhOz+Dw1a=+( zS_deW=bSKQs5KKklr7LLE!2+SP){oL1uc%V=@Gf#8B`CfqYN#NgQ$z5J(wsYj)WQv z=9A4dsnGSZv8mb|65@whX)_&=Xer$fN=(8Zsx%FulAw}ghKc2)p^Z{9oCGRVY9gK2 z+jSvEOMYCWu#*I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)BMYVh zN(#bff2^DL4tL|VU)?PY)@?ghy!P^e>|ryURkpG{;&m~y>sdHeb>ruEeag;dUTRY z(data); napi_value result = nullptr; napi_create_int32(env, OpenFileCB->result, &result); @@ -377,7 +377,7 @@ void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); delete OpenFileCB; OpenFileCB = nullptr; - HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete end."); + HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete end."); } napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h index df74c121..aa9348d7 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -1,10 +1,10 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device 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 + * 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, diff --git a/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp index 8889db96..22d41c96 100644 --- a/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp +++ b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp @@ -1,10 +1,10 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device 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 + * 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, -- Gitee From ce67cb4538567d5aa16ce0be45cec927dca9d56e Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Tue, 17 May 2022 09:02:20 +0800 Subject: [PATCH 22/22] clear hap test code Signed-off-by: linjun9528 --- .../innerkits/file_extension_hap/.gitignore | 4 -- .../file_extension_hap/entry/.gitignore | 3 - .../ohosTest/ets/TestAbility/TestAbility.ts | 39 ------------ .../ohosTest/ets/TestAbility/pages/index.ets | 34 ---------- .../ets/TestRunner/OpenHarmonyTestRunner.ts | 58 ------------------ .../src/ohosTest/ets/test/Ability.test.ets | 13 ---- .../entry/src/ohosTest/ets/test/List.test.ets | 5 -- .../entry/src/ohosTest/module.json5 | 37 ----------- .../resources/base/element/string.json | 16 ----- .../ohosTest/resources/base/media/icon.png | Bin 6790 -> 0 bytes .../resources/base/profile/test_pages.json | 5 -- 11 files changed, 214 deletions(-) delete mode 100644 frameworks/innerkits/file_extension_hap/.gitignore delete mode 100644 frameworks/innerkits/file_extension_hap/entry/.gitignore delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/profile/test_pages.json diff --git a/frameworks/innerkits/file_extension_hap/.gitignore b/frameworks/innerkits/file_extension_hap/.gitignore deleted file mode 100644 index 39187ebe..00000000 --- a/frameworks/innerkits/file_extension_hap/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/node_modules -/local.properties -/.idea -**/build \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/.gitignore b/frameworks/innerkits/file_extension_hap/entry/.gitignore deleted file mode 100644 index 4f9a9738..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/node_modules -/.preview -/build \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts deleted file mode 100644 index d5e778f1..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from 'hypium/index' -import testsuite from '../test/List.test' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - console.log('TestAbility onCreate') - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - console.log('TestAbility onDestroy') - } - - onWindowStageCreate(windowStage) { - console.log('TestAbility onWindowStageCreate') - windowStage.setUIContent(this.context, 'TestAbility/pages/index', null) - - globalThis.abilityContext = this.context; - } - - onWindowStageDestroy() { - console.log('TestAbility onWindowStageDestroy') - } - - onForeground() { - console.log('TestAbility onForeground') - } - - onBackground() { - console.log('TestAbility onBackground') - } -}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets deleted file mode 100644 index 733600ab..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets +++ /dev/null @@ -1,34 +0,0 @@ -import router from '@ohos.router'; - -@Entry -@Component -struct Index { - aboutToAppear() { - console.info('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/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index 7a0024d4..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,58 +0,0 @@ -import TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout' - ]) - let targetParams = ''; - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - console.log("onAbilityCreateCallback"); -} - -async function addAbilityMonitorCallback(err: any) { - console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - console.info("OpenHarmonyTestRunner OnPrepare ") - } - - async onRun() { - console.log('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 - cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) - console.info('cmd : '+cmd) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - console.info('executeShellCommand : err : ' + JSON.stringify(err)); - console.info('executeShellCommand : data : ' + d.stdResult); - console.info('executeShellCommand : data : ' + d.exitCode); - }) - console.info('OpenHarmonyTestRunner onRun end') - } -}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 1236e0ce..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,13 +0,0 @@ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - it('assertContain',0, function () { - console.info("it begin") - let a = 'abc' - let b = 'b' - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index d766fe24..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test' - -export default function testsuite() { - abilityTest() -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 deleted file mode 100644 index 5d696c10..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,37 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 84078007..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "entry_test_desc", - "value": "i am an entry for tv" - }, - { - "name": "TestAbility_desc", - "value": "the tv entry test ability" - }, - { - "name": "TestAbility_label", - "value": "tvBase" - } - ] -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$U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