From e2a103396be4aef7de44d02c213061e8fdeeeeeb Mon Sep 17 00:00:00 2001 From: yueyan Date: Thu, 25 May 2023 14:39:53 +0800 Subject: [PATCH] fix:fossboot check Signed-off-by: yueyan --- drivers_external_device_manager/.clang-format | 29 + drivers_external_device_manager/LICENSE | 178 +++++++ drivers_external_device_manager/OAT.xml | 101 ++++ drivers_external_device_manager/README.en.md | 36 ++ drivers_external_device_manager/README.md | 39 ++ drivers_external_device_manager/README_zh.md | 79 +++ drivers_external_device_manager/bundle.json | 49 ++ drivers_external_device_manager/extdevmgr.gni | 16 + ...architecture-of-the-ext-device-manager.png | Bin 0 -> 34345 bytes .../frameworks/js/napi/BUILD.gn | 22 + .../js/napi/driver_extension_ability/BUILD.gn | 52 ++ .../driver_extension_ability.js | 36 ++ .../driver_extension_ability_module.cpp | 56 ++ .../js/napi/driver_extension_context/BUILD.gn | 50 ++ .../driver_extension_context.js | 39 ++ .../driver_extension_context_module.cpp | 57 ++ .../interfaces/innerkits/idriver_ext_mgr.h | 33 ++ .../sa_profile/5110.xml | 24 + .../sa_profile/BUILD.gn | 33 ++ .../sa_profile/hdf_ext_devmgr.cfg | 14 + .../service/native/driver_extension/BUILD.gn | 91 ++++ .../include/driver_extension.h | 84 +++ .../include/driver_extension_context.h | 64 +++ .../include/driver_extension_module_loader.h | 37 ++ .../include/js_driver_extension.h | 147 ++++++ .../include/js_driver_extension_context.h | 32 ++ .../driver_extension/src/driver_extension.cpp | 79 +++ .../src/driver_extension_context.cpp | 48 ++ .../src/driver_extension_module_loader.cpp | 42 ++ .../src/js_driver_extension.cpp | 494 ++++++++++++++++++ .../src/js_driver_extension_context.cpp | 116 ++++ .../services/BUILD.gn | 75 +++ .../bus_extension/usb/usb_bus_extension.h | 42 ++ .../bus_extension/usb/usb_dev_subscriber.h | 41 ++ .../bus_extension/usb/usb_device_info.h | 36 ++ .../bus_extension/usb/usb_driver_info.h | 33 ++ .../include/device_manager/etx_device_mgr.h | 50 ++ .../include/driver_ext_mgr.h | 37 ++ .../src/bus_extension/bus_extension.cpp | 36 ++ .../src/bus_extension/driver_info.cpp | 111 ++++ .../bus_extension/usb/usb_bus_extension.cpp | 138 +++++ .../bus_extension/usb/usb_dev_subscriber.cpp | 151 ++++++ .../src/bus_extension/usb/usb_driver_info.cpp | 91 ++++ .../src/device_manager/etx_device_mgr.cpp | 39 ++ .../src/driver_etx_mgr.cpp | 43 ++ .../zidl/include/driver_ext_mgr_stub.h | 40 ++ .../services/zidl/src/driver_ext_mgr_stub.cpp | 28 + .../test/fuzztest/BUILD.gn | 24 + .../fuzztest/bus_extension_fuzzer/BUILD.gn | 24 + .../usbdriverinfo_fuzzer/BUILD.gn | 41 ++ .../usbdriverinfo_fuzzer/corpus/init | 16 + .../usbdriverinfo_fuzzer/project.xml | 25 + .../usbdriverinfo_fuzzer.cpp | 93 ++++ .../usbdriverinfo_fuzzer.h | 19 + .../utils/BUILD.gn | 27 + .../utils/include/ext_object.h | 119 +++++ .../utils/include/hilog_wrapper.h | 98 ++++ .../utils/include/ibus_extension.h | 41 ++ 58 files changed, 3695 insertions(+) create mode 100644 drivers_external_device_manager/.clang-format create mode 100644 drivers_external_device_manager/LICENSE create mode 100644 drivers_external_device_manager/OAT.xml create mode 100644 drivers_external_device_manager/README.en.md create mode 100644 drivers_external_device_manager/README.md create mode 100644 drivers_external_device_manager/README_zh.md create mode 100644 drivers_external_device_manager/bundle.json create mode 100644 drivers_external_device_manager/extdevmgr.gni create mode 100644 drivers_external_device_manager/figures/architecture-of-the-ext-device-manager.png create mode 100644 drivers_external_device_manager/frameworks/js/napi/BUILD.gn create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/BUILD.gn create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability.js create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability_module.cpp create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_context/BUILD.gn create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context.js create mode 100644 drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context_module.cpp create mode 100644 drivers_external_device_manager/interfaces/innerkits/idriver_ext_mgr.h create mode 100644 drivers_external_device_manager/sa_profile/5110.xml create mode 100644 drivers_external_device_manager/sa_profile/BUILD.gn create mode 100644 drivers_external_device_manager/sa_profile/hdf_ext_devmgr.cfg create mode 100644 drivers_external_device_manager/service/native/driver_extension/BUILD.gn create mode 100644 drivers_external_device_manager/service/native/driver_extension/include/driver_extension.h create mode 100644 drivers_external_device_manager/service/native/driver_extension/include/driver_extension_context.h create mode 100644 drivers_external_device_manager/service/native/driver_extension/include/driver_extension_module_loader.h create mode 100644 drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension.h create mode 100644 drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension_context.h create mode 100644 drivers_external_device_manager/service/native/driver_extension/src/driver_extension.cpp create mode 100644 drivers_external_device_manager/service/native/driver_extension/src/driver_extension_context.cpp create mode 100644 drivers_external_device_manager/service/native/driver_extension/src/driver_extension_module_loader.cpp create mode 100644 drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension.cpp create mode 100644 drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension_context.cpp create mode 100644 drivers_external_device_manager/services/BUILD.gn create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_bus_extension.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_dev_subscriber.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_device_info.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_driver_info.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/device_manager/etx_device_mgr.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/include/driver_ext_mgr.h create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/bus_extension.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/driver_info.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_driver_info.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp create mode 100644 drivers_external_device_manager/services/native/driver_extension_manager/src/driver_etx_mgr.cpp create mode 100644 drivers_external_device_manager/services/zidl/include/driver_ext_mgr_stub.h create mode 100644 drivers_external_device_manager/services/zidl/src/driver_ext_mgr_stub.cpp create mode 100644 drivers_external_device_manager/test/fuzztest/BUILD.gn create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/BUILD.gn create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/BUILD.gn create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/corpus/init create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/project.xml create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.cpp create mode 100644 drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.h create mode 100644 drivers_external_device_manager/utils/BUILD.gn create mode 100644 drivers_external_device_manager/utils/include/ext_object.h create mode 100644 drivers_external_device_manager/utils/include/hilog_wrapper.h create mode 100644 drivers_external_device_manager/utils/include/ibus_extension.h diff --git a/drivers_external_device_manager/.clang-format b/drivers_external_device_manager/.clang-format new file mode 100644 index 000000000..7f3af8a9c --- /dev/null +++ b/drivers_external_device_manager/.clang-format @@ -0,0 +1,29 @@ +BasedOnStyle: Webkit +ColumnLimit: 120 +PointerAlignment: Right +AlignAfterOpenBracket: DontAlign +AlignTrailingComments: true +AlignConsecutiveMacros: Consecutive +IndentCaseLabels: true +BreakBeforeBinaryOperators: None +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpacesInCStyleCastParentheses: false +AlignEscapedNewlines: Left +NamespaceIndentation: None +FixNamespaceComments: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true +BreakConstructorInitializers: BeforeColon +AlignArrayOfStructures: Left +AllowShortFunctionsOnASingleLine: Empty +AllowShortLambdasOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: true +SpaceInEmptyBlock: false +LambdaBodyIndentation: Signature +BreakBeforeTernaryOperators: false +Cpp11BracedListStyle: true +SpaceAroundPointerQualifiers: Both + +ForEachMacros: + - 'DLIST_FOR_EACH_ENTRY' + - 'DLIST_FOR_EACH_ENTRY_REVERSE' + - 'DLIST_FOR_EACH_ENTRY_SAFE' \ No newline at end of file diff --git a/drivers_external_device_manager/LICENSE b/drivers_external_device_manager/LICENSE new file mode 100644 index 000000000..e454a5258 --- /dev/null +++ b/drivers_external_device_manager/LICENSE @@ -0,0 +1,178 @@ + + 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 + diff --git a/drivers_external_device_manager/OAT.xml b/drivers_external_device_manager/OAT.xml new file mode 100644 index 000000000..61c759965 --- /dev/null +++ b/drivers_external_device_manager/OAT.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/drivers_external_device_manager/README.en.md b/drivers_external_device_manager/README.en.md new file mode 100644 index 000000000..4788d5fd4 --- /dev/null +++ b/drivers_external_device_manager/README.en.md @@ -0,0 +1,36 @@ +# drivers_external_device_manager + +#### 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/drivers_external_device_manager/README.md b/drivers_external_device_manager/README.md new file mode 100644 index 000000000..2ab58a30b --- /dev/null +++ b/drivers_external_device_manager/README.md @@ -0,0 +1,39 @@ +# drivers_external_device_manager + +#### 介绍 +{**以下是 Gitee 平台说明,您可以替换此简介** +Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 +无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/drivers_external_device_manager/README_zh.md b/drivers_external_device_manager/README_zh.md new file mode 100644 index 000000000..861502402 --- /dev/null +++ b/drivers_external_device_manager/README_zh.md @@ -0,0 +1,79 @@ +# External Device Manager +- [简介] +- [目录] +- [说明] + - [扩展外部设备管理框架使用说明] +- [相关仓] + +## 简介 + +该仓主要存放OpenHarmony驱动子系统扩展外部设备管理框架核心源码信息(包括扩展外部设备管理、扩展驱动管理服务、扩展设备管理、扩展驱动包信息管理、扩展驱动能力控制器、总线扩展核心、总线扩展插件),承载扩展驱动包全流程生命周期管理,旨在为开发者提供更高效、安全、且低成本的扩展外设驱动开发解决方案,做到即插即用的用户体验。 + + +**图 1** 扩展外部设备管理框架架构图 +![](figures/architecture-of-the-ext-device-manager.png) + +## 目录 + +``` +/drivers/external_device_manager +├── frameworks # 无独立进程的桥接实现 +│   └── js # 对外提供应该JS API需要 +│   └──-napi # napi代码实现 +│   ├── driver_ext_ability # ext ability桥接类 +│   ├── driver_ext_context # ext context桥接类 +│   └── driver_ext_manager # device ext manager桥接类 +├── interfaces # 对外提供.d.ts接口定义和capi实现 +│   ├── innerkits # 部件接口,系统内部件间接口 +│   └── kits # 提供应用的接口 +│   └── js # js接口 +├── sa_profile # SA定义 +├── services # 扩展设备管理系统服务实现 +│   ├── native +│   │   ├── driver_extension # driver extension ability 和driver extension context定义和实现 +│   │   │   ├── include # driver extension接口定义 +│   │   │   └── src # driver extension接口实现 +│   │   └── driver_extension_manager #各子模块实现 +│   │   ├── include +│   │   │   ├── bus_extension # 总线管理接口定义 +│   │   │   ├── device_manager # 设备管理接口定义 +│   │   │   ├── driver_ability_controller # ability生命周期管理接口定义 +│   │   │   └── driver_pkg_manager # 包管理接口定义 +│   │   └── src +│   │   ├── bus_extension # 总线管理接口实现 +│   │   ├── device_manager # 设备管理接口实现 +│   │   ├── driver_ability_controller # ability生命周期管理接口实现 +│   │   └── driver_pkg_manager# 包管理接口实现 +│   └── zidl # js跨进程实现 +│   ├── include# js跨进程接口定义 +│   └── src # js跨进程接口实现 +└── utils # 通用接口实现和 hilog封装 + └── include # 通用接口定义 +``` + +## 说明 + +### 扩展外部设备管理框架使用说明 + +基于扩展驱动Ability实现扩展外部设备管理框架,为开发者提供系统非板载的扩展外设包开发方案,完成扩展驱动包全流程(开发/部署/安装/运行/能力/开放)生命周期管理。开发者只需以HAP包形式开发和发布扩展驱动,对其他三方HAP和系统服务提供硬件接口能力,实现三方扩展外部设备快速接入。 + +扩展外设设备管理框架主要包含六部分: + +1、驱动扩展Ability----应用态扩展驱动能力的抽象,是应用Stage模型ExtensionAbility类中的一种。 +2、扩展驱动管理服务----支持扩展驱动管理服务按需启动能力,负责设备管理,包信息管理,总线扩展核心模块生命周期管理。 +3、扩展设备管理----提供扩展设备查询和绑定能力,负责设备列表管理,设备与驱动匹配管理。 +4、扩展驱动包信息管理----负责扩展驱动包信息解析,存储,设备匹配,支持扩展驱动包的安装,更新,卸载能力。 +5、扩展驱动Ability控制器----负责扩展驱动Ability生命周期管控,包括扩展驱动Ability的启动,停止。 +6、总线扩展核心----负责总线设备枚举、总线驱动包解析、包与设备匹配能力。 +7、USB总线扩展插件----负责USB设备热插拔监听,USB设备信息读取。 +8、USB C API----提供USB设备对三方应用提供的硬件访问接口。 + +## 相关仓 + +[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md) + +[drivers\_hdf\_core](https://gitee.com/openharmony/drivers_hdf_core/blob/master/README_zh.md) + +[drivers\_interface](https://gitee.com/openharmony/drivers_interface/blob/master/README_ZH.md) + +[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md) diff --git a/drivers_external_device_manager/bundle.json b/drivers_external_device_manager/bundle.json new file mode 100644 index 000000000..6aa635e4d --- /dev/null +++ b/drivers_external_device_manager/bundle.json @@ -0,0 +1,49 @@ +{ + "name": "@ohos/external_device_manager", + "description": "external device driver framework", + "version": "4.0", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "drivers/external_device_manager" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "external_device_manager", + "subsystem": "hdf", + "features": [], + "adapted_system_type": [ + "standard", + "small" + ], + "rom": "735KB", + "ram": "8000KB", + "deps": { + "components": [ + "hiviewdfx_hilog_native", + "c_utils", + "init", + "ipc", + "samgr", + "selinux" + ], + "third_party": [ + "bounds_checking_function", + "googletest" + ] + }, + "build": { + "sub_component": [ + "//drivers/external_device_manager/frameworks/js/napi:napi_packages", + "//drivers/external_device_manager/service/native/driver_extension:driver_extension_module", + "//drivers/external_device_manager/sa_profile:ext_dev_mgr_sa", + "//drivers/external_device_manager/services:driver_extension_manager", + "//drivers/external_device_manager/services:bus_extension" + + ], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file diff --git a/drivers_external_device_manager/extdevmgr.gni b/drivers_external_device_manager/extdevmgr.gni new file mode 100644 index 000000000..8f487eead --- /dev/null +++ b/drivers_external_device_manager/extdevmgr.gni @@ -0,0 +1,16 @@ +# Copyright (c) 2023 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") +ext_mgr_path = "//drivers/external_device_manager" +utils_path = "//drivers/external_device_manager/utils" \ No newline at end of file diff --git a/drivers_external_device_manager/figures/architecture-of-the-ext-device-manager.png b/drivers_external_device_manager/figures/architecture-of-the-ext-device-manager.png new file mode 100644 index 0000000000000000000000000000000000000000..bb1ac62c3a463e68db696d82a903ce048f8abab7 GIT binary patch literal 34345 zcmeFZcT`i|)-Q~YHHxCd0@6evC`gyy9zaAOfPjE>Fcj&%6HtjD2!u}PBE3rsgia`- z34%b7Pz*(S7XpOxZS*0=q zw=YsqP+V4g@<@Y%;twJP#i_Lm=YTu=A5ZxMms2hp3bGW%z4QyfhclKkDl!xlrN~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H_S^phJp`@@ literal 0 HcmV?d00001 diff --git a/drivers_external_device_manager/frameworks/js/napi/BUILD.gn b/drivers_external_device_manager/frameworks/js/napi/BUILD.gn new file mode 100644 index 000000000..410fc1932 --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2023 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") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +group("napi_packages") { + deps = [ + "driver_extension_ability:driverextensionability", + "driver_extension_context:driverextensioncontext_napi", + ] +} diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/BUILD.gn b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/BUILD.gn new file mode 100644 index 000000000..b9bcdbd5c --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//build/ohos.gni") + +es2abc_gen_abc("gen_driver_extension_ability_abc") { + src_js = rebase_path("driver_extension_ability.js") + dst_file = rebase_path(target_out_dir + "/driver_extension_ability.abc") + in_puts = [ "driver_extension_ability.js" ] + out_puts = [ target_out_dir + "/driver_extension_ability.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("driver_extension_ability_js") { + input = "driver_extension_ability.js" + output = target_out_dir + "/driver_extension_ability.o" +} + +gen_js_obj("driver_extension_ability_abc") { + input = get_label_info(":gen_driver_extension_ability_abc", + "target_out_dir") + "/driver_extension_ability.abc" + output = target_out_dir + "/driver_extension_ability_abc.o" + dep = ":gen_driver_extension_ability_abc" +} + +ohos_shared_library("driverextensionability") { + sources = [ "driver_extension_ability_module.cpp" ] + + deps = [ + ":driver_extension_ability_abc", + ":driver_extension_ability_js", + ] + + external_deps = [ "napi:ace_napi" ] + + defines = [ "ENABLE_ERRCODE" ] + + relative_install_dir = "module/app/ability" + subsystem_name = "hdf" + part_name = "external_device_manager" +} diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability.js b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability.js new file mode 100644 index 000000000..9ffe5ad45 --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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. + */ + +var ExtensionAbility = requireNapi("app.ability.ExtensionAbility") + +class DriverExtensionAbility extends ExtensionAbility { + onInit(want) { + console.log('onInit, want:' + want.abilityName); + } + + onConnect(want) { + console.log('onConnect, want:' + want.abilityName); + } + + onDisconnect(want) { + console.log('onDisconnect'); + } + + onRelease() { + console.log('onRelease'); + } +} + +export default DriverExtensionAbility diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability_module.cpp b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability_module.cpp new file mode 100644 index 000000000..5333cebec --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_ability/driver_extension_ability_module.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 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_driver_extension_ability_js_start[]; +extern const char _binary_driver_extension_ability_js_end[]; +extern const char _binary_driver_extension_ability_abc_start[]; +extern const char _binary_driver_extension_ability_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_app_ability_DriverExtensionAbility_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "app.ability.DriverExtensionAbility", + .fileName = "app/ability/libdriverextensionability.so/driver_extension_ability.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_app_ability_DriverExtensionAbility_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_driver_extension_ability_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_driver_extension_ability_js_end - _binary_driver_extension_ability_js_start; + } +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_app_ability_DriverExtensionAbility_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_driver_extension_ability_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_driver_extension_ability_abc_end - _binary_driver_extension_ability_abc_start; + } +} \ No newline at end of file diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/BUILD.gn b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/BUILD.gn new file mode 100644 index 000000000..8626683db --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2023 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//build/ohos.gni") + +es2abc_gen_abc("gen_driver_extension_context_abc") { + src_js = rebase_path("driver_extension_context.js") + dst_file = rebase_path(target_out_dir + "/driver_extension_context.abc") + in_puts = [ "driver_extension_context.js" ] + out_puts = [ target_out_dir + "/driver_extension_context.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("driver_extension_context_js") { + input = "driver_extension_context.js" + output = target_out_dir + "/driver_extension_context.o" +} + +gen_js_obj("driver_extension_context_abc") { + input = get_label_info(":gen_driver_extension_context_abc", + "target_out_dir") + "/driver_extension_context.abc" + output = target_out_dir + "/driver_extension_context_abc.o" + dep = ":gen_driver_extension_context_abc" +} + +ohos_shared_library("driverextensioncontext_napi") { + sources = [ "driver_extension_context_module.cpp" ] + + deps = [ + ":driver_extension_context_abc", + ":driver_extension_context_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + subsystem_name = "hdf" + part_name = "external_device_manager" +} diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context.js b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context.js new file mode 100644 index 000000000..b6d045257 --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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. + */ + +var ExtensionContext = requireNapi("application.ExtensionContext") +var Caller = requireNapi("application.Caller") + +const ERROR_CODE_INVALID_PARAM = 401; +const ERROR_MSG_INVALID_PARAM = "Invalid input parameter."; +class ParamError extends Error { + constructor() { + super(ERROR_MSG_INVALID_PARAM); + this.code = ERROR_CODE_INVALID_PARAM; + } +} + +class DriverExtensionContext extends ExtensionContext { + constructor(obj) { + super(obj); + } + + updateDriverState() { + console.log("updateDriverState"); + return this.__context_impl__.updateDriverState(); + } +} + +export default DriverExtensionContext diff --git a/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context_module.cpp b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context_module.cpp new file mode 100644 index 000000000..b1bee8118 --- /dev/null +++ b/drivers_external_device_manager/frameworks/js/napi/driver_extension_context/driver_extension_context_module.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 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_driver_extension_context_js_start[]; +extern const char _binary_driver_extension_context_js_end[]; +extern const char _binary_driver_extension_context_abc_start[]; +extern const char _binary_driver_extension_context_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_DriverExtensionContext_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.DriverExtensionContext", + .fileName = "application/libdriverextensioncontext_napi.so/DriverExtensionContext.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_DriverExtensionContext_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_driver_extension_context_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_driver_extension_context_js_end - _binary_driver_extension_context_js_start; + } +} + +// ability_context JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_DriverExtensionContext_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_driver_extension_context_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_driver_extension_context_abc_end - _binary_driver_extension_context_abc_start; + } +} diff --git a/drivers_external_device_manager/interfaces/innerkits/idriver_ext_mgr.h b/drivers_external_device_manager/interfaces/innerkits/idriver_ext_mgr.h new file mode 100644 index 000000000..592104e9c --- /dev/null +++ b/drivers_external_device_manager/interfaces/innerkits/idriver_ext_mgr.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 IDRIVER_EXT_MGR_H +#define IDRIVER_EXT_MGR_H +#include + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace ExternalDeviceManager { +class IDriverExtMgr : public IRemoteBroker { +public: + virtual int32_t QueryDevice() = 0; + +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.driver.IExtDeviceManager"); +}; +} // namespace ExternalDeviceManager +} // namespace OHOS +#endif // IDRIVER_EXT_MGR_H \ No newline at end of file diff --git a/drivers_external_device_manager/sa_profile/5110.xml b/drivers_external_device_manager/sa_profile/5110.xml new file mode 100644 index 000000000..0f18c59bd --- /dev/null +++ b/drivers_external_device_manager/sa_profile/5110.xml @@ -0,0 +1,24 @@ + + + + hdf_ext_devmgr + + 5110 + libdriver_extension_manager.z.so + true + false + 1 + + diff --git a/drivers_external_device_manager/sa_profile/BUILD.gn b/drivers_external_device_manager/sa_profile/BUILD.gn new file mode 100644 index 000000000..ce847efcb --- /dev/null +++ b/drivers_external_device_manager/sa_profile/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2023 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") +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("etxdevmgr_sa_profile") { + sources = [ "5110.xml" ] + part_name = "external_device_manager" +} + +ohos_prebuilt_etc("hdf_ext_devmgr.init") { + source = "hdf_ext_devmgr.cfg" + relative_install_dir = "init" + part_name = "external_device_manager" +} + +group("ext_dev_mgr_sa") { + deps = [ + ":etxdevmgr_sa_profile", + ":hdf_ext_devmgr.init", + ] +} diff --git a/drivers_external_device_manager/sa_profile/hdf_ext_devmgr.cfg b/drivers_external_device_manager/sa_profile/hdf_ext_devmgr.cfg new file mode 100644 index 000000000..3482b75a4 --- /dev/null +++ b/drivers_external_device_manager/sa_profile/hdf_ext_devmgr.cfg @@ -0,0 +1,14 @@ +{ + "services" : [{ + "name" : "hdf_ext_devmgr", + "path" : ["/system/bin/sa_main", "/system/profile/hdf_ext_devmgr.xml"], + "ondemand" : false, + "uid" : "hdf_ext_devmgr", + "gid" : ["hdf_ext_devmgr", "shell"], + "permission" : [ + "ohos.permission.LISTEN_BUNDLE_CHANGE" + ], + "apl" : "system_basic" + } + ] +} diff --git a/drivers_external_device_manager/service/native/driver_extension/BUILD.gn b/drivers_external_device_manager/service/native/driver_extension/BUILD.gn new file mode 100644 index 000000000..f975524c1 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/BUILD.gn @@ -0,0 +1,91 @@ +# Copyright (c) 2023 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") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +config("ability_config") { + visibility = [ ":*" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_services_path}/common/include", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } +} + +ohos_shared_library("driver_extension") { + include_dirs = [ + "include", + ] + + sources = [ + "src/js_driver_extension.cpp", + "src/js_driver_extension_context.cpp", + "src/driver_extension.cpp", + "src/driver_extension_context.cpp", + ] + + deps = [ + "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:ability_business_error", + "${ability_runtime_native_path}/appkit:app_context", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:runtime", + "c_utils:utils", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "ipc:ipc_napi_common", + "napi:ace_napi", + ] + + subsystem_name = "hdf" + part_name = "external_device_manager" +} + +ohos_shared_library("driver_extension_module") { + include_dirs = + [ "include" ] + + sources = [ "src/driver_extension_module_loader.cpp" ] + + configs = [ ":ability_config" ] + + deps = [ ":driver_extension" ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ace_engine:ace_uicontent", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] + + relative_install_dir = "extensionability/" + subsystem_name = "hdf" + part_name = "external_device_manager" +} \ No newline at end of file diff --git a/drivers_external_device_manager/service/native/driver_extension/include/driver_extension.h b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension.h new file mode 100644 index 000000000..cd46ce60d --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H + +#include "extension_base.h" + +namespace OHOS { +namespace AbilityRuntime { +class DriverExtensionContext; +class Runtime; +class DriverExtension; +using CreatorDriverFunc = std::function& runtime)>; +/** + * @brief Basic driver components. + */ +class DriverExtension : public ExtensionBase, + public std::enable_shared_from_this { +public: + DriverExtension() = default; + virtual ~DriverExtension() = default; + + /** + * @brief Create and init context. + * + * @param record the extension record. + * @param application the application info. + * @param handler the extension handler. + * @param token the remote token. + * @return The created context. + */ + virtual std::shared_ptr CreateAndInitContext( + const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + /**DRIVER + * @brief Init the extension. + * + * @param record the extension record. + * @param application the application info. + * @param handler the extension handler. + * @param token the remote token. + */ + virtual void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + /** + * @brief Create Extension. + * + * @param runtime The runtime. + * @return The DriverExtension instance. + */ + static DriverExtension* Create(const std::unique_ptr& runtime); + + /** + * @brief Set a creator function. + * + * @param creator The function for create a driver-extension ability. + */ + static void SetCreator(const CreatorDriverFunc& creator); + +private: + static CreatorDriverFunc creator_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_H diff --git a/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_context.h b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_context.h new file mode 100644 index 000000000..740c7da9a --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_context.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_CONTEXT_H + +#include "extension_context.h" + +#include "ability_connect_callback.h" +#include "connection_manager.h" +#include "local_call_container.h" +#include "start_options.h" +#include "want.h" + +namespace OHOS { +namespace AbilityRuntime { +/** + * @brief context supply for driver + * + */ +class DriverExtensionContext : public ExtensionContext { +public: + DriverExtensionContext() = default; + virtual ~DriverExtensionContext() = default; + + /** + * @brief Update the state of driver. + * + * @return errCode ERR_OK on success, others on failure. + */ + ErrCode UpdateDriverState(); + + using SelfType = DriverExtensionContext; + static const size_t CONTEXT_TYPE_ID; + +protected: + bool IsContext(size_t contextTypeId) override + { + return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId); + } + +private: + /** + * @brief Get Current Ability Type + * + * @return Current Ability Type + */ + OHOS::AppExecFwk::AbilityType GetAbilityInfoType() const; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_CONTEXT_H diff --git a/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_module_loader.h b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_module_loader.h new file mode 100644 index 000000000..fb6c461d2 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/include/driver_extension_module_loader.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_MODULE_LOADER_H +#define OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_MODULE_LOADER_H + +#include "extension_module_loader.h" + +namespace OHOS::AbilityRuntime { +class DriverExtensionModuleLoader : public ExtensionModuleLoader, public Singleton { + DECLARE_SINGLETON(DriverExtensionModuleLoader); + +public: + /** + * @brief Create Extension. + * + * @param runtime The runtime. + * @return The Extension instance. + */ + virtual Extension *Create(const std::unique_ptr& runtime) const override; + + virtual std::map GetParams() override; +}; +} +#endif // OHOS_ABILITY_RUNTIME_DRIVER_EXTENSION_MODULE_LOADER_H diff --git a/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension.h b/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension.h new file mode 100644 index 000000000..d07d2bfc3 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_H +#define OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_H + +#include "configuration.h" +#include "driver_extension.h" + +class NativeReference; +class NativeValue; +class NativeObject; + +namespace OHOS { +namespace AbilityRuntime { +class DriverExtension; +class JsRuntime; +/** + * @brief Basic driver components. + */ +class JsDriverExtension : public DriverExtension, + public std::enable_shared_from_this { +public: + explicit JsDriverExtension(JsRuntime& jsRuntime); + virtual ~JsDriverExtension() override; + + /** + * @brief Create JsDriverExtension. + * + * @param runtime The runtime. + * @return The JsDriverExtension instance. + */ + static JsDriverExtension* Create(const std::unique_ptr& runtime); + + /** + * @brief Init the extension. + * + * @param record the extension record. + * @param application the application info. + * @param handler the extension handler. + * @param token the remote token. + */ + virtual void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + /** + * @brief Called when this extension is started. You must override this function if you want to perform some + * initialization operations during extension startup. + * + * This function can be called only once in the entire lifecycle of an extension. + * @param Want Indicates the {@link Want} structure containing startup information about the extension. + */ + virtual void OnStart(const AAFwk::Want &want) override; + + /** + * @brief Called when this Driver extension is connected for the first time. + * + * You can override this function to implement your own processing logic. + * + * @param want Indicates the {@link Want} structure containing connection information about the Driver extension. + * @return Returns a pointer to the sid of the connected Driver extension. + */ + virtual sptr OnConnect(const AAFwk::Want &want) override; + + /** + * @brief Called when this Driver extension is connected for the first time. + * + * You can override this function to implement your own processing logic. + * + * @param want Indicates the {@link Want} structure containing connection information about the Driver extension. + * @param callbackInfo Indicates the lifecycle transaction callback information + * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback + * @return Returns a pointer to the sid of the connected Driver extension. + */ + virtual sptr OnConnect(const AAFwk::Want &want, + AppExecFwk::AbilityTransactionCallbackInfo> *callbackInfo, bool &isAsyncCallback) override; + + /** + * @brief Called when all abilities connected to this Driver extension are disconnected. + * + * You can override this function to implement your own processing logic. + * + */ + virtual void OnDisconnect(const AAFwk::Want &want) override; + + /** + * @brief Called when all abilities connected to this Driver extension are disconnected. + * + * You can override this function to implement your own processing logic. + * @param callbackInfo Indicates the lifecycle transaction callback information + * @param isAsyncCallback Indicates whether it is an asynchronous lifecycle callback + */ + void OnDisconnect(const AAFwk::Want &want, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, + bool &isAsyncCallback) override; + + /** + * @brief Called when this extension enters the STATE_STOP state. + * + * The extension in the STATE_STOP is being destroyed. + * You can override this function to implement your own processing logic. + */ + virtual void OnStop() override; + + /** + * @brief Called when extension need dump info. + * + * @param params The params from driver. + * @param info The dump info to show. + */ + virtual void Dump(const std::vector ¶ms, std::vector &info) override; + +private: + NativeValue* CallObjectMethod(const char* name, NativeValue* const *argv = nullptr, size_t argc = 0); + + void BindContext(NativeEngine& engine, NativeObject* obj); + + void GetSrcPath(std::string &srcPath); + + NativeValue *CallOnConnect(const AAFwk::Want &want); + + NativeValue *CallOnDisconnect(const AAFwk::Want &want, bool withResult = false); + + bool CheckPromise(NativeValue *result); + + bool CallPromise(NativeValue *result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo); + + JsRuntime& jsRuntime_; + std::unique_ptr jsObj_; + std::shared_ptr shellContextRef_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_H diff --git a/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension_context.h b/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension_context.h new file mode 100644 index 000000000..c5476eead --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/include/js_driver_extension_context.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_CONTEXT_H + +#include + +#include "ability_connect_callback.h" +#include "driver_extension_context.h" +#include "event_handler.h" +#include "js_free_install_observer.h" +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +NativeValue* CreateJsDriverExtensionContext(NativeEngine& engine, std::shared_ptr context); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_DRIVER_EXTENSION_CONTEXT_H diff --git a/drivers_external_device_manager/service/native/driver_extension/src/driver_extension.cpp b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension.cpp new file mode 100644 index 000000000..a14bc12e0 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023 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 "driver_extension.h" + +#include "configuration_utils.h" +#include "connection_manager.h" +#include "hilog_wrapper.h" +#include "js_driver_extension.h" +#include "runtime.h" +#include "driver_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; + +CreatorDriverFunc DriverExtension::creator_ = nullptr; +void DriverExtension::SetCreator(const CreatorDriverFunc& creator) +{ + creator_ = creator; +} + +DriverExtension* DriverExtension::Create(const std::unique_ptr& runtime) +{ + if (!runtime) { + return new DriverExtension(); + } + + if (creator_) { + return creator_(runtime); + } + + HILOG_INFO("DriverExtension::Create runtime"); + switch (runtime->GetLanguage()) { + case Runtime::Language::JS: + return JsDriverExtension::Create(runtime); + + default: + return new DriverExtension(); + } +} + +void DriverExtension::Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) +{ + ExtensionBase::Init(record, application, handler, token); + HILOG_INFO("DriverExtension begin init context"); +} + +std::shared_ptr DriverExtension::CreateAndInitContext( + const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) +{ + std::shared_ptr context = + ExtensionBase::CreateAndInitContext(record, application, handler, token); + if (context == nullptr) { + HILOG_ERROR("DriverExtension::CreateAndInitContext context is nullptr"); + return context; + } + return context; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_context.cpp b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_context.cpp new file mode 100644 index 000000000..a8a65e82a --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_context.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 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 "driver_extension_context.h" + +#include "ability_connection.h" +#include "ability_manager_client.h" +#include "hilog_wrapper.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace AbilityRuntime { +const size_t DriverExtensionContext::CONTEXT_TYPE_ID(std::hash {} ("DriverExtensionContext")); + +ErrCode DriverExtensionContext::UpdateDriverState() +{ + HILOG_INFO("%{public}s begin.", __func__); + ErrCode err = ERR_OK; + if (err != ERR_OK) { + HILOG_ERROR("DriverContext::UpdateDriverState is failed %{public}d", err); + } + return err; +} + +AppExecFwk::AbilityType DriverExtensionContext::GetAbilityInfoType() const +{ + std::shared_ptr info = GetAbilityInfo(); + if (info == nullptr) { + HILOG_ERROR("DriverContext::GetAbilityInfoType info == nullptr"); + return AppExecFwk::AbilityType::UNKNOWN; + } + + return info->type; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_module_loader.cpp b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_module_loader.cpp new file mode 100644 index 000000000..550f4fcde --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/src/driver_extension_module_loader.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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 "driver_extension_module_loader.h" +#include "driver_extension.h" + +namespace OHOS::AbilityRuntime { +DriverExtensionModuleLoader::DriverExtensionModuleLoader() = default; +DriverExtensionModuleLoader::~DriverExtensionModuleLoader() = default; + +Extension *DriverExtensionModuleLoader::Create(const std::unique_ptr& runtime) const +{ + return DriverExtension::Create(runtime); +} + +std::map DriverExtensionModuleLoader::GetParams() +{ + std::map params; + // type means extension type in ExtensionAbilityType of extension_ability_info.h, 18 means driver. + params.insert(std::pair("type", "18")); + // extension name + params.insert(std::pair("name", "DriverExtension")); + return params; +} + +extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtensionModule() +{ + return &DriverExtensionModuleLoader::GetInstance(); +} +} // namespace OHOS::AbilityRuntime diff --git a/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension.cpp b/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension.cpp new file mode 100644 index 000000000..105ea09c7 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension.cpp @@ -0,0 +1,494 @@ +/* + * Copyright (c) 2023 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_driver_extension.h" + +#include "ability_info.h" +#include "hitrace_meter.h" +#include "hilog_wrapper.h" +#include "js_extension_common.h" +#include "js_extension_context.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "js_driver_extension_context.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_common_configuration.h" +#include "napi_common_want.h" +#include "napi_remote_object.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr size_t ARGC_ONE = 1; +} + +namespace { +NativeValue *PromiseCallback(NativeEngine *engine, NativeCallbackInfo *info) +{ + if (info == nullptr || info->functionInfo == nullptr || info->functionInfo->data == nullptr) { + HILOG_ERROR("PromiseCallback, Invalid input info."); + return nullptr; + } + void *data = info->functionInfo->data; + auto *callbackInfo = static_cast *>(data); + callbackInfo->Call(); + AppExecFwk::AbilityTransactionCallbackInfo<>::Destroy(callbackInfo); + info->functionInfo->data = nullptr; + return nullptr; +} + +NativeValue *OnConnectPromiseCallback(NativeEngine *engine, NativeCallbackInfo *info) +{ + if (info == nullptr || info->functionInfo == nullptr || info->functionInfo->data == nullptr) { + HILOG_ERROR("PromiseCallback, Invalid input info."); + return nullptr; + } + void *data = info->functionInfo->data; + auto *callbackInfo = static_cast> *>(data); + sptr service = nullptr; + if (info->argc > 0) { + service = NAPI_ohos_rpc_getNativeRemoteObject(reinterpret_cast(engine), + reinterpret_cast(info->argv[0])); + } + callbackInfo->Call(service); + AppExecFwk::AbilityTransactionCallbackInfo>::Destroy(callbackInfo); + info->functionInfo->data = nullptr; + return nullptr; +} +} + +using namespace OHOS::AppExecFwk; + +NativeValue *AttachDriverExtensionContext(NativeEngine *engine, void *value, void *) +{ + HILOG_INFO("AttachDriverExtensionContext"); + if (value == nullptr) { + HILOG_WARN("invalid parameter."); + return nullptr; + } + auto ptr = reinterpret_cast *>(value)->lock(); + if (ptr == nullptr) { + HILOG_WARN("invalid context."); + return nullptr; + } + NativeValue *object = CreateJsDriverExtensionContext(*engine, ptr); + auto contextObj = JsRuntime::LoadSystemModuleByEngine(engine, + "application.DriverExtensionContext", &object, 1)->Get(); + NativeObject *nObject = ConvertNativeValueTo(contextObj); + nObject->ConvertToNativeBindingObject(engine, DetachCallbackFunc, AttachDriverExtensionContext, + value, nullptr); + auto workContext = new (std::nothrow) std::weak_ptr(ptr); + nObject->SetNativePointer(workContext, + [](NativeEngine *, void *data, void *) { + HILOG_INFO("Finalizer for weak_ptr driver extension context is called"); + delete static_cast *>(data); + }, nullptr); + return contextObj; +} + +JsDriverExtension* JsDriverExtension::Create(const std::unique_ptr& runtime) +{ + return new JsDriverExtension(static_cast(*runtime)); +} + +JsDriverExtension::JsDriverExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {} +JsDriverExtension::~JsDriverExtension() = default; + +void JsDriverExtension::Init(const std::shared_ptr &record, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + DriverExtension::Init(record, application, handler, token); + std::string srcPath = ""; + GetSrcPath(srcPath); + if (srcPath.empty()) { + HILOG_ERROR("Failed to get srcPath"); + return; + } + + std::string moduleName(Extension::abilityInfo_->moduleName); + moduleName.append("::").append(abilityInfo_->name); + HILOG_DEBUG("JsStaticSubscriberExtension::Init moduleName:%{public}s,srcPath:%{public}s.", + moduleName.c_str(), srcPath.c_str()); + HandleScope handleScope(jsRuntime_); + auto& engine = jsRuntime_.GetNativeEngine(); + + jsObj_ = jsRuntime_.LoadModule( + moduleName, srcPath, abilityInfo_->hapPath, abilityInfo_->compileMode == CompileMode::ES_MODULE); + if (jsObj_ == nullptr) { + HILOG_ERROR("Failed to get jsObj_"); + return; + } + + HILOG_INFO("JsDriverExtension::Init ConvertNativeValueTo."); + NativeObject* obj = ConvertNativeValueTo(jsObj_->Get()); + if (obj == nullptr) { + HILOG_ERROR("Failed to get JsDriverExtension object"); + return; + } + + BindContext(engine, obj); + + SetExtensionCommon(JsExtensionCommon::Create(jsRuntime_, static_cast(*jsObj_), shellContextRef_)); +} + +void JsDriverExtension::BindContext(NativeEngine& engine, NativeObject* obj) +{ + auto context = GetContext(); + if (context == nullptr) { + HILOG_ERROR("Failed to get context"); + return; + } + HILOG_INFO("JsDriverExtension::Init CreateJsDriverExtensionContext."); + NativeValue* contextObj = CreateJsDriverExtensionContext(engine, context); + shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(&engine, "application.DriverExtensionContext", + &contextObj, ARGC_ONE); + contextObj = shellContextRef_->Get(); + NativeObject *nativeObj = ConvertNativeValueTo(contextObj); + if (nativeObj == nullptr) { + HILOG_ERROR("Failed to get context native object"); + return; + } + auto workContext = new (std::nothrow) std::weak_ptr(context); + nativeObj->ConvertToNativeBindingObject(&engine, DetachCallbackFunc, AttachDriverExtensionContext, + workContext, nullptr); + HILOG_INFO("JsDriverExtension::Init Bind."); + context->Bind(jsRuntime_, shellContextRef_.get()); + HILOG_INFO("JsDriverExtension::SetProperty."); + obj->SetProperty("context", contextObj); + HILOG_INFO("Set driver extension context"); + + nativeObj->SetNativePointer(workContext, + [](NativeEngine*, void* data, void*) { + HILOG_INFO("Finalizer for weak_ptr driver extension context is called"); + delete static_cast*>(data); + }, nullptr); + + HILOG_INFO("JsDriverExtension::Init end."); +} + +void JsDriverExtension::OnStart(const AAFwk::Want &want) +{ + Extension::OnStart(want); + HILOG_INFO("JsDriverExtension OnStart begin.."); + HandleScope handleScope(jsRuntime_); + NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine(); + napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast(nativeEngine), want); + NativeValue* nativeWant = reinterpret_cast(napiWant); + NativeValue* argv[] = {nativeWant}; + CallObjectMethod("onInit", argv, ARGC_ONE); + HILOG_INFO("%{public}s end.", __func__); +} + +void JsDriverExtension::OnStop() +{ + DriverExtension::OnStop(); + HILOG_INFO("JsDriverExtension OnStop begin."); + CallObjectMethod("onRelease"); + bool ret = ConnectionManager::GetInstance().DisconnectCaller(GetContext()->GetToken()); + if (ret) { + ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid()); + HILOG_INFO("The driver extension connection is not disconnected."); + } + HILOG_INFO("%{public}s end.", __func__); +} + +sptr JsDriverExtension::OnConnect(const AAFwk::Want &want) +{ + HandleScope handleScope(jsRuntime_); + NativeValue *result = CallOnConnect(want); + NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine(); + auto remoteObj = NAPI_ohos_rpc_getNativeRemoteObject( + reinterpret_cast(nativeEngine), reinterpret_cast(result)); + if (remoteObj == nullptr) { + HILOG_ERROR("remoteObj nullptr."); + } + return remoteObj; +} + +sptr JsDriverExtension::OnConnect(const AAFwk::Want &want, + AppExecFwk::AbilityTransactionCallbackInfo> *callbackInfo, bool &isAsyncCallback) +{ + HandleScope handleScope(jsRuntime_); + NativeEngine *nativeEngine = &jsRuntime_.GetNativeEngine(); + NativeValue *result = CallOnConnect(want); + bool isPromise = CheckPromise(result); + if (!isPromise) { + isAsyncCallback = false; + sptr remoteObj = NAPI_ohos_rpc_getNativeRemoteObject(reinterpret_cast(nativeEngine), + reinterpret_cast(result)); + if (remoteObj == nullptr) { + HILOG_ERROR("remoteObj nullptr."); + } + return remoteObj; + } + + bool callResult = false; + do { + auto *retObj = ConvertNativeValueTo(result); + if (retObj == nullptr) { + HILOG_ERROR("CallPromise, Failed to convert native value to NativeObject."); + break; + } + NativeValue *then = retObj->GetProperty("then"); + if (then == nullptr) { + HILOG_ERROR("CallPromise, Failed to get property: then."); + break; + } + if (!then->IsCallable()) { + HILOG_ERROR("CallPromise, property then is not callable."); + break; + } + auto promiseCallback = nativeEngine->CreateFunction("promiseCallback", strlen("promiseCallback"), + OnConnectPromiseCallback, callbackInfo); + NativeValue *argv[1] = { promiseCallback }; + nativeEngine->CallFunction(result, then, argv, 1); + callResult = true; + } while (false); + + if (!callResult) { + HILOG_ERROR("Failed to call promise."); + isAsyncCallback = false; + } else { + isAsyncCallback = true; + } + return nullptr; +} + +void JsDriverExtension::OnDisconnect(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + Extension::OnDisconnect(want); + HILOG_DEBUG("%{public}s begin.", __func__); + CallOnDisconnect(want, false); + HILOG_DEBUG("%{public}s end.", __func__); +} + +void JsDriverExtension::OnDisconnect(const AAFwk::Want &want, + AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + Extension::OnDisconnect(want); + HILOG_DEBUG("%{public}s begin.", __func__); + NativeValue *result = CallOnDisconnect(want, true); + bool isPromise = CheckPromise(result); + if (!isPromise) { + isAsyncCallback = false; + return; + } + bool callResult = CallPromise(result, callbackInfo); + if (!callResult) { + HILOG_ERROR("Failed to call promise."); + isAsyncCallback = false; + } else { + isAsyncCallback = true; + } + + HILOG_DEBUG("%{public}s end.", __func__); +} + +NativeValue* JsDriverExtension::CallObjectMethod(const char* name, NativeValue* const *argv, size_t argc) +{ + HILOG_INFO("JsDriverExtension::CallObjectMethod(%{public}s), begin", name); + + if (!jsObj_) { + HILOG_WARN("Not found DriverExtension.js"); + return nullptr; + } + + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + + NativeValue* value = jsObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("Failed to get DriverExtension object"); + return nullptr; + } + + NativeValue* method = obj->GetProperty(name); + if (method == nullptr || method->TypeOf() != NATIVE_FUNCTION) { + HILOG_ERROR("Failed to get '%{public}s' from DriverExtension object", name); + return nullptr; + } + HILOG_INFO("JsDriverExtension::CallFunction(%{public}s), success", name); + return nativeEngine.CallFunction(value, method, argv, argc); +} + +void JsDriverExtension::GetSrcPath(std::string &srcPath) +{ + if (!Extension::abilityInfo_->isModuleJson) { + /* 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"); + } +} + +NativeValue *JsDriverExtension::CallOnConnect(const AAFwk::Want &want) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + Extension::OnConnect(want); + HILOG_DEBUG("%{public}s begin.", __func__); + NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine(); + napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast(nativeEngine), want); + auto* nativeWant = reinterpret_cast(napiWant); + NativeValue* argv[] = {nativeWant}; + if (!jsObj_) { + HILOG_WARN("Not found DriverExtension.js"); + return nullptr; + } + + NativeValue* value = jsObj_->Get(); + auto* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("Failed to get DriverExtension object"); + return nullptr; + } + + NativeValue* method = obj->GetProperty("onConnect"); + if (method == nullptr) { + HILOG_ERROR("Failed to get onConnect from DriverExtension object"); + return nullptr; + } + HILOG_INFO("JsDriverExtension::CallFunction onConnect, success"); + NativeValue* remoteNative = nativeEngine->CallFunction(value, method, argv, ARGC_ONE); + if (remoteNative == nullptr) { + HILOG_ERROR("remoteNative nullptr."); + } + HILOG_DEBUG("%{public}s end.", __func__); + return remoteNative; +} + +NativeValue *JsDriverExtension::CallOnDisconnect(const AAFwk::Want &want, bool withResult) +{ + HandleEscape handleEscape(jsRuntime_); + NativeEngine *nativeEngine = &jsRuntime_.GetNativeEngine(); + napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast(nativeEngine), want); + NativeValue *nativeWant = reinterpret_cast(napiWant); + NativeValue *argv[] = { nativeWant }; + if (!jsObj_) { + HILOG_WARN("Not found DriverExtension.js"); + return nullptr; + } + + NativeValue *value = jsObj_->Get(); + NativeObject *obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("Failed to get DriverExtension object"); + return nullptr; + } + + NativeValue *method = obj->GetProperty("onDisconnect"); + if (method == nullptr) { + HILOG_ERROR("Failed to get onDisconnect from DriverExtension object"); + return nullptr; + } + + if (withResult) { + return handleEscape.Escape(nativeEngine->CallFunction(value, method, argv, ARGC_ONE)); + } else { + nativeEngine->CallFunction(value, method, argv, ARGC_ONE); + return nullptr; + } +} + +bool JsDriverExtension::CheckPromise(NativeValue *result) +{ + if (result == nullptr) { + HILOG_DEBUG("CheckPromise, result is null, no need to call promise."); + return false; + } + if (!result->IsPromise()) { + HILOG_DEBUG("CheckPromise, result is not promise, no need to call promise."); + return false; + } + return true; +} + +bool JsDriverExtension::CallPromise(NativeValue *result, AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo) +{ + auto *retObj = ConvertNativeValueTo(result); + if (retObj == nullptr) { + HILOG_ERROR("CallPromise, Failed to convert native value to NativeObject."); + return false; + } + NativeValue *then = retObj->GetProperty("then"); + if (then == nullptr) { + HILOG_ERROR("CallPromise, Failed to get property: then."); + return false; + } + if (!then->IsCallable()) { + HILOG_ERROR("CallPromise, property then is not callable."); + return false; + } + HandleScope handleScope(jsRuntime_); + auto &nativeEngine = jsRuntime_.GetNativeEngine(); + auto promiseCallback = nativeEngine.CreateFunction("promiseCallback", strlen("promiseCallback"), PromiseCallback, + callbackInfo); + NativeValue *argv[1] = { promiseCallback }; + nativeEngine.CallFunction(result, then, argv, 1); + return true; +} + +void JsDriverExtension::Dump(const std::vector ¶ms, std::vector &info) +{ + Extension::Dump(params, info); + HILOG_INFO("%{public}s called.", __func__); + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + // create js array object of params + NativeValue* arrayValue = nativeEngine.CreateArray(params.size()); + NativeArray* array = ConvertNativeValueTo(arrayValue); + uint32_t index = 0; + for (const auto ¶m : params) { + array->SetElement(index++, CreateJsValue(nativeEngine, param)); + } + + NativeValue* argv[] = { arrayValue }; + NativeValue* dumpInfo = CallObjectMethod("onDump", argv, ARGC_ONE); + if (dumpInfo == nullptr) { + HILOG_ERROR("dumpInfo nullptr."); + return; + } + NativeArray* dumpInfoNative = ConvertNativeValueTo(dumpInfo); + if (dumpInfoNative == nullptr) { + HILOG_ERROR("dumpInfoNative nullptr."); + return; + } + for (uint32_t i = 0; i < dumpInfoNative->GetLength(); i++) { + std::string dumpInfoStr; + if (!ConvertFromJsValue(nativeEngine, dumpInfoNative->GetElement(i), dumpInfoStr)) { + HILOG_ERROR("Parse dumpInfoStr failed"); + return; + } + info.push_back(dumpInfoStr); + } + HILOG_DEBUG("Dump info size: %{public}zu", info.size()); +} +} +} diff --git a/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension_context.cpp b/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension_context.cpp new file mode 100644 index 000000000..4feaeb866 --- /dev/null +++ b/drivers_external_device_manager/service/native/driver_extension/src/js_driver_extension_context.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2023 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_driver_extension_context.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_runtime/js_caller_complex.h" +#include "hilog_wrapper.h" +#include "js_extension_context.h" +#include "js_error_utils.h" +#include "js_data_struct_converter.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "napi/native_api.h" +#include "napi_common_ability.h" +#include "napi_common_want.h" +#include "napi_common_util.h" +#include "napi_remote_object.h" +#include "napi_common_start_options.h" +#include "start_options.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr int32_t INDEX_ZERO = 0; +constexpr int32_t ERROR_CODE_ONE = 1; +constexpr size_t ARGC_ZERO = 0; + +class JsDriverExtensionContext final { +public: + explicit JsDriverExtensionContext(const std::shared_ptr& context) : context_(context) {} + ~JsDriverExtensionContext() = default; + + static void Finalizer(NativeEngine* engine, void* data, void* hint) + { + HILOG_INFO("JsAbilityContext::Finalizer is called"); + std::unique_ptr(static_cast(data)); + } + + static NativeValue* UpdateDriverState(NativeEngine* engine, NativeCallbackInfo* info) + { + JsDriverExtensionContext* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnUpdateDriverState(*engine, *info) : nullptr; + } + +private: + std::weak_ptr context_; + sptr freeInstallObserver_ = nullptr; + + NativeValue* OnUpdateDriverState(NativeEngine& engine, NativeCallbackInfo& info) + { + HILOG_INFO("OnUpdateDriverState is called"); + + AsyncTask::CompleteCallback complete = + [weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) { + HILOG_INFO("UpdateDriverState begin"); + auto context = weak.lock(); + if (!context) { + HILOG_WARN("context is released"); + task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released")); + return; + } + + ErrCode innerErrorCode = context->UpdateDriverState(); + if (innerErrorCode == 0) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsErrorByNativeErr(engine, innerErrorCode)); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ZERO) ? nullptr : info.argv[INDEX_ZERO]; + NativeValue* result = nullptr; + AsyncTask::Schedule("JSDriverExtensionContext::OnUpdateDriverState", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } +}; +} // namespace + +NativeValue* CreateJsDriverExtensionContext(NativeEngine& engine, std::shared_ptr context) +{ + HILOG_INFO("CreateJsDriverExtensionContext begin"); + std::shared_ptr abilityInfo = nullptr; + if (context) { + abilityInfo = context->GetAbilityInfo(); + } + NativeValue* objValue = CreateJsExtensionContext(engine, context, abilityInfo); + NativeObject* object = ConvertNativeValueTo(objValue); + + std::unique_ptr jsContext = std::make_unique(context); + object->SetNativePointer(jsContext.release(), JsDriverExtensionContext::Finalizer, nullptr); + + const char *moduleName = "JsDriverExtensionContext"; + BindNativeFunction(engine, *object, "updateDriverState", moduleName, JsDriverExtensionContext::UpdateDriverState); + + return objValue; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/drivers_external_device_manager/services/BUILD.gn b/drivers_external_device_manager/services/BUILD.gn new file mode 100644 index 000000000..35579ce5c --- /dev/null +++ b/drivers_external_device_manager/services/BUILD.gn @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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("../extdevmgr.gni") + +ohos_shared_library("driver_extension_manager") { + install_enable = true + sources = [ + "${ext_mgr_path}/services/zidl/src/driver_ext_mgr_stub.cpp", + "native/driver_extension_manager/src/driver_etx_mgr.cpp", + "native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp" + ] + + include_dirs = [ + "${ext_mgr_path}/services/native/driver_extension_manager/include", + "${ext_mgr_path}/services/native/driver_extension_manager/include/device_manager", + "${ext_mgr_path}/interfaces/innerkits/", + "${ext_mgr_path}/services/zidl/include/", + ] + configs = [ + "${utils_path}:utils_config" + ] + external_deps = [ + "ability_runtime:ability_manager", + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + subsystem_name = "hdf" + part_name = "external_device_manager" +} + +ohos_shared_library("bus_extension") { + sources = [ + "native/driver_extension_manager/src/bus_extension/driver_info.cpp", + "native/driver_extension_manager/src/bus_extension/bus_extension.cpp", + "native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp", + "native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp", + "native/driver_extension_manager/src/bus_extension/usb/usb_driver_info.cpp", + ] + include_dirs = [ + "//third_party/jsoncpp/include/json", + "native/driver_extension_manager/include/bus_extension/usb" + ] + configs = [ + "${utils_path}:coverage_flags", + "${utils_path}:utils_config" + ] + deps =[ + "//third_party/jsoncpp:jsoncpp", + ":driver_extension_manager" + ] + external_deps = [ + "drivers_interface_usb:libusb_proxy_1.0", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "bundle_framework:appexecfwk_base", + ] + + install_enable = true + subsystem_name = "hdf" + part_name = "external_device_manager" +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_bus_extension.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_bus_extension.h new file mode 100644 index 000000000..69f342534 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_bus_extension.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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 USB_BUS_EXTENSION_H +#define USB_BUS_EXTENSION_H +#include "ibus_extension.h" +#include "usb_device_info.h" +#include "v1_0/iusb_interface.h" +#include "usb_dev_subscriber.h" +namespace OHOS { +namespace ExternalDeviceManager { +using namespace std; +using namespace OHOS::HDI::Usb::V1_0; +class UsbBusExtension : public IBusExtension { +public: + UsbBusExtension(); + ~UsbBusExtension(); + int32_t SetDevChangeCallback(shared_ptr callback) override; + bool MatchDriver(const DriverInfo &driver, const DeviceInfo &device) override; + shared_ptr ParseDriverInfo(const vector &metadata) override; + void SetUsbInferface(sptr iusb); + +private: + sptr subScriber_ = nullptr; + sptr usbInterface_ = nullptr; // in usb HDI; + vector ParseCommaStrToVectorUint16(const string &str); +}; +} +} +#endif \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_dev_subscriber.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_dev_subscriber.h new file mode 100644 index 000000000..f5a905e78 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_dev_subscriber.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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 USB_DEV_SUBSCRIBER_H +#define USB_DEV_SUBSCRIBER_H +#include "ibus_extension.h" +#include "usb_device_info.h" +#include "v1_0/iusbd_subscriber.h" +#include "v1_0/iusb_interface.h" +namespace OHOS { +namespace ExternalDeviceManager { +using namespace OHOS::HDI::Usb::V1_0; + +class UsbDevSubscriber : public IUsbdSubscriber { +public: + void Init(shared_ptr callback, sptr iusb); + int32_t DeviceEvent(const USBDeviceInfo &info) override; + int32_t PortChangedEvent(const PortInfo &info) override; + string ToString(void); +private: + shared_ptr callback_; + map> deviceInfos_; + sptr iusb_; + int32_t OnDeviceConnect(const UsbDev &usbDev); + int32_t OnDeviceDisconnect(const UsbDev &usbDev); +}; +} +} +#endif \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_device_info.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_device_info.h new file mode 100644 index 000000000..830505339 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_device_info.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 USB_DEVICE_INFO_H +#define USB_DEVICE_INFO_H +#include "ibus_extension.h" +namespace OHOS { +namespace ExternalDeviceManager { +class UsbDeviceInfo : public DeviceInfo { +public: + UsbDeviceInfo(uint32_t busDeviceId, const std::string &description = "") + : DeviceInfo(busDeviceId, description) { } + ~UsbDeviceInfo() = default; +private: + friend class UsbBusExtension; + friend class UsbDevSubscriber; + uint16_t bcdUSB_ = 0; + uint8_t deviceClass_ = 0; + uint16_t idVendor_ = 0; + uint16_t idProduct_ = 0; +}; +} +} +#endif \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_driver_info.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_driver_info.h new file mode 100644 index 000000000..5f5afcae7 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/bus_extension/usb/usb_driver_info.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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 USB_DRIVER_INFO_H +#define USB_DRIVER_INFO_H +#include +#include "ibus_extension.h" +namespace OHOS { +namespace ExternalDeviceManager { +class UsbDriverInfo : public DriverInfoExt { +public: + int32_t Serialize(string &metaData) override; + int32_t UnSerialize(const string &metaData) override; +private: + friend class UsbBusExtension; + std::vector pids_; + std::vector vids_; +}; +} +} +#endif \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/device_manager/etx_device_mgr.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/device_manager/etx_device_mgr.h new file mode 100644 index 000000000..aa40581ae --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/device_manager/etx_device_mgr.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 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 DEVICE_MANAGER_ETX_DEVICE_MGR_H +#define DEVICE_MANAGER_ETX_DEVICE_MGR_H +#include +#include +#include + +#include "ext_object.h" +#include "ibus_extension.h" +namespace OHOS { +namespace ExternalDeviceManager { +class Device final { +public: + Device(std::shared_ptr info) : info_(info) {}; + + bool HasDriver() const; + +private: + std::shared_ptr driver_; + std::shared_ptr info_; +}; + +class ExtDeviceManager final { +public: + DECLARE_DELAYED_SINGLETON(ExtDeviceManager) + + int32_t Init(); + Device &RegisterDevice(const DeviceInfo &devInfo); + void UnRegisterDevice(const DeviceInfo &devInfo); + +private: + std::forward_list deviceList_; + std::mutex deviceListMutex_; +}; +} // namespace ExternalDeviceManager +} // namespace OHOS +#endif // DEVICE_MANAGER_ETX_DEVICE_MGR_H \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/include/driver_ext_mgr.h b/drivers_external_device_manager/services/native/driver_extension_manager/include/driver_ext_mgr.h new file mode 100644 index 000000000..e672e4a7b --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/include/driver_ext_mgr.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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 DRIVER_EXT_MGR_H +#define DRIVER_EXT_MGR_H +#include "driver_ext_mgr_stub.h" +#include "singleton.h" +#include "system_ability.h" + +namespace OHOS { +namespace ExternalDeviceManager { +class DriverExtMgr : public SystemAbility, public DriverExtMgrStub { + DECLARE_SYSTEM_ABILITY(DriverExtMgr) + DECLARE_DELAYED_SINGLETON(DriverExtMgr); + +public: + void OnStart() override; + void OnStop() override; + int Dump(int fd, const std::vector &args) override; + + int32_t QueryDevice() override; +}; +} // namespace ExternalDeviceManager +} // namespace OHOS +#endif // DRIVER_EXT_MGR_H diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/bus_extension.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/bus_extension.cpp new file mode 100644 index 000000000..95abee2fe --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/bus_extension.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 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 "string_ex.h" +#include "hilog_wrapper.h" +#include "ibus_extension.h" +#include "usb_bus_extension.h" +namespace OHOS { +namespace ExternalDeviceManager { +shared_ptr IBusExtension::GetInstance(const string &busType) +{ + if (LowerStr(busType) == "usb") { + return make_shared(); + } + return nullptr; +} + +__attribute__ ((constructor)) static void RegBusExtension() +{ + EDM_LOGI(MODULE_COMMON, "installing UsbBusExtension"); + RegisterBusExtension(BusType::BUS_TYPE_USB); +} +} +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/driver_info.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/driver_info.cpp new file mode 100644 index 000000000..ef10fe510 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/driver_info.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 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 "string_ex.h" +#include "json.h" +#include "hilog_wrapper.h" +#include "ibus_extension.h" +#include "usb_driver_info.h" +namespace OHOS { +namespace ExternalDeviceManager { +int32_t DriverInfo::Serialize(string &str) +{ + string extInfo; + if (this->driverInfoExt_ == nullptr) { + EDM_LOGE(MODULE_COMMON, "Serialize error, this->driverInfoExt_ is nullptr"); + return -1; + } + this->driverInfoExt_->Serialize(extInfo); + Json::Value root; + root["bus"] = this->bus_; + root["vendor"] = this->vendor_; + root["version"] = this->version_; + root["ext_info"] = extInfo; + Json::StreamWriterBuilder builder; + builder["indentation"] = ""; + str = Json::writeString(builder, root); + EDM_LOGI(MODULE_COMMON, "DriverInfo Serialize Done, %{public}s", str.c_str()); + return 0; +} +static bool IsJsonObjValid(const Json::Value &jsonObj, const string &member, uint32_t type) +{ + if (!jsonObj.isMember(member)) { + EDM_LOGE(MODULE_COMMON, "the json obj do not has menber :%{public}s", member.c_str()); + return false; + } + auto realType = jsonObj[member].type(); + if (realType != type) { + EDM_LOGE(MODULE_COMMON, "the json obj member[%{public}s] type error, need:%{public}d, which is:%{public}d", + member.c_str(), type, realType); + return false; + } + return true; +} + +int32_t DriverInfo::UnSerialize(const string &str) +{ + Json::CharReaderBuilder builder; + const unique_ptr reader(builder.newCharReader()); + JSONCPP_STRING err; + Json::Value jsonObj; + string extInfo; + auto rawJsonLength = static_cast(str.length()); + EDM_LOGD(MODULE_COMMON, "UnSeiralize, input str is : [%{public}s], length = %{public}d", \ + str.c_str(), rawJsonLength); + bool ret = reader->parse(str.c_str(), \ + str.c_str() + rawJsonLength, \ + &jsonObj,\ + &err); + if (ret == false) { + EDM_LOGE(MODULE_COMMON, "UnSeiralize error, parse json string error, ret = %{public}d, str is : %{public}s", \ + ret, str.c_str()); + EDM_LOGE(MODULE_COMMON, "JsonErr:%{public}s", err.c_str()); + return -1; + } + if (jsonObj.size() == 0) { + EDM_LOGE(MODULE_COMMON, "JsonObj size is 0"); + return 0; + } + if (!IsJsonObjValid(jsonObj, "bus", Json::stringValue)\ + ||!IsJsonObjValid(jsonObj, "vendor", Json::stringValue)\ + ||!IsJsonObjValid(jsonObj, "version", Json::stringValue)\ + ||!IsJsonObjValid(jsonObj, "ext_info", Json::stringValue)) { + EDM_LOGE(MODULE_COMMON, "json member or member type error"); + return -1; + } + auto busType = jsonObj["bus"].asString(); + if (LowerStr(busType) == "usb") { + this->driverInfoExt_ = make_shared(); + } else { + EDM_LOGE(MODULE_COMMON, "unknow bus type"); + return -1; + } + extInfo = jsonObj["ext_info"].asString(); + if (this->driverInfoExt_ == nullptr) { + EDM_LOGE(MODULE_COMMON, "error, this->driverInfoExt_ is nullptr"); + return -1; + } + ret = this->driverInfoExt_->UnSerialize(extInfo); + if (ret != 0) { + EDM_LOGE(MODULE_COMMON, "parse ext_info error"); + return -1; + } + this->bus_ = jsonObj["bus"].asString(); + this->vendor_ = jsonObj["vendor"].asString(); + this->version_ = jsonObj["version"].asString(); + return 0; +} +} +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp new file mode 100644 index 000000000..5cff80341 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2023 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 "string_ex.h" +#include "sstream" +#include "iostream" + +#include "hilog_wrapper.h" +#include "ibus_extension.h" +#include "usb_dev_subscriber.h" +#include "usb_driver_info.h" +#include "usb_device_info.h" +#include "usb_bus_extension.h" +namespace OHOS { +namespace ExternalDeviceManager { +using namespace std; + +UsbBusExtension::UsbBusExtension() +{ + this->subScriber_ = nullptr; + this->usbInterface_ = nullptr; +} + +UsbBusExtension::~UsbBusExtension() +{ + if (this->usbInterface_ != nullptr && this->subScriber_ != nullptr) { + this->usbInterface_->UnbindUsbdSubscriber(this->subScriber_); + } +} + +void UsbBusExtension::SetUsbInferface(sptr iusb) +{ + this->usbInterface_ = iusb; +} + +int32_t UsbBusExtension::SetDevChangeCallback(shared_ptr devCallback) +{ + if (this->usbInterface_ == nullptr) { + this->usbInterface_ = IUsbInterface::Get(); + if (this->usbInterface_ == nullptr) { + EDM_LOGE(MODULE_BUS_USB, "get IUsbInterface error"); + return -1; + } + EDM_LOGD(MODULE_BUS_USB, "get usbInferface sucess"); + } + if (this->subScriber_ == nullptr) { + this->subScriber_ = new UsbDevSubscriber(); + if (this->subScriber_ == nullptr) { + EDM_LOGE(MODULE_BUS_USB, "get usbDevSubscriber error"); + return -1; + } + EDM_LOGD(MODULE_BUS_USB, "get subScriber_ sucess"); + } + + this->subScriber_->Init(devCallback, usbInterface_); + this->usbInterface_->BindUsbdSubscriber(subScriber_); + return 0; +}; + +bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &device) +{ + if (LowerStr(driver.GetBusName()) != "usb") { + EDM_LOGW(MODULE_BUS_USB, "driver bus not support by this module [UsbBusExtension]"); + return false; + } + if (device.GetBusType() != BusType::BUS_TYPE_USB) { + EDM_LOGW(MODULE_BUS_USB, "deivce type not support"); + return false; + } + const UsbDriverInfo *usbDriverInfo = static_cast(driver.GetInfoExt().get()); + const UsbDeviceInfo *usbDeviceInfo = static_cast(&device); + if (usbDriverInfo == nullptr || usbDeviceInfo == nullptr) { + EDM_LOGE(MODULE_BUS_USB, "static_cast error, the usbDriverInfo or usbDeviceInfo is nullptr"); + return false; + } + + auto vidFind = find(usbDriverInfo->vids_.begin(), usbDriverInfo->vids_.end(), usbDeviceInfo->idVendor_); + if (vidFind == usbDriverInfo->vids_.end()) { + EDM_LOGI(MODULE_BUS_USB, "vid not match\n"); + return false; + } + auto pidFind = find(usbDriverInfo->pids_.begin(), usbDriverInfo->pids_.end(), usbDeviceInfo->idProduct_); + if (pidFind == usbDriverInfo->pids_.end()) { + EDM_LOGI(MODULE_BUS_USB, "pid not match\n"); + return false; + } + EDM_LOGI(MODULE_BUS_USB, "Driver and Device match sucess\n"); + return true; +} + +shared_ptr UsbBusExtension::ParseDriverInfo(const vector &metadata) +{ + shared_ptr usbDriverInfo = make_shared(); + if (usbDriverInfo == nullptr) { + EDM_LOGE(MODULE_BUS_USB, "creat UsbDriverInfo obj fail\n"); + return nullptr; + } + for (auto meta : metadata) { + if (LowerStr(meta.name) == "pid") { + usbDriverInfo->pids_ = this->ParseCommaStrToVectorUint16(meta.value); + } else if (LowerStr(meta.name) == "vid") { + usbDriverInfo->vids_ = this->ParseCommaStrToVectorUint16(meta.value); + } + } + return usbDriverInfo; +} + +vector UsbBusExtension::ParseCommaStrToVectorUint16(const string &str) +{ + vector ret; + stringstream ss(str); + string s; + int num; + while (getline(ss, s, ',')) { + stringstream(s) >> num; + ret.push_back(num); + } + if (ret.size() == 0) { + EDM_LOGW(MODULE_BUS_USB, "parse error, size 0, str:%{public}s.", str.c_str()); + } else { + EDM_LOGD(MODULE_BUS_USB, "parse sucess, size %{public}lu, str:%{public}s", ret.size(), str.c_str()); + } + + return ret; +} +} +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp new file mode 100644 index 000000000..be8177936 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2023 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 "string" +#include "securec.h" +#include "hilog_wrapper.h" +#include "usb_dev_subscriber.h" +namespace OHOS { +namespace ExternalDeviceManager { +using namespace std; +constexpr uint32_t MAX_DEV_ID_SIZE = 100; +constexpr uint32_t ACT_DEVUP = 0; +constexpr uint32_t ACT_DEVDOWN = 1; +constexpr uint32_t SHIFT_16 = 16; +struct UsbDevDescLite { + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize0; + uint16_t idVendor; + uint16_t idProduct; +} __attribute__((packed)); + +static string ToDeviceDesc(const UsbDev& usbDev, const UsbDevDescLite& desc) +{ + char buffer[MAX_DEV_ID_SIZE]; + auto ret = sprintf_s(buffer, sizeof(buffer), "USB&BUS_%02X&DEV_%02X&PID_%04X&VID_%04X&CLASS_%02X",\ + usbDev.busNum, usbDev.devAddr, desc.idProduct, desc.idVendor, desc.bDeviceClass); + if (ret != 0) { + EDM_LOGE(MODULE_BUS_USB, "ToBusDeivceId sprintf_s error. ret = %{public}d", ret); + return string(); + } + return string(buffer); +} + +static uint32_t ToBusDeivceId(const UsbDev& usbDev) +{ + uint32_t devId = (usbDev.busNum << SHIFT_16) + usbDev.devAddr; + return devId; +} + + +void UsbDevSubscriber::Init(shared_ptr callback, sptr iusb) +{ + this->iusb_ = iusb; + this->callback_ = callback; +}; + +int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) +{ + int32_t ret = 0; + if (this->iusb_ == nullptr) { + return -1; + } + vector descData; + ret = this->iusb_->GetDeviceDescriptor(usbDev, descData); + if (ret != 0) { + EDM_LOGE(MODULE_BUS_USB, "GetDeviceDescriptor fail, ret = %{public}d\n", ret); + return -1; + } + uint8_t *buffer = descData.data(); + uint32_t length = descData.size(); + if (length == 0) { + EDM_LOGE(MODULE_BUS_USB, "GetRawDescriptor failed len=%{public}d busNum:%{public}d devAddr:%{public}d",\ + length, usbDev.busNum, usbDev.devAddr); + return -1; + } + UsbDevDescLite deviceDescriptor = *(reinterpret_cast(buffer)); + if (deviceDescriptor.bLength != sizeof(UsbDevDescLite)) { + EDM_LOGE(MODULE_BUS_USB, "UsbdDeviceDescriptor size error"); + return -1; + } + string desc = ToDeviceDesc(usbDev, deviceDescriptor); + uint32_t busDevId = ToBusDeivceId(usbDev); + auto usbDevInfo = make_shared(busDevId, desc); + + usbDevInfo->bcdUSB_ = deviceDescriptor.bcdUSB; + usbDevInfo->idProduct_ = deviceDescriptor.idProduct; + usbDevInfo->idVendor_ = deviceDescriptor.idVendor; + usbDevInfo->deviceClass_ = deviceDescriptor.bDeviceClass; + + this->deviceInfos_[busDevId] = usbDevInfo; + if (this->callback_ != nullptr) { + this->callback_->OnDeviceAdd(usbDevInfo); + } + EDM_LOGD(MODULE_BUS_USB, "OnDeviceConnect:"); + EDM_LOGD(MODULE_BUS_USB, "%{public}s", desc.c_str()); + return 0; +}; + +int32_t UsbDevSubscriber::OnDeviceDisconnect(const UsbDev &usbDev) +{ + uint32_t busDevId = ToBusDeivceId(usbDev); + if (this->callback_ != nullptr) { + auto deviceInfo = this->deviceInfos_[busDevId]; + if (deviceInfo != nullptr) { + this->callback_->OnDeviceRemove(deviceInfo); + } else { + EDM_LOGW(MODULE_BUS_USB, "no dev in map, busDevId=%{public}08X \n", busDevId); + } + } + this->deviceInfos_.erase(busDevId); + return 0; +} + +int32_t UsbDevSubscriber::DeviceEvent(const USBDeviceInfo &usbDevInfo) +{ + UsbDev usbDev = {usbDevInfo.busNum, usbDevInfo.devNum}; + int32_t ret = 0; + if (usbDevInfo.status == ACT_DEVUP) { + ret = this->OnDeviceConnect(usbDev); + } else if (usbDevInfo.status == ACT_DEVDOWN) { + ret = this->OnDeviceDisconnect(usbDev); + } else { + EDM_LOGW(MODULE_BUS_USB, "status not support, %{public}d \n", usbDevInfo.status); + } + EDM_LOGD(MODULE_BUS_USB, "ret = %{public}d, %{public}s", ret, this->ToString().c_str()); + return ret; +} + +int32_t UsbDevSubscriber::PortChangedEvent(const PortInfo &usbDevInfo) +{ + return 0; +} + +string UsbDevSubscriber::ToString(void) +{ + string str = "DeviceInfos: Device count:" + to_string(this->deviceInfos_.size()) + "\n"; + int i = 0; + for (auto it = this->deviceInfos_.begin(); it != deviceInfos_.end(); it++) { + str += "[" +to_string(i++) + "]" + to_string(it->first) + "\n"; + } + return str; +} +} +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_driver_info.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_driver_info.cpp new file mode 100644 index 000000000..355ba5679 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/bus_extension/usb/usb_driver_info.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 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 "iostream" +#include "json.h" +#include "hilog_wrapper.h" +#include "usb_driver_info.h" +namespace OHOS { +namespace ExternalDeviceManager { +int32_t UsbDriverInfo::Serialize(string &driverStr) +{ + Json::Value valueRoot; + Json::Value valueVids; + Json::Value valuePids; + for (auto vid : vids_) { + valueVids.append(Json::Value(vid)); + }; + for (auto pid : pids_) { + valuePids.append(Json::Value(pid)); + }; + valueRoot["vids"] = valueVids; + valueRoot["pids"] = valuePids; + Json::StreamWriterBuilder builder; + builder["indentation"] = ""; + driverStr = Json::writeString(builder, valueRoot); + return 0; +} + +int32_t UsbDriverInfo::UnSerialize(const string &driverStr) +{ + EDM_LOGD(MODULE_BUS_USB, "UsbDrvInfo UnSerialize begin"); + Json::CharReaderBuilder builder; + unique_ptr const reader(builder.newCharReader()); + JSONCPP_STRING err; + Json::Value jsonObj; + bool ret = reader->parse(driverStr.c_str(), driverStr.c_str() + driverStr.length(), &jsonObj, &err); + if (ret == false) { + EDM_LOGE(MODULE_BUS_USB, "UnSeiralize error, parse json string error, ret = %{public}d, str is : %{public}s",\ + ret, driverStr.c_str()); + EDM_LOGE(MODULE_BUS_USB, "JsonErr:%{public}s", err.c_str()); + return -1; + } + if (jsonObj.size() == 0) { + EDM_LOGE(MODULE_BUS_USB, "Json size error"); + return -1; + } + EDM_LOGD(MODULE_BUS_USB, "parse json sucess"); + if (!jsonObj.isMember("vids") || !jsonObj.isMember("pids")) { + EDM_LOGE(MODULE_BUS_USB, "json member error, need menbers: vids, pids"); + return -1; + } + if (jsonObj["pids"].type() != Json::arrayValue || jsonObj["vids"].type() != Json::arrayValue) { + EDM_LOGE(MODULE_BUS_USB, "json member type error, pids type is : %{public}d, vids type is %{public}d", \ + jsonObj["pids"].type(), jsonObj["vids"].type()); + return -1; + } + EDM_LOGD(MODULE_BUS_USB, "menber type check sucess"); + vector vids_; + vector pids_; + for (auto vid : jsonObj["vids"]) { + if (vid.type() != Json::intValue) { + EDM_LOGE(MODULE_BUS_USB, "json vids type error, %{public}d", vid.type()); + return -1; + } + vids_.push_back(vid.asUInt()); + } + for (auto pid : jsonObj["pids"]) { + if (pid.type() != Json::intValue) { + EDM_LOGE(MODULE_BUS_USB, "json pid type error, %{public}d", pid.type()); + return -1; + } + pids_.push_back(pid.asUInt()); + } + this->pids_ = pids_; + this->vids_ = vids_; + return 0; +} +} +} \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp new file mode 100644 index 000000000..17edd020a --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 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 "etx_device_mgr.h" + +namespace OHOS { +namespace ExternalDeviceManager { +BusExtensionCore::BusExtensionCore() +{ + return; +} +BusExtensionCore::~BusExtensionCore() +{ + return; +} + +int32_t BusExtensionCore::Init() +{ + return 0; +} +int32_t BusExtensionCore::Register( + BusType busType, std::shared_ptr busExtension) +{ + return 0; +} +} // namespace ExternalDeviceManager +} // namespace OHOS \ No newline at end of file diff --git a/drivers_external_device_manager/services/native/driver_extension_manager/src/driver_etx_mgr.cpp b/drivers_external_device_manager/services/native/driver_extension_manager/src/driver_etx_mgr.cpp new file mode 100644 index 000000000..ac409b701 --- /dev/null +++ b/drivers_external_device_manager/services/native/driver_extension_manager/src/driver_etx_mgr.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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 "driver_ext_mgr.h" + +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace ExternalDeviceManager { +const bool G_REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); + +DriverExtMgr::DriverExtMgr() : SystemAbility(HDF_EXTERNAL_DEVICE_MANAGER_SA_ID, true) {} +DriverExtMgr::~DriverExtMgr() {} + +void DriverExtMgr::OnStart() {} + +void DriverExtMgr::OnStop() {} + +int DriverExtMgr::Dump(int fd, const std::vector &args) +{ + return 0; +} + +int32_t DriverExtMgr::QueryDevice() +{ + return 0; +} +} // namespace ExternalDeviceManager +} // namespace OHOS diff --git a/drivers_external_device_manager/services/zidl/include/driver_ext_mgr_stub.h b/drivers_external_device_manager/services/zidl/include/driver_ext_mgr_stub.h new file mode 100644 index 000000000..46bf28877 --- /dev/null +++ b/drivers_external_device_manager/services/zidl/include/driver_ext_mgr_stub.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 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 DRIVER_EXT_MGR_STUB_H +#define DRIVER_EXT_MGR_STUB_H +#include "idriver_ext_mgr.h" +#include "iremote_stub.h" +#include "message_option.h" +#include "nocopyable.h" + +namespace OHOS { +namespace ExternalDeviceManager { +class DriverExtMgrStub : public IRemoteStub { +public: + DISALLOW_COPY_AND_MOVE(DriverExtMgrStub); + + DriverExtMgrStub() = default; + + virtual ~DriverExtMgrStub() = default; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t QueryDeviceStub(); +}; +} // namespace ExternalDeviceManager +} // namespace OHOS + +#endif // DRIVER_EXT_MGR_STUB_H \ No newline at end of file diff --git a/drivers_external_device_manager/services/zidl/src/driver_ext_mgr_stub.cpp b/drivers_external_device_manager/services/zidl/src/driver_ext_mgr_stub.cpp new file mode 100644 index 000000000..3f76c4ca5 --- /dev/null +++ b/drivers_external_device_manager/services/zidl/src/driver_ext_mgr_stub.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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 "driver_ext_mgr_stub.h" +namespace OHOS { +namespace ExternalDeviceManager { +int DriverExtMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + return 0; +} +int32_t DriverExtMgrStub::QueryDeviceStub() +{ + return 0; +} +} // namespace ExternalDeviceManager +} // namespace OHOS diff --git a/drivers_external_device_manager/test/fuzztest/BUILD.gn b/drivers_external_device_manager/test/fuzztest/BUILD.gn new file mode 100644 index 000000000..f43b1e514 --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/BUILD.gn @@ -0,0 +1,24 @@ +# 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/config/features.gni") +import("//build/test.gni") + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + "bus_extension_fuzzer:bus_extension_fuzzer", + ] +} diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/BUILD.gn b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/BUILD.gn new file mode 100644 index 000000000..5a1a6cd2e --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/BUILD.gn @@ -0,0 +1,24 @@ +# 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/config/features.gni") +import("//build/test.gni") + +group("bus_extension_fuzzer") { + testonly = true + deps = [] + + deps += [ + "usbdriverinfo_fuzzer:UsbDriverInfoFuzzTest", + ] +} diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/BUILD.gn b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/BUILD.gn new file mode 100644 index 000000000..9e9a5a54e --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/BUILD.gn @@ -0,0 +1,41 @@ +# 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/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//drivers/external_device_manager/extdevmgr.gni") + +module_output_path = "${part_name}/fuzztest" +ohos_fuzztest("UsbDriverInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//drivers/external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer" + + sources = [ + "usbdriverinfo_fuzzer.cpp", + ] + include_dirs = [ + + ] + deps = [ + "${ext_mgr_path}/framework/bus_extension:bus_extension", + ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "bundle_framework:appexecfwk_base", + ] + defines = [ ] + configs = [ + "${utils_path}:utils_config", + ] +} diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/corpus/init b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/corpus/init new file mode 100644 index 000000000..8eb5a7d6e --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/project.xml b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/project.xml new file mode 100644 index 000000000..d37d5e342 --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 20 + + 2048 + + \ No newline at end of file diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.cpp b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.cpp new file mode 100644 index 000000000..de3fed7cc --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 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 "iostream" +#include "string" +#include "securec.h" +#include "ibus_extension.h" +#include "usb_driver_info.h" +#include "hilog_wrapper.h" +#include "usbdriverinfo_fuzzer.h" +namespace OHOS { +namespace ExtDevMgr { +using namespace std; + +bool IBusGetFuzzer(const uint8_t *data, size_t size) +{ + string str(reinterpret_cast(data)); + auto bus = IBusExtension::GetInstance(str); + return true; +} + +bool DriverInfoUnSerializeFuzzer(const uint8_t *data, size_t size) +{ + string drvInfoStr(reinterpret_cast(data)); + if (drvInfoStr.size() == 0) { + return false; + } + + DriverInfo devInfo; + devInfo.UnSerialize(drvInfoStr); + UsbDriverInfo usbDevInfo; + usbDevInfo.UnSerialize(drvInfoStr); + return true; +} +bool ParseDriverInfoTest(const uint8_t *data, size_t size) +{ + auto bus = IBusExtension::GetInstance("USB"); + string str(reinterpret_cast(data)); + Metadata vids; + Metadata pids; + vids.name = "vid"; + vids.value = str; + pids.name = "pid"; + pids.value = str; + vector metadata = {vids, pids}; + auto ret = bus->ParseDriverInfo(metadata); + return true; +} + +using TestFuncDef = bool (*)(const uint8_t *data, size_t size); + +TestFuncDef g_allTestFunc[] = { + IBusGetFuzzer, + DriverInfoUnSerializeFuzzer, + ParseDriverInfoTest, +}; + +bool DoSomethingInterestingWithMyAPI(const uint8_t *rawData, size_t size) +{ + if (size < sizeof(int)) { + return false; + } + int index = *(reinterpret_cast(rawData)); + rawData += sizeof(int); + size -= sizeof(int); + int funcCount = sizeof(g_allTestFunc) / sizeof(g_allTestFunc[0]); + + auto func = g_allTestFunc[index % funcCount]; + if (func != nullptr) { + auto ret = func(rawData, size); + return ret; + } + return false; +} +} // namespace ExtDevMgr +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ExtDevMgr::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.h b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.h new file mode 100644 index 000000000..71f3d1e00 --- /dev/null +++ b/drivers_external_device_manager/test/fuzztest/bus_extension_fuzzer/usbdriverinfo_fuzzer/usbdriverinfo_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 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 USB_DRIVER_INFO_FUZZER +#define USB_DRIVER_INFO_FUZZER +#define FUZZ_PROJECT_NAME "usbdriverinfo_fuzzer" + +#endif \ No newline at end of file diff --git a/drivers_external_device_manager/utils/BUILD.gn b/drivers_external_device_manager/utils/BUILD.gn new file mode 100644 index 000000000..def4ea211 --- /dev/null +++ b/drivers_external_device_manager/utils/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2023 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. + +config("utils_config") { + include_dirs = ["include"] +} + +declare_args() { + external_device_manager_coverage= false +} + +config("coverage_flags") { + if (external_device_manager_coverage) { + cflags = ["--coverage"] + ldflags = ["--coverage"] + } +} diff --git a/drivers_external_device_manager/utils/include/ext_object.h b/drivers_external_device_manager/utils/include/ext_object.h new file mode 100644 index 000000000..c3e62633e --- /dev/null +++ b/drivers_external_device_manager/utils/include/ext_object.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2023 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 EXT_OBJECT_H +#define EXT_OBJECT_H +#include +#include +#include "singleton.h" +namespace OHOS { +namespace ExternalDeviceManager { +enum BusType : uint32_t { + BUS_TYPE_INVALID = 0, + BUS_TYPE_USB = 1, +}; +class IBusExtension; + +class DriverInfoExt { +public: + virtual ~DriverInfoExt() = default; + virtual int32_t Serialize(std::string &str) = 0; + virtual int32_t UnSerialize(const std::string &str) = 0; +}; + +class DriverInfo : public DriverInfoExt { +public: + int32_t Serialize(std::string &str) override; + int32_t UnSerialize(const std::string &str) override; + std::string GetBusName() const + { + return bus_; + } + std::shared_ptr GetInfoExt() const + { + return driverInfoExt_; + } +private: + std::string bus_; + std::string vendor_; + std::string version_; + std::shared_ptr driverInfoExt_; +}; + +class DeviceInfo { +public: + DeviceInfo(uint32_t busDeviceId, const std::string &description = "") : description_(description) + { + devInfo_.devBusInfo.busDeviceId = busDeviceId; + } + virtual ~DeviceInfo() = default; + BusType GetBusType() const + { + return devInfo_.devBusInfo.busType; + } + +private: + friend class DevChangeCallback; + union DevInfo { + uint64_t deviceId; + struct { + uint32_t busDeviceId; + BusType busType; + } devBusInfo; + } devInfo_; + std::string description_ {""}; +}; + +class ExtDeviceManager; +class IDevChangeCallback { +public: + virtual ~IDevChangeCallback(); + virtual int32_t OnDeviceAdd(std::shared_ptr device); + virtual int32_t OnDeviceRemove(std::shared_ptr device); +}; + +class DevChangeCallback final : public IDevChangeCallback { +public: + DevChangeCallback(BusType busType, std::shared_ptr extDevMgr) + : busType_(busType), extDevMgr_(extDevMgr) {}; + int32_t OnDeviceAdd(std::shared_ptr device) override; + int32_t OnDeviceRemove(std::shared_ptr device) override; + +private: + BusType busType_; + std::shared_ptr extDevMgr_; +}; + + +class BusExtensionCore { + DECLARE_DELAYED_SINGLETON(BusExtensionCore) +public: + int32_t Init(); + int32_t Register(BusType busType, std::shared_ptr busExtension); + +private: + std::unordered_map> busExtensions_; + const uint32_t MAX_BUS_EXTENSIONS = 100; +}; + +// bus extension should register by __attribute__ ((constructor)) when loading so +template +void RegisterBusExtension(BusType busType) +{ + DelayedSingleton::GetInstance()->Register(\ + busType, std::make_shared()); +} +} // namespace ExternalDeviceManager +} // namespace OHOS +#endif // EXT_OBJECT_H \ No newline at end of file diff --git a/drivers_external_device_manager/utils/include/hilog_wrapper.h b/drivers_external_device_manager/utils/include/hilog_wrapper.h new file mode 100644 index 000000000..0970a6e65 --- /dev/null +++ b/drivers_external_device_manager/utils/include/hilog_wrapper.h @@ -0,0 +1,98 @@ +/* + * 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 HILOG_WRAPPER_H +#define HILOG_WRAPPER_H + +#define CONFIG_HILOG +#ifdef CONFIG_HILOG +#include "hilog/log.h" +namespace OHOS { +namespace ExternalDeviceManager { +#define FORMATED_EDM(fmt, ...) "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__ + +#ifdef EDM_LOGF +#undef EDM_LOGF +#endif + +#ifdef EDM_LOGE +#undef EDM_LOGE +#endif + +#ifdef EDM_LOGW +#undef EDM_LOGW +#endif + +#ifdef EDM_LOGI +#undef EDM_LOGI +#endif + +#ifdef EDM_LOGD +#undef EDM_LOGD +#endif + +// param of log interface, such as EDM_LOGF. +enum UsbMgrSubModule { + MODULE_SERVICE = 0, + MODULE_DEV_MGR, + MODULE_PKG_MGR, + MODULE_EA_MGR, + MODULE_BUS_USB, + MODULE_COMMON, + EDM_MODULE_BUTT, +}; + +// 0xD002900: subsystem:Usb module:Usb, reserved 8 bit. +constexpr unsigned int BASE_EDM_DOMAIN_ID = 0xD002550; + +enum UsbMgrDomainId { + EDM_SERVICE_DOMAIN = BASE_EDM_DOMAIN_ID + MODULE_SERVICE, + EDM_DEV_MGR_DOMAIN, + EDM_PKG_MGR_DOMAIN, + EDM_EA_MGR_DOMAIN, + EDM_BUS_USB_DOMAIN, + EDM_COMMON_DOMAIN, + EDM_BUTT, +}; + +constexpr OHOS::HiviewDFX::HiLogLabel EDM_MGR_LABEL[EDM_MODULE_BUTT] = { + {LOG_CORE, EDM_SERVICE_DOMAIN, "EdmService"}, + {LOG_CORE, EDM_DEV_MGR_DOMAIN, "EdmDevMgr"}, + {LOG_CORE, EDM_PKG_MGR_DOMAIN, "EdmPkgMgr"}, + {LOG_CORE, EDM_EA_MGR_DOMAIN, "EdmEaMgr"}, + {LOG_CORE, EDM_BUS_USB_DOMAIN, "EdmBusUsbMgr"}, + {LOG_CORE, EDM_COMMON_DOMAIN, "EdmCommon"}, +}; + +// In order to improve performance, do not check the module range, module should less than EDM_MODULE_BUTT. +#define EDM_LOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__)) +#define EDM_LOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__)) +#define EDM_LOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__)) +#define EDM_LOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__)) +#define EDM_LOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__)) +} // namespace ExternalDeviceManager +} // namespace OHOS + +#else + +#define EDM_LOGF(...) +#define EDM_LOGE(...) +#define EDM_LOGW(...) +#define EDM_LOGI(...) +#define EDM_LOGD(...) + +#endif // CONFIG_HILOG + +#endif // HILOG_WRAPPER_H diff --git a/drivers_external_device_manager/utils/include/ibus_extension.h b/drivers_external_device_manager/utils/include/ibus_extension.h new file mode 100644 index 000000000..de3db9fb1 --- /dev/null +++ b/drivers_external_device_manager/utils/include/ibus_extension.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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 IUSB_EXTENSION_H +#define IUSB_EXTENSION_H +#include +#include +#include +#include +#include "application_info.h" +#include "ext_object.h" +namespace OHOS { +namespace ExternalDeviceManager { +using namespace std; +using namespace OHOS::AppExecFwk; + + +class IBusExtension { +public: + virtual ~IBusExtension() = default; + static shared_ptr GetInstance(const string &busType); + virtual shared_ptr ParseDriverInfo(const vector &metadata) = 0; + virtual bool MatchDriver(const DriverInfo &driver, const DeviceInfo &device) = 0; + virtual int32_t SetDevChangeCallback(shared_ptr callback) = 0; +}; +} +} + +#endif \ No newline at end of file -- Gitee