From c3cd228ee50571e8da8f9b9626aa2ce1a1499448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 6 Sep 2021 11:29:19 +0800 Subject: [PATCH 1/4] support L1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- BUILD.gn | 22 + LICENSE | 356 ++-- README_zh.md | 190 +- common/include/constants.h | 124 ++ common/include/ipc/ipc_def.h | 53 + common/include/ipc/lite/ipc_cmd_register.h | 120 ++ .../ipc/model/ipc_authenticate_device_req.h | 62 + .../ipc/model/ipc_check_authentication_req.h | 40 + .../ipc/model/ipc_get_trustdevice_req.h | 40 + .../ipc/model/ipc_get_trustdevice_rsp.h | 94 +- .../ipc/model/ipc_notify_auth_result_req.h | 75 + .../model/ipc_notify_check_auth_result_req.h | 64 + .../ipc/model/ipc_notify_device_found_req.h | 53 + .../ipc/model/ipc_notify_device_state_req.h | 53 + .../model/ipc_notify_discover_result_req.h | 53 + .../ipc/model/ipc_register_listener_req.h} | 116 +- common/include/ipc/model/ipc_req.h | 42 + common/include/ipc/model/ipc_rsp.h | 42 + .../ipc/model/ipc_start_discovery_req.h | 100 +- .../ipc/model/ipc_stop_discovery_req.h | 42 + .../include/ipc/standard/ipc_cmd_register.h | 99 + .../log/device_manager_log.h} | 67 +- .../include/utils}/anonymous_string.h | 50 +- common/include/utils/device_manager_errno.h | 61 + .../utils}/single_instance.h | 9 + common/src/ipc/lite/ipc_cmd_register.cpp | 69 + .../src/ipc/standard/ipc_cmd_register.cpp | 105 +- common/src/log/device_manager_log.cpp | 80 + .../src/utils}/anonymous_string.cpp | 140 +- device_manager.7z | Bin 0 -> 56365 bytes devicemanager.gni | 4 + interfaces/inner_kits/native_cpp/BUILD.gn | 153 +- .../native_cpp/include/device_manager.h | 115 +- .../include/device_manager_callback.h | 114 +- ..._manager_proxy.h => device_manager_impl.h} | 106 +- .../include/device_manager_listener_stub.h | 64 - .../native_cpp/include/dm_device_info.h | 112 +- .../native_cpp/include/dm_subscribe_info.h | 163 +- .../native_cpp/include/ipc/ipc_client.h | 37 + .../native_cpp/include/ipc/ipc_client_proxy.h | 94 +- .../include/ipc/lite/ipc_client_manager.h | 42 + .../ipc/lite/ipc_client_server_proxy.h | 45 + .../include/ipc/lite/ipc_client_stub.h | 43 + .../include/ipc/standard/ipc_client_manager.h | 58 + .../ipc/standard/ipc_client_server_proxy.h | 39 + .../include/ipc/standard/ipc_client_stub.h | 40 + .../include/ipc/standard/ipc_remote_broker.h | 38 + .../include/notify/device_manager_notify.h | 69 + .../native_cpp/src/device_manager.cpp | 341 +--- .../native_cpp/src/device_manager_impl.cpp | 247 +++ .../src/device_manager_listener_stub.cpp | 303 --- .../native_cpp/src/device_manager_proxy.cpp | 316 --- .../native_cpp/src/ipc/ipc_client_proxy.cpp | 48 + .../src/ipc/lite/ipc_client_manager.cpp | 92 + .../src/ipc/lite/ipc_client_server_proxy.cpp | 138 ++ .../src/ipc/lite/ipc_client_stub.cpp | 57 + .../src/ipc/lite/ipc_cmd_parser.cpp | 287 +++ .../src/ipc/standard/ipc_client_manager.cpp | 152 ++ .../ipc/standard/ipc_client_server_proxy.cpp | 47 + .../src/ipc/standard/ipc_client_stub.cpp | 45 + .../src/ipc/standard/ipc_cmd_parser.cpp | 302 +++ .../src/notify/device_manager_notify.cpp | 270 +++ ...hos.distributedHardware.deviceManager.d.ts | 311 +++ interfaces/kits/js/BUILD.gn | 35 +- .../kits/js/include/native_devicemanager_js.h | 301 +-- interfaces/kits/js/src/dm_native_event.cpp | 20 +- .../kits/js/src/native_devicemanager_js.cpp | 1795 +++++++++-------- ohos.build | 6 +- services/devicemanagerservice/BUILD.gn | 229 ++- .../hichain_connector.h} | 177 +- .../include/device_manager_listener_proxy.h | 44 - .../include/device_manager_stub.h | 48 - .../include/encrypt/encrypt_utils.h | 63 + .../include/ipc/ipc_server_adapter.h | 47 + .../include/ipc/ipc_server_listener_adapter.h | 42 + .../include/ipc/lite/ipc_server_listener.h | 41 + .../include/ipc/lite/ipc_server_listenermgr.h | 50 + .../include/ipc/lite/ipc_server_stub.h | 27 + .../ipc/standard/ipc_server_client_proxy.h | 35 + .../ipc/standard/ipc_server_listener.h | 36 + .../standard/ipc_server_stub.h} | 174 +- .../include/message/msg_codec.h | 40 + .../include/message/msg_common.h | 49 + .../include/message/msg_request_auth.h | 73 + .../include/message/msg_response_auth.h | 56 + .../include/message/msg_sync_group.h | 40 + .../auth_manager.h} | 110 +- .../include/requestauth/request_session.h | 127 +- .../include/softbus/softbus_adapter.h | 162 +- .../include/softbus/softbus_session.h | 52 + .../src/auth/hichain_connector.cpp | 154 ++ .../src/authdemo/device_client_channel.cpp | 166 -- .../src/authdemo/device_server_channel.cpp | 205 -- .../src/authdemo/hichain_adapter.cpp | 384 ---- .../src/device_manager_listener_proxy.cpp | 294 --- .../src/device_manager_service.cpp | 291 --- .../src/device_manager_stub.cpp | 205 -- .../src/encrypt/encrypt_utils.cpp | 358 ++++ .../src/ipc/ipc_server_adapter.cpp | 165 ++ .../src/ipc/ipc_server_listener_adapter.cpp | 117 ++ .../src/ipc/lite/ipc_cmd_parser.cpp | 215 ++ .../src/ipc/lite/ipc_server_listener.cpp | 90 + .../src/ipc/lite/ipc_server_listenermgr.cpp | 66 + .../src/ipc/lite/ipc_server_main.cpp | 52 + .../src/ipc/lite/ipc_server_stub.cpp | 234 +++ .../src/ipc/standard/ipc_cmd_parser.cpp | 284 +++ .../ipc/standard/ipc_server_client_proxy.cpp | 48 + .../src/ipc/standard/ipc_server_listener.cpp | 49 + .../src/ipc/standard/ipc_server_stub.cpp | 197 ++ .../src/message/msg_codec.cpp | 68 + .../src/message/msg_common.cpp | 52 + .../src/message/msg_request_auth.cpp | 291 +++ .../src/message/msg_response_auth.cpp | 115 ++ .../src/message/msg_sync_group.cpp | 40 + .../src/requestauth/auth_manager.cpp | 172 ++ .../src/requestauth/request_session.cpp | 231 +++ .../src/softbus/softbus_adapter.cpp | 1043 +++++----- .../src/softbus/softbus_session.cpp | 194 ++ 118 files changed, 10654 insertions(+), 5718 deletions(-) create mode 100644 BUILD.gn create mode 100644 common/include/constants.h create mode 100644 common/include/ipc/ipc_def.h create mode 100644 common/include/ipc/lite/ipc_cmd_register.h create mode 100644 common/include/ipc/model/ipc_authenticate_device_req.h create mode 100644 common/include/ipc/model/ipc_check_authentication_req.h create mode 100644 common/include/ipc/model/ipc_get_trustdevice_req.h rename interfaces/inner_kits/native_cpp/src/dm_device_info.cpp => common/include/ipc/model/ipc_get_trustdevice_rsp.h (51%) create mode 100644 common/include/ipc/model/ipc_notify_auth_result_req.h create mode 100644 common/include/ipc/model/ipc_notify_check_auth_result_req.h create mode 100644 common/include/ipc/model/ipc_notify_device_found_req.h create mode 100644 common/include/ipc/model/ipc_notify_device_state_req.h create mode 100644 common/include/ipc/model/ipc_notify_discover_result_req.h rename common/{log/include/device_manager_log.h => include/ipc/model/ipc_register_listener_req.h} (45%) create mode 100644 common/include/ipc/model/ipc_req.h create mode 100644 common/include/ipc/model/ipc_rsp.h rename interfaces/inner_kits/native_cpp/src/dm_subscribe_info.cpp => common/include/ipc/model/ipc_start_discovery_req.h (41%) create mode 100644 common/include/ipc/model/ipc_stop_discovery_req.h create mode 100644 common/include/ipc/standard/ipc_cmd_register.h rename common/{utils/include/device_manager_errno.h => include/log/device_manager_log.h} (56%) rename {services/devicemanagerservice/include/util => common/include/utils}/anonymous_string.h (97%) create mode 100644 common/include/utils/device_manager_errno.h rename common/{utils/include => include/utils}/single_instance.h (78%) create mode 100644 common/src/ipc/lite/ipc_cmd_register.cpp rename interfaces/inner_kits/native_cpp/include/idevice_manager_listener.h => common/src/ipc/standard/ipc_cmd_register.cpp (33%) create mode 100644 common/src/log/device_manager_log.cpp rename {services/devicemanagerservice/src/util => common/src/utils}/anonymous_string.cpp (96%) create mode 100644 device_manager.7z rename interfaces/inner_kits/native_cpp/include/{device_manager_proxy.h => device_manager_impl.h} (32%) delete mode 100644 interfaces/inner_kits/native_cpp/include/device_manager_listener_stub.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h rename services/devicemanagerservice/include/authdemo/device_server_channel.h => interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h (40%) create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h create mode 100644 interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h create mode 100644 interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h create mode 100644 interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp delete mode 100644 interfaces/inner_kits/native_cpp/src/device_manager_listener_stub.cpp delete mode 100644 interfaces/inner_kits/native_cpp/src/device_manager_proxy.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/ipc_client_proxy.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp create mode 100644 interfaces/kits/js/@ohos.distributedHardware.deviceManager.d.ts rename services/devicemanagerservice/include/{authdemo/hichain_adapter.h => auth/hichain_connector.h} (38%) delete mode 100644 services/devicemanagerservice/include/device_manager_listener_proxy.h delete mode 100644 services/devicemanagerservice/include/device_manager_stub.h create mode 100644 services/devicemanagerservice/include/encrypt/encrypt_utils.h create mode 100644 services/devicemanagerservice/include/ipc/ipc_server_adapter.h create mode 100644 services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h create mode 100644 services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h create mode 100644 services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h create mode 100644 services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h create mode 100644 services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h create mode 100644 services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h rename services/devicemanagerservice/include/{device_manager_service.h => ipc/standard/ipc_server_stub.h} (44%) create mode 100644 services/devicemanagerservice/include/message/msg_codec.h create mode 100644 services/devicemanagerservice/include/message/msg_common.h create mode 100644 services/devicemanagerservice/include/message/msg_request_auth.h create mode 100644 services/devicemanagerservice/include/message/msg_response_auth.h create mode 100644 services/devicemanagerservice/include/message/msg_sync_group.h rename services/devicemanagerservice/include/{authdemo/device_client_channel.h => requestauth/auth_manager.h} (34%) rename interfaces/inner_kits/native_cpp/include/idevice_manager.h => services/devicemanagerservice/include/requestauth/request_session.h (30%) create mode 100644 services/devicemanagerservice/include/softbus/softbus_session.h create mode 100644 services/devicemanagerservice/src/auth/hichain_connector.cpp delete mode 100644 services/devicemanagerservice/src/authdemo/device_client_channel.cpp delete mode 100644 services/devicemanagerservice/src/authdemo/device_server_channel.cpp delete mode 100644 services/devicemanagerservice/src/authdemo/hichain_adapter.cpp delete mode 100644 services/devicemanagerservice/src/device_manager_listener_proxy.cpp delete mode 100644 services/devicemanagerservice/src/device_manager_service.cpp delete mode 100644 services/devicemanagerservice/src/device_manager_stub.cpp create mode 100644 services/devicemanagerservice/src/encrypt/encrypt_utils.cpp create mode 100644 services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp create mode 100644 services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp create mode 100644 services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp create mode 100644 services/devicemanagerservice/src/ipc/lite/ipc_server_listener.cpp create mode 100644 services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp create mode 100644 services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp create mode 100644 services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp create mode 100644 services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp create mode 100644 services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp create mode 100644 services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp create mode 100644 services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp create mode 100644 services/devicemanagerservice/src/message/msg_codec.cpp create mode 100644 services/devicemanagerservice/src/message/msg_common.cpp create mode 100644 services/devicemanagerservice/src/message/msg_request_auth.cpp create mode 100644 services/devicemanagerservice/src/message/msg_response_auth.cpp create mode 100644 services/devicemanagerservice/src/message/msg_sync_group.cpp create mode 100644 services/devicemanagerservice/src/requestauth/auth_manager.cpp create mode 100644 services/devicemanagerservice/src/requestauth/request_session.cpp create mode 100644 services/devicemanagerservice/src/softbus/softbus_session.cpp diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 000000000..d9945174c --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,22 @@ +# 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. + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + lite_component("devicemanager_lite") { + features = [ + "services/devicemanagerservice:devicemanagerservice", + "interfaces/inner_kits/native_cpp:devicemanagersdk", + ] + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index f91efc558..e454a5258 100644 --- a/LICENSE +++ b/LICENSE @@ -1,178 +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 - + + 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/README_zh.md b/README_zh.md index 92a18a6b9..bafeebfba 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,95 +1,95 @@ -# **DeviceManager组件** - -## 简介 - -DeviceManager组件是OpenHarmony为开发者提供的一套分布式设备账号无关的认证组网接口。 - -其组成及依赖如下所示: - -![](figures/devicemanager_zh.png) - -## 目录 - -``` -foundation/distributedhardware/devicemanager -├── common -│   ├── log #log相关头文件存放目录 -│   └── utils #公共能力头文件存放目录 -├── interfaces -│   ├── inner_kits #内部接口头文件存放目录 -│   │   └── native_cpp #内部native接口及实现存放目录 -│   kits #外接口头文件存放目录 -│   └── js #外部JS接口及实现存放目录 -└── services - └── devicemanagerservice #devicemanagerservice服务实现核心代码 - ├── include - │   ├── authdemo #与设备认证相关头文件(非正式) - │   └── softbus #与软总线相关头文件 - └── src - ├── authdemo #设备认证功能示例代码(非正式) - └── softbus #通道建立及组网功能核心代码 -``` - -## 约束 - -- 开发语言:JS -- 适用于Hi3516DV300单板等OpenHarmony设备 - - -## 接口说明 - -当前版本设备管理服务不具备权限管理的能力。 - -以下模块的JS接口为非正式API,仅供分布式Demo应用使用,展示分布式能力,不排除对这些接口进行变更的可能性,后续版本将提供正式API。 - -参见 *ohos.distributedHardware.deviceManager.d.ts* - -| 原型 | 描述 | -| ------- | ---------- | -| createDeviceManager(bundleName: string, callback: AsyncCallback): void | 以异步方法获取DeviceManager实例 | -| release(): void | 释放DeviceManager实例 | -| getTrustedDeviceListSync(): Array | 获取信任设备列表 | -| authenticateDevice(deviceInfo: DeviceInfo): void | 设备认证 | -| on(type: 'authResult', callback: Callback<{ deviceId: string, status: number, reason: number }>): void | 订阅设备认证回调 | -| off(type: 'authResult', callback?: Callback<{ deviceId: string, status: number, reason: number }>): void | 取消订阅设备认证回调 | - - -### 示例如下: -``` -deviceManager.createDeviceManager(app.getInfo. appID, (err, data) => { - if (err) { - console.info(TAG + "createDeviceManager err:" + JSON.stringify(err)); - return; - } - console.info(TAG + "createDeviceManager success"); - dmClass = data; -} - -var deviceInfo ={ - "deviceId": "XXXXXXXX", - "deviceName": "", - deviceType: 0 -}; -dmClass.authenticateDevice(deviceInfo); -``` - -## 使用说明 - -当前版本是一个临时Demo认证方案,默认无法成功建立连接和PIN码认证,仅用于验证分布式能力,后续会提供正式的设备认证方案。 - -如果开发者感兴趣,可以通过修改代码来验证分布式能力。 - -**注:该方法存在一定安全风险,仅用于验证分布式能力。** -``` -devicemanager\services\devicemanagerservice\src\authdemo\hichain_adapter.cpp - -// PIN_CODE一般为随机6位数字字符串, 例如; -const std::string PIN_CODE = "123456"; - -// PORT为server端的监听端口号,随机端口范围一般为1024~65534, 例如 -const int32_t PORT = 10001; -``` - -## 相关仓 - -**device_manager** +# **DeviceManager组件** + +## 简介 + +DeviceManager组件是OpenHarmony为开发者提供的一套分布式设备账号无关的认证组网接口。 + +其组成及依赖如下所示: + +![](figures/devicemanager_zh.png) + +## 目录 + +``` +foundation/distributedhardware/devicemanager +├── common +│   ├── log #log相关头文件存放目录 +│   └── utils #公共能力头文件存放目录 +├── interfaces +│   ├── inner_kits #内部接口头文件存放目录 +│   │   └── native_cpp #内部native接口及实现存放目录 +│   kits #外接口头文件存放目录 +│   └── js #外部JS接口及实现存放目录 +└── services + └── devicemanagerservice #devicemanagerservice服务实现核心代码 + ├── include + │   ├── authdemo #与设备认证相关头文件(非正式) + │   └── softbus #与软总线相关头文件 + └── src + ├── authdemo #设备认证功能示例代码(非正式) + └── softbus #通道建立及组网功能核心代码 +``` + +## 约束 + +- 开发语言:JS +- 适用于Hi3516DV300单板等OpenHarmony设备 + + +## 接口说明 + +当前版本设备管理服务不具备权限管理的能力。 + +以下模块的JS接口为非正式API,仅供分布式Demo应用使用,展示分布式能力,不排除对这些接口进行变更的可能性,后续版本将提供正式API。 + +参见 *ohos.distributedHardware.deviceManager.d.ts* + +| 原型 | 描述 | +| ------- | ---------- | +| createDeviceManager(bundleName: string, callback: AsyncCallback): void | 以异步方法获取DeviceManager实例 | +| release(): void | 释放DeviceManager实例 | +| getTrustedDeviceListSync(): Array | 获取信任设备列表 | +| authenticateDevice(deviceInfo: DeviceInfo): void | 设备认证 | +| on(type: 'authResult', callback: Callback<{ deviceId: string, status: number, reason: number }>): void | 订阅设备认证回调 | +| off(type: 'authResult', callback?: Callback<{ deviceId: string, status: number, reason: number }>): void | 取消订阅设备认证回调 | + + +### 示例如下: +``` +deviceManager.createDeviceManager(app.getInfo. appID, (err, data) => { + if (err) { + console.info(TAG + "createDeviceManager err:" + JSON.stringify(err)); + return; + } + console.info(TAG + "createDeviceManager success"); + dmClass = data; +} + +var deviceInfo ={ + "deviceId": "XXXXXXXX", + "deviceName": "", + deviceType: 0 +}; +dmClass.authenticateDevice(deviceInfo); +``` + +## 使用说明 + +当前版本是一个临时Demo认证方案,默认无法成功建立连接和PIN码认证,仅用于验证分布式能力,后续会提供正式的设备认证方案。 + +如果开发者感兴趣,可以通过修改代码来验证分布式能力。 + +**注:该方法存在一定安全风险,仅用于验证分布式能力。** +``` +devicemanager\services\devicemanagerservice\src\authdemo\hichain_adapter.cpp + +// PIN_CODE一般为随机6位数字字符串, 例如; +const std::string PIN_CODE = "123456"; + +// PORT为server端的监听端口号,随机端口范围一般为1024~65534, 例如 +const int32_t PORT = 10001; +``` + +## 相关仓 + +**device_manager** diff --git a/common/include/constants.h b/common/include/constants.h new file mode 100644 index 000000000..7a09f0e47 --- /dev/null +++ b/common/include/constants.h @@ -0,0 +1,124 @@ +/* + * 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 OHOS_DEVICE_MANAGER_CONSTANTS_H +#define OHOS_DEVICE_MANAGER_CONSTANTS_H + +#include +#include + +namespace OHOS { +namespace DistributedHardware { + const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; + const std::string HOST_PKG_NAME_KEY = "hostPackageName"; + + const int32_t LOG_MAX_LEN = 512; + const int32_t MIN_PIN_TOKEN = 10000000; + const int32_t MAX_PIN_TOKEN = 90000000; + const int32_t MIN_PIN_CODE = 100000; + const int32_t MAX_PIN_CODE = 900000; + const int32_t TOKEN_LEN = 9; + + const int32_t FAIL = -1; + const int32_t SUCCESS = 0; + const int32_t ERROR_START_REMOTE_DM = 2006; + const int32_t ERROR_DUPLICATE_REQUEST = 2010; + const int32_t ERROR_REQUEST_CANCEL = 2013; + const int32_t ERROR_USER_REJECT = 2015; + const int32_t ERROR_USER_BUSY = 2016; + const int32_t ERROR_SESSION_NOT_EXIT = 2019; + + const int32_t ENCRYPT_TAG_LEN = 32; + + const std::string TAG_REQUESTER = "REQUESTER"; + const std::string TAG_TOKEN = "TOKEN"; + const std::string TAG_HOST = "HOST"; + const std::string TAG_TARGET = "TARGET"; + const std::string TAG_VISIBILITY = "VISIBILITY"; + const std::string TAG_GROUPIDS = "GROUPIDLIST"; + const std::string TAG_REPLY = "REPLY"; + const std::string TAG_NET_ID = "NETID"; + const std::string TAG_GROUP_ID = "GROUPID"; + const std::string TAG_GROUP_NAME = "GROUPNAME"; + const std::string TAG_REQUEST_ID = "REQUESTID"; + const std::string TAG_DEVICE_ID = "DEVICEID"; + const std::string TAG_DEVICE_TYPE = "DEVICETYPE"; + const std::string TAG_APP_NAME = "APPNAME"; + const std::string TAG_APP_DESCRIPTION = "APPDESC"; + const std::string TAG_APP_ICON = "APPICON"; + const std::string TAG_APP_THUMBNAIL = "APPTHUM"; + const std::string TAG_INDEX = "INDEX"; + const std::string TAG_SLICE_NUM = "SLICE"; + const std::string TAG_THUMBNAIL_SIZE = "THUMSIZE"; + const std::string TAG_AUTH_TYPE = "AUTHTYPE"; + + const std::string TAG_VER = "ITF_VER"; + const std::string TAG_TYPE = "MSG_TYPE"; + const std::string DM_ITF_VER = "1.0"; + const std::string TAG = "DM_MSG_CODEC"; + + // GroupConstants + const int32_t GROUP_VISIBILITY_IS_PUBLIC = -1; + const int32_t GROUP_VISIBILITY_IS_PRIVATE = 0; + const std::string REQUEST_AUTH_ADD_ID = "REQUEST_AUTH_ADD_ID"; + const std::string INVITATE_AUTH_ADD_ID = "INVITE_AUTH_ADD_ID"; + const int32_t PIN_CODE_INVALID = -1; + + // AuthConstants + const int32_t SESSION_TYPE_IS_DEVICE_AUTH = 0; + const int32_t SESSION_TYPE_IS_APP_AUTH = 1; + const int32_t SESSION_REPLY_UNKNOWN = -1; + const int32_t SESSION_REPLY_ACCEPT = 0; + const int32_t REQUEST_OPERATION = 0; + const int32_t QR_OPERATION = 1; + const int32_t PIN_OPERATION = 2; + const int32_t START_ACTIVITY_DIALOG = 1; + const int32_t START_ACTIVITY_QR = 2; + const int32_t START_ACTIVITY_FINISH = 3; + const int32_t START_ACTIVITY_PIN = 4; + const int32_t AUTH_STATUS_SKIP = 3; + const int32_t DEFAULT_PIN_CODE = 0; + const int32_t DEFAULT_PIN_TOKEN = 0; + const std::string DEVICE_NAME_KEY = "deviceName"; + const std::string DISPLAY_TIME_KEY = "displayTime"; + const std::string QR_BITMAP_KEY = "qrBitMap"; + const std::string PIN_CODE_KEY = "pinCode"; + const std::string START_ACTIVITY_KEY = "startActivityType"; + const std::string AUTH_TYPE = "authType"; + const std::string PIN_TOKEN = "pinToken"; + const int32_t MSG_TYPE_TO_REMOTE = 0; + const int32_t MSG_TYPE_TO_CLOSED_CHANNEL = 1; + const std::string APP_NAME_KEY = "appName"; + const std::string APP_DESCRIPTION_KEY = "appDescription"; + const std::string APP_ICON_KEY = "appIcon"; + const std::string APP_THUMBNAIL_KEY = "appThumbnail"; + const int32_t SLICE_NUM_INVALID = -1; + const int32_t AUTH_TYPE_QR = 0; + const int32_t AUTH_TYPE_PIN = 1; + + // DmService constants + const int32_t MSG_MAX_SIZE = 45 * 1024; + const int32_t DES_SLICE_MAX_NUM = 5; + const int32_t ABILITY_ON = 1; + const int32_t ABILITY_INVALID = -1; + const int32_t DES_MAX_LEN = 256; + const int32_t ICON_MAX_LEN = 32 * 1024; + const int32_t THUMB_MAX_LEN = 153 * 1024; + + const int32_t DEVICE_UUID_LENGTH = 65; + const int32_t PEER_TO_PEER_GROUP = 256; +} +} +#endif \ No newline at end of file diff --git a/common/include/ipc/ipc_def.h b/common/include/ipc/ipc_def.h new file mode 100644 index 000000000..200090b5b --- /dev/null +++ b/common/include/ipc/ipc_def.h @@ -0,0 +1,53 @@ +/* + * 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 DEVICE_MANAGER_IPC_DEF_H +#define DEVICE_MANAGER_IPC_DEF_H + +namespace OHOS { +namespace DistributedHardware { +#define DEVICE_MANAGER_SERVICE_NAME "dev_mgr_svc" +#define MAX_DM_IPC_LEN 4096 + +#define DECLARE_IPC_MODEL(className) \ +public: \ + className() = default; \ + virtual ~className() = default; \ +public: \ + className(const className&) = delete; \ + className& operator= (const className&) = delete; \ + className(className&&) = delete; \ + className& operator= (className&&) = delete; \ + +#define DECLARE_IPC_INTERFACE(className) \ + DECLARE_IPC_MODEL(className) + +enum IpcCmdID { + REGISTER_DEVICE_MANAGER_LISTENER = 0, + UNREGISTER_DEVICE_MANAGER_LISTENER, + GET_TRUST_DEVICE_LIST, + START_DEVICE_DISCOVER, + STOP_DEVICE_DISCOVER, + AUTHENTICATE_DEVICE, + CHECK_AUTHENTICATION, + SERVER_DEVICE_STATE_NOTIFY, + SERVER_DEVICE_FOUND, + SERVER_DISCOVER_FINISH, + SERVER_AUTH_RESULT, + SERVER_CHECK_AUTH_RESULT, +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // DEVICE_MANAGER_IPC_DEF_H diff --git a/common/include/ipc/lite/ipc_cmd_register.h b/common/include/ipc/lite/ipc_cmd_register.h new file mode 100644 index 000000000..26f542335 --- /dev/null +++ b/common/include/ipc/lite/ipc_cmd_register.h @@ -0,0 +1,120 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H +#define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H + +#include +#include + +#include "liteipc_adapter.h" +#include "single_instance.h" + +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB, paraC, paraD) \ + static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD); \ + class IpcRegisterSetRequestFunc##cmdCode \ + { \ + public: \ + IpcRegisterSetRequestFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterSetRequestFunc(cmdCode, IpcSetRequest##cmdCode); \ + } \ + }; \ + IpcRegisterSetRequestFunc##cmdCode g_IpcRegisterSetRequestFunc##cmdCode; \ + static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD) \ + +#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) \ + static int32_t IpcReadResponse##cmdCode(paraA, paraB); \ + class IpcRegisterReadResponseFunc##cmdCode \ + { \ + public: \ + IpcRegisterReadResponseFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterReadResponseFunc(cmdCode, IpcReadResponse##cmdCode); \ + } \ + }; \ + IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ + static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ + +#define ON_IPC_CMD(cmdCode, paraA, paraB, paraC) \ + static void IpcCmdProcess##cmdCode(paraA, paraB, paraC); \ + class IpcRegisterCmdProcessFunc##cmdCode \ + { \ + public: \ + IpcRegisterCmdProcessFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterCmdProcessFunc(cmdCode, IpcCmdProcess##cmdCode); \ + } \ + }; \ + IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ + static void IpcCmdProcess##cmdCode(paraA, paraB, paraC) \ + +#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB, paraC) \ + static void IpcServerCmdProcess##cmdCode(paraA, paraB, paraC); \ + class IpcRegisterServerCmdProcessFunc##cmdCode \ + { \ + public: \ + IpcRegisterServerCmdProcessFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterServerCmdProcessFunc(cmdCode, IpcServerCmdProcess##cmdCode); \ + } \ + }; \ + IpcRegisterServerCmdProcessFunc##cmdCode g_IpcRegisterServerCmdProcessFunc##cmdCode; \ + static void IpcServerCmdProcess##cmdCode(paraA, paraB, paraC) + +using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t bufferLen); +using ReadResponseFunc = int32_t (*)(IpcIo& reply, std::shared_ptr pBaseRsp); +using OnIpcCmdFunc = void (*)(IpcIo &reply, const IpcContext &ctx, void *ipcMsg); +using OnIpcServerCmdFunc = void (*)(void *origin, IpcIo &req, IpcIo &reply); + +class IpcCmdRegister { +DECLARE_SINGLE_INSTANCE(IpcCmdRegister); +public: + void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) + { + setIpcRequestFuncMap_.emplace(cmdCode, setIpcRequestFunc); + }; + void RegisterReadResponseFunc(int32_t cmdCode, ReadResponseFunc readResponseFunc) + { + readResponseFuncMap_.emplace(cmdCode, readResponseFunc); + }; + void RegisterCmdProcessFunc(int32_t cmdCode, OnIpcCmdFunc onIpcCmdFunc) + { + onIpcCmdFuncMap_.emplace(cmdCode, onIpcCmdFunc); + }; + void RegisterServerCmdProcessFunc(int32_t cmdCode, OnIpcServerCmdFunc onIpcServerCmdFunc) + { + onIpcServerCmdFuncMap_.emplace(cmdCode, onIpcServerCmdFunc); + }; + int32_t SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen); + int32_t ReadResponse(int32_t cmdCode, IpcIo& reply, std::shared_ptr pBaseRsp); + int32_t OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext &ctx, void *ipcMsg); + int32_t OnIpcServerCmd(int32_t cmdCode, void *origin, IpcIo &req, IpcIo &reply); +private: + std::unordered_map setIpcRequestFuncMap_; + std::unordered_map readResponseFuncMap_; + std::unordered_map onIpcCmdFuncMap_; + std::unordered_map onIpcServerCmdFuncMap_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_authenticate_device_req.h b/common/include/ipc/model/ipc_authenticate_device_req.h new file mode 100644 index 000000000..0eafe35b9 --- /dev/null +++ b/common/include/ipc/model/ipc_authenticate_device_req.h @@ -0,0 +1,62 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcAuthenticateDeviceReq : public IpcReq { +DECLARE_IPC_MODEL(IpcAuthenticateDeviceReq); +public: + const DmDeviceInfo& GetDeviceInfo() const + { + return deviceInfo_; + } + + void SetDeviceInfo(const DmDeviceInfo &deviceInfo) + { + deviceInfo_ = deviceInfo; + } + + const DmAppImageInfo& GetAppImageInfo() const + { + return appImageInfo_; + } + + void SetAppImageInfo(const DmAppImageInfo &appImageInfo) + { + appImageInfo_ = appImageInfo; + } + + const std::string& GetExtra() const + { + return extra_; + } + + void SetExtra(std::string &extra) + { + extra_ = extra; + } +private: + DmDeviceInfo deviceInfo_; + DmAppImageInfo appImageInfo_; + std::string extra_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_AUTHENTICATE_DEVICE_REQ_H diff --git a/common/include/ipc/model/ipc_check_authentication_req.h b/common/include/ipc/model/ipc_check_authentication_req.h new file mode 100644 index 000000000..ea136b421 --- /dev/null +++ b/common/include/ipc/model/ipc_check_authentication_req.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CHECK_AUTHENTICATE_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_CHECK_AUTHENTICATE_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcCheckAuthenticateReq : public IpcReq { +DECLARE_IPC_MODEL(IpcCheckAuthenticateReq); +public: + const std::string& GetAuthPara() const + { + return authPara_; + } + + void SetAuthPara(std::string &authPara) + { + authPara_ = authPara; + } +private: + std::string authPara_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CHECK_AUTHENTICATE_REQ_H diff --git a/common/include/ipc/model/ipc_get_trustdevice_req.h b/common/include/ipc/model/ipc_get_trustdevice_req.h new file mode 100644 index 000000000..695d87186 --- /dev/null +++ b/common/include/ipc/model/ipc_get_trustdevice_req.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetTrustdeviceReq : public IpcReq { +DECLARE_IPC_MODEL(IpcGetTrustdeviceReq); +public: + const std::string& GetExtra() const + { + return extra_; + } + + void SetExtra(std::string &extra) + { + extra_ = extra; + } +private: + std::string extra_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_GET_TRUST_DEVICE_REQ_H diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp b/common/include/ipc/model/ipc_get_trustdevice_rsp.h similarity index 51% rename from interfaces/inner_kits/native_cpp/src/dm_device_info.cpp rename to common/include/ipc/model/ipc_get_trustdevice_rsp.h index b4a3bfa5e..6df09e883 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp +++ b/common/include/ipc/model/ipc_get_trustdevice_rsp.h @@ -1,50 +1,44 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -bool DmDeviceInfo::ReadFromParcel(Parcel &parcel) -{ - deviceId = parcel.ReadString(); - deviceName = parcel.ReadString(); - deviceTypeId = (DMDeviceType)parcel.ReadUint8(); - return true; -} - -DmDeviceInfo *DmDeviceInfo::Unmarshalling(Parcel &parcel) -{ - DmDeviceInfo *info = new (std::nothrow) DmDeviceInfo(); - if (info == nullptr) { - return nullptr; - } - - if (!info->ReadFromParcel(parcel)) { - delete info; - info = nullptr; - } - return info; -} - -bool DmDeviceInfo::Marshalling(Parcel &parcel) const -{ - parcel.WriteString(deviceId); - parcel.WriteString(deviceName); - parcel.WriteUint8((uint8_t)deviceTypeId); - return true; -} -} // namespace DistributedHardware -} // namespace OHOS +/* + * 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 OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H +#define OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H + +#include + +#include "dm_device_info.h" + +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetTrustdeviceRsp : public IpcRsp { +DECLARE_IPC_MODEL(IpcGetTrustdeviceRsp); +public: + std::vector GetDeviceVec() const + { + return deviceVec_; + } + + void SetDeviceVec(std::vector& deviceVec) + { + deviceVec_ = deviceVec; + } +private: + std::vector deviceVec_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_GET_TRUSTDEVICE_RSP_H diff --git a/common/include/ipc/model/ipc_notify_auth_result_req.h b/common/include/ipc/model/ipc_notify_auth_result_req.h new file mode 100644 index 000000000..b7119a893 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_auth_result_req.h @@ -0,0 +1,75 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H + +#include + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyAuthResultReq : public IpcReq { +DECLARE_IPC_MODEL(IpcNotifyAuthResultReq); +public: + std::string GetDeviceId() const + { + return deviceId_; + } + + void SetDeviceId(std::string& deviceId) + { + deviceId_ = deviceId; + } + + int32_t GetPinToken() const + { + return pinToken_; + } + + void SetPinToken(int32_t pinToken) + { + pinToken_ = pinToken; + } + + int32_t GetStatus() const + { + return status_; + } + + void SetStatus(int32_t status) + { + status_ = status; + } + + int32_t GetReason() const + { + return reason_; + } + + void SetReason(int32_t reason) + { + reason_ = reason; + } +private: + std::string deviceId_; + int32_t pinToken_; + int32_t status_; + int32_t reason_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H diff --git a/common/include/ipc/model/ipc_notify_check_auth_result_req.h b/common/include/ipc/model/ipc_notify_check_auth_result_req.h new file mode 100644 index 000000000..f20f28582 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_check_auth_result_req.h @@ -0,0 +1,64 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H + +#include + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyCheckAuthResultReq : public IpcReq { +DECLARE_IPC_MODEL(IpcNotifyCheckAuthResultReq); +public: + std::string GetDeviceId() const + { + return deviceId_; + } + + void SetDeviceId(std::string& deviceId) + { + deviceId_ = deviceId; + } + + int32_t GetResult() const + { + return result_; + } + + void SetResult(int32_t result) + { + result_ = result; + } + + int32_t GetFlag() const + { + return flag_; + } + + void SetFlag(int32_t flag) + { + flag_ = flag; + } +private: + std::string deviceId_; + int32_t result_; + int32_t flag_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H diff --git a/common/include/ipc/model/ipc_notify_device_found_req.h b/common/include/ipc/model/ipc_notify_device_found_req.h new file mode 100644 index 000000000..7ffb99d88 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_device_found_req.h @@ -0,0 +1,53 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H + +#include "dm_device_info.h" + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyDeviceFoundReq : public IpcReq { +DECLARE_IPC_MODEL(IpcNotifyDeviceFoundReq); +public: + const DmDeviceInfo& GetDeviceInfo() const + { + return dmDeviceInfo_; + } + + void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo) + { + dmDeviceInfo_ = dmDeviceInfo; + } + + uint16_t GetSubscribeId() const + { + return subscribeId_; + } + + void SetSubscribeId(uint16_t subscribeId) + { + subscribeId_ = subscribeId; + } +private: + uint16_t subscribeId_; + DmDeviceInfo dmDeviceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_FOUND_REQ_H diff --git a/common/include/ipc/model/ipc_notify_device_state_req.h b/common/include/ipc/model/ipc_notify_device_state_req.h new file mode 100644 index 000000000..2ae13ea04 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_device_state_req.h @@ -0,0 +1,53 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H + +#include "dm_device_info.h" + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyDeviceStateReq : public IpcReq { +DECLARE_IPC_MODEL(IpcNotifyDeviceStateReq); +public: + int32_t GetDeviceState() const + { + return deviceState_; + } + + void SetDeviceState(int32_t deviceState) + { + deviceState_ = deviceState; + } + + const DmDeviceInfo& GetDeviceInfo() const + { + return dmDeviceInfo_; + } + + void SetDeviceInfo(DmDeviceInfo& dmDeviceInfo) + { + dmDeviceInfo_ = dmDeviceInfo; + } +private: + int32_t deviceState_; + DmDeviceInfo dmDeviceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DEVICE_STATE_REQ_H diff --git a/common/include/ipc/model/ipc_notify_discover_result_req.h b/common/include/ipc/model/ipc_notify_discover_result_req.h new file mode 100644 index 000000000..1eb3f5b08 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_discover_result_req.h @@ -0,0 +1,53 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H + +#include + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyDiscoverResultReq : public IpcReq { +DECLARE_IPC_MODEL(IpcNotifyDiscoverResultReq); +public: + uint16_t GetSubscribeId() const + { + return subscribeId_; + } + + void SetSubscribeId(uint16_t subscribeId) + { + subscribeId_ = subscribeId; + } + + int32_t GetResult() const + { + return result_; + } + + void SetResult(int32_t result) + { + result_ = result; + } +private: + uint16_t subscribeId_; + int32_t result_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H diff --git a/common/log/include/device_manager_log.h b/common/include/ipc/model/ipc_register_listener_req.h similarity index 45% rename from common/log/include/device_manager_log.h rename to common/include/ipc/model/ipc_register_listener_req.h index 2350623f2..67690a5b8 100644 --- a/common/log/include/device_manager_log.h +++ b/common/include/ipc/model/ipc_register_listener_req.h @@ -1,54 +1,62 @@ -/* - * 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 OHOS_DEVICE_MANAGER_LOG_H -#define OHOS_DEVICE_MANAGER_LOG_H -#include "hilog/log.h" - -namespace OHOS { -namespace DistributedHardware { -static constexpr OHOS::HiviewDFX::HiLogLabel DM_LABEL = {LOG_CORE, LOG_DOMAIN, DH_LOG_TAG}; - -#define PRINT_LOG(Level, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Level(DM_LABEL, "[%{public}s] " fmt, __FUNCTION__, ##__VA_ARGS__) - -#ifdef HILOGD -#undef HILOGD -#endif - -#ifdef HILOGI -#undef HILOGI -#endif - -#ifdef HILOGW -#undef HILOGW -#endif - -#ifdef HILOGE -#undef HILOGE -#endif - -#ifdef HILOGF -#undef HILOGF -#endif - -#define HILOGD(fmt, ...) PRINT_LOG(Debug, fmt, ##__VA_ARGS__) -#define HILOGI(fmt, ...) PRINT_LOG(Info, fmt, ##__VA_ARGS__) -#define HILOGW(fmt, ...) PRINT_LOG(Warn, fmt, ##__VA_ARGS__) -#define HILOGE(fmt, ...) PRINT_LOG(Error, fmt, ##__VA_ARGS__) -#define HILOGF(fmt, ...) PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LOG_H +/* + * 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 OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H + +#include "ipc_req.h" + +#ifdef LITE_DEVICE +#include "liteipc_adapter.h" +#else +#include "iremote_stub.h" +#endif + +namespace OHOS { +namespace DistributedHardware { +class IpcRegisterListenerReq : public IpcReq { +DECLARE_IPC_MODEL(IpcRegisterListenerReq); +public: +#ifdef LITE_DEVICE + SvcIdentity GetSvcIdentity() const + { + return svcIdentity_; + } + + void SetSvcIdentity(SvcIdentity svcIdentity) + { + svcIdentity_ = svcIdentity; + } +#else + sptr GetListener() const + { + return listener_; + } + + void SetListener(sptr listener) + { + listener_ = listener; + } +#endif +private: +#ifdef LITE_DEVICE + SvcIdentity svcIdentity_; +#else + sptr listener_; +#endif +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_REGISTER_LISTENER_REQ_H diff --git a/common/include/ipc/model/ipc_req.h b/common/include/ipc/model/ipc_req.h new file mode 100644 index 000000000..ac6e99d80 --- /dev/null +++ b/common/include/ipc/model/ipc_req.h @@ -0,0 +1,42 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_REQ_H + +#include + +#include "ipc_def.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcReq { +DECLARE_IPC_MODEL(IpcReq); +public: + const std::string& GetPkgName() const + { + return pkgName_; + } + + void SetPkgName(std::string &pkgName) + { + pkgName_ = pkgName; + } +private: + std::string pkgName_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_REQ_H diff --git a/common/include/ipc/model/ipc_rsp.h b/common/include/ipc/model/ipc_rsp.h new file mode 100644 index 000000000..28791359b --- /dev/null +++ b/common/include/ipc/model/ipc_rsp.h @@ -0,0 +1,42 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_RSP_H +#define OHOS_DEVICE_MANAGER_IPC_RSP_H + +#include + +#include "ipc_def.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcRsp { +DECLARE_IPC_MODEL(IpcRsp); +public: + int32_t GetErrCode() const + { + return errCode_; + } + + void SetErrCode(int32_t errCode) + { + errCode_ = errCode; + } +private: + int32_t errCode_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_RSP_H diff --git a/interfaces/inner_kits/native_cpp/src/dm_subscribe_info.cpp b/common/include/ipc/model/ipc_start_discovery_req.h similarity index 41% rename from interfaces/inner_kits/native_cpp/src/dm_subscribe_info.cpp rename to common/include/ipc/model/ipc_start_discovery_req.h index 0bba105f1..341641e61 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_subscribe_info.cpp +++ b/common/include/ipc/model/ipc_start_discovery_req.h @@ -1,58 +1,42 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dm_subscribe_info.h" - -namespace OHOS { -namespace DistributedHardware { -bool DmSubscribeInfo::ReadFromParcel(Parcel &parcel) -{ - subscribeId = parcel.ReadInt16(); - mode = (DmDiscoverMode)parcel.ReadInt32(); - medium = (DmExchangeMedium)parcel.ReadInt32(); - freq = (DmExchangeFreq)parcel.ReadInt32(); - isSameAccount = parcel.ReadBool(); - isWakeRemote = parcel.ReadBool(); - capability = parcel.ReadString(); - return true; -} - -DmSubscribeInfo *DmSubscribeInfo::Unmarshalling(Parcel &parcel) -{ - DmSubscribeInfo *info = new (std::nothrow) DmSubscribeInfo(); - if (info == nullptr) { - return nullptr; - } - - if (!info->ReadFromParcel(parcel)) { - delete info; - info = nullptr; - } - return info; -} - -bool DmSubscribeInfo::Marshalling(Parcel &parcel) const -{ - parcel.WriteInt16(subscribeId); - parcel.WriteInt32((int32_t)mode); - parcel.WriteInt32((int32_t)medium); - parcel.WriteInt32((uint8_t)freq); - parcel.WriteBool(isSameAccount); - parcel.WriteBool(isWakeRemote); - parcel.WriteString(capability); - return true; -} -} // namespace DistributedHardware -} // namespace OHOS +/* + * 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 OHOS_DEVICE_MANAGER_IPC_START_DISCOVERY_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_START_DISCOVERY_REQ_H + +#include "ipc_req.h" + +#include "dm_subscribe_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcStartDiscoveryReq : public IpcReq { +DECLARE_IPC_MODEL(IpcStartDiscoveryReq); +public: + const DmSubscribeInfo& GetSubscribeInfo() const + { + return subscribeInfo_; + } + + void SetSubscribeInfo(DmSubscribeInfo &subscribeInfo) + { + subscribeInfo_ = subscribeInfo; + } +private: + DmSubscribeInfo subscribeInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_START_DISCOVERY_REQ_H diff --git a/common/include/ipc/model/ipc_stop_discovery_req.h b/common/include/ipc/model/ipc_stop_discovery_req.h new file mode 100644 index 000000000..90cf69cd1 --- /dev/null +++ b/common/include/ipc/model/ipc_stop_discovery_req.h @@ -0,0 +1,42 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H +#define OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H + +#include + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcStopDiscoveryReq : public IpcReq { +DECLARE_IPC_MODEL(IpcStopDiscoveryReq); +public: + uint16_t GetSubscribeId() const + { + return subscribeId_; + } + + void SetSubscribeId(uint16_t subscribeId) + { + subscribeId_ = subscribeId; + } +private: + uint16_t subscribeId_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H diff --git a/common/include/ipc/standard/ipc_cmd_register.h b/common/include/ipc/standard/ipc_cmd_register.h new file mode 100644 index 000000000..d2f5e8563 --- /dev/null +++ b/common/include/ipc/standard/ipc_cmd_register.h @@ -0,0 +1,99 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H +#define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H + +#include +#include + +#include "iremote_broker.h" +#include "single_instance.h" + +#include "ipc_types.h" +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB) \ + static int32_t IpcSetRequest##cmdCode(paraA, paraB); \ + class IpcRegisterSetRequestFunc##cmdCode \ + { \ + public: \ + IpcRegisterSetRequestFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterSetRequestFunc(cmdCode, IpcSetRequest##cmdCode); \ + } \ + }; \ + IpcRegisterSetRequestFunc##cmdCode g_IpcRegisterSetRequestFunc##cmdCode; \ + static int32_t IpcSetRequest##cmdCode(paraA, paraB) \ + +#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) \ + static int32_t IpcReadResponse##cmdCode(paraA, paraB); \ + class IpcRegisterReadResponseFunc##cmdCode \ + { \ + public: \ + IpcRegisterReadResponseFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterReadResponseFunc(cmdCode, IpcReadResponse##cmdCode); \ + } \ + }; \ + IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ + static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ + +#define ON_IPC_CMD(cmdCode, paraA, paraB) \ + static int32_t IpcCmdProcess##cmdCode(paraA, paraB); \ + class IpcRegisterCmdProcessFunc##cmdCode \ + { \ + public: \ + IpcRegisterCmdProcessFunc##cmdCode() \ + { \ + IpcCmdRegister::GetInstance().RegisterCmdProcessFunc(cmdCode, IpcCmdProcess##cmdCode); \ + } \ + }; \ + IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ + static int32_t IpcCmdProcess##cmdCode(paraA, paraB) + +using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, MessageParcel& data); +using ReadResponseFunc = int32_t (*)(MessageParcel& reply, std::shared_ptr pBaseRsp); +using OnIpcCmdFunc = int32_t (*)(MessageParcel &data, MessageParcel &reply); + +class IpcCmdRegister { +DECLARE_SINGLE_INSTANCE(IpcCmdRegister); +public: + void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) + { + setIpcRequestFuncMap_.emplace(cmdCode, setIpcRequestFunc); + }; + void RegisterReadResponseFunc(int32_t cmdCode, ReadResponseFunc readResponseFunc) + { + readResponseFuncMap_.emplace(cmdCode, readResponseFunc); + }; + void RegisterCmdProcessFunc(int32_t cmdCode, OnIpcCmdFunc onIpcCmdFunc) + { + onIpcCmdFuncMap_.emplace(cmdCode, onIpcCmdFunc); + }; + int32_t SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, MessageParcel& data); + int32_t ReadResponse(int32_t cmdCode, MessageParcel& reply, std::shared_ptr pBaseRsp); + int32_t OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply); +private: + std::unordered_map setIpcRequestFuncMap_; + std::unordered_map readResponseFuncMap_; + std::unordered_map onIpcCmdFuncMap_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H \ No newline at end of file diff --git a/common/utils/include/device_manager_errno.h b/common/include/log/device_manager_log.h similarity index 56% rename from common/utils/include/device_manager_errno.h rename to common/include/log/device_manager_log.h index e2b8cf2c5..1fa10032a 100644 --- a/common/utils/include/device_manager_errno.h +++ b/common/include/log/device_manager_log.h @@ -1,36 +1,31 @@ -/* - * 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 OHOS_DEVICE_MANAGER_ERRNO_H -#define OHOS_DEVICE_MANAGER_ERRNO_H -#include "errors.h" - -namespace OHOS { -namespace DistributedHardware { -enum { - DISTRIBUTEDHARDWARE_MODULE_DEVICEMANAGER = 0x00 -}; - -// Error code for Common -constexpr ErrCode DEVICE_MANAGER_ERR_OFFSET = ErrCodeOffset(SUBSYS_DISTRIBUTEDHARDWARE, - DISTRIBUTEDHARDWARE_MODULE_DEVICEMANAGER); -enum { - ERR_DEVICEMANAGER_OPERATION_FAILED = DEVICE_MANAGER_ERR_OFFSET + 1, - ERR_DEVICEMANAGER_SERVICE_NOT_READY = DEVICE_MANAGER_ERR_OFFSET + 2, - ERR_DEVICEMANAGER_DEVICE_ALREADY_TRUSTED = DEVICE_MANAGER_ERR_OFFSET + 3, -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LOG_H +/* + * 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 OHOS_DEVICE_MANAGER_LOG_H +#define OHOS_DEVICE_MANAGER_LOG_H + +namespace OHOS { +namespace DistributedHardware { +typedef enum { + DM_LOG_DEBUG, + DM_LOG_INFO, + DM_LOG_WARN, + DM_LOG_ERROR, +} DMLogLevel; + +void DMLog(DMLogLevel logLevel, const char *fmt, ...); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_LOG_H diff --git a/services/devicemanagerservice/include/util/anonymous_string.h b/common/include/utils/anonymous_string.h similarity index 97% rename from services/devicemanagerservice/include/util/anonymous_string.h rename to common/include/utils/anonymous_string.h index dd58b7384..4144e517c 100644 --- a/services/devicemanagerservice/include/util/anonymous_string.h +++ b/common/include/utils/anonymous_string.h @@ -1,26 +1,26 @@ -/* - * 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 ANONYMOUS_STRING_H -#define ANONYMOUS_STRING_H -#include - -namespace OHOS { -namespace DistributedHardware { -std::string GetAnonyString(const std::string &value); -std::string GetAnonyInt32(const int32_t value); -} -} +/* + * 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 ANONYMOUS_STRING_H +#define ANONYMOUS_STRING_H +#include + +namespace OHOS { +namespace DistributedHardware { +std::string GetAnonyString(const std::string &value); +std::string GetAnonyInt32(const int32_t value); +} +} #endif \ No newline at end of file diff --git a/common/include/utils/device_manager_errno.h b/common/include/utils/device_manager_errno.h new file mode 100644 index 000000000..ab01276d9 --- /dev/null +++ b/common/include/utils/device_manager_errno.h @@ -0,0 +1,61 @@ +/* + * 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 OHOS_DEVICE_MANAGER_ERRNO_H +#define OHOS_DEVICE_MANAGER_ERRNO_H + +namespace OHOS { +namespace DistributedHardware { +enum { + DEVICEMANAGER_FAILED = (-10000), + DEVICEMANAGER_SERVICE_NOT_READY, + DEVICEMANAGER_DEVICE_ALREADY_TRUSTED, + DEVICEMANAGER_GET_TRUSTED_DEVICE_FAILED, + DEVICEMANAGER_ALREADY_INIT, + DEVICEMANAGER_INIT_FAILED, + DEVICEMANAGER_MALLOC_ERROR, + DEVICEMANAGER_LOCK_ERROR, + DEVICEMANAGER_INVALID_PARAM, + DEVICEMANAGER_INVALID_VALUE, + DEVICEMANAGER_COPY_FAILED, + DEVICEMANAGER_NULLPTR, + DEVICEMANAGER_DISCOVERY_FAILED, + DEVICEMANAGER_FLATTEN_OBJECT, + DEVICEMANAGER_WRITE_FAILED, + DEVICEMANAGER_IPC_FAILED, + DEVICEMANAGER_IPC_TRANSACTION_FAILED, + DEVICEMANAGER_IPC_NOT_REGISTER_FUNC, + HICHAIN_GROUP_CREATE_FAILED, + HICHAIN_MEMBER_ADD_FAILED, + HICHAIN_CREATE_CHANNEL_FAILED, + MSG_DECODE_PARA_FAILED, + ENCRYPT_UTILS_INVALID_PARAM, + ENCRYPT_UTILS_GCM_SETKEY_FAILED, + ENCRYPT_UTILS_GCM_CRYPT_FAILED, + ENCRYPT_UTILS_GCM_AUTH_DECRYPT_FAILED, + ENCRYPT_UTILS_AES_GCM_ENCRYPT_FAILED, + ENCRYPT_UTILS_AES_GCM_DECRYPT_FAILED, + ERR_GEN_RANDOM_PINTOKEN_FAILED, + PIN_CODE_CHECK_FAILED, + PIN_TOKEN_CHECK_FAILED, + DEVICEMANAGER_CREATE_SESSION_SERVER_FAILED, + DEVICEMANAGER_OPEN_SESSION_FAILED, + AUTH_PARA_INVALID, + ENCODE_DATA_ERROR, + DEVICEMANAGER_OK = 0 +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_ERRNO_H diff --git a/common/utils/include/single_instance.h b/common/include/utils/single_instance.h similarity index 78% rename from common/utils/include/single_instance.h rename to common/include/utils/single_instance.h index f149f90e7..0eeb3853e 100644 --- a/common/utils/include/single_instance.h +++ b/common/include/utils/single_instance.h @@ -34,6 +34,15 @@ private: \ className() = default; \ ~className() = default; \ +#define DECLARE_SINGLE_INSTANCE_INIT(className, funcName) \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() \ + { \ + funcName(); \ + }; \ + ~className() = default; \ + #define IMPLEMENT_SINGLE_INSTANCE(className) \ className & className::GetInstance() \ { \ diff --git a/common/src/ipc/lite/ipc_cmd_register.cpp b/common/src/ipc/lite/ipc_cmd_register.cpp new file mode 100644 index 000000000..c4d823288 --- /dev/null +++ b/common/src/ipc/lite/ipc_cmd_register.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcCmdRegister); + +int32_t IpcCmdRegister::SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); + if (setRequestMapIter == setIpcRequestFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register SetRequestFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + return (setRequestMapIter->second)(pBaseReq, request, buffer, buffLen); +} + +int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + DMLog(DM_LOG_INFO, "In"); + auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); + if (readResponseMapIter == readResponseFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register ReadResponseFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + return (readResponseMapIter->second)(reply, pBaseRsp); +} + +int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); + if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + (onIpcCmdMapIter->second)(reply, ctx, ipcMsg); + return DEVICEMANAGER_OK; +} + +int32_t IpcCmdRegister::OnIpcServerCmd(int32_t cmdCode, void *origin, IpcIo &req, IpcIo &reply) +{ + auto onIpcServerCmdMapIter = onIpcServerCmdFuncMap_.find(cmdCode); + if (onIpcServerCmdMapIter == onIpcServerCmdFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + (onIpcServerCmdMapIter->second)(origin, req, reply); + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_listener.h b/common/src/ipc/standard/ipc_cmd_register.cpp similarity index 33% rename from interfaces/inner_kits/native_cpp/include/idevice_manager_listener.h rename to common/src/ipc/standard/ipc_cmd_register.cpp index bf55490d3..69a91ec16 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_listener.h +++ b/common/src/ipc/standard/ipc_cmd_register.cpp @@ -1,50 +1,55 @@ -/* - * 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 OHOS_DEVICE_MANAGER_LISTENER_INTERFACE_H -#define OHOS_DEVICE_MANAGER_LISTENER_INTERFACE_H - -#include "iremote_broker.h" -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -enum { - ON_DEVICE_ONLINE = 0, - ON_DEVICE_OFFLINE = 1, - ON_DEVICE_CHANGE = 2, - ON_DEVICE_FOUND = 3, - ON_DISCOVER_SUCCESS = 4, - ON_DISCOVER_FAILED = 5, - ON_AUTH_RESULT = 6, -}; - -class IDeviceManagerListener : public OHOS::IRemoteBroker { -public: - virtual ~IDeviceManagerListener() {} - virtual int32_t OnDeviceOnline(std::string &packageName, const DmDeviceInfo &deviceInfo) = 0; - virtual int32_t OnDeviceOffline(std::string &packageName, const DmDeviceInfo &deviceInfo) = 0; - virtual int32_t OnDeviceChanged(std::string &packageName, const DmDeviceInfo &deviceInfo) = 0; - virtual int32_t OnDeviceFound(std::string &packageName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo) = 0; - virtual int32_t OnDiscoverFailed(std::string &packageName, uint16_t subscribeId, int32_t failedReason) = 0; - virtual int32_t OnDiscoverySuccess(std::string &packageName, uint16_t subscribeId) = 0; - virtual int32_t OnAuthResult(std::string &packageName, std::string &deviceId, int32_t status, int32_t reason) = 0; - -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanagerlistener"); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LISTENER_INTERFACE_H +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcCmdRegister); + +int32_t IpcCmdRegister::SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, MessageParcel& data) +{ + auto setRequestMapIter = setIpcRequestFuncMap_.find(cmdCode); + if (setRequestMapIter == setIpcRequestFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register SetRequestFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + return (setRequestMapIter->second)(pBaseReq, data); +} + +int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + auto readResponseMapIter = readResponseFuncMap_.find(cmdCode); + if (readResponseMapIter == readResponseFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register ReadResponseFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + return (readResponseMapIter->second)(reply, pBaseRsp); +} + +int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, MessageParcel &data, MessageParcel &reply) +{ + auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); + if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { + DMLog(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); + return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; + } + return (onIpcCmdMapIter->second)(data, reply); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/common/src/log/device_manager_log.cpp b/common/src/log/device_manager_log.cpp new file mode 100644 index 000000000..786e7efd3 --- /dev/null +++ b/common/src/log/device_manager_log.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_log.h" + +#include "securec.h" + +#include "constants.h" + +#ifdef HI_LOG_ENABLE +#include "hilog/log.h" + +#define DMLOGD(buf) ((void)HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, \ + DH_LOG_TAG, "%{public}s:", buf)) +#define DMLOGE(buf) ((void)HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, \ + DH_LOG_TAG, "%{public}s:", buf)) +#define DMLOGI(buf) ((void)HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, \ + DH_LOG_TAG, "%{public}s:", buf)) +#define DMLOGW(buf) ((void)HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, \ + DH_LOG_TAG, "%{public}s:", buf)) + +#else + +#include +#include + +#define DMLOGD(buf) printf("[D][" DH_LOG_TAG "]:%s\n", buf) +#define DMLOGE(buf) printf("[E][" DH_LOG_TAG "]:%s\n", buf) +#define DMLOGI(buf) printf("[I][" DH_LOG_TAG "]:%s\n", buf) +#define DMLOGW(buf) printf("[W][" DH_LOG_TAG "]:%s\n", buf) + +#endif + +namespace OHOS { +namespace DistributedHardware { +void DMLog(DMLogLevel logLevel, const char *fmt, ...) +{ + char logBuf[LOG_MAX_LEN] = {0}; + va_list arg; + int32_t ret = 0; + + (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + va_start(arg, fmt); + ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); + va_end(arg); + if (ret < 0) { + DMLOGE("DM log length error."); + return; + } + switch (logLevel) { + case DM_LOG_DEBUG: + DMLOGD(logBuf); + break; + case DM_LOG_INFO: + DMLOGI(logBuf); + break; + case DM_LOG_WARN: + DMLOGW(logBuf); + break; + case DM_LOG_ERROR: + DMLOGE(logBuf); + break; + default: + break; + } +} +} +} // namespace OHOS diff --git a/services/devicemanagerservice/src/util/anonymous_string.cpp b/common/src/utils/anonymous_string.cpp similarity index 96% rename from services/devicemanagerservice/src/util/anonymous_string.cpp rename to common/src/utils/anonymous_string.cpp index 69ed71a76..4b7ccaa0c 100644 --- a/services/devicemanagerservice/src/util/anonymous_string.cpp +++ b/common/src/utils/anonymous_string.cpp @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "anonymous_string.h" - -#include "securec.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { - const int INT32_STRING_LENGTH = 40; - const int INT32_SHORT_ID_LENGTH = 20; - const int INT32_PLAINTEXT_LENGTH = 4; - const int INT32_MIN_ID_LENGTH = 3; -} - -std::string GetAnonyString(const std::string &value) -{ - std::string res; - std::string tmpStr("******"); - int32_t strLen = value.length(); - if (strLen < INT32_MIN_ID_LENGTH) { - return tmpStr; - } - - if (strLen <= INT32_SHORT_ID_LENGTH) { - res += value[0]; - res += tmpStr; - res += value[strLen - 1]; - } else { - res.append(value, 0, INT32_PLAINTEXT_LENGTH); - res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); - } - - return res; -} - -std::string GetAnonyInt32(const int32_t value) -{ - char tempBuffer[INT32_STRING_LENGTH] = ""; - int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); - if (secRet <= 0) { - std::string nullString(""); - return nullString; - } - int32_t length = strlen(tempBuffer); - for (int32_t i = 1; i < length - 1; i++) { - tempBuffer[i] = '*'; - } - if (length == 0x01) { - tempBuffer[0] = '*'; - } - - std::string tempSting(tempBuffer); - return tempSting; -} -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "anonymous_string.h" + +#include "securec.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { + const int INT32_STRING_LENGTH = 40; + const int INT32_SHORT_ID_LENGTH = 20; + const int INT32_PLAINTEXT_LENGTH = 4; + const int INT32_MIN_ID_LENGTH = 3; +} + +std::string GetAnonyString(const std::string &value) +{ + std::string res; + std::string tmpStr("******"); + int32_t strLen = value.length(); + if (strLen < INT32_MIN_ID_LENGTH) { + return tmpStr; + } + + if (strLen <= INT32_SHORT_ID_LENGTH) { + res += value[0]; + res += tmpStr; + res += value[strLen - 1]; + } else { + res.append(value, 0, INT32_PLAINTEXT_LENGTH); + res += tmpStr; + res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + } + + return res; +} + +std::string GetAnonyInt32(const int32_t value) +{ + char tempBuffer[INT32_STRING_LENGTH] = ""; + int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); + if (secRet <= 0) { + std::string nullString(""); + return nullString; + } + int32_t length = strlen(tempBuffer); + for (int32_t i = 1; i < length - 1; i++) { + tempBuffer[i] = '*'; + } + if (length == 0x01) { + tempBuffer[0] = '*'; + } + + std::string tempSting(tempBuffer); + return tempSting; +} +} } \ No newline at end of file diff --git a/device_manager.7z b/device_manager.7z new file mode 100644 index 0000000000000000000000000000000000000000..005a80189be1aed9a264978657fe114853c80b59 GIT binary patch literal 56365 zcmV(yKue?1nAk} zDSxux&LXecNxQ6x>I$qdFAUPqZ9bcMTGm3L@)x@OUGqFOW~o0YegUP)B-CO)d0@`6 zMMl*M$^QW&)2`1UgoWrXR=PAnTrwth-JppG@M-HgWwk0h_T?PQv6E>i12^TFyfFK? z^`CS9Z(->@Ca4|~Qu;?#AKBGgS?8h0FO*j#h8%hvCN1;}i|?^7Df)dkA0OlNIS2dv zv}Ej6^@d+C;!1fV;I~a;7(WC~2WLQKjy~tQoS>;If)0`yuY}$bcw?mIxPOz7aJUEP zTRP@~lR*qp0y~e~Ad`0I=5$jQ>LTs|F9i)ZMq#m5dRSDH*|DVHLGL&sC(fOpCB_hz zSr(DX-4UNtO>fA|>!{4}vW0={#>wCb6=4BstHPzVv@J`Qux@Z+seK}J{iOZ&Ik8er zh{#y$0s`Nx8ag=Y@qKDZRUhB}1v%T*YGNN-*#$rzJu17p(q*ZXgTX&aQBu}OE^m%L zRHUr25mP$E5>DJ#S|&#=2kYO%cAkB*YaK*E=hu)2NNyzB-;DsV54ucjUX942uFlt< zAuZPMN_Pv5e1pQ{<{W+{Hthz&=O9qk zbwXX=d5jZ`x#GX=MkZsx4IB4T91F7Rg7Cg6V;X+Q^j1)C(HQ#AdIR&rN;f>Wp1_9l zxqwkXV$OT99_SiDi}?``^_}UMa@g8RuDaqAyDj-r`}u9T(AFan3{NKSH#osT*&353 z0-4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6tc%fTSNkv-5(F8=ci0G#JxY+vh!$@nXukSp8!h?c)o zV1mGX)#GGS8dSc(#!GU%D)DHdj4mSju#gljUyAl|cqAAuH{R&;)1@WSjV1r3I!=tgOWyD06pduMx%6hBVzikB6$rJ znh;?`as33?7rjlDC51PsXn=L$H^m$4FiR{Zmn3mjmN%!w9;8cN5!UPMrA6IXN`(q~ z(b*Htn5^-7wvi1m?E%f)37`b6!dbvqtV%UHx)v5oA6yNxtvBj?w3y`);B#SCYfDWx z088MT_ePq%P0~ZlCQ%UA23Q^kqBtMjNPPGA`bYocpmPZNYGV%jFw z2KBt#(f`m$EU;qFNz&1z<0bKVes{jDBJnWSK literal 0 HcmV?d00001 diff --git a/devicemanager.gni b/devicemanager.gni index 179cd6027..722a50bbb 100644 --- a/devicemanager.gni +++ b/devicemanager.gni @@ -20,3 +20,7 @@ services_path = "${devicemanager_path}/services" innerkits_path = "${devicemanager_path}/interfaces/inner_kits" +build_flags = [ + "-Werror", + "-Wall", + ] \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index dde1bdd95..4d4766d04 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -11,70 +11,119 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") +} import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -config("dmnativeinnerkit_config") { - visibility = [ ":*" ] - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "include", - "${common_path}/log/include", - "${common_path}/utils/include", - ] +if (defined(ohos_lite)) { + shared_library("devicemanagersdk") { + include_dirs = [ + "include", + "include/ipc", + "include/ipc/lite", + "include/notify", + "${common_path}/include/log", + "${common_path}/include/utils", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${common_path}/include/ipc/lite", + "${common_path}/include", + ] + include_dirs += [ + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//third_party/json/include" + ] - cflags = [ - "-Wall", - "-Werror", - "-Wdate-time", - "-Wfloat-equal", - "-Wshadow", - "-Wformat=2", - "-fdata-sections", - "-ffunction-sections", - "-Os", - ] + sources = [ + "${common_path}/src/log/device_manager_log.cpp", + "${common_path}/src/ipc/lite/ipc_cmd_register.cpp", + "src/ipc/lite/ipc_client_manager.cpp", + "src/ipc/lite/ipc_client_server_proxy.cpp", + "src/ipc/lite/ipc_client_stub.cpp", + "src/ipc/lite/ipc_cmd_parser.cpp", + "src/ipc/ipc_client_proxy.cpp", + "src/notify/device_manager_notify.cpp", + "src/device_manager.cpp", + "src/device_manager_impl.cpp", + ] - cflags_cc = [ - "-Os", - ] -} + defines = [ + "LITE_DEVICE", + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerkit\"", + "LOG_DOMAIN=0xD004100", + ] -config("dmnativeinnerkit_public_config") { - include_dirs = [ "include" ] -} + cflags_cc = build_flags -ohos_shared_library("devicemanagersdk") { - sources = [ - "src/device_manager_proxy.cpp", - "src/device_manager_listener_stub.cpp", - "src/device_manager.cpp", - "src/dm_device_info.cpp", - "src/dm_subscribe_info.cpp", + deps = [ + "//utils/native/lite:utils", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", + "//third_party/bounds_checking_function:libsec_shared", + ] + } +} else { + ohos_shared_library("devicemanagersdk") { + include_dirs = [ + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "include", + "include/ipc/standard", + "include/ipc", + "include/notify", + "${common_path}/include/log", + "${common_path}/include/utils", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${common_path}/include/ipc/standard", + "${common_path}/include", + "//third_party/json/include" ] + + sources = [ + "${common_path}/src/log/device_manager_log.cpp", + "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", + "src/ipc/standard/ipc_client_manager.cpp", + "src/ipc/standard/ipc_client_server_proxy.cpp", + "src/ipc/standard/ipc_client_stub.cpp", + "src/ipc/standard/ipc_cmd_parser.cpp", + "src/ipc/ipc_client_proxy.cpp", + "src/notify/device_manager_notify.cpp", + "src/device_manager.cpp", + "src/device_manager_impl.cpp", + ] - configs = [ ":dmnativeinnerkit_config" ] + cflags_cc = build_flags - public_configs = [ ":dmnativeinnerkit_public_config" ] + deps = [ "//utils/native/base:utils" ] - deps = [ "//utils/native/base:utils" ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerkit\"", + "LOG_DOMAIN=0xD004100", + ] - defines = [ - "DH_LOG_TAG=\"devicemanagerkit\"", - "LOG_DOMAIN=0xD004100", - ] + external_deps = [ + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_L2:samgr_proxy", - ] + subsystem_name = "distributedhardware" - subsystem_name = "distributedhardware" + part_name = "device_manager_base" + } - part_name = "device_manager_base" } diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index a21f8a14c..f820ac94b 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -1,67 +1,48 @@ -/* - * 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 OHOS_DEVICE_MANAGER_H -#define OHOS_DEVICE_MANAGER_H -#include "iremote_object.h" - -#include - -#include "device_manager_callback.h" -#include "device_manager_listener_stub.h" -#include "idevice_manager.h" -#include "single_instance.h" -#include "dm_subscribe_info.h" - -namespace OHOS { -namespace DistributedHardware { -class DmDeathRecipient : public IRemoteObject::DeathRecipient { -public: - void OnRemoteDied(const wptr& remote) override; - DmDeathRecipient() = default; - ~DmDeathRecipient() = default; -}; - -class DeviceManager { -friend class DmDeathRecipient; -DECLARE_SINGLE_INSTANCE(DeviceManager); -public: - int32_t InitDeviceManager(std::string &packageName, std::shared_ptr dmInitCallback); - int32_t UnInitDeviceManager(std::string &packageName); - int32_t GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList); - int32_t RegisterDevStateCallback(std::string &packageName, std::string &extra, - std::shared_ptr callback); - int32_t UnRegisterDevStateCallback(std::string &packageName); - int32_t StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo, - std::shared_ptr callback); - int32_t StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId); - int32_t AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, std::string &extra, - std::shared_ptr callback); - -private: - int32_t InitDeviceManagerService(); - bool IsInit(std::string &packageName); - -private: - std::mutex lock_; - sptr dmInterface_; - sptr dmRecipient_; - std::map> dmListener_; - std::map> dmInitCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_H +/* + * 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 DEVICE_MANAGER_H +#define DEVICE_MANAGER_H + +#include +#include + +#include "device_manager_callback.h" +#include "dm_subscribe_info.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceManager { +public: + static DeviceManager& GetInstance(); +public: + virtual int32_t InitDeviceManager(std::string &pkgName, std::shared_ptr dmInitCallback) = 0; + virtual int32_t UnInitDeviceManager(std::string &pkgName) = 0; + virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, + std::vector &deviceList) = 0; + virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra, + std::shared_ptr callback) = 0; + virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) = 0; + virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, + std::shared_ptr callback) = 0; + virtual int32_t StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) = 0; + virtual int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, + const DmAppImageInfo &imageInfo, std::string &extra, std::shared_ptr callback) = 0; + virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara, + std::shared_ptr callback) = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_H diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 58aff430f..40b650323 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -1,52 +1,62 @@ -/* - * 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 OHOS_DEVICE_MANAGER_CALLBACK_H -#define OHOS_DEVICE_MANAGER_CALLBACK_H -#include "dm_device_info.h" - -namespace OHOS { -namespace DistributedHardware { -class DmInitCallback { -public: - virtual ~DmInitCallback() {} - virtual void OnRemoteDied() = 0; -}; - -class DeviceStateCallback { -public: - virtual ~DeviceStateCallback() {} - virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) = 0; - virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) = 0; -}; - -class DiscoverCallback { -public: - virtual ~DiscoverCallback() {} - virtual void OnDiscoverySuccess(uint16_t subscribeId) = 0; - virtual void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) = 0; - virtual void OnDeviceFound(uint16_t subscribeId, DmDeviceInfo &deviceInfo) = 0; -}; - -class AuthenticateCallback { -public: - virtual ~AuthenticateCallback() {} - virtual void OnAuthResult(std::string &deviceId, int32_t status, int32_t reason) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_CALLBACK_H +/* + * 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 OHOS_DEVICE_MANAGER_CALLBACK_H +#define OHOS_DEVICE_MANAGER_CALLBACK_H + +#include +#include + +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class DmInitCallback { +public: + virtual ~DmInitCallback() {} + virtual void OnRemoteDied() = 0; +}; + +class DeviceStateCallback { +public: + virtual ~DeviceStateCallback() {} + virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) = 0; + virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) = 0; + virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) = 0; + virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) = 0; +}; + +class DiscoverCallback { +public: + virtual ~DiscoverCallback() {} + virtual void OnDiscoverySuccess(uint16_t subscribeId) = 0; + virtual void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) = 0; + virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) = 0; +}; + +class AuthenticateCallback { +public: + virtual ~AuthenticateCallback() {} + virtual void OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) = 0; +}; + +class CheckAuthCallback { +public: + virtual ~CheckAuthCallback() {} + virtual void OnResult(std::string &deviceId, int32_t resultCode, int32_t flag) = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_proxy.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h similarity index 32% rename from interfaces/inner_kits/native_cpp/include/device_manager_proxy.h rename to interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 8d8a9755f..f6204254a 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_proxy.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -1,49 +1,57 @@ -/* - * 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 OHOS_DEVICE_MANAGER_PROXY_H -#define OHOS_DEVICE_MANAGER_PROXY_H - -#include "idevice_manager.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerProxy : public IRemoteProxy { -public: - explicit DeviceManagerProxy(const sptr& impl) : IRemoteProxy(impl) {}; - ~DeviceManagerProxy() {}; - - int32_t GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) override; - int32_t RegisterDeviceManagerListener(std::string &packageName, sptr listener) override; - int32_t UnRegisterDeviceManagerListener(std::string &packageName) override; - int32_t RegisterDeviceStateCallback(std::string &packageName, std::string &extra) override; - int32_t UnRegisterDeviceStateCallback(std::string &packageName) override; - int32_t StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo) override; - int32_t StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) override; - int32_t AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, std::string &extra) override; - -private: - template - int32_t GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); - bool WriteInterfaceToken(MessageParcel &data); - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_PROXY_H +/* + * 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 OHOS_DEVICE_MANAGER_IMPL_H +#define OHOS_DEVICE_MANAGER_IMPL_H + +#include + +#include "device_manager.h" + +#include "ipc_client_proxy.h" +#include "ipc_client_manager.h" + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerImpl : public DeviceManager { +DECLARE_SINGLE_INSTANCE(DeviceManagerImpl); +public: + virtual int32_t InitDeviceManager(std::string &pkgName, + std::shared_ptr dmInitCallback) override; + virtual int32_t UnInitDeviceManager(std::string &pkgName) override; + virtual int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, + std::vector &deviceList) override; + virtual int32_t RegisterDevStateCallback(std::string &pkgName, std::string &extra, + std::shared_ptr callback) override; + virtual int32_t UnRegisterDevStateCallback(std::string &pkgName) override; + virtual int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, + std::shared_ptr callback) override; + virtual int32_t StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) override; + virtual int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, + const DmAppImageInfo &imageInfo, std::string &extra, + std::shared_ptr callback) override; + virtual int32_t CheckAuthentication(std::string &pkgName, std::string &authPara, + std::shared_ptr callback) override; +protected: + bool CheckAppImageInfoValid(const DmAppImageInfo &imageInfo); +private: + std::shared_ptr ipcClientProxy_ = + std::make_shared(std::make_shared()); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IMPL_H diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_listener_stub.h b/interfaces/inner_kits/native_cpp/include/device_manager_listener_stub.h deleted file mode 100644 index 600b96457..000000000 --- a/interfaces/inner_kits/native_cpp/include/device_manager_listener_stub.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DEVICE_MANAGER_LISTENER_STUB_H -#define OHOS_DEVICE_MANAGER_LISTENER_STUB_H - -#include -#include "iremote_stub.h" -#include "idevice_manager_listener.h" - -#include "device_manager_callback.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerListenerStub : public IRemoteStub { -public: - DeviceManagerListenerStub(); - ~DeviceManagerListenerStub(); - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) override; - int32_t OnDeviceOnline(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceOffline(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceChanged(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceFound(std::string &packageName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override; - int32_t OnDiscoverFailed(std::string &packageName, uint16_t subscribeId, int32_t failedReason) override; - int32_t OnDiscoverySuccess(std::string &packageName, uint16_t subscribeId) override; - int32_t OnAuthResult(std::string &packageName, std::string &deviceId, int32_t status, int32_t reason) override; - void AddDeviceStateCallback(std::shared_ptr callback); - void RemoveDeviceStateCallback(); - void AddDiscoverCallback(uint16_t subscribeId, std::shared_ptr callback); - void RemoveDiscoverCallback(uint16_t subscribeId); - void AddAuthenticateCallback(std::string deviceId, std::shared_ptr callback); - -private: - template - int32_t GetParcelableInfo(MessageParcel &reply, T &parcelableInfo); - int32_t OnDeviceOnlineInner(MessageParcel &data, MessageParcel &reply); - int32_t OnDeviceOfflineInner(MessageParcel &data, MessageParcel &reply); - int32_t OnDeviceChangedInner(MessageParcel &data, MessageParcel &reply); - int32_t OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply); - int32_t OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply); - int32_t OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply); - int32_t OnAuthResultInner(MessageParcel &data, MessageParcel &reply); - - using ListenerFunc = int32_t (DeviceManagerListenerStub::*)(MessageParcel& data, MessageParcel& reply); - std::map memberFuncMap_; - std::shared_ptr deviceStateCallback_; - std::map> deviceDiscoverCallbacks_; - std::map> authenticateCallback_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LISTENER_STUB_H diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 58952222e..555750589 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -1,51 +1,61 @@ -/* - * 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 OHOS_DEVICE_MANAGER_DEVICE_INFO_H -#define OHOS_DEVICE_MANAGER_DEVICE_INFO_H - -#include "parcel.h" - -namespace OHOS { -namespace DistributedHardware { -enum DMDeviceType : uint8_t { - DEVICE_TYPE_UNKNOWN = 0x00, - DEVICE_TYPE_WIFI_CAMERA = 0x08, - DEVICE_TYPE_AUDIO = 0x0A, - DEVICE_TYPE_PC = 0x0C, - DEVICE_TYPE_PHONE = 0x0E, - DEVICE_TYPE_PAD = 0x11, - DEVICE_TYPE_WATCH = 0x6D, - DEVICE_TYPE_CAR = 0x83, - DEVICE_TYPE_TV = 0x9C, -}; - -enum DmDeviceState : uint8_t { - DEVICE_STATE_UNKNOWN = 0, - DEVICE_STATE_ONLINE = 1, - DEVICE_STATE_OFFLINE = 2, -}; - -struct DmDeviceInfo : public Parcelable { - std::string deviceId; - std::string deviceName; - DMDeviceType deviceTypeId; - bool ReadFromParcel(Parcel &parcel); - virtual bool Marshalling(Parcel &parcel) const override; - static DmDeviceInfo *Unmarshalling(Parcel &parcel); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_DEVICE_INFO_H +/* + * 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 OHOS_DEVICE_MANAGER_DEVICE_INFO_H +#define OHOS_DEVICE_MANAGER_DEVICE_INFO_H + +#include + +#define DM_MAX_DEVICE_ID_LEN 96 +#define DM_MAX_DEVICE_NAME_LEN 65 +#define DM_APPICON_MAX_LEN 32*1024 +#define DM_APPTHUMBNAIL_MAX_LEN 153*1024 + +namespace OHOS { +namespace DistributedHardware { +typedef enum DMDeviceType { + DEVICE_TYPE_UNKNOWN = 0x00, + DEVICE_TYPE_WIFI_CAMERA = 0x08, + DEVICE_TYPE_AUDIO = 0x0A, + DEVICE_TYPE_PC = 0x0C, + DEVICE_TYPE_PHONE = 0x0E, + DEVICE_TYPE_PAD = 0x11, + DEVICE_TYPE_WATCH = 0x6D, + DEVICE_TYPE_CAR = 0x83, + DEVICE_TYPE_TV = 0x9C, +} DMDeviceType; + +typedef enum DmDeviceState { + DEVICE_STATE_UNKNOWN = 0, + DEVICE_STATE_ONLINE = 1, + DEVICE_STATE_OFFLINE = 2, + DEVICE_INFO_CHANGED = 3, +} DmDeviceState; + +typedef struct DmDeviceInfo { + char deviceId[DM_MAX_DEVICE_ID_LEN]; + char deviceName[DM_MAX_DEVICE_NAME_LEN]; + DMDeviceType deviceTypeId; +} DmDeviceInfo; + +typedef struct DmAppImageInfo { + int32_t appIconLen; + const uint8_t* appIcon; + int32_t appThumbnailLen; + const uint8_t* appThumbnail; +}DmAppImageInfo; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_DEVICE_INFO_H diff --git a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h index 2a6f982ee..64181e1fd 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h @@ -1,82 +1,81 @@ -/* - * 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 OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H -#define OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H - -#include "parcel.h" - -namespace OHOS { -namespace DistributedHardware { -enum DmDiscoverMode : int32_t { - /* Passive */ - DISCOVER_MODE_PASSIVE = 0x55, - /* Proactive */ - DISCOVER_MODE_ACTIVE = 0xAA -}; - -enum DmExchangeMedium : int32_t { - /** Automatic medium selection */ - AUTO = 0, - /** Bluetooth */ - BLE = 1, - /** Wi-Fi */ - COAP = 2, - /** USB */ - USB = 3, - MEDIUM_BUTT -}; - -/** - * @brief Enumerates frequencies for publishing services. - * - * This enumeration applies only to Bluetooth and is not supported currently. - */ -enum DmExchangeFreq : int32_t { - /** Low */ - LOW = 0, - /** Medium */ - MID = 1, - /** High */ - HIGH = 2, - /** Super-high */ - SUPER_HIGH = 3, - FREQ_BUTT -}; - -const std::string DM_CAPABILITY_DDMP = "ddmpCapability"; - -struct DmSubscribeInfo : public Parcelable { - /** Service ID */ - uint16_t subscribeId; - /** Discovery mode for service subscription. For details, see {@link DmDiscoverMode}. */ - DmDiscoverMode mode; - /** Service subscription medium. For details, see {@link DmExchangeMedium}. */ - DmExchangeMedium medium; - /** Service subscription frequency. For details, see {@link DmExchangeFreq}. */ - DmExchangeFreq freq; - /** only find the device with the same account */ - bool isSameAccount; - /** find the sleeping devices */ - bool isWakeRemote; - /** Service subscription capability. */ - std::string capability; - bool ReadFromParcel(Parcel &parcel); - virtual bool Marshalling(Parcel &parcel) const override; - static DmSubscribeInfo *Unmarshalling(Parcel &parcel); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H +/* + * 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 OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H +#define OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H + +#include + +#define DM_MAX_DEVICE_CAPABILITY_LEN 65 + +namespace OHOS { +namespace DistributedHardware { +typedef enum DmDiscoverMode { + /* Passive */ + DM_DISCOVER_MODE_PASSIVE = 0x55, + /* Proactive */ + DM_DISCOVER_MODE_ACTIVE = 0xAA +} DmDiscoverMode; + +typedef enum DmExchangeMedium { + /** Automatic medium selection */ + DM_AUTO = 0, + /** Bluetooth */ + DM_BLE = 1, + /** Wi-Fi */ + DM_COAP = 2, + /** USB */ + DM_USB = 3, + DM_MEDIUM_BUTT +} DmExchangeMedium; + +/** + * @brief Enumerates frequencies for publishing services. + * + * This enumeration applies only to Bluetooth and is not supported currently. + */ +typedef enum DmExchangeFreq { + /** Low */ + DM_LOW = 0, + /** Medium */ + DM_MID = 1, + /** High */ + DM_HIGH = 2, + /** Super-high */ + DM_SUPER_HIGH = 3, + DM_FREQ_BUTT +} DmExchangeFreq; + +const static char * DM_CAPABILITY_OSD = "osdCapability"; + +typedef struct DmSubscribeInfo { + /** Service ID */ + uint16_t subscribeId; + /** Discovery mode for service subscription. For details, see {@link DmDiscoverMode}. */ + DmDiscoverMode mode; + /** Service subscription medium. For details, see {@link DmExchangeMedium}. */ + DmExchangeMedium medium; + /** Service subscription frequency. For details, see {@link DmExchangeFreq}. */ + DmExchangeFreq freq; + /** only find the device with the same account */ + bool isSameAccount; + /** find the sleeping devices */ + bool isWakeRemote; + /** Service subscription capability. */ + char capability[DM_MAX_DEVICE_CAPABILITY_LEN]; +} DmSubscribeInfo; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_SUBSCRIBE_INFO_H diff --git a/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h new file mode 100644 index 000000000..8fc50aae9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h @@ -0,0 +1,37 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_H + +#include +#include +#include + +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClient { +DECLARE_IPC_INTERFACE(IpcClient); +public: + virtual int32_t Init(std::string &pkgName) = 0; + virtual int32_t UnInit(std::string &pkgName) = 0; + virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/authdemo/device_server_channel.h b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h similarity index 40% rename from services/devicemanagerservice/include/authdemo/device_server_channel.h rename to interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h index 6e3b279fc..eedac7566 100644 --- a/services/devicemanagerservice/include/authdemo/device_server_channel.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h @@ -1,53 +1,41 @@ -/* - * 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 OHOS_DEVICE_SERVER_CHANNEL_H -#define OHOS_DEVICE_SERVER_CHANNEL_H - -#include -#include -#include - -#include "device_auth.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceServerChannel { -public: - DeviceServerChannel(const DeviceGroupManager& deviceGroupManager, - std::function onError) - : socketFd_(-1), clientFd_(-1), deviceGroupManager_(deviceGroupManager), onError_(onError) {} - ~DeviceServerChannel(); - - DeviceServerChannel()=delete; - DeviceServerChannel(const DeviceServerChannel&)=delete; - DeviceServerChannel &operator=(const DeviceServerChannel&)=delete; - -public: - int32_t Start(const int32_t port); - bool Send(const char* data, const int32_t dataLen); - void Receive(); - void OnDataReceived(const char* data, const int32_t dataLen); - void ResetConnection(); - -private: - int32_t socketFd_; - int32_t clientFd_; - const DeviceGroupManager& deviceGroupManager_; - std::function onError_; -}; -} -} -#endif \ No newline at end of file +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H + +#include +#include + +#include "ipc_client.h" +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientProxy : public IpcClient { +DECLARE_IPC_INTERFACE(IpcClientProxy); +public: + IpcClientProxy(std::shared_ptr ipcClientManager) : ipcClientManager_(ipcClientManager) {}; +public: + virtual int32_t Init(std::string &pkgName); + virtual int32_t UnInit(std::string &pkgName); + virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); +private: + std::shared_ptr ipcClientManager_ {nullptr}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h new file mode 100644 index 000000000..ca27cd4c4 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h @@ -0,0 +1,42 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H + +#include +#include +#include + +#include "ipc_client.h" +#include "ipc_client_server_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientManager : public IpcClient { +DECLARE_IPC_INTERFACE(IpcClientManager); +public: + virtual int32_t Init(std::string &pkgName) override; + virtual int32_t UnInit(std::string &pkgName) override; + virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; +private: + bool IsInit(std::string &pkgName); +private: + IpcClientServerProxy serverProxy_; + std::set packageInitSet_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h new file mode 100644 index 000000000..c13ffc602 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h @@ -0,0 +1,45 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H + +#include +#include +#include + +#include "iproxy_client.h" +#include "liteipc_adapter.h" +#include "samgr_lite.h" + +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientServerProxy { +public: + int32_t Init(); + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); +private: + IClientProxy *GetServerProxy(void); + int32_t RegisterServerDeathCb(void); +private: + std::mutex lock_; + IClientProxy *serviceProxy_ {nullptr}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h new file mode 100644 index 000000000..a9cec772d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h @@ -0,0 +1,43 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H + +#include +#include + +#include "liteipc_adapter.h" + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientStub { +DECLARE_SINGLE_INSTANCE(IpcClientStub); +public: + int32_t Init(); + SvcIdentity GetSvcIdentity() const + { + return clientIdentity_; + } +private: + std::mutex lock_; + bool bInit {false}; + SvcIdentity clientIdentity_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h new file mode 100644 index 000000000..b029b22a8 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h @@ -0,0 +1,58 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H + +#include +#include +#include +#include + +#include "iremote_object.h" + +#include "ipc_client.h" +#include "ipc_client_stub.h" +#include "ipc_def.h" +#include "ipc_remote_broker.h" + +namespace OHOS { +namespace DistributedHardware { +class DmDeathRecipient : public IRemoteObject::DeathRecipient { +public: + void OnRemoteDied(const wptr& remote) override; + DmDeathRecipient() = default; + ~DmDeathRecipient() = default; +}; + +class IpcClientManager : public IpcClient { +friend class DmDeathRecipient; +DECLARE_IPC_INTERFACE(IpcClientManager); +public: + virtual int32_t Init(std::string &pkgName) override; + virtual int32_t UnInit(std::string &pkgName) override; + virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; +private: + bool IsInit(std::string &pkgName); + int32_t ClientInit(); +private: + std::mutex lock_; + std::map> dmListener_; + sptr dmInterface_ {nullptr}; + sptr dmRecipient_ {nullptr}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h new file mode 100644 index 000000000..6c60aea5e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h @@ -0,0 +1,39 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H + +#include +#include + +#include "iremote_proxy.h" +#include "ipc_remote_broker.h" +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientServerProxy : public IRemoteProxy { +public: + explicit IpcClientServerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + ~IpcClientServerProxy() {}; + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h new file mode 100644 index 000000000..70f27ebab --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H +#define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H + +#include +#include + +#include "iremote_stub.h" +#include "iremote_broker.h" + +#include "ipc_remote_broker.h" +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcClientStub : public IRemoteStub { +public: + IpcClientStub() {}; + ~IpcClientStub() {}; + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) override; + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h new file mode 100644 index 000000000..dfb7cc5a8 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h @@ -0,0 +1,38 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H +#define OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H + +#include +#include + +#include "iremote_broker.h" + +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IIpcRemoteBroker : public OHOS::IRemoteBroker { +public: + virtual ~IIpcRemoteBroker() {} + virtual int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) = 0; +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager"); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h new file mode 100644 index 000000000..afe27b5fa --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -0,0 +1,69 @@ +/* + * 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 OHOS_DEVICE_MANAGER_NOTIFY_H +#define OHOS_DEVICE_MANAGER_NOTIFY_H + +#include +#include +#include +#include + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" +#include "device_manager_callback.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotify { +DECLARE_SINGLE_INSTANCE(DeviceManagerNotify); +public: + void RegisterDeathRecipientCallback(std::string &pkgName, std::shared_ptr dmInitCallback); + void UnRegisterDeathRecipientCallback(std::string &pkgName); + void RegisterDeviceStateCallback(std::string &pkgName, std::shared_ptr callback); + void UnRegisterDeviceStateCallback(std::string &pkgName); + void RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId, + std::shared_ptr callback); + void UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId); + void RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId, + std::shared_ptr callback); + void UnRegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId); + void UnRegisterPackageCallback(std::string &pkgName); + void RegisterCheckAuthenticationCallback(std::string &pkgName, std::string &authPara, + std::shared_ptr callback); + void UnRegisterCheckAuthenticationCallback(std::string &pkgName); +public: + void OnRemoteDied(); + void OnDeviceOnline(std::string &pkgName, const DmDeviceInfo &deviceInfo); + void OnDeviceOffline(std::string &pkgName, const DmDeviceInfo &deviceInfo); + void OnDeviceChanged(std::string &pkgName, const DmDeviceInfo &deviceInfo); + void OnDeviceFound(std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo); + void OnDiscoverFailed(std::string &pkgName, uint16_t subscribeId, int32_t failedReason); + void OnDiscoverySuccess(std::string &pkgName, uint16_t subscribeId); + void OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, uint32_t status, + uint32_t reason); + void OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, int32_t flag); +private: + std::mutex lock_; + std::map> deviceStateCallback_; + std::map>> deviceDiscoverCallbacks_; + std::map>> authenticateCallback_; + std::map>> checkauthcallback_; + std::map> dmInitCallback_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_NOTIFY_H diff --git a/interfaces/inner_kits/native_cpp/src/device_manager.cpp b/interfaces/inner_kits/native_cpp/src/device_manager.cpp index 65da53e98..30cc8174f 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager.cpp @@ -1,314 +1,27 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager.h" - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "device_manager_errno.h" -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(DeviceManager); - -int32_t DeviceManager::InitDeviceManagerService() -{ - HILOGI("DeviceManager::InitDeviceManagerService start"); - if (dmInterface_ != nullptr) { - HILOGI("DeviceManagerService Already Init"); - return ERR_OK; - } - - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - HILOGE("Get SystemAbilityManager Failed"); - return ERR_NO_INIT; - } - - auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); - if (object == nullptr) { - HILOGE("Get DeviceManager SystemAbility Failed"); - return ERR_DEVICEMANAGER_SERVICE_NOT_READY; - } - - if (dmRecipient_ == nullptr) { - dmRecipient_ = sptr(new DmDeathRecipient()); - } - - if (!object->AddDeathRecipient(dmRecipient_)) { - HILOGE("InitDeviceManagerService: AddDeathRecipient Failed"); - } - - dmInterface_ = iface_cast(object); - HILOGI("DeviceManager::InitDeviceManagerService completed"); - return ERR_OK; -} - -bool DeviceManager::IsInit(std::string &packageName) -{ - if (dmInterface_ == nullptr) { - HILOGE("DeviceManager not Init"); - return false; - } - - if (dmListener_.find(packageName) == dmListener_.end()) { - HILOGE("dmListener_ not Init for %{public}s", packageName.c_str()); - return false; - } - return true; -} - -int32_t DeviceManager::InitDeviceManager(std::string &packageName, std::shared_ptr dmInitCallback) -{ - HILOGI("DeviceManager::InitDeviceManager start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty() || dmInitCallback == nullptr) { - HILOGE("InitDeviceManager error: Invalid parameter"); - return ERR_INVALID_VALUE; - } - - HILOGI("InitDeviceManager in, packageName %{public}s", packageName.c_str()); - std::lock_guard autoLock(lock_); - int32_t ret = InitDeviceManagerService(); - if (ret != ERR_OK) { - HILOGE("InitDeviceManager Failed with ret %{public}d", ret); - return ret; - } - - auto iter = dmListener_.find(packageName); - if (iter != dmListener_.end()) { - HILOGI("dmListener_ Already Init"); - dmInitCallback_[packageName] = dmInitCallback; - return ERR_OK; - } - - sptr listener = sptr(new DeviceManagerListenerStub()); - ret = dmInterface_->RegisterDeviceManagerListener(packageName, listener); - if (ret != ERR_OK) { - HILOGE("InitDeviceManager: RegisterDeviceManagerListener Failed with ret %{public}d", ret); - return ret; - } - - dmListener_[packageName] = listener; - dmInitCallback_[packageName] = dmInitCallback; - - HILOGI("DeviceManager::InitDeviceManager completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::UnInitDeviceManager(std::string &packageName) -{ - HILOGI("DeviceManager::UnInitDeviceManager start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty()) { - HILOGE("InitDeviceManager error: Invalid parameter"); - return ERR_INVALID_VALUE; - } - - HILOGI("UnInitDeviceManager in, packageName %{public}s", packageName.c_str()); - std::lock_guard autoLock(lock_); - if (dmInterface_ == nullptr) { - HILOGE("DeviceManager not Init"); - return ERR_NO_INIT; - } - - auto iter = dmListener_.find(packageName); - if (iter != dmListener_.end()) { - int32_t ret = dmInterface_->UnRegisterDeviceManagerListener(packageName); - if (ret != ERR_OK) { - HILOGE("UnInitDeviceManager: UnRegisterDeviceManagerListener Failed with ret %{public}d", ret); - return ret; - } - dmListener_.erase(packageName); - dmInitCallback_.erase(packageName); - } - - if (dmListener_.empty()) { - dmRecipient_ = nullptr; - dmInterface_ = nullptr; - } - HILOGI("DeviceManager::UnInitDeviceManager completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) -{ - HILOGI("DeviceManager::GetTrustedDeviceList start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty()) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("GetTrustedDeviceList in, packageName %{public}s", packageName.c_str()); - int32_t ret = dmInterface_->GetTrustedDeviceList(packageName, extra, deviceList); - if (ret != ERR_OK) { - HILOGE("RegisterDevStateCallback Failed with ret %{public}d", ret); - return ret; - } - HILOGI("DeviceManager::GetTrustedDeviceList completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::RegisterDevStateCallback(std::string &packageName, std::string &extra, - std::shared_ptr callback) -{ - HILOGI("DeviceManager::RegisterDevStateCallback start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty() || callback == nullptr) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("RegisterDevStateCallback in, packageName %{public}s", packageName.c_str()); - int32_t ret = dmInterface_->RegisterDeviceStateCallback(packageName, extra); - if (ret != ERR_OK) { - HILOGE("RegisterDevStateCallback Failed with ret %{public}d", ret); - return ret; - } - - std::lock_guard autoLock(lock_); - dmListener_[packageName]->AddDeviceStateCallback(callback); - HILOGI("DeviceManager::RegisterDevStateCallback completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::UnRegisterDevStateCallback(std::string &packageName) -{ - HILOGI("DeviceManager::UnRegisterDevStateCallback start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty()) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("UnRegisterDevStateCallback in, packageName %{public}s", packageName.c_str()); - int32_t ret = dmInterface_->UnRegisterDeviceStateCallback(packageName); - if (ret != ERR_OK) { - HILOGE("UnRegisterDeviceStateCallback Failed with ret %{public}d", ret); - return ret; - } - - std::lock_guard autoLock(lock_); - dmListener_[packageName]->RemoveDeviceStateCallback(); - HILOGI("DeviceManager::UnRegisterDevStateCallback completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo, - std::shared_ptr callback) -{ - HILOGI("DeviceManager::StartDeviceDiscovery start, packageName: %{public}s", packageName.c_str()); - if (packageName.empty() || callback == nullptr) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("StartDeviceDiscovery in, packageName %{public}s", packageName.c_str()); - { - std::lock_guard autoLock(lock_); - dmListener_[packageName]->AddDiscoverCallback(subscribeInfo.subscribeId, callback); - } - int32_t ret = dmInterface_->StartDeviceDiscovery(packageName, subscribeInfo); - if (ret != ERR_OK) { - HILOGE("StartDeviceDiscovery Failed with ret %{public}d", ret); - return ret; - } - - HILOGI("DeviceManager::StartDeviceDiscovery completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) -{ - HILOGI("DeviceManager::StopDeviceDiscovery start , packageName: %{public}s", packageName.c_str()); - if (packageName.empty()) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("StopDeviceDiscovery in, packageName %{public}s", packageName.c_str()); - int32_t ret = dmInterface_->StopDeviceDiscovery(packageName, subscribeId); - if (ret != ERR_OK) { - HILOGE("StopDeviceDiscovery Failed with ret %{public}d", ret); - return ret; - } - - std::lock_guard autoLock(lock_); - dmListener_[packageName]->RemoveDiscoverCallback(subscribeId); - HILOGI("DeviceManager::StopDeviceDiscovery completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t DeviceManager::AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, std::string &extra, - std::shared_ptr callback) -{ - HILOGI("DeviceManager::AuthenticateDevice start , packageName: %{public}s", packageName.c_str()); - if (packageName.empty()) { - HILOGE("Invalid para"); - return ERR_INVALID_VALUE; - } - - if (!IsInit(packageName)) { - HILOGE("DeviceManager not Init for %{public}s", packageName.c_str()); - return ERR_NO_INIT; - } - - HILOGI("AuthenticateDevice in, packageName %{public}s", packageName.c_str()); - int32_t ret = dmInterface_->AuthenticateDevice(packageName, deviceInfo, extra); - if (ret != ERR_OK) { - HILOGE("AuthenticateDevice Failed with ret %{public}d", ret); - return ret; - } - - std::lock_guard autoLock(lock_); - dmListener_[packageName]->AddAuthenticateCallback(deviceInfo.deviceId, callback); - HILOGI("DeviceManager::AuthenticateDevice completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -void DmDeathRecipient::OnRemoteDied(const wptr& remote) -{ - (void)remote; - HILOGW("DmDeathRecipient : OnRemoteDied"); - for (auto iter : DeviceManager::GetInstance().dmInitCallback_) { - iter.second->OnRemoteDied(); - } -} -} // namespace DistributedHardware -} // namespace OHOS +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager.h" + +#include "device_manager_impl.h" + +namespace OHOS { +namespace DistributedHardware { +DeviceManager& DeviceManager::GetInstance() +{ + return DeviceManagerImpl::GetInstance(); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp new file mode 100644 index 000000000..8690be875 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_impl.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "device_manager_notify.h" +#include "constants.h" + +#include "ipc_authenticate_device_req.h" +#include "ipc_check_authentication_req.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_rsp.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DeviceManagerImpl); + +int32_t DeviceManagerImpl::InitDeviceManager(std::string &pkgName, std::shared_ptr dmInitCallback) +{ + DMLog(DM_LOG_INFO, "DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty() || dmInitCallback == nullptr) { + DMLog(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter"); + return DEVICEMANAGER_INVALID_VALUE; + } + + int32_t ret = ipcClientProxy_->Init(pkgName); + if (ret != DEVICEMANAGER_OK) { + return ret; + } + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + DMLog(DM_LOG_INFO, "success"); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::UnInitDeviceManager(std::string &pkgName) +{ + DMLog(DM_LOG_INFO, "DeviceManager::UnInitDeviceManager start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "InitDeviceManager error: Invalid parameter"); + return DEVICEMANAGER_INVALID_VALUE; + } + + int32_t ret = ipcClientProxy_->UnInit(pkgName); + if (ret != DEVICEMANAGER_OK) { + return ret; + } + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName); + DMLog(DM_LOG_INFO, "DeviceManager::UnInitDeviceManager completed with errcode %d", ret); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::GetTrustedDeviceList(std::string &pkgName, std::string &extra, + std::vector &deviceList) +{ + DMLog(DM_LOG_INFO, "DeviceManager::GetTrustedDeviceList start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetExtra(extra); + if (ipcClientProxy_->SendRequest(GET_TRUST_DEVICE_LIST, req, rsp) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_IPC_FAILED; + } + if (rsp->GetErrCode() == DEVICEMANAGER_OK) { + deviceList = rsp->GetDeviceVec(); + } + DMLog(DM_LOG_INFO, "DeviceManager::GetTrustedDeviceList completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::RegisterDevStateCallback(std::string &pkgName, std::string &extra, + std::shared_ptr callback) +{ + DMLog(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty() || callback == nullptr) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + DMLog(DM_LOG_INFO, "DeviceManager::RegisterDevStateCallback completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::UnRegisterDevStateCallback(std::string &pkgName) +{ + DMLog(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); + DMLog(DM_LOG_INFO, "DeviceManager::UnRegisterDevStateCallback completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &subscribeInfo, + std::shared_ptr callback) +{ + DMLog(DM_LOG_INFO, "DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str()); + if (pkgName.empty() || callback == nullptr) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + DMLog(DM_LOG_INFO, "DeviceManager StartDeviceDiscovery in, pkgName %s", pkgName.c_str()); + DeviceManagerNotify::GetInstance().RegisterDiscoverCallback(pkgName, subscribeInfo.subscribeId, callback); + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetSubscribeInfo(subscribeInfo); + if (ipcClientProxy_->SendRequest(START_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_IPC_FAILED; + } + + int32_t ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "DeviceManager StartDeviceDiscovery Failed with ret %d", ret); + return ret; + } + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::StopDeviceDiscovery(std::string &pkgName, uint16_t subscribeId) +{ + DMLog(DM_LOG_INFO, "DeviceManager::StopDeviceDiscovery start , pkgName: %s", pkgName.c_str()); + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + DMLog(DM_LOG_INFO, "StopDeviceDiscovery in, pkgName %s", pkgName.c_str()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetSubscribeId(subscribeId); + if (ipcClientProxy_->SendRequest(STOP_DEVICE_DISCOVER, req, rsp) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_IPC_FAILED; + } + + int32_t ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "StopDeviceDiscovery Failed with ret %d", ret); + return ret; + } + DeviceManagerNotify::GetInstance().UnRegisterDiscoverCallback(pkgName, subscribeId); + DMLog(DM_LOG_INFO, "DeviceManager::StopDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, + const DmAppImageInfo &imageInfo, std::string &extra, std::shared_ptr callback) +{ + DMLog(DM_LOG_INFO, "DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); + if (pkgName.empty() || !CheckAppImageInfoValid(imageInfo)) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + DMLog(DM_LOG_INFO, "AuthenticateDevice in, pkgName %s", pkgName.c_str()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetExtra(extra); + req->SetDeviceInfo(deviceInfo); + req->SetAppImageInfo(imageInfo); + if (ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_IPC_FAILED; + } + + int32_t ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "AuthenticateDevice Failed with ret %d", ret); + return ret; + } + std::string strDeviceId = deviceInfo.deviceId; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); + DMLog(DM_LOG_INFO, "DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t DeviceManagerImpl::CheckAuthentication(std::string &pkgName, std::string &authPara, + std::shared_ptr callback) +{ + DMLog(DM_LOG_INFO, "DeviceManager::CheckAuthentication start , pkgName: %s", pkgName.c_str()); + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + DMLog(DM_LOG_INFO, "CheckAuthentication in, pkgName %s", pkgName.c_str()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetAuthPara(authPara); + if (ipcClientProxy_->SendRequest(CHECK_AUTHENTICATION, req, rsp) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_IPC_FAILED; + } + + int32_t ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "CheckAuthentication Failed with ret %d", ret); + return ret; + } + DeviceManagerNotify::GetInstance().RegisterCheckAuthenticationCallback(pkgName, authPara, callback); + DMLog(DM_LOG_INFO, "DeviceManager::CheckAuthentication completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +bool DeviceManagerImpl::CheckAppImageInfoValid(const DmAppImageInfo &imageInfo) +{ + if (imageInfo.appIconLen < 0 || + imageInfo.appIconLen > ICON_MAX_LEN || + imageInfo.appThumbnailLen < 0 || + imageInfo.appThumbnailLen > THUMB_MAX_LEN) { + return false; + } + if ((imageInfo.appIconLen == 0 && imageInfo.appIcon != nullptr) || + (imageInfo.appThumbnailLen == 0 && imageInfo.appThumbnail != nullptr)) { + return false; + } + return true; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_listener_stub.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_listener_stub.cpp deleted file mode 100644 index e3fc817a7..000000000 --- a/interfaces/inner_kits/native_cpp/src/device_manager_listener_stub.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager_listener_stub.h" - -#include "ipc_skeleton.h" -#include "ipc_types.h" - -#include "device_manager_log.h" - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -DeviceManagerListenerStub::DeviceManagerListenerStub() -{ - memberFuncMap_[ON_DEVICE_ONLINE] = &DeviceManagerListenerStub::OnDeviceOnlineInner; - memberFuncMap_[ON_DEVICE_OFFLINE] = &DeviceManagerListenerStub::OnDeviceOfflineInner; - memberFuncMap_[ON_DEVICE_CHANGE] = &DeviceManagerListenerStub::OnDeviceChangedInner; - memberFuncMap_[ON_DEVICE_FOUND] = &DeviceManagerListenerStub::OnDeviceFoundInner; - memberFuncMap_[ON_DISCOVER_SUCCESS] = &DeviceManagerListenerStub::OnDiscoverySuccessInner; - memberFuncMap_[ON_DISCOVER_FAILED] = &DeviceManagerListenerStub::OnDiscoverFailedInner; - memberFuncMap_[ON_AUTH_RESULT] = &DeviceManagerListenerStub::OnAuthResultInner; -} - -DeviceManagerListenerStub::~DeviceManagerListenerStub() -{ - memberFuncMap_.clear(); -} - -int32_t DeviceManagerListenerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - HILOGI("code = %{public}d, flags= %{public}d.", code, option.GetFlags()); - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (data.ReadInterfaceToken() != DeviceManagerListenerStub::GetDescriptor()) { - HILOGE("interface token check failed!"); - return ERR_INVALID_STATE; - } - return (this->*memberFunc)(data, reply); - } - HILOGW("unsupport code: %{public}d", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -template -int32_t DeviceManagerListenerStub::GetParcelableInfo(MessageParcel &reply, T &parcelableInfo) -{ - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { - HILOGE("readParcelableInfo failed"); - return ERR_INVALID_VALUE; - } - parcelableInfo = *info; - return ERR_NONE; -} - -int32_t DeviceManagerListenerStub::OnDeviceOnlineInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - DmDeviceInfo deviceInfo; - int32_t result = GetParcelableInfo(data, deviceInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - int32_t ret = OnDeviceOnline(packageName, deviceInfo); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDeviceOfflineInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - DmDeviceInfo deviceInfo; - int32_t result = GetParcelableInfo(data, deviceInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - int32_t ret = OnDeviceOffline(packageName, deviceInfo); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDeviceChangedInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - DmDeviceInfo deviceInfo; - int32_t result = GetParcelableInfo(data, deviceInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo deviceInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - int32_t ret = OnDeviceChanged(packageName, deviceInfo); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - uint16_t subscribeId = data.ReadInt16(); - DmDeviceInfo deviceInfo; - int32_t result = GetParcelableInfo(data, deviceInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - int32_t ret = OnDeviceFound(packageName, subscribeId, deviceInfo); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - uint16_t subscribeId = data.ReadInt16(); - int32_t failedReason = data.ReadInt32(); - - int32_t ret = OnDiscoverFailed(packageName, subscribeId, failedReason); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - uint16_t subscribeId = data.ReadInt16(); - - int32_t ret = OnDiscoverySuccess(packageName, subscribeId); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnAuthResultInner(MessageParcel &data, MessageParcel &reply) -{ - string packageName = data.ReadString(); - string deviceId = data.ReadString(); - int32_t status = data.ReadInt32(); - int32_t reason = data.ReadInt32(); - - int32_t ret = OnAuthResult(packageName, deviceId, status, reason); - reply.WriteInt32(ret); - return ret; -} - -int32_t DeviceManagerListenerStub::OnDeviceOnline(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - HILOGI("OnDeviceOnline packageName:%{public}s", packageName.c_str()); - if (deviceStateCallback_ == nullptr) { - HILOGE("OnDeviceOnlinecallback not register"); - return ERR_NULL_OBJECT; - } - deviceStateCallback_->OnDeviceOnline(deviceInfo); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnDeviceOffline(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - HILOGI("OnDeviceOffline packageName:%{public}s", packageName.c_str()); - if (deviceStateCallback_ == nullptr) { - HILOGE("OnDeviceOnlinecallback not register"); - return ERR_NULL_OBJECT; - } - deviceStateCallback_->OnDeviceOffline(deviceInfo); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnDeviceChanged(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - HILOGI("OnDeviceChanged packageName:%{public}s", packageName.c_str()); - if (deviceStateCallback_ == nullptr) { - HILOGE("OnDeviceOnlinecallback not register"); - return ERR_NULL_OBJECT; - } - deviceStateCallback_->OnDeviceChanged(deviceInfo); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnDeviceFound(std::string &packageName, uint16_t subscribeId, - const DmDeviceInfo &deviceInfo) -{ - HILOGI("OnDeviceFound packageName:%{public}s, subscribeId:%{public}d.", packageName.c_str(), (int32_t)subscribeId); - auto iter = deviceDiscoverCallbacks_.find(subscribeId); - if (iter == deviceDiscoverCallbacks_.end()) { - HILOGE("OnDeviceFound: no register discoverCallback for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - auto callback = iter->second; - if (callback == nullptr) { - HILOGE("OnDeviceFound: discoverCallback is nullptr for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - callback->OnDeviceFound(subscribeId, const_cast(deviceInfo)); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnDiscoverFailed(std::string &packageName, uint16_t subscribeId, - int32_t failedReason) -{ - HILOGI("OnDiscoverFailed packageName:%{public}s, subscribeId %{public}d, reason %{public}d", - packageName.c_str(), subscribeId, failedReason); - auto iter = deviceDiscoverCallbacks_.find(subscribeId); - if (iter == deviceDiscoverCallbacks_.end()) { - HILOGE("OnDiscoverFailed: no register discoverCallback for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - auto callback = iter->second; - if (callback == nullptr) { - HILOGE("OnDiscoverFailed: discoverCallback is nullptr for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - callback->OnDiscoverFailed(subscribeId, failedReason); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnDiscoverySuccess(std::string &packageName, uint16_t subscribeId) -{ - HILOGI("OnDiscoverySuccess packageName:%{public}s, subscribeId %{public}d", packageName.c_str(), subscribeId); - auto iter = deviceDiscoverCallbacks_.find(subscribeId); - if (iter == deviceDiscoverCallbacks_.end()) { - HILOGE("OnDiscoverySuccess: no register discoverCallback for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - auto callback = iter->second; - if (callback == nullptr) { - HILOGE("OnDiscoverySuccess: discoverCallback is nullptr for subscribeId %{public}d", subscribeId); - return ERR_NULL_OBJECT; - } - callback->OnDiscoverySuccess(subscribeId); - return ERR_OK; -} - -int32_t DeviceManagerListenerStub::OnAuthResult(std::string &packageName, std::string &deviceId, int32_t status, - int32_t reason) -{ - HILOGI("OnAuthResult packageName:%{public}s, status %{public}d, reason %{public}d", - packageName.c_str(), status, reason); - auto iter = authenticateCallback_.find(deviceId); - if (iter == authenticateCallback_.end()) { - HILOGE("OnAuthResult: cannot find Auth callback"); - return ERR_NULL_OBJECT; - } - auto callback = iter->second; - if (callback == nullptr) { - HILOGE("OnAuthResult: Auth callback is nullptr"); - return ERR_NULL_OBJECT; - } - callback->OnAuthResult(deviceId, status, reason); - authenticateCallback_.erase(deviceId); - return ERR_OK; -} - -void DeviceManagerListenerStub::AddDeviceStateCallback(std::shared_ptr callback) -{ - deviceStateCallback_ = callback; -} - -void DeviceManagerListenerStub::RemoveDeviceStateCallback() -{ - deviceStateCallback_ = nullptr; -} - -void DeviceManagerListenerStub::AddDiscoverCallback(uint16_t subscribeId, std::shared_ptr callback) -{ - deviceDiscoverCallbacks_[subscribeId] = callback; -} - -void DeviceManagerListenerStub::RemoveDiscoverCallback(uint16_t subscribeId) -{ - deviceDiscoverCallbacks_.erase(subscribeId); -} - -void DeviceManagerListenerStub::AddAuthenticateCallback(std::string deviceId, - std::shared_ptr callback) -{ - authenticateCallback_[deviceId] = callback; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_proxy.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_proxy.cpp deleted file mode 100644 index d5045590c..000000000 --- a/interfaces/inner_kits/native_cpp/src/device_manager_proxy.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager_proxy.h" - -#include "ipc_types.h" - -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -bool DeviceManagerProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(DeviceManagerProxy::GetDescriptor())) { - HILOGE("write interface token failed"); - return false; - } - return true; -} - -int32_t DeviceManagerProxy::RegisterDeviceManagerListener(std::string &packageName, sptr listener) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteRemoteObject(listener)) { - HILOGE("write callback failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(REGISTER_DEVICE_MANAGER_LISTENER, data, reply, option); - if (error != ERR_NONE) { - HILOGE("RegisterDeviceManagerListener SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::UnRegisterDeviceManagerListener(std::string &packageName) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(UNREGISTER_DEVICE_MANAGER_LISTENER, data, reply, option); - if (error != ERR_NONE) { - HILOGE("UnRegisterDeviceManagerListener SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::RegisterDeviceStateCallback(std::string &packageName, std::string &extra) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(extra)) { - HILOGE("write extra failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(REGISTER_DEVICE_STATE_CALLBACK, data, reply, option); - if (error != ERR_NONE) { - HILOGE("RegisterDeviceStateCallback SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::UnRegisterDeviceStateCallback(std::string &packageName) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(UNREGISTER_DEVICE_STATE_CALLBACK, data, reply, option); - if (error != ERR_NONE) { - HILOGE("UnRegisterDeviceStateCallback SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -template -int32_t DeviceManagerProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) -{ - int32_t infoSize = reply.ReadInt32(); - for (int32_t i = 0; i < infoSize; i++) { - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { - HILOGE("Read Parcelable infos failed"); - return ERR_INVALID_VALUE; - } - parcelableInfos.emplace_back(*info); - } - HILOGI("get parcelable infos success"); - return ERR_NONE; -} - -int32_t DeviceManagerProxy::GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(extra)) { - HILOGE("write extra failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(GET_TRUST_DEVICE_LIST, data, reply, option); - if (error != ERR_NONE) { - HILOGE("GetTrustedDeviceList SendRequest fail, error: %{public}d", error); - return error; - } - - error = GetParcelableInfos(reply, deviceList); - if (error != ERR_NONE) { - HILOGE("GetTrustedDeviceList GetParcelableInfos fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&subscribeInfo)) { - HILOGE("write subscribeInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(START_DEVICE_DISCOVER, data, reply, option); - if (error != ERR_NONE) { - HILOGE("StartDeviceDiscovery SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt16(subscribeId)) { - HILOGE("write subscribeInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(STOP_DEVICE_DISCOVER, data, reply, option); - if (error != ERR_NONE) { - HILOGE("StopDeviceDiscovery SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} - -int32_t DeviceManagerProxy::AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, - std::string &extra) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&deviceInfo)) { - HILOGE("write deviceInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(extra)) { - HILOGE("write extra failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(AUTHENTICATE_DEVICE, data, reply, option); - if (error != ERR_NONE) { - HILOGE("AuthenticateDevice SendRequest fail, error: %{public}d", error); - return error; - } - return ERR_NONE; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/ipc_client_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/ipc_client_proxy.cpp new file mode 100644 index 000000000..98fe1be22 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/ipc_client_proxy.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_proxy.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcClientProxy::Init(std::string &pkgName) +{ + if (ipcClientManager_ == nullptr) { + return DEVICEMANAGER_NULLPTR; + } + return ipcClientManager_->Init(pkgName); +} + +int32_t IpcClientProxy::UnInit(std::string &pkgName) +{ + if (ipcClientManager_ == nullptr) { + return DEVICEMANAGER_NULLPTR; + } + return ipcClientManager_->UnInit(pkgName); +} + +int32_t IpcClientProxy::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + if (req == nullptr || rsp == nullptr || ipcClientManager_ == nullptr) { + DMLog(DM_LOG_INFO, "req,rsp or ipc client is null"); + return DEVICEMANAGER_NULLPTR; + } + return ipcClientManager_->SendRequest(cmdCode, req, rsp); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp new file mode 100644 index 000000000..0ae523818 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_manager.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +#include "ipc_client_stub.h" +#include "ipc_register_listener_req.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcClientManager::Init(std::string &pkgName) +{ + if (IsInit(pkgName)) { + DMLog(DM_LOG_INFO, "already init"); + return DEVICEMANAGER_OK; + } + if (serverProxy_.Init() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "server proxy init failed."); + return DEVICEMANAGER_INIT_FAILED; + } + if (IpcClientStub::GetInstance().Init() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "ipcclientstub init failed."); + return DEVICEMANAGER_INIT_FAILED; + } + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetSvcIdentity(IpcClientStub::GetInstance().GetSvcIdentity()); + int32_t ret = serverProxy_.SendCmd(REGISTER_DEVICE_MANAGER_LISTENER, req, rsp); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret); + return ret; + } + ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "DeviceManager::InitDeviceManager completed, pkgName: %s, ret=%d", pkgName.c_str(), ret); + return ret; + } + packageInitSet_.emplace(pkgName); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientManager::UnInit(std::string &pkgName) +{ + DMLog(DM_LOG_INFO, "UnInitDeviceManager in, pkgName %s", pkgName.c_str()); + if (!IsInit(pkgName)) { + return DEVICEMANAGER_FAILED; + } + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + int32_t ret = serverProxy_.SendCmd(UNREGISTER_DEVICE_MANAGER_LISTENER, req, rsp); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "UnRegisterDeviceManagerListener Failed with ret %d", ret); + return ret; + } + packageInitSet_.erase(pkgName); + DMLog(DM_LOG_INFO, "UnInitDeviceManager SUCCESS"); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + std::string pkgName = req->GetPkgName(); + if (!IsInit(pkgName)) { + return DEVICEMANAGER_SERVICE_NOT_READY; + } + return serverProxy_.SendCmd(cmdCode, req, rsp); +} + +bool IpcClientManager::IsInit(std::string &pkgName) +{ + return (packageInitSet_.count(pkgName) > 0); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp new file mode 100644 index 000000000..7594a1f5b --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_server_proxy.h" + +#include + +#include "securec.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" +#include "device_manager_notify.h" + +#include "ipc_def.h" +#include "ipc_cmd_register.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { + const int32_t INVALID_CB_ID = 0xFF; +} +static uint32_t g_deathCbId = INVALID_CB_ID; +static SvcIdentity g_svcIdentity; +static std::shared_ptr pCurRsp; + +void __attribute__((weak)) HOS_SystemInit(void) +{ + SAMGR_Bootstrap(); + return; +} + +int32_t DMDeathCallback(const IpcContext *ctx, void *ipcMsg, IpcIo *data, void *arg) +{ + (void)ctx; + (void)ipcMsg; + (void)data; + (void)arg; + DMLog(DM_LOG_INFO, "ATTENTION SERVICE (%s) DEAD !!!\n", DEVICE_MANAGER_SERVICE_NAME); + UnregisterDeathCallback(g_svcIdentity, g_deathCbId); + g_deathCbId = INVALID_CB_ID; + g_svcIdentity.handle = 0; + g_svcIdentity.token = 0; + g_svcIdentity.cookie = 0; + DeviceManagerNotify::GetInstance().OnRemoteDied(); + return DEVICEMANAGER_OK; +} + +static int32_t SendCmdResultCb(IOwner owner, int code, IpcIo *reply) +{ + int32_t cmdCode = *(int32_t *)owner; + DMLog(DM_LOG_INFO, "SendCmdResultCb code:%d", cmdCode); + (void)IpcCmdRegister::GetInstance().ReadResponse(cmdCode, *reply, pCurRsp); + return DEVICEMANAGER_OK; +} + +IClientProxy *IpcClientServerProxy::GetServerProxy(void) +{ + IClientProxy *clientProxy = nullptr; + IUnknown *iUnknown = nullptr; + + DMLog(DM_LOG_INFO, "start get client proxy"); + iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME); + if (iUnknown == nullptr) { + return nullptr; + } + if (iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&clientProxy) != DEVICEMANAGER_OK || + clientProxy == nullptr) { + DMLog(DM_LOG_ERROR, "QueryInterface failed"); + } + return clientProxy; +} + +int IpcClientServerProxy::RegisterServerDeathCb(void) +{ + g_svcIdentity = SAMGR_GetRemoteIdentity(DEVICE_MANAGER_SERVICE_NAME, nullptr); + g_deathCbId = INVALID_CB_ID; + if (RegisterDeathCallback(nullptr, g_svcIdentity, DMDeathCallback, nullptr, &g_deathCbId) != EC_SUCCESS) { + DMLog(DM_LOG_ERROR, "reg death callback failed"); + return DEVICEMANAGER_FAILED; + } + return DEVICEMANAGER_OK; +} + +int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + DMLog(DM_LOG_INFO, "SendCmd:%d", cmdCode); + uint8_t data[MAX_DM_IPC_LEN] = {0}; + IpcIo request; + + if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, request, data, MAX_DM_IPC_LEN) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_FAILED; + } + { + std::lock_guard autoLock(lock_); + pCurRsp = rsp; + if (serviceProxy_ != nullptr && + serviceProxy_->Invoke(serviceProxy_, cmdCode, &request, &cmdCode, SendCmdResultCb) != 0) { + DMLog(DM_LOG_ERROR, "serviceProxy_ invoke failed."); + return DEVICEMANAGER_FAILED; + } + } + DMLog(DM_LOG_INFO, "SendCmd:%d end", cmdCode); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientServerProxy::Init(void) +{ + if (serviceProxy_ != nullptr) { + DMLog(DM_LOG_INFO, "ServerProxy already Init"); + return DEVICEMANAGER_OK; + } + HOS_SystemInit(); + serviceProxy_ = GetServerProxy(); + if (serviceProxy_ == nullptr) { + DMLog(DM_LOG_ERROR, "get ipc client proxy failed"); + return DEVICEMANAGER_FAILED; + } + if (RegisterServerDeathCb() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "register server death cb failed"); + return DEVICEMANAGER_FAILED; + } + DMLog(DM_LOG_INFO, "ServerProxyInit ok"); + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp new file mode 100644 index 000000000..7bcaee9bf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_stub.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "device_manager_notify.h" + +#include "ipc_def.h" +#include "ipc_cmd_register.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcClientStub); + +static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg, IpcIo *io, void *arg) +{ + (void)arg; + if (ipcMsg == nullptr || io == nullptr || ctx == nullptr) { + DMLog(DM_LOG_ERROR, "invalid param"); + return DEVICEMANAGER_INVALID_PARAM; + } + + uint32_t code = 0; + GetCode(ipcMsg, &code); + DMLog(DM_LOG_INFO, "receive ipc transact code(%u)", code); + return IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg); +} + +int32_t IpcClientStub::Init() +{ + std::lock_guard autoLock(lock_); + if (bInit) { + return DEVICEMANAGER_OK; + } + if (RegisterIpcCallback(ClientIpcInterfaceMsgHandle, 0, IPC_WAIT_FOREVER, &clientIdentity_, nullptr) != 0) { + DMLog(DM_LOG_ERROR, "register ipc cb failed"); + return DEVICEMANAGER_FAILED; + } + bInit = true; + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp new file mode 100644 index 000000000..ed8768a8d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" +#include "ipc_def.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "device_manager_notify.h" + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" + +#include "ipc_register_listener_req.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_check_authentication_req.h" + +namespace OHOS { +namespace DistributedHardware { +ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + SvcIdentity svcIdentity = pReq->GetSvcIdentity(); + + IpcIoInit(&request, buffer, buffLen, 1); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushSvc(&request, &svcIdentity); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::string pkgName = pBaseReq->GetPkgName(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushString(&request, extra.c_str()); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + int32_t deviceNum = IpcIoPopInt32(&reply); + uint32_t deviceTotalSize = deviceNum * (int32_t)sizeof(DmDeviceInfo); + + if (deviceTotalSize > 0) { + std::vector deviceInfoVec; + DmDeviceInfo *pDmDeviceinfo = (DmDeviceInfo *)IpcIoPopFlatObj(&reply, &deviceTotalSize); + if (pDmDeviceinfo == nullptr) { + DMLog(DM_LOG_ERROR, "GetTrustedDeviceList read node info failed!"); + pRsp->SetErrCode(DEVICEMANAGER_IPC_TRANSACTION_FAILED); + return DEVICEMANAGER_IPC_TRANSACTION_FAILED; + } + for (int32_t i = 0; i < deviceNum; ++i) { + pDmDeviceinfo = pDmDeviceinfo + i; + deviceInfoVec.emplace_back(*pDmDeviceinfo); + } + pRsp->SetDeviceVec(deviceInfoVec); + } + pRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushFlatObj(&request, &dmSubscribeInfo, sizeof(DmSubscribeInfo)); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushUint16(&request, subscribeId); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushString(&request, extra.c_str()); + IpcIoPushFlatObj(&request, &deviceInfo, sizeof(DmDeviceInfo)); + // L1 暂时没有考虑appimage校验(8k限制) + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(CHECK_AUTHENTICATION, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string authPara = pReq->GetAuthPara(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, authPara.c_str()); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_AUTHENTICATION, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&reply, &len); + DmDeviceState deviceState = static_cast(IpcIoPopInt32(&reply)); + uint32_t size; + const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); + if (pkgName == "" || len == 0 || deviceInfo == NULL) { + DMLog(DM_LOG_ERROR, "OnDeviceOnline, get para failed"); + FreeBuffer(&ctx, ipcMsg); + return; + } + switch (deviceState) { + case DEVICE_STATE_ONLINE: + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, *deviceInfo); + break; + case DEVICE_STATE_OFFLINE: + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, *deviceInfo); + break; + case DEVICE_INFO_CHANGED: + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, *deviceInfo); + break; + default: + DMLog(DM_LOG_ERROR, "unknown device state:%d", deviceState); + break; + } + FreeBuffer(&ctx, ipcMsg); +} + +ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&reply, &len); + uint16_t subscribeId = IpcIoPopUint16(&reply); + uint32_t size; + const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); + if (pkgName == "" || len == 0 || deviceInfo == NULL) { + DMLog(DM_LOG_ERROR, "OnDeviceChanged, get para failed"); + FreeBuffer(&ctx, ipcMsg); + return; + } + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, *deviceInfo); + FreeBuffer(&ctx, ipcMsg); +} + +ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&reply, &len); + uint16_t subscribeId = IpcIoPopUint16(&reply); + int32_t failedReason = IpcIoPopInt32(&reply); + + if (pkgName == "" || len == 0) { + DMLog(DM_LOG_ERROR, "OnDiscoverySuccess, get para failed"); + FreeBuffer(&ctx, ipcMsg); + return; + } + if (failedReason == DEVICEMANAGER_OK) { + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + } else { + DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason); + } + FreeBuffer(&ctx, ipcMsg); +} + +ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&reply, &len); + size_t devIdLen = 0; + std::string deviceId = (const char *)IpcIoPopString(&reply, &devIdLen); + int32_t pinToken = IpcIoPopInt32(&reply); + int32_t status = IpcIoPopInt32(&reply); + int32_t reason = IpcIoPopInt32(&reply); + + if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { + DMLog(DM_LOG_ERROR, "OnAuthResult, get para failed"); + FreeBuffer(&ctx, ipcMsg); + return; + } + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason); + FreeBuffer(&ctx, ipcMsg); +} + +ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +{ + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&reply, &len); + size_t devIdLen = 0; + std::string deviceId = (const char *)IpcIoPopString(&reply, &devIdLen); + int32_t resultCode = IpcIoPopInt32(&reply); + int32_t flag = IpcIoPopInt32(&reply); + + if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { + DMLog(DM_LOG_ERROR, "OnAuthResult, get para failed"); + FreeBuffer(&ctx, ipcMsg); + return; + } + DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag); + FreeBuffer(&ctx, ipcMsg); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp new file mode 100644 index 000000000..dd9835764 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_manager.h" + +#include "ipc_remote_broker.h" +#include "iremote_object.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "device_manager_notify.h" + +#include "ipc_register_listener_req.h" + +namespace OHOS { +namespace DistributedHardware { +void DmDeathRecipient::OnRemoteDied(const wptr& remote) +{ + (void)remote; + DMLog(DM_LOG_WARN, "DmDeathRecipient : OnRemoteDied"); + DeviceManagerNotify::GetInstance().OnRemoteDied(); +} + +int32_t IpcClientManager::ClientInit() +{ + DMLog(DM_LOG_INFO, "InitDeviceManagerService start"); + if (dmInterface_ != nullptr) { + DMLog(DM_LOG_INFO, "DeviceManagerService Already Init"); + return DEVICEMANAGER_OK; + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + DMLog(DM_LOG_ERROR, "Get SystemAbilityManager Failed"); + return DEVICEMANAGER_SERVICE_NOT_READY; + } + + auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); + if (object == nullptr) { + DMLog(DM_LOG_ERROR, "Get DeviceManager SystemAbility Failed"); + return DEVICEMANAGER_SERVICE_NOT_READY; + } + + if (dmRecipient_ == nullptr) { + dmRecipient_ = sptr(new DmDeathRecipient()); + } + if (!object->AddDeathRecipient(dmRecipient_)) { + DMLog(DM_LOG_ERROR, "InitDeviceManagerService: AddDeathRecipient Failed"); + } + dmInterface_ = iface_cast(object); + DMLog(DM_LOG_INFO, "DeviceManager::InitDeviceManagerService completed"); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientManager::Init(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + int32_t ret = ClientInit(); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "InitDeviceManager Failed with ret %d", ret); + return ret; + } + if (dmListener_.count(pkgName) > 0) { + DMLog(DM_LOG_INFO, "dmListener_ Already Init"); + return DEVICEMANAGER_OK; + } + + sptr listener = sptr(new IpcClientStub()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetListener(listener); + ret = dmInterface_->SendCmd(REGISTER_DEVICE_MANAGER_LISTENER, req, rsp); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "InitDeviceManager: RegisterDeviceManagerListener Failed with ret %d", ret); + return ret; + } + ret = rsp->GetErrCode(); + if (ret != DEVICEMANAGER_OK) { + return ret; + } + dmListener_[pkgName] = listener; + DMLog(DM_LOG_INFO, "completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientManager::UnInit(std::string &pkgName) +{ + DMLog(DM_LOG_INFO, "in, pkgName %s", pkgName.c_str()); + if (dmInterface_ == nullptr) { + DMLog(DM_LOG_ERROR, "DeviceManager not Init"); + return DEVICEMANAGER_SERVICE_NOT_READY; + } + + std::lock_guard autoLock(lock_); + if (dmListener_.count(pkgName) > 0) { + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + int32_t ret = dmInterface_->SendCmd(UNREGISTER_DEVICE_MANAGER_LISTENER, req, rsp); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "UnRegisterDeviceManagerListener Failed with ret %d", ret); + return ret; + } + dmListener_.erase(pkgName); + } + if (dmListener_.empty()) { + dmInterface_ = nullptr; + dmRecipient_ = nullptr; + } + DMLog(DM_LOG_INFO, "completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + std::string pkgName = req->GetPkgName(); + if (!IsInit(pkgName)) { + return DEVICEMANAGER_SERVICE_NOT_READY; + } + return dmInterface_->SendCmd(cmdCode, req, rsp); +} + +bool IpcClientManager::IsInit(std::string &pkgName) +{ + if (dmInterface_ == nullptr) { + DMLog(DM_LOG_ERROR, "DeviceManager not Init"); + return false; + } + std::lock_guard autoLock(lock_); + if (dmListener_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "dmListener_ not Init for %s", pkgName.c_str()); + return false; + } + return true; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp new file mode 100644 index 000000000..685a1735e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_server_proxy.h" + +#include "ipc_cmd_register.h" +#include "ipc_types.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DMLog(DM_LOG_ERROR, "remote service null"); + return DEVICEMANAGER_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_FAILED; + } + if (remote->SendRequest(cmdCode, data, reply, option) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "SendRequest fail, cmd:%d", cmdCode); + return DEVICEMANAGER_IPC_FAILED; + } + return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp new file mode 100644 index 000000000..1ef212aba --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_client_stub.h" + +#include "ipc_skeleton.h" +#include "ipc_types.h" + +#include "ipc_cmd_register.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + DMLog(DM_LOG_INFO, "code = %d, flags= %d.", code, option.GetFlags()); + if (IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply) == DEVICEMANAGER_OK) { + return DEVICEMANAGER_OK; + } + DMLog(DM_LOG_WARN, "unsupport code: %d", code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t IpcClientStub::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + DMLog(DM_LOG_ERROR, "error"); + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp new file mode 100644 index 000000000..537d87240 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" + +#include "securec.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "device_manager_notify.h" + +#include "ipc_def.h" +#include "ipc_register_listener_req.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_check_authentication_req.h" + +namespace OHOS { +namespace DistributedHardware { +ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + sptr listener = pReq->GetListener(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteRemoteObject(listener)) { + DMLog(DM_LOG_ERROR, "write listener failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::string pkgName = pBaseReq->GetPkgName(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write papam failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkg failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteString(extra)) { + DMLog(DM_LOG_ERROR, "write extra failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + int32_t deviceNum = reply.ReadInt32(); + int32_t deviceTotalSize = deviceNum * (int32_t)sizeof(DmDeviceInfo); + if (deviceTotalSize > 0) { + std::vector deviceInfoVec; + DmDeviceInfo *pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData(deviceTotalSize); + if (pDmDeviceinfo == nullptr) { + DMLog(DM_LOG_ERROR, "GetTrustedDeviceList read node info failed!"); + pRsp->SetErrCode(DEVICEMANAGER_IPC_TRANSACTION_FAILED); + return DEVICEMANAGER_IPC_TRANSACTION_FAILED; + } + for (int32_t i = 0; i < deviceTotalSize; ++i) { + pDmDeviceinfo = pDmDeviceinfo + i; + deviceInfoVec.emplace_back(*pDmDeviceinfo); + } + pRsp->SetDeviceVec(deviceInfoVec); + } + pRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteRawData(&dmSubscribeInfo, sizeof(DmSubscribeInfo))) { + DMLog(DM_LOG_ERROR, "write subscribe info failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt16(subscribeId)) { + DMLog(DM_LOG_ERROR, "write subscribeId failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + DmAppImageInfo imageInfo = pReq->GetAppImageInfo(); + + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteString(extra)) { + DMLog(DM_LOG_ERROR, "write extra failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) { + DMLog(DM_LOG_ERROR, "write deviceInfo failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(imageInfo.appIconLen)) { + DMLog(DM_LOG_ERROR, "write imageinfo appicon len failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(imageInfo.appThumbnailLen)) { + DMLog(DM_LOG_ERROR, "write imageinfo appThumbnailLen failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (imageInfo.appIconLen > 0 && !data.WriteRawData(imageInfo.appIcon, imageInfo.appIconLen)) { + DMLog(DM_LOG_ERROR, "write imageinfo appIcon failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (imageInfo.appThumbnailLen > 0 && !data.WriteRawData(imageInfo.appThumbnail, imageInfo.appThumbnailLen)) { + DMLog(DM_LOG_ERROR, "write imageinfo appThumbnail failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(CHECK_AUTHENTICATION, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string authPara = pReq->GetAuthPara(); + if (!data.WriteString(authPara)) { + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(CHECK_AUTHENTICATION, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + DmDeviceState deviceState = static_cast(data.ReadInt32()); + DmDeviceInfo dmDeviceInfo; + size_t deviceSize = sizeof(DmDeviceInfo); + void *deviceInfo = (void *)data.ReadRawData(deviceSize); + if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) { + reply.WriteInt32(DEVICEMANAGER_COPY_FAILED); + return DEVICEMANAGER_OK; + } + switch (deviceState) { + case DEVICE_STATE_ONLINE: + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo); + break; + case DEVICE_STATE_OFFLINE: + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo); + break; + case DEVICE_INFO_CHANGED: + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo); + break; + default: + DMLog(DM_LOG_ERROR, "unknown device state:%d", deviceState); + break; + } + reply.WriteInt32(DEVICEMANAGER_OK); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + uint16_t subscribeId = data.ReadInt16(); + DmDeviceInfo dmDeviceInfo; + size_t deviceSize = sizeof(DmDeviceInfo); + void *deviceInfo = (void *)data.ReadRawData(deviceSize); + if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) { + reply.WriteInt32(DEVICEMANAGER_COPY_FAILED); + return DEVICEMANAGER_OK; + } + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo); + reply.WriteInt32(DEVICEMANAGER_OK); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + uint16_t subscribeId = data.ReadInt16(); + int32_t failedReason = data.ReadInt32(); + + if (failedReason == DEVICEMANAGER_OK) { + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + } else { + DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason); + } + reply.WriteInt32(DEVICEMANAGER_OK); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string deviceId = data.ReadString(); + int32_t pinToken = data.ReadInt32(); + int32_t status = data.ReadInt32(); + int32_t reason = data.ReadInt32(); + + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason); + reply.WriteInt32(DEVICEMANAGER_OK); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string deviceId = data.ReadString(); + int32_t resultCode = data.ReadInt32(); + int32_t flag = data.ReadInt32(); + + DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag); + reply.WriteInt32(DEVICEMANAGER_OK); + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp new file mode 100644 index 000000000..84bc6b81c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_notify.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" +#include "nlohmann/json.hpp" +#include "constants.h" +#include "device_manager.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify); + +void DeviceManagerNotify::RegisterDeathRecipientCallback(std::string &pkgName, + std::shared_ptr dmInitCallback) +{ + std::lock_guard autoLock(lock_); + dmInitCallback_[pkgName] = dmInitCallback; +} + +void DeviceManagerNotify::UnRegisterDeathRecipientCallback(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + dmInitCallback_.erase(pkgName); +} + +void DeviceManagerNotify::RegisterDeviceStateCallback(std::string &pkgName, + std::shared_ptr callback) +{ + std::lock_guard autoLock(lock_); + deviceStateCallback_[pkgName] = callback; +} + +void DeviceManagerNotify::UnRegisterDeviceStateCallback(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + deviceStateCallback_.erase(pkgName); +} + +void DeviceManagerNotify::RegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId, + std::shared_ptr callback) +{ + std::lock_guard autoLock(lock_); + if (deviceDiscoverCallbacks_.count(pkgName) == 0) { + deviceDiscoverCallbacks_[pkgName] = std::map>(); + } + deviceDiscoverCallbacks_[pkgName][subscribeId] = callback; +} + +void DeviceManagerNotify::UnRegisterDiscoverCallback(std::string &pkgName, uint16_t subscribeId) +{ + std::lock_guard autoLock(lock_); + if (deviceDiscoverCallbacks_.count(pkgName) > 0) { + deviceDiscoverCallbacks_[pkgName].erase(subscribeId); + if (deviceDiscoverCallbacks_[pkgName].empty()) { + deviceDiscoverCallbacks_.erase(pkgName); + } + } +} + +void DeviceManagerNotify::RegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId, + std::shared_ptr callback) +{ + std::lock_guard autoLock(lock_); + if (authenticateCallback_.count(pkgName) == 0) { + authenticateCallback_[pkgName] = std::map>(); + } + authenticateCallback_[pkgName][deviceId] = callback; +} + +void DeviceManagerNotify::UnRegisterAuthenticateCallback(std::string &pkgName, std::string &deviceId) +{ + std::lock_guard autoLock(lock_); + if (authenticateCallback_.count(pkgName) > 0) { + authenticateCallback_[pkgName].erase(deviceId); + if (authenticateCallback_[pkgName].empty()) { + authenticateCallback_.erase(pkgName); + } + } +} + +void DeviceManagerNotify::UnRegisterPackageCallback(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + deviceStateCallback_.erase(pkgName); + deviceDiscoverCallbacks_.erase(pkgName); + authenticateCallback_.erase(pkgName); + dmInitCallback_.erase(pkgName); +} + +void DeviceManagerNotify::RegisterCheckAuthenticationCallback(std::string &pkgName, std::string &authPara, + std::shared_ptr callback) +{ + std::lock_guard autoLock(lock_); + if (checkauthcallback_.count(pkgName) == 0) { + checkauthcallback_[pkgName] = std::map>(); + } + checkauthcallback_[pkgName][authPara] = callback; +} + +void DeviceManagerNotify::UnRegisterCheckAuthenticationCallback(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + deviceStateCallback_.erase(pkgName); + deviceDiscoverCallbacks_.erase(pkgName); + authenticateCallback_.erase(pkgName); + dmInitCallback_.erase(pkgName); + checkauthcallback_.erase(pkgName); +} + +void DeviceManagerNotify::OnRemoteDied() +{ + DMLog(DM_LOG_WARN, "DeviceManager : OnRemoteDied"); + for (auto iter : dmInitCallback_) { + iter.second->OnRemoteDied(); + } +} + +void DeviceManagerNotify::OnDeviceOnline(std::string &pkgName, const DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDeviceOnline pkgName:%s", pkgName.c_str()); + std::lock_guard autoLock(lock_); + if (deviceStateCallback_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDeviceOnlinecallback not register"); + return; + } + deviceStateCallback_[pkgName]->OnDeviceOnline(deviceInfo); +} + +void DeviceManagerNotify::OnDeviceOffline(std::string &pkgName, const DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDeviceOffline pkgName:%s", pkgName.c_str()); + std::lock_guard autoLock(lock_); + if (deviceStateCallback_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDeviceOfflinecallback not register"); + return; + } + deviceStateCallback_[pkgName]->OnDeviceOffline(deviceInfo); +} + +void DeviceManagerNotify::OnDeviceChanged(std::string &pkgName, const DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDeviceChanged pkgName:%s", pkgName.c_str()); + std::lock_guard autoLock(lock_); + if (deviceStateCallback_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDeviceChangedcallback not register"); + return; + } + deviceStateCallback_[pkgName]->OnDeviceChanged(deviceInfo); +} + +void DeviceManagerNotify::OnDeviceFound(std::string &pkgName, uint16_t subscribeId, + const DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDeviceFound pkgName:%s, subscribeId:%d.", pkgName.c_str(), + (int32_t)subscribeId); + std::lock_guard autoLock(lock_); + if (deviceDiscoverCallbacks_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for this package"); + return; + } + std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName]; + auto iter = discoverCallMap.find(subscribeId); + if (iter == discoverCallMap.end()) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDeviceFound: no register discoverCallback for subscribeId %d", + subscribeId); + return; + } + iter->second->OnDeviceFound(subscribeId, deviceInfo); +} + +void DeviceManagerNotify::OnDiscoverFailed(std::string &pkgName, uint16_t subscribeId, int32_t failedReason) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDiscoverFailed pkgName:%s, subscribeId %d, reason %d", + pkgName.c_str(), subscribeId, failedReason); + std::lock_guard autoLock(lock_); + if (deviceDiscoverCallbacks_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for this package"); + return; + } + std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName]; + auto iter = discoverCallMap.find(subscribeId); + if (iter == discoverCallMap.end()) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDiscoverFailed: no register discoverCallback for subscribeId %d", + subscribeId); + return; + } + iter->second->OnDiscoverFailed(subscribeId, failedReason); +} + +void DeviceManagerNotify::OnDiscoverySuccess(std::string &pkgName, uint16_t subscribeId) +{ + DMLog(DM_LOG_INFO, "DeviceManager OnDiscoverySuccess pkgName:%s, subscribeId:%d.", pkgName.c_str(), + subscribeId); + std::lock_guard autoLock(lock_); + if (deviceDiscoverCallbacks_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for this package"); + return; + } + std::map>& discoverCallMap = deviceDiscoverCallbacks_[pkgName]; + auto iter = discoverCallMap.find(subscribeId); + if (iter == discoverCallMap.end()) { + DMLog(DM_LOG_ERROR, "DeviceManager OnDiscoverySuccess: no register discoverCallback for subscribeId %d", + subscribeId); + return; + } + iter->second->OnDiscoverySuccess(subscribeId); +} + +void DeviceManagerNotify::OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, + uint32_t status, uint32_t reason) +{ + DMLog(DM_LOG_INFO, "DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d", + pkgName.c_str(), status, reason); + std::lock_guard autoLock(lock_); + if (authenticateCallback_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for this package"); + return; + } + std::map>& authCallMap = authenticateCallback_[pkgName]; + auto iter = authCallMap.find(deviceId); + if (iter == authCallMap.end()) { + DMLog(DM_LOG_ERROR, "DeviceManager OnAuthResult: no register authCallback for deviceID %s", deviceId.c_str()); + return; + } + iter->second->OnAuthResult(deviceId, pinToken, status, reason); + authenticateCallback_[pkgName].erase(deviceId); + if (authenticateCallback_[pkgName].empty()) { + authenticateCallback_.erase(pkgName); + } +} + +void DeviceManagerNotify::OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, + int32_t flag) +{ + DMLog(DM_LOG_INFO, "DeviceManagerNotify::OnResult pkgName:%s, resultCode:%d, flag:%d", + pkgName.c_str(), resultCode, flag); + std::lock_guard autoLock(lock_); + if (checkauthcallback_.count(pkgName) == 0) { + DMLog(DM_LOG_ERROR, "DeviceManager OnResult: no register authCallback for this package"); + return; + } + std::map>& CheckAuthCallmap = checkauthcallback_[pkgName]; + auto iter = CheckAuthCallmap.find(deviceId); + if (iter == CheckAuthCallmap.end()) { + DMLog(DM_LOG_ERROR, "DeviceManager OnResult: no register CheckAuthCallmap for deviceID %s", deviceId.c_str()); + return; + } + iter->second->OnResult(deviceId, resultCode, flag); + checkauthcallback_[pkgName].erase(deviceId); + if (checkauthcallback_[pkgName].empty()) { + checkauthcallback_.erase(pkgName); + } +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/kits/js/@ohos.distributedHardware.deviceManager.d.ts b/interfaces/kits/js/@ohos.distributedHardware.deviceManager.d.ts new file mode 100644 index 000000000..2be9b26d7 --- /dev/null +++ b/interfaces/kits/js/@ohos.distributedHardware.deviceManager.d.ts @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2020 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 { AsyncCallback, Callback } from './basic'; + + declare namespace deviceManager { + /** + * DeviceInfo + */ + interface DeviceInfo { + /** + * Device ID. + */ + deviceId: string; + + /** + * Device name of the device. + */ + deviceName: string; + + /** + * Device type of the device. + */ + deviceType: DeviceType; + } + + /** + * Device Type definitions + */ + enum DeviceType { + /** + * Indicates an unknown device type. + */ + UNKNOWN_TYPE = 0, + + /** + * Indicates a speak. + */ + SPEAKER = 0x0A, + + /** + * Indicates a smartphone. + */ + PHONE = 0x0E, + + /** + * Indicates a tablet. + */ + TABLET = 0x11, + + /** + * Indicates a smart watch. + */ + WEARABLE = 0x6D, + + /** + * Indicates a car. + */ + CAR = 0x83, + + /** + * Indicates a smart TV. + */ + TV = 0x9C, + } + + /** + * Device state change event definition + */ + enum DeviceStateChangeAction { + /** + * device online action + */ + ONLINE = 0, + + /** + * device ready action, the device information synchronization was completed + */ + READY = 1, + + /** + * device offline action + */ + OFFLINE = 2, + + /** + * device change action + */ + CHANGE = 3, + } + + /** + * Service subscribe info for device discover + * + * @systemapi this method can be used only by system applications + */ + interface SubscribeInfo { + /** + * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process + */ + subscribeId: number; + + /** + * Discovery mode for service subscription. + */ + mode: DiscoverMode; + + /** + * Service subscription medium. + */ + medium: ExchangeMedium; + + /** + * Service subscription frequency. + */ + freq: ExchangeFreq; + + /** + * only find the device with the same account. + */ + isSameAccount: boolean; + + /** + * find the sleeping devices. + */ + isWakeRemote: boolean; + + /** + * Subscribe capability. + */ + capability: SubscribeCap; + } + + /** + * device discover mode + * + * @systemapi this method can be used only by system applications + */ + enum DiscoverMode { + /** + * Passive. + */ + DISCOVER_MODE_PASSIVE = 0x55, + + /** + * Proactive. + */ + DISCOVER_MODE_ACTIVE = 0xAA + } + + /** + * device discover medium + * + * @systemapi this method can be used only by system applications + */ + enum ExchangeMedium { + /** + * Automatic medium selection. + */ + AUTO = 0, + + /** + * Bluetooth + */ + BLE = 1, + + /** + * Wi-Fi + */ + COAP = 2, + + /** + * USB + */ + USB = 3 + } + + /** + * device discover freq + * + * @systemapi this method can be used only by system applications + */ + enum ExchangeFreq { + /** + * Low + */ + Low = 0, + + /** + * Medium + */ + MID = 1, + + /** + * High + */ + HIGH = 2, + + /** + * Super-high + */ + SUPER_HIGH = 3 + } + + /** + * device discover capability + * + * @systemapi this method can be used only by system applications + */ + enum SubscribeCap { + /** + * ddmpCapability + */ + SUBSCRIBE_CAPABILITY_DDMP = 0 + } + + /** + * Creates a {@code DeviceManager} instance + * + *

To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then + * use this instance to call other device management methods. + * + * @param bundleName Indicates the bundle name of the application. + * @param callback Indicates the callback to the invoked upon {@code DeviceManager} instance creation. + */ + function createDeviceManager(bundleName: string, callback: AsyncCallback): void; + + /** + * Provides methods for managing devices. + */ + interface DeviceManager { + /** + * Releases the {@code DeviceManager} instance after the methods for device management are no longer used + */ + release(): void; + + /** + * obtain a list of trusted devices. + * + * @param options Indicates the extra parameters to be passed to this method for device filtering or sorting. + * This parameter can be null. For details about available values, see {@link #TARGET_PACKAGE_NAME} and + * {@link #SORT_TYPE}. + * @return Returns a list of trusted devices. + */ + getTrustedDeviceListSync(): Array; + + /** + * Start to discover device. + * + * @param bundleName Indicates the bundle name of the application. + * @param subscribeInfo subscribe info to discover device + * @systemapi this method can be used only by system applications. + */ + startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; + + /** + * Stop to discover device. + * + * @param bundleName Indicates the bundle name of the application. + * @param subscribeId Service subscribe ID + * @systemapi this method can be used only by system applications. + */ + stopDeviceDiscovery(subscribeId: number): void; + + /** + * authenticate the specified device. + * + * @param bundleName Indicates the bundle name of the application. + * @param deviceInfo deviceInfo of device to authenticate + * @systemapi this method can be used only by system applications. + */ + authenticateDevice(deviceInfo: DeviceInfo): void; + + /** + * Register a device state callback so that the application can be notified upon device state changes based on + * the application bundle name. + * + * @param bundleName Indicates the bundle name of the application. + * @param callback Indicates the device state callback to register. + */ + on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; + + /** + * UnRegister device state callback based on the application bundle name + * + * @param bundleName Indicates the bundle name of the application. + * @param callback Indicates the device state callback to register. + */ + off(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; + + + + } + + + + + +} \ No newline at end of file diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index f2ea6932d..6eec0120e 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -14,51 +14,38 @@ import("//build/ohos.gni") import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -config("dmnativejs_config") { - visibility = [ ":*" ] +ohos_shared_library("devicemanager") { include_dirs = [ "//third_party/node/src", + "//third_party/json/include", + "${common_path}/include", "//foundation/ace/napi/native_engine", "//foundation/ace/napi/interfaces/kits", "//utils/native/base/include", "include", - "${common_path}/log/include", - "${common_path}/utils/include", + "${common_path}/include/log", + "${common_path}/include/utils", + "${common_path}/include/ipc", "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/standard", ] - cflags = [ - "-Wall", - "-Werror", - "-Wdate-time", - "-Wfloat-equal", - "-Wshadow", - "-Wformat=2", - "-fdata-sections", - "-ffunction-sections", - "-Os", - ] - - cflags_cc = [ - "-Os", - ] -} - -ohos_shared_library("devicemanager") { sources = [ + "${common_path}/src/log/device_manager_log.cpp", "src/native_devicemanager_js.cpp", "src/dm_native_event.cpp", ] - configs = [ ":dmnativejs_config" ] - deps = [ "//utils/native/base:utils", "//foundation/ace/napi:ace_napi", "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", ] + cflags_cc = build_flags + defines = [ + "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerkit_js\"", "LOG_DOMAIN=0xD004100", ] diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 872d7b457..0b087f5d0 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -1,145 +1,156 @@ -/* - * 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 OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H -#define OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H - -#include -#include -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "device_manager_callback.h" -#include "dm_native_event.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" - -const int DM_NAPI_BUF_LENGTH = 256; - -struct AsyncCallbackInfo { - napi_env env = nullptr; - napi_async_work asyncWork = nullptr; - - char bundleName[DM_NAPI_BUF_LENGTH] = {0}; - size_t bundleNameLen = 0; - - napi_ref callback = nullptr; - int32_t status = -1; -}; - -enum DmNapiDevStateChangeAction { - ONLINE = 0, - READY = 1, - OFFLINE = 2, - CHANGE = 3 -}; - -class DmNapiInitCallback : public OHOS::DistributedHardware::DmInitCallback { -public: - explicit DmNapiInitCallback(std::string &bundleName) : bundleName_(bundleName) {} - virtual ~DmNapiInitCallback() {} - void OnRemoteDied() override; - -private: - std::string bundleName_; -}; - -class DmNapiDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback { -public: - explicit DmNapiDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName) {} - virtual ~DmNapiDeviceStateCallback() {}; - void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - -private: - std::string bundleName_; -}; - -class DmNapiDiscoverCallback : public OHOS::DistributedHardware::DiscoverCallback { -public: - explicit DmNapiDiscoverCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) {} - virtual ~DmNapiDiscoverCallback() {}; - void OnDeviceFound(uint16_t subscribeId, OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) override; - void OnDiscoverySuccess(uint16_t subscribeId) override; - void IncreaseRefCount(); - void DecreaseRefCount(); - int32_t GetRefCount(); - -private: - std::atomic refCount_; - std::string bundleName_; -}; - -class DmNapiAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback { -public: - explicit DmNapiAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) {} - virtual ~DmNapiAuthenticateCallback() {}; - void OnAuthResult(std::string &deviceId, int32_t status, int32_t reason) override; - -private: - std::string bundleName_; -}; - -class DeviceManagerNapi : public DmNativeEvent { -public: - explicit DeviceManagerNapi(napi_env env, napi_value thisVar); - virtual ~DeviceManagerNapi(); - static napi_value Init(napi_env env, napi_value exports); - static napi_value Constructor(napi_env env, napi_callback_info info); - static napi_value CreateDeviceManager(napi_env env, napi_callback_info info); - static napi_value ReleaseDeviceManager(napi_env env, napi_callback_info info); - static napi_value GetTrustedDeviceListSync(napi_env env, napi_callback_info info); - static napi_value StartDeviceDiscoverSync(napi_env env, napi_callback_info info); - static napi_value StopDeviceDiscoverSync(napi_env env, napi_callback_info info); - static napi_value AuthenticateDeviceSync(napi_env env, napi_callback_info info); - static napi_value JsOn(napi_env env, napi_callback_info info); - static napi_value JsOff(napi_env env, napi_callback_info info); - static void HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo); - static DeviceManagerNapi *GetDeviceManagerNapi(std::string &buldleName); - static void CreateDmCallback(std::string &bundleName, std::string &eventType); - static void ReleaseDmCallback(std::string &bundleName, std::string &eventType); - static void DeviceInfoToJsArray(const napi_env& env, - const std::vector& vecDevInfo, - const int idx, napi_value& arrayResult); - static void SetValueInt32(const napi_env& env, const std::string& fieldStr, const int intValue, - napi_value& result); - static void SetValueUtf8String(const napi_env& env, const std::string& fieldStr, const std::string& str, - napi_value& result); - static void JsObjectToString(const napi_env& env, const napi_value& object, - const std::string& fieldStr, const int bufLen, std::string& fieldRef); - static void JsObjectToBool(const napi_env& env, const napi_value& object, - const std::string& fieldStr, bool& fieldRef); - static void JsObjectToInt(const napi_env& env, const napi_value& object, const std::string& fieldStr, - int& fieldRef); - static int32_t JsToDmSubscribeInfo(const napi_env& env, const napi_value& object, - OHOS::DistributedHardware::DmSubscribeInfo& info); - static void JsToDmDeviceInfo(const napi_env& env, const napi_value& object, - OHOS::DistributedHardware::DmDeviceInfo& info); - void OnDeviceStateChange(DmNapiDevStateChangeAction action, - const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo); - void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo); - void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason); - void OnAuthResult(const std::string& deviceId, int32_t status, int32_t reason); - -private: - napi_env env_; - napi_ref wrapper_; - static napi_ref sConstructor_; - std::string bundleName_; -}; - -#endif // OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H +/* + * 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 OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H +#define OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H + +#include +#include +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "device_manager_callback.h" +#include "dm_native_event.h" +#include "dm_device_info.h" +#include "dm_subscribe_info.h" + +const int DM_NAPI_BUF_LENGTH = 256; + +struct AsyncCallbackInfo { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + + char bundleName[DM_NAPI_BUF_LENGTH] = {0}; + size_t bundleNameLen = 0; + + napi_ref callback = nullptr; + int32_t status = -1; +}; + +enum DmNapiDevStateChangeAction { + ONLINE = 0, + READY = 1, + OFFLINE = 2, + CHANGE = 3 +}; + +class DmNapiInitCallback : public OHOS::DistributedHardware::DmInitCallback { +public: + explicit DmNapiInitCallback(std::string &bundleName) : bundleName_(bundleName) {} + virtual ~DmNapiInitCallback() {} + void OnRemoteDied() override; + +private: + std::string bundleName_; +}; + +class DmNapiDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback { +public: + explicit DmNapiDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName) {} + virtual ~DmNapiDeviceStateCallback() {}; + void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; + void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; + void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; + void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; + +private: + std::string bundleName_; +}; + +class DmNapiDiscoverCallback : public OHOS::DistributedHardware::DiscoverCallback { +public: + explicit DmNapiDiscoverCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) {} + virtual ~DmNapiDiscoverCallback() {}; + void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; + void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) override; + void OnDiscoverySuccess(uint16_t subscribeId) override; + void IncreaseRefCount(); + void DecreaseRefCount(); + int32_t GetRefCount(); + +private: + std::atomic refCount_; + std::string bundleName_; +}; + +class DmNapiAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback { +public: + explicit DmNapiAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) {} + virtual ~DmNapiAuthenticateCallback() {}; + void OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) override; + +private: + std::string bundleName_; +}; + +class DmNapiCheckAuthCallback : public OHOS::DistributedHardware::CheckAuthCallback { +public: + explicit DmNapiCheckAuthCallback(std::string &bundleName) : bundleName_(bundleName) {} + virtual ~DmNapiCheckAuthCallback() {}; + void OnResult(std::string &deviceId, int32_t resultCode, int32_t flag) override; + +private: + std::string bundleName_; +}; + +class DeviceManagerNapi : public DmNativeEvent { +public: + explicit DeviceManagerNapi(napi_env env, napi_value thisVar); + virtual ~DeviceManagerNapi(); + static napi_value Init(napi_env env, napi_value exports); + static napi_value Constructor(napi_env env, napi_callback_info info); + static napi_value CreateDeviceManager(napi_env env, napi_callback_info info); + static napi_value ReleaseDeviceManager(napi_env env, napi_callback_info info); + static napi_value GetTrustedDeviceListSync(napi_env env, napi_callback_info info); + static napi_value StartDeviceDiscoverSync(napi_env env, napi_callback_info info); + static napi_value StopDeviceDiscoverSync(napi_env env, napi_callback_info info); + static napi_value AuthenticateDeviceSync(napi_env env, napi_callback_info info); + static napi_value JsOn(napi_env env, napi_callback_info info); + static napi_value JsOff(napi_env env, napi_callback_info info); + static void HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo); + static DeviceManagerNapi *GetDeviceManagerNapi(std::string &buldleName); + static void CreateDmCallback(std::string &bundleName, std::string &eventType); + static void ReleaseDmCallback(std::string &bundleName, std::string &eventType); + static void DeviceInfoToJsArray(const napi_env& env, + const std::vector& vecDevInfo, + const int idx, napi_value& arrayResult); + static void SetValueInt32(const napi_env& env, const std::string& fieldStr, const int intValue, + napi_value& result); + static void SetValueUtf8String(const napi_env& env, const std::string& fieldStr, const std::string& str, + napi_value& result); + static void JsObjectToString(const napi_env& env, const napi_value& object, + const std::string& fieldStr, char *dest, const int destLen); + static void JsObjectToBool(const napi_env& env, const napi_value& object, + const std::string& fieldStr, bool& fieldRef); + static void JsObjectToInt(const napi_env& env, const napi_value& object, const std::string& fieldStr, + int& fieldRef); + static int32_t JsToDmSubscribeInfo(const napi_env& env, const napi_value& object, + OHOS::DistributedHardware::DmSubscribeInfo& info); + static void JsToDmDeviceInfo(const napi_env& env, const napi_value& object, + OHOS::DistributedHardware::DmDeviceInfo& info); + void OnDeviceStateChange(DmNapiDevStateChangeAction action, + const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo); + void OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo); + void OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason); + void OnAuthResult(const std::string& deviceId, int32_t pinToken, int32_t status, int32_t reason); + void OnResult(const std::string& deviceId, int32_t resultCode, int32_t flag); + +private: + napi_env env_; + napi_ref wrapper_; + static napi_ref sConstructor_; + std::string bundleName_; +}; + +#endif // OHOS_DEVICE_MANAGER_NATIVE_DEVICEMANAGER_JS_H diff --git a/interfaces/kits/js/src/dm_native_event.cpp b/interfaces/kits/js/src/dm_native_event.cpp index d3aca3d17..c8f2294f6 100644 --- a/interfaces/kits/js/src/dm_native_event.cpp +++ b/interfaces/kits/js/src/dm_native_event.cpp @@ -38,7 +38,7 @@ DmNativeEvent::~DmNativeEvent() void DmNativeEvent::On(std::string &eventType, napi_value handler) { - HILOGI("DmNativeEvent On in for event: %{public}s", eventType.c_str()); + DMLog(DM_LOG_INFO, "DmNativeEvent On in for event: %s", eventType.c_str()); auto listener = std::make_shared(); listener->eventType = eventType; napi_create_reference(env_, handler, 1, &listener->handlerRef); @@ -47,17 +47,17 @@ void DmNativeEvent::On(std::string &eventType, napi_value handler) void DmNativeEvent::Off(std::string &eventType) { - HILOGI("DmNativeEvent Off in for event: %{public}s", eventType.c_str()); + DMLog(DM_LOG_INFO, "DmNativeEvent Off in for event: %s", eventType.c_str()); napi_handle_scope scope = nullptr; napi_open_handle_scope(env_, &scope); if (scope == nullptr) { - HILOGE("scope is nullptr"); + DMLog(DM_LOG_ERROR, "scope is nullptr"); return; } auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { - HILOGE("eventType %{public}s not find", eventType.c_str()); + DMLog(DM_LOG_ERROR, "eventType %s not find", eventType.c_str()); return; } auto listener = iter->second; @@ -68,38 +68,38 @@ void DmNativeEvent::Off(std::string &eventType) void DmNativeEvent::OnEvent(const std::string &eventType, size_t argc, const napi_value* argv) { - HILOGI("OnEvent for %{public}s", eventType.c_str()); + DMLog(DM_LOG_INFO, "OnEvent for %s", eventType.c_str()); napi_handle_scope scope = nullptr; napi_open_handle_scope(env_, &scope); if (scope == nullptr) { - HILOGE("scope is nullptr"); + DMLog(DM_LOG_ERROR, "scope is nullptr"); return; } auto iter = eventMap_.find(eventType); if (iter == eventMap_.end()) { - HILOGE("eventType %{public}s not find", eventType.c_str()); + DMLog(DM_LOG_ERROR, "eventType %s not find", eventType.c_str()); return; } auto listener = iter->second; napi_value thisVar = nullptr; napi_status status = napi_get_reference_value(env_, thisVarRef_, &thisVar); if (status != napi_ok) { - HILOGE("napi_get_reference_value thisVar for %{public}s failed, status=%{public}d", eventType.c_str(), status); + DMLog(DM_LOG_ERROR, "napi_get_reference_value thisVar for %s failed, status=%d", eventType.c_str(), status); return; } napi_value handler = nullptr; status = napi_get_reference_value(env_, listener->handlerRef, &handler); if (status != napi_ok) { - HILOGE("napi_get_reference_value handler for %{public}s failed, status=%{public}d", eventType.c_str(), status); + DMLog(DM_LOG_ERROR, "napi_get_reference_value handler for %s failed, status=%d", eventType.c_str(), status); return; } napi_value callResult = nullptr; status = napi_call_function(env_, thisVar, handler, argc, argv, &callResult); if (status != napi_ok) { - HILOGE("napi_call_function for %{public}s failed, status=%{public}d", eventType.c_str(), status); + DMLog(DM_LOG_ERROR, "napi_call_function for %s failed, status=%d", eventType.c_str(), status); return; } napi_close_handle_scope(env_, scope); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 15a9df211..57274d3b6 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1,886 +1,909 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "native_devicemanager_js.h" - -#include - -#include "device_manager.h" -#include "device_manager_log.h" - -using namespace OHOS::DistributedHardware; - -namespace { -#define GET_PARAMS(env, info, num) \ - size_t argc = num; \ - napi_value argv[num] = { nullptr }; \ - napi_value thisVar = nullptr; \ - void *data = nullptr; \ - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)) - -const std::string DM_NAPI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; -const std::string DM_NAPI_EVENT_DEVICE_FOUND = "deviceFound"; -const std::string DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFail"; -const std::string DM_NAPI_EVENT_DEVICE_AUTH_RESULT = "authResult"; -const std::string DM_NAPI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; - -const std::string DEVICE_MANAGER_NAPI_CLASS_NAME = "DeviceManager"; - -const int DM_NAPI_ARGS_ONE = 1; -const int DM_NAPI_ARGS_TWO = 2; -const int DM_NAPI_SUB_ID_MAX = 65535; - -std::map g_deviceManagerMap; -std::map> g_initCallbackMap; -std::map> g_deviceStateCallbackMap; -std::map> g_discoverCallbackMap; -std::map> g_authCallbackMap; -} - -enum DmNapiSubscribeCap { - DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP = 0 -}; - -napi_ref DeviceManagerNapi::sConstructor_ = nullptr; - -void DmNapiInitCallback::OnRemoteDied() -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnRemoteDied, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnEvent("serviceDie", 0, nullptr); -} - -void DmNapiDeviceStateCallback::OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, deviceInfo); -} - -void DmNapiDeviceStateCallback::OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, deviceInfo); -} - -void DmNapiDeviceStateCallback::OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, deviceInfo); -} - -void DmNapiDeviceStateCallback::OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, deviceInfo); -} - -void DmNapiDiscoverCallback::OnDeviceFound(uint16_t subscribeId, - OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - - HILOGI("OnDeviceFound for %{public}s, subscribeId %{public}d", bundleName_.c_str(), (int32_t)subscribeId); - deviceManagerNapi->OnDeviceFound(subscribeId, deviceInfo); -} - -void DmNapiDiscoverCallback::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDiscoverFailed, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - - deviceManagerNapi->OnDiscoverFailed(subscribeId, failedReason); -} - -void DmNapiDiscoverCallback::OnDiscoverySuccess(uint16_t subscribeId) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnDiscoverySuccess, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - HILOGE("DiscoverySuccess for %{public}s, subscribeId %{public}d", bundleName_.c_str(), (int32_t)subscribeId); -} - -void DmNapiDiscoverCallback::IncreaseRefCount() -{ - refCount_++; -} - -void DmNapiDiscoverCallback::DecreaseRefCount() -{ - refCount_--; -} - -int32_t DmNapiDiscoverCallback::GetRefCount() -{ - return refCount_; -} - -void DmNapiAuthenticateCallback::OnAuthResult(std::string &deviceId, int32_t status, int32_t reason) -{ - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - HILOGE("OnAuthResult, deviceManagerNapi not find for bunderName %{public}s", bundleName_.c_str()); - return; - } - deviceManagerNapi->OnAuthResult(deviceId, status, reason); -} - -DeviceManagerNapi::DeviceManagerNapi(napi_env env, napi_value thisVar) : DmNativeEvent(env, thisVar) -{ - env_ = env; - wrapper_ = nullptr; -} - -DeviceManagerNapi::~DeviceManagerNapi() -{ - if (wrapper_ != nullptr) { - napi_delete_reference(env_, wrapper_); - } -} - -DeviceManagerNapi *DeviceManagerNapi::GetDeviceManagerNapi(std::string &buldleName) -{ - auto iter = g_deviceManagerMap.find(buldleName); - if (iter == g_deviceManagerMap.end()) { - return nullptr; - } - return iter->second; -} - -void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, - const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - napi_value result; - napi_create_object(env_, &result); - SetValueInt32(env_, "action", (int)action, result); - - napi_value device; - napi_create_object(env_, &device); - SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); - SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); - SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); - - napi_set_named_property(env_, result, "device", device); - OnEvent("deviceStateChange", DM_NAPI_ARGS_ONE, &result); -} - -void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) -{ - HILOGI("OnDeviceFound for subscribeId %{public}d", (int32_t)subscribeId); - napi_value result; - napi_create_object(env_, &result); - SetValueInt32(env_, "subscribeId", (int)subscribeId, result); - - napi_value device; - napi_create_object(env_, &device); - SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); - SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); - SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); - - napi_set_named_property(env_, result, "device", device); - OnEvent("deviceFound", DM_NAPI_ARGS_ONE, &result); -} - -void DeviceManagerNapi::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) -{ - HILOGI("OnDiscoverFailed for subscribeId %{public}d", (int32_t)subscribeId); - napi_value result; - napi_create_object(env_, &result); - SetValueInt32(env_, "subscribeId", (int)subscribeId, result); - SetValueInt32(env_, "reason", (int)failedReason, result); - OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result); -} - -void DeviceManagerNapi::OnAuthResult(const std::string& deviceId, int32_t status, int32_t reason) -{ - HILOGI("OnAuthResult for status: %{public}d, reason: %{public}d", status, reason); - napi_value result; - napi_create_object(env_, &result); - - SetValueUtf8String(env_, "deviceId", deviceId, result); - SetValueInt32(env_, "status", (int)status, result); - SetValueInt32(env_, "reason", (int)reason, result); - OnEvent("authResult", DM_NAPI_ARGS_ONE, &result); -} - -void DeviceManagerNapi::SetValueUtf8String(const napi_env &env, const std::string& fieldStr, const std::string& str, - napi_value& result) -{ - napi_value value; - napi_create_string_utf8(env, str.c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, fieldStr.c_str(), value); -} - -void DeviceManagerNapi::SetValueInt32(const napi_env& env, const std::string& fieldStr, const int intValue, - napi_value& result) -{ - napi_value value; - napi_create_int32(env, intValue, &value); - napi_set_named_property(env, result, fieldStr.c_str(), value); -} - -void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env& env, - const std::vector& vecDevInfo, - const int idx, napi_value& arrayResult) -{ - napi_value result; - napi_create_object(env, &result); - - SetValueUtf8String(env, "deviceId", vecDevInfo[idx].deviceId.c_str(), result); - SetValueUtf8String(env, "deviceName", vecDevInfo[idx].deviceName.c_str(), result); - SetValueInt32(env, "deviceType", (int)vecDevInfo[idx].deviceTypeId, result); - - napi_status status = napi_set_element(env, arrayResult, idx, result); - if (status != napi_ok) { - HILOGE("DmDeviceInfo To JsArray set element error: %{public}d", status); - } -} - -void DeviceManagerNapi::JsObjectToString(const napi_env& env, const napi_value& object, - const std::string& fieldStr, const int bufLen, std::string& fieldRef) -{ - bool hasProperty = false; - NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); - if (hasProperty) { - napi_value field; - napi_valuetype valueType; - - napi_get_named_property(env, object, fieldStr.c_str(), &field); - NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); - NAPI_ASSERT_RETURN_VOID(env, valueType == napi_string, "Wrong argument type. String expected."); - if (bufLen <= 0) { - HILOGE("js object to str bufLen invalid"); - return; - } - std::unique_ptr buf = std::make_unique(bufLen); - if (buf == nullptr) { - HILOGE("js object to str malloc failed"); - return; - } - (void)memset_s(buf.get(), bufLen, 0, bufLen); - size_t result = 0; - NAPI_CALL_RETURN_VOID(env, napi_get_value_string_utf8(env, field, buf.get(), bufLen, &result)); - fieldRef = buf.get(); - } else { - HILOGE("devicemanager napi js to str no property: %{public}s", fieldStr.c_str()); - } -} - -void DeviceManagerNapi::JsObjectToInt(const napi_env& env, const napi_value& object, - const std::string& fieldStr, int& fieldRef) -{ - bool hasProperty = false; - NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); - if (hasProperty) { - napi_value field; - napi_valuetype valueType; - - napi_get_named_property(env, object, fieldStr.c_str(), &field); - NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); - NAPI_ASSERT_RETURN_VOID(env, valueType == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, field, &fieldRef); - } else { - HILOGE("devicemanager napi js to int no property: %{public}s", fieldStr.c_str()); - } -} - -void DeviceManagerNapi::JsObjectToBool(const napi_env& env, const napi_value& object, - const std::string& fieldStr, bool& fieldRef) -{ - bool hasProperty = false; - NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); - if (hasProperty) { - napi_value field; - napi_valuetype valueType; - - napi_get_named_property(env, object, fieldStr.c_str(), &field); - NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); - NAPI_ASSERT_RETURN_VOID(env, valueType == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, field, &fieldRef); - } else { - HILOGE("devicemanager napi js to bool no property: %{public}s", fieldStr.c_str()); - } -} - -int32_t DeviceManagerNapi::JsToDmSubscribeInfo(const napi_env& env, const napi_value& object, - OHOS::DistributedHardware::DmSubscribeInfo& info) -{ - int subscribeId = -1; - JsObjectToInt(env, object, "subscribeId", subscribeId); - if (subscribeId < 0 || subscribeId > DM_NAPI_SUB_ID_MAX) { - HILOGE("DeviceManagerNapi::JsToDmSubscribeInfo, subscribeId error, subscribeId: %{public}d ", subscribeId); - return -1; - } - - info.subscribeId = (uint16_t)subscribeId; - - int mode = -1; - JsObjectToInt(env, object, "mode", mode); - info.mode = (DmDiscoverMode)mode; - - int medium = -1; - JsObjectToInt(env, object, "medium", medium); - info.medium = (DmExchangeMedium)medium; - - int freq = -1; - JsObjectToInt(env, object, "freq", freq); - info.freq = (DmExchangeFreq)freq; - - JsObjectToBool(env, object, "isSameAccount", info.isSameAccount); - JsObjectToBool(env, object, "isWakeRemote", info.isWakeRemote); - - int capability = -1; - JsObjectToInt(env, object, "capability", capability); - if (capability == DmNapiSubscribeCap::DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP) { - info.capability = std::string(DM_CAPABILITY_DDMP); - } - return 0; -} - -void DeviceManagerNapi::JsToDmDeviceInfo(const napi_env& env, const napi_value& object, - OHOS::DistributedHardware::DmDeviceInfo& info) -{ - JsObjectToString(env, object, "deviceId", DM_NAPI_BUF_LENGTH, info.deviceId); - JsObjectToString(env, object, "deviceName", DM_NAPI_BUF_LENGTH, info.deviceName); - int deviceType = -1; - JsObjectToInt(env, object, "deviceType", deviceType); - info.deviceTypeId = (DMDeviceType)deviceType; -} - - -void DeviceManagerNapi::CreateDmCallback(std::string &bundleName, std::string &eventType) -{ - HILOGE("CreateDmCallback for bunderName %{public}s eventType %{public}s", bundleName.c_str(), eventType.c_str()); - if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { - auto iter = g_deviceStateCallbackMap.find(bundleName); - if (iter == g_deviceStateCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - std::string extra = ""; - int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra, callback); - if (ret != 0) { - HILOGE("RegisterDevStateCallback failed for bunderName %{public}s", bundleName.c_str()); - return; - } - g_deviceStateCallbackMap[bundleName] = callback; - } - return; - } - - if (eventType == DM_NAPI_EVENT_DEVICE_FOUND || eventType == DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL) { - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(bundleName); - if (iter == g_discoverCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - g_discoverCallbackMap[bundleName] = callback; - discoverCallback = callback; - } else { - discoverCallback = iter->second; - } - - discoverCallback->IncreaseRefCount(); - return; - } - - if (eventType == DM_NAPI_EVENT_DEVICE_AUTH_RESULT) { - auto iter = g_authCallbackMap.find(bundleName); - if (iter == g_authCallbackMap.end()) { - auto callback = std::make_shared(bundleName); - g_authCallbackMap[bundleName] = callback; - } - return; - } -} - -void DeviceManagerNapi::ReleaseDmCallback(std::string &bundleName, std::string &eventType) -{ - if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { - auto iter = g_deviceStateCallbackMap.find(bundleName); - if (iter == g_deviceStateCallbackMap.end()) { - HILOGE("ReleaseDmCallback: cannot find stateCallback for bunderName %{public}s", bundleName.c_str()); - return; - } - int32_t ret = DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName); - if (ret != 0) { - HILOGE("RegisterDevStateCallback failed for bunderName %{public}s", bundleName.c_str()); - return; - } - g_deviceStateCallbackMap.erase(bundleName); - return; - } - - if (eventType == DM_NAPI_EVENT_DEVICE_FOUND || eventType == DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL) { - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(bundleName); - if (iter == g_discoverCallbackMap.end()) { - return; - } - - discoverCallback = iter->second; - discoverCallback->DecreaseRefCount(); - if (discoverCallback->GetRefCount() == 0) { - g_discoverCallbackMap.erase(bundleName); - } - return; - } - - if (eventType == DM_NAPI_EVENT_DEVICE_AUTH_RESULT) { - auto iter = g_authCallbackMap.find(bundleName); - if (iter == g_authCallbackMap.end()) { - return; - } - - g_authCallbackMap.erase(bundleName); - } -} - -napi_value DeviceManagerNapi::GetTrustedDeviceListSync(napi_env env, napi_callback_info info) -{ - HILOGI("GetTrustedDeviceList in"); - size_t argc = 0; - napi_value thisVar = nullptr; - napi_value array = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); - - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - std::string extra = ""; - std::vector devList; - int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(deviceManagerWrapper->bundleName_, extra, devList); - if (ret != 0) { - HILOGE("GetTrustedDeviceList for bunderName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); - return array; - } - - if (devList.size() > 0) { - bool isArray = false; - napi_create_array(env, &array); - napi_is_array(env, array, &isArray); - if (isArray == false) { - HILOGE("napi_create_array fail"); - } - - for (size_t i = 0; i != devList.size(); ++i) { - DeviceInfoToJsArray(env, devList, i, array); - } - } else { - HILOGE("devList is null"); - } - - return array; -} - -napi_value DeviceManagerNapi::StartDeviceDiscoverSync(napi_env env, napi_callback_info info) -{ - HILOGI("StartDeviceDiscoverSync in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); - napi_value result = nullptr; - napi_valuetype valueType; - napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); - - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - - std::shared_ptr discoverCallback = nullptr; - auto iter = g_discoverCallbackMap.find(deviceManagerWrapper->bundleName_); - if (iter == g_discoverCallbackMap.end()) { - discoverCallback = std::make_shared(deviceManagerWrapper->bundleName_); - g_discoverCallbackMap[deviceManagerWrapper->bundleName_] = discoverCallback; - } else { - discoverCallback = iter->second; - } - DmSubscribeInfo subInfo; - int32_t res = JsToDmSubscribeInfo(env, argv[0], subInfo); - NAPI_ASSERT(env, res == 0, "Wrong subscribeId "); - - int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(deviceManagerWrapper->bundleName_, - subInfo, discoverCallback); - if (ret != 0) { - HILOGE("StartDeviceDiscovery for bunderName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); - return result; - } - - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::StopDeviceDiscoverSync(napi_env env, napi_callback_info info) -{ - HILOGI("StopDeviceDiscoverSync in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); - napi_value result = nullptr; - napi_valuetype valueType; - napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected."); - - int32_t subscribeId = 0; - napi_get_value_int32(env, argv[0], &subscribeId); - NAPI_ASSERT(env, subscribeId <= DM_NAPI_SUB_ID_MAX, "Wrong argument. subscribeId Too Big."); - - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(deviceManagerWrapper->bundleName_, - (int16_t)subscribeId); - if (ret != 0) { - HILOGE("StopDeviceDiscovery for bunderName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); - return result; - } - - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::AuthenticateDeviceSync(napi_env env, napi_callback_info info) -{ - HILOGI("AuthenticateDeviceSync in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); - napi_value result = nullptr; - napi_valuetype valueType; - napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); - - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - - std::shared_ptr authCallback = nullptr; - auto iter = g_authCallbackMap.find(deviceManagerWrapper->bundleName_); - if (iter == g_authCallbackMap.end()) { - authCallback = std::make_shared(deviceManagerWrapper->bundleName_); - g_authCallbackMap[deviceManagerWrapper->bundleName_] = authCallback; - } else { - authCallback = iter->second; - } - DmDeviceInfo deviceInfo; - JsToDmDeviceInfo(env, argv[0], deviceInfo); - - std::string extra = ""; - int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(deviceManagerWrapper->bundleName_, deviceInfo, - extra, authCallback); - if (ret != 0) { - HILOGE("AuthenticateDevice for bunderName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); - return result; - } - - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::JsOn(napi_env env, napi_callback_info info) -{ - HILOGI("JsOn in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); - NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_TWO, "Wrong number of arguments, required 2"); - - napi_valuetype eventValueType = napi_undefined; - napi_typeof(env, argv[0], &eventValueType); - NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1"); - - napi_valuetype eventHandleType = napi_undefined; - napi_typeof(env, argv[1], &eventHandleType); - NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2"); - - size_t typeLen = 0; - napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen); - - NAPI_ASSERT(env, typeLen > 0, "typeLen == 0"); - std::unique_ptr type = std::make_unique(typeLen + 1); - napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen); - - std::string eventType = type.get(); - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - - HILOGI("JsOn for bunderName %{public}s, eventType %{public}s ", deviceManagerWrapper->bundleName_.c_str(), - eventType.c_str()); - deviceManagerWrapper->On(eventType, argv[1]); - CreateDmCallback(deviceManagerWrapper->bundleName_, eventType); - - napi_value result = nullptr; - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info) -{ - HILOGI("JsOff in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); - size_t requireArgc = 1; - NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments, required 1"); - - napi_valuetype eventValueType = napi_undefined; - napi_typeof(env, argv[0], &eventValueType); - NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1"); - - if (argc > requireArgc) { - napi_valuetype eventHandleType = napi_undefined; - napi_typeof(env, argv[1], &eventHandleType); - NAPI_ASSERT(env, eventValueType == napi_function, "type mismatch for parameter 2"); - } - - size_t typeLen = 0; - napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen); - - NAPI_ASSERT(env, typeLen > 0, "typeLen == 0"); - std::unique_ptr type = std::make_unique(typeLen + 1); - napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen); - - std::string eventType = type.get(); - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - - HILOGI("JsOff for bunderName %{public}s, eventType %{public}s ", deviceManagerWrapper->bundleName_.c_str(), - eventType.c_str()); - deviceManagerWrapper->Off(eventType); - ReleaseDmCallback(deviceManagerWrapper->bundleName_, eventType); - - napi_value result = nullptr; - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::ReleaseDeviceManager(napi_env env, napi_callback_info info) -{ - HILOGI("ReleaseDeviceManager in"); - size_t argc = 0; - napi_value thisVar = nullptr; - napi_value result = nullptr; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); - - DeviceManagerNapi *deviceManagerWrapper = nullptr; - napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); - HILOGI("ReleaseDeviceManager for bunderName %{public}s", deviceManagerWrapper->bundleName_.c_str()); - int32_t ret = DeviceManager::GetInstance().UnInitDeviceManager(deviceManagerWrapper->bundleName_); - if (ret != 0) { - HILOGE("ReleaseDeviceManager for bunderName %{public}s failed, ret %{public}d", - deviceManagerWrapper->bundleName_.c_str(), ret); - napi_create_uint32(env, ret, &result); - return result; - } - - g_deviceManagerMap.erase(deviceManagerWrapper->bundleName_); - g_initCallbackMap.erase(deviceManagerWrapper->bundleName_); - g_deviceStateCallbackMap.erase(deviceManagerWrapper->bundleName_); - g_discoverCallbackMap.erase(deviceManagerWrapper->bundleName_); - g_authCallbackMap.erase(deviceManagerWrapper->bundleName_); - napi_get_undefined(env, &result); - return result; -} - -void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo) -{ - napi_value resourceName; - napi_create_string_latin1(env, "createDeviceManagerCallback", NAPI_AUTO_LENGTH, &resourceName); - napi_create_async_work( - env, nullptr, resourceName, - [](napi_env env, void *data) { - (void)env; - AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data; - std::string bundleName = std::string(asCallbackInfo->bundleName); - std::shared_ptr initCallback = std::make_shared(bundleName); - if (DeviceManager::GetInstance().InitDeviceManager(bundleName, initCallback) != 0) { - HILOGE("InitDeviceManager for bunderName %{public}s failed", bundleName.c_str()); - return; - } - g_initCallbackMap[bundleName] = initCallback; - asCallbackInfo->status = 0; - }, - [](napi_env env, napi_status status, void *data) { - (void)status; - AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data; - napi_value result[DM_NAPI_ARGS_TWO] = { 0 }; - napi_value ctor; - napi_value argv; - napi_get_reference_value(env, sConstructor_, &ctor); - napi_create_string_utf8(env, asCallbackInfo->bundleName, NAPI_AUTO_LENGTH, &argv); - napi_status ret = napi_new_instance(env, ctor, DM_NAPI_ARGS_ONE, &argv, &result[1]); - if (ret != napi_ok) { - HILOGE("Create DeviceManagerNapi for bunderName %{public}s failed", asCallbackInfo->bundleName); - asCallbackInfo->status = -1; - } - - if (asCallbackInfo->status == 0) { - HILOGI("InitDeviceManager for bunderName %{public}s success", asCallbackInfo->bundleName); - napi_get_undefined(env, &result[0]); - napi_value callback = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(env, asCallbackInfo->callback, &callback); - napi_call_function(env, nullptr, callback, DM_NAPI_ARGS_TWO, &result[0], &callResult); - napi_delete_reference(env, asCallbackInfo->callback); - } else { - HILOGI("InitDeviceManager for bunderName %{public}s failed", asCallbackInfo->bundleName); - napi_value message = nullptr; - napi_create_object(env, &result[0]); - napi_create_int32(env, asCallbackInfo->status, &message); - napi_set_named_property(env, result[0], "code", message); - napi_get_undefined(env, &result[1]); - } - napi_delete_async_work(env, asCallbackInfo->asyncWork); - delete asCallbackInfo; - }, - (void *)asCallbackInfo, - &asCallbackInfo->asyncWork); - napi_queue_async_work(env, asCallbackInfo->asyncWork); -} - -napi_value DeviceManagerNapi::CreateDeviceManager(napi_env env, napi_callback_info info) -{ - HILOGI("CreateDeviceManager in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); - NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_TWO, "Wrong number of arguments, required 2"); - - napi_valuetype bundleNameValueType = napi_undefined; - napi_typeof(env, argv[0], &bundleNameValueType); - NAPI_ASSERT(env, bundleNameValueType == napi_string, "type mismatch for parameter 0"); - - napi_valuetype funcValueType = napi_undefined; - napi_typeof(env, argv[1], &funcValueType); - NAPI_ASSERT(env, funcValueType == napi_function, "type mismatch for parameter 1"); - - auto *asCallbackInfo = new AsyncCallbackInfo(); - asCallbackInfo->env = env; - napi_get_value_string_utf8(env, argv[0], asCallbackInfo->bundleName, DM_NAPI_BUF_LENGTH - 1, - &asCallbackInfo->bundleNameLen); - napi_create_reference(env, argv[1], 1, &asCallbackInfo->callback); - - HandleCreateDmCallBack(env, asCallbackInfo); - - napi_value result = nullptr; - napi_get_undefined(env, &result); - return result; -} - -napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) -{ - HILOGI("DeviceManagerNapi Constructor in"); - GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); - NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_ONE, "Wrong number of arguments, required 1"); - - napi_valuetype valueType = napi_undefined; - napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_string, "type mismatch for parameter 1"); - - char bundleName[DM_NAPI_BUF_LENGTH] = { 0 }; - size_t typeLen = 0; - napi_get_value_string_utf8(env, argv[0], bundleName, sizeof(bundleName), &typeLen); - - HILOGI("create DeviceManagerNapi for packageName:%{public}s", bundleName); - DeviceManagerNapi *obj = new DeviceManagerNapi(env, thisVar); - obj->bundleName_ = std::string(bundleName); - g_deviceManagerMap[obj->bundleName_] = obj; - napi_wrap(env, thisVar, reinterpret_cast(obj), - [](napi_env env, void *data, void *hint) { - (void)env; - (void)hint; - DeviceManagerNapi *deviceManager = (DeviceManagerNapi *)data; - delete deviceManager; - }, - nullptr, &(obj->wrapper_)); - return thisVar; -} - -napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports) -{ - napi_value dmClass; - napi_property_descriptor dmProperties[] = { - DECLARE_NAPI_FUNCTION("release", ReleaseDeviceManager), - DECLARE_NAPI_FUNCTION("getTrustedDeviceListSync", GetTrustedDeviceListSync), - DECLARE_NAPI_FUNCTION("startDeviceDiscovery", StartDeviceDiscoverSync), - DECLARE_NAPI_FUNCTION("stopDeviceDiscovery", StopDeviceDiscoverSync), - DECLARE_NAPI_FUNCTION("authenticateDevice", AuthenticateDeviceSync), - DECLARE_NAPI_FUNCTION("on", JsOn), - DECLARE_NAPI_FUNCTION("off", JsOff) - }; - - napi_property_descriptor static_prop[] = { - DECLARE_NAPI_STATIC_FUNCTION("createDeviceManager", CreateDeviceManager), - }; - - HILOGD("DeviceManagerNapi::Init() is called!"); - NAPI_CALL(env, - napi_define_class(env, DEVICE_MANAGER_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr, - sizeof(dmProperties) / sizeof(dmProperties[0]), dmProperties, &dmClass)); - NAPI_CALL(env, napi_create_reference(env, dmClass, 1, &sConstructor_)); - NAPI_CALL(env, napi_set_named_property(env, exports, DEVICE_MANAGER_NAPI_CLASS_NAME.c_str(), dmClass)); - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(static_prop) / sizeof(static_prop[0]), static_prop)); - HILOGI("All props and functions are configured.."); - return exports; -} - -/* - * Function registering all props and functions of ohos.distributedhardware - */ -static napi_value Export(napi_env env, napi_value exports) -{ - HILOGI("Export() is called!"); - DeviceManagerNapi::Init(env, exports); - return exports; -} - -/* - * module define - */ -static napi_module g_dmModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Export, - .nm_modname = "distributedhardware.devicemanager", - .nm_priv = ((void *)0), - .reserved = {0} - }; - -/* - * module register - */ -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - HILOGI("RegisterModule() is called!"); - napi_module_register(&g_dmModule); -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_devicemanager_js.h" + +#include +#include "nlohmann/json.hpp" + +#include "device_manager.h" +#include "device_manager_log.h" +#include "constants.h" + +using namespace OHOS::DistributedHardware; + +namespace { +#define GET_PARAMS(env, info, num) \ + size_t argc = num; \ + napi_value argv[num] = { nullptr }; \ + napi_value thisVar = nullptr; \ + void *data = nullptr; \ + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)) + +const std::string DM_NAPI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; +const std::string DM_NAPI_EVENT_DEVICE_FOUND = "deviceFound"; +const std::string DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFail"; +const std::string DM_NAPI_EVENT_DEVICE_AUTH_RESULT = "authResult"; +const std::string DM_NAPI_EVENT_DEVICE_SERVICE_DIE = "serviceDie"; + +const std::string DEVICE_MANAGER_NAPI_CLASS_NAME = "DeviceManager"; + +const int DM_NAPI_ARGS_ONE = 1; +const int DM_NAPI_ARGS_TWO = 2; +const int DM_NAPI_SUB_ID_MAX = 65535; + +std::map g_deviceManagerMap; +std::map> g_initCallbackMap; +std::map> g_deviceStateCallbackMap; +std::map> g_discoverCallbackMap; +std::map> g_authCallbackMap; +} + +enum DmNapiSubscribeCap { + DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP = 0 +}; + +napi_ref DeviceManagerNapi::sConstructor_ = nullptr; + +void DmNapiInitCallback::OnRemoteDied() +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnRemoteDied, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnEvent("serviceDie", 0, nullptr); +} + +void DmNapiDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDeviceOnline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, deviceInfo); +} + +void DmNapiDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDeviceOnline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, deviceInfo); +} + +void DmNapiDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDeviceOffline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, deviceInfo); +} + +void DmNapiDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDeviceChanged, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, deviceInfo); +} + +void DmNapiDiscoverCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDeviceFound, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + + DMLog(DM_LOG_INFO, "OnDeviceFound for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); + deviceManagerNapi->OnDeviceFound(subscribeId, deviceInfo); +} + +void DmNapiDiscoverCallback::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDiscoverFailed, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + + deviceManagerNapi->OnDiscoverFailed(subscribeId, failedReason); +} + +void DmNapiDiscoverCallback::OnDiscoverySuccess(uint16_t subscribeId) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnDiscoverySuccess, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + DMLog(DM_LOG_ERROR, "DiscoverySuccess for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); +} + +void DmNapiDiscoverCallback::IncreaseRefCount() +{ + refCount_++; +} + +void DmNapiDiscoverCallback::DecreaseRefCount() +{ + refCount_--; +} + +int32_t DmNapiDiscoverCallback::GetRefCount() +{ + return refCount_; +} + +void DmNapiAuthenticateCallback::OnAuthResult(std::string &deviceId, int32_t pinToken, int32_t status, int32_t reason) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnAuthResult, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnAuthResult(deviceId, pinToken, status, reason); +} + +void DmNapiCheckAuthCallback::OnResult(std::string &deviceId, int32_t resultCode, int32_t flag) +{ + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); + if (deviceManagerNapi == nullptr) { + DMLog(DM_LOG_ERROR, "OnResult, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + return; + } + deviceManagerNapi->OnResult(deviceId, resultCode, flag); +} + +DeviceManagerNapi::DeviceManagerNapi(napi_env env, napi_value thisVar) : DmNativeEvent(env, thisVar) +{ + env_ = env; + wrapper_ = nullptr; +} + +DeviceManagerNapi::~DeviceManagerNapi() +{ + if (wrapper_ != nullptr) { + napi_delete_reference(env_, wrapper_); + } +} + +DeviceManagerNapi *DeviceManagerNapi::GetDeviceManagerNapi(std::string &buldleName) +{ + auto iter = g_deviceManagerMap.find(buldleName); + if (iter == g_deviceManagerMap.end()) { + return nullptr; + } + return iter->second; +} + +void DeviceManagerNapi::OnDeviceStateChange(DmNapiDevStateChangeAction action, const DmDeviceInfo &deviceInfo) +{ + napi_value result; + napi_create_object(env_, &result); + SetValueInt32(env_, "action", (int)action, result); + + napi_value device; + napi_create_object(env_, &device); + SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); + SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); + SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); + + napi_set_named_property(env_, result, "device", device); + OnEvent("deviceStateChange", DM_NAPI_ARGS_ONE, &result); +} + +void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "OnDeviceFound for subscribeId %d", (int32_t)subscribeId); + napi_value result; + napi_create_object(env_, &result); + SetValueInt32(env_, "subscribeId", (int)subscribeId, result); + + napi_value device; + napi_create_object(env_, &device); + SetValueUtf8String(env_, "deviceId", deviceInfo.deviceId, device); + SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); + SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); + + napi_set_named_property(env_, result, "device", device); + OnEvent("deviceFound", DM_NAPI_ARGS_ONE, &result); +} + +void DeviceManagerNapi::OnDiscoverFailed(uint16_t subscribeId, int32_t failedReason) +{ + DMLog(DM_LOG_INFO, "OnDiscoverFailed for subscribeId %d", (int32_t)subscribeId); + napi_value result; + napi_create_object(env_, &result); + SetValueInt32(env_, "subscribeId", (int)subscribeId, result); + SetValueInt32(env_, "reason", (int)failedReason, result); + OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result); +} + +void DeviceManagerNapi::OnAuthResult(const std::string& deviceId, int32_t pinToken, int32_t status, int32_t reason) +{ + DMLog(DM_LOG_INFO, "OnAuthResult for status: %d, reason: %d", status, reason); + napi_value result; + napi_create_object(env_, &result); + + SetValueUtf8String(env_, "deviceId", deviceId, result); + SetValueInt32(env_, "pinToken", (int)pinToken, result); + SetValueInt32(env_, "status", (int)status, result); + SetValueInt32(env_, "reason", (int)reason, result); + OnEvent("authResult", DM_NAPI_ARGS_ONE, &result); +} + +void DeviceManagerNapi::OnResult(const std::string& deviceId, int32_t resultCode, int32_t flag) +{ + DMLog(DM_LOG_INFO, "Result for resultCode: %d, flag: %d", resultCode, flag); + napi_value result; + napi_create_object(env_, &result); + + SetValueUtf8String(env_, "deviceId", deviceId, result); + SetValueInt32(env_, "status", (int)resultCode, result); + SetValueInt32(env_, "reason", (int)flag, result); + OnEvent("Result", DM_NAPI_ARGS_ONE, &result); +} + +void DeviceManagerNapi::SetValueUtf8String(const napi_env &env, const std::string& fieldStr, const std::string& str, + napi_value& result) +{ + napi_value value; + napi_create_string_utf8(env, str.c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, fieldStr.c_str(), value); +} + +void DeviceManagerNapi::SetValueInt32(const napi_env& env, const std::string& fieldStr, const int intValue, + napi_value& result) +{ + napi_value value; + napi_create_int32(env, intValue, &value); + napi_set_named_property(env, result, fieldStr.c_str(), value); +} + +void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env& env, + const std::vector& vecDevInfo, + const int idx, napi_value& arrayResult) +{ + napi_value result; + napi_create_object(env, &result); + + SetValueUtf8String(env, "deviceId", vecDevInfo[idx].deviceId, result); + SetValueUtf8String(env, "deviceName", vecDevInfo[idx].deviceName, result); + SetValueInt32(env, "deviceType", (int)vecDevInfo[idx].deviceTypeId, result); + + napi_status status = napi_set_element(env, arrayResult, idx, result); + if (status != napi_ok) { + DMLog(DM_LOG_ERROR, "DmDeviceInfo To JsArray set element error: %d", status); + } +} + +void DeviceManagerNapi::JsObjectToString(const napi_env& env, const napi_value& object, + const std::string& fieldStr, char *dest, const int destLen) +{ + bool hasProperty = false; + NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); + if (hasProperty) { + napi_value field; + napi_valuetype valueType; + + napi_get_named_property(env, object, fieldStr.c_str(), &field); + NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); + NAPI_ASSERT_RETURN_VOID(env, valueType == napi_string, "Wrong argument type. String expected."); + size_t result = 0; + NAPI_CALL_RETURN_VOID(env, napi_get_value_string_utf8(env, field, dest, destLen, &result)); + } else { + DMLog(DM_LOG_ERROR, "devicemanager napi js to str no property: %s", fieldStr.c_str()); + } +} + +void DeviceManagerNapi::JsObjectToInt(const napi_env& env, const napi_value& object, + const std::string& fieldStr, int& fieldRef) +{ + bool hasProperty = false; + NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); + if (hasProperty) { + napi_value field; + napi_valuetype valueType; + + napi_get_named_property(env, object, fieldStr.c_str(), &field); + NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); + NAPI_ASSERT_RETURN_VOID(env, valueType == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, field, &fieldRef); + } else { + DMLog(DM_LOG_ERROR, "devicemanager napi js to int no property: %s", fieldStr.c_str()); + } +} + +void DeviceManagerNapi::JsObjectToBool(const napi_env& env, const napi_value& object, + const std::string& fieldStr, bool& fieldRef) +{ + bool hasProperty = false; + NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); + if (hasProperty) { + napi_value field; + napi_valuetype valueType; + + napi_get_named_property(env, object, fieldStr.c_str(), &field); + NAPI_CALL_RETURN_VOID(env, napi_typeof(env, field, &valueType)); + NAPI_ASSERT_RETURN_VOID(env, valueType == napi_boolean, "Wrong argument type. Bool expected."); + napi_get_value_bool(env, field, &fieldRef); + } else { + DMLog(DM_LOG_ERROR, "devicemanager napi js to bool no property: %s", fieldStr.c_str()); + } +} + +int32_t DeviceManagerNapi::JsToDmSubscribeInfo(const napi_env& env, const napi_value& object, + DmSubscribeInfo& info) +{ + int subscribeId = -1; + JsObjectToInt(env, object, "subscribeId", subscribeId); + if (subscribeId < 0 || subscribeId > DM_NAPI_SUB_ID_MAX) { + DMLog(DM_LOG_ERROR, "DeviceManagerNapi::JsToDmSubscribeInfo, subscribeId error, subscribeId: %d ", subscribeId); + return -1; + } + + info.subscribeId = (uint16_t)subscribeId; + + int mode = -1; + JsObjectToInt(env, object, "mode", mode); + info.mode = (DmDiscoverMode)mode; + + int medium = -1; + JsObjectToInt(env, object, "medium", medium); + info.medium = (DmExchangeMedium)medium; + + int freq = -1; + JsObjectToInt(env, object, "freq", freq); + info.freq = (DmExchangeFreq)freq; + + JsObjectToBool(env, object, "isSameAccount", info.isSameAccount); + JsObjectToBool(env, object, "isWakeRemote", info.isWakeRemote); + + int capability = -1; + JsObjectToInt(env, object, "capability", capability); + if (capability == DmNapiSubscribeCap::DM_NAPI_SUBSCRIBE_CAPABILITY_DDMP) { + (void)strncpy_s(info.capability, sizeof(info.capability), DM_CAPABILITY_OSD, strlen(DM_CAPABILITY_OSD)); + } + return 0; +} + +void DeviceManagerNapi::JsToDmDeviceInfo(const napi_env& env, const napi_value& object, + DmDeviceInfo& info) +{ + JsObjectToString(env, object, "deviceId", info.deviceId, sizeof(info.deviceId)); + JsObjectToString(env, object, "deviceName", info.deviceName, sizeof(info.deviceName)); + int deviceType = -1; + JsObjectToInt(env, object, "deviceType", deviceType); + info.deviceTypeId = (DMDeviceType)deviceType; +} + + +void DeviceManagerNapi::CreateDmCallback(std::string &bundleName, std::string &eventType) +{ + DMLog(DM_LOG_ERROR, "CreateDmCallback for bunderName %s eventType %s", bundleName.c_str(), eventType.c_str()); + if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { + auto iter = g_deviceStateCallbackMap.find(bundleName); + if (iter == g_deviceStateCallbackMap.end()) { + auto callback = std::make_shared(bundleName); + std::string extra = ""; + int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra, callback); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); + return; + } + g_deviceStateCallbackMap[bundleName] = callback; + } + return; + } + + if (eventType == DM_NAPI_EVENT_DEVICE_FOUND || eventType == DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL) { + std::shared_ptr discoverCallback = nullptr; + auto iter = g_discoverCallbackMap.find(bundleName); + if (iter == g_discoverCallbackMap.end()) { + auto callback = std::make_shared(bundleName); + g_discoverCallbackMap[bundleName] = callback; + discoverCallback = callback; + } else { + discoverCallback = iter->second; + } + + discoverCallback->IncreaseRefCount(); + return; + } + + if (eventType == DM_NAPI_EVENT_DEVICE_AUTH_RESULT) { + auto iter = g_authCallbackMap.find(bundleName); + if (iter == g_authCallbackMap.end()) { + auto callback = std::make_shared(bundleName); + g_authCallbackMap[bundleName] = callback; + } + return; + } +} + +void DeviceManagerNapi::ReleaseDmCallback(std::string &bundleName, std::string &eventType) +{ + if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { + auto iter = g_deviceStateCallbackMap.find(bundleName); + if (iter == g_deviceStateCallbackMap.end()) { + DMLog(DM_LOG_ERROR, "ReleaseDmCallback: cannot find stateCallback for bunderName %s", bundleName.c_str()); + return; + } + int32_t ret = DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "RegisterDevStateCallback failed for bunderName %s", bundleName.c_str()); + return; + } + g_deviceStateCallbackMap.erase(bundleName); + return; + } + + if (eventType == DM_NAPI_EVENT_DEVICE_FOUND || eventType == DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL) { + std::shared_ptr discoverCallback = nullptr; + auto iter = g_discoverCallbackMap.find(bundleName); + if (iter == g_discoverCallbackMap.end()) { + return; + } + + discoverCallback = iter->second; + discoverCallback->DecreaseRefCount(); + if (discoverCallback->GetRefCount() == 0) { + g_discoverCallbackMap.erase(bundleName); + } + return; + } + + if (eventType == DM_NAPI_EVENT_DEVICE_AUTH_RESULT) { + auto iter = g_authCallbackMap.find(bundleName); + if (iter == g_authCallbackMap.end()) { + return; + } + + g_authCallbackMap.erase(bundleName); + } +} + +napi_value DeviceManagerNapi::GetTrustedDeviceListSync(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "GetTrustedDeviceList in"); + size_t argc = 0; + napi_value thisVar = nullptr; + napi_value array = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); + NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); + + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + std::string extra = ""; + std::vector devList; + int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(deviceManagerWrapper->bundleName_, extra, devList); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "GetTrustedDeviceList for bunderName %s failed, ret %d", + deviceManagerWrapper->bundleName_.c_str(), ret); + return array; + } + + if (devList.size() > 0) { + bool isArray = false; + napi_create_array(env, &array); + napi_is_array(env, array, &isArray); + if (isArray == false) { + DMLog(DM_LOG_ERROR, "napi_create_array fail"); + } + + for (size_t i = 0; i != devList.size(); ++i) { + DeviceInfoToJsArray(env, devList, i, array); + } + } else { + DMLog(DM_LOG_ERROR, "devList is null"); + } + + return array; +} + +napi_value DeviceManagerNapi::StartDeviceDiscoverSync(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "StartDeviceDiscoverSync in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); + napi_value result = nullptr; + napi_valuetype valueType; + napi_typeof(env, argv[0], &valueType); + NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); + + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + + std::shared_ptr discoverCallback = nullptr; + auto iter = g_discoverCallbackMap.find(deviceManagerWrapper->bundleName_); + if (iter == g_discoverCallbackMap.end()) { + discoverCallback = std::make_shared(deviceManagerWrapper->bundleName_); + g_discoverCallbackMap[deviceManagerWrapper->bundleName_] = discoverCallback; + } else { + discoverCallback = iter->second; + } + DmSubscribeInfo subInfo; + int32_t res = JsToDmSubscribeInfo(env, argv[0], subInfo); + NAPI_ASSERT(env, res == 0, "Wrong subscribeId "); + + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(deviceManagerWrapper->bundleName_, + subInfo, discoverCallback); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "StartDeviceDiscovery for bunderName %s failed, ret %d", + deviceManagerWrapper->bundleName_.c_str(), ret); + return result; + } + + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::StopDeviceDiscoverSync(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "StopDeviceDiscoverSync in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); + napi_value result = nullptr; + napi_valuetype valueType; + napi_typeof(env, argv[0], &valueType); + NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. Object expected."); + + int32_t subscribeId = 0; + napi_get_value_int32(env, argv[0], &subscribeId); + NAPI_ASSERT(env, subscribeId <= DM_NAPI_SUB_ID_MAX, "Wrong argument. subscribeId Too Big."); + + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(deviceManagerWrapper->bundleName_, + (int16_t)subscribeId); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "StopDeviceDiscovery for bunderName %s failed, ret %d", + deviceManagerWrapper->bundleName_.c_str(), ret); + return result; + } + + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::AuthenticateDeviceSync(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "AuthenticateDeviceSync in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); + napi_value result = nullptr; + napi_valuetype valueType; + napi_typeof(env, argv[0], &valueType); + NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected."); + + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + + std::shared_ptr authCallback = nullptr; + auto iter = g_authCallbackMap.find(deviceManagerWrapper->bundleName_); + if (iter == g_authCallbackMap.end()) { + authCallback = std::make_shared(deviceManagerWrapper->bundleName_); + g_authCallbackMap[deviceManagerWrapper->bundleName_] = authCallback; + } else { + authCallback = iter->second; + } + DmDeviceInfo deviceInfo; + JsToDmDeviceInfo(env, argv[0], deviceInfo); + + DmAppImageInfo appImageInfo; + appImageInfo.appIconLen = 0; + appImageInfo.appIcon = nullptr; + appImageInfo.appThumbnailLen = 0; + appImageInfo.appThumbnail = nullptr; + + nlohmann::json jsonObj; + jsonObj[APP_NAME_KEY] = "devicemanager"; + jsonObj[APP_DESCRIPTION_KEY] = "this is a dm test process"; + jsonObj[TARGET_PKG_NAME_KEY] = "com.huawei.devicemanager"; + jsonObj[AUTH_TYPE] = AUTH_TYPE_PIN; + std::string extra = jsonObj.dump(); + int32_t ret = DeviceManager::GetInstance().AuthenticateDevice(deviceManagerWrapper->bundleName_, deviceInfo, + appImageInfo, extra, authCallback); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "AuthenticateDevice for bunderName %s failed, ret %d", + deviceManagerWrapper->bundleName_.c_str(), ret); + return result; + } + + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::JsOn(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "JsOn in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); + NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_TWO, "Wrong number of arguments, required 2"); + + napi_valuetype eventValueType = napi_undefined; + napi_typeof(env, argv[0], &eventValueType); + NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1"); + + napi_valuetype eventHandleType = napi_undefined; + napi_typeof(env, argv[1], &eventHandleType); + NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2"); + + size_t typeLen = 0; + napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen); + + NAPI_ASSERT(env, typeLen > 0, "typeLen == 0"); + std::unique_ptr type = std::make_unique(typeLen + 1); + napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen); + + std::string eventType = type.get(); + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + + DMLog(DM_LOG_INFO, "JsOn for bunderName %s, eventType %s ", deviceManagerWrapper->bundleName_.c_str(), + eventType.c_str()); + deviceManagerWrapper->On(eventType, argv[1]); + CreateDmCallback(deviceManagerWrapper->bundleName_, eventType); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "JsOff in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); + size_t requireArgc = 1; + NAPI_ASSERT(env, argc >= requireArgc, "Wrong number of arguments, required 1"); + + napi_valuetype eventValueType = napi_undefined; + napi_typeof(env, argv[0], &eventValueType); + NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1"); + + if (argc > requireArgc) { + napi_valuetype eventHandleType = napi_undefined; + napi_typeof(env, argv[1], &eventHandleType); + NAPI_ASSERT(env, eventValueType == napi_function, "type mismatch for parameter 2"); + } + + size_t typeLen = 0; + napi_get_value_string_utf8(env, argv[0], nullptr, 0, &typeLen); + + NAPI_ASSERT(env, typeLen > 0, "typeLen == 0"); + std::unique_ptr type = std::make_unique(typeLen + 1); + napi_get_value_string_utf8(env, argv[0], type.get(), typeLen + 1, &typeLen); + + std::string eventType = type.get(); + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + + DMLog(DM_LOG_INFO, "JsOff for bunderName %s, eventType %s ", deviceManagerWrapper->bundleName_.c_str(), + eventType.c_str()); + deviceManagerWrapper->Off(eventType); + ReleaseDmCallback(deviceManagerWrapper->bundleName_, eventType); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::ReleaseDeviceManager(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "ReleaseDeviceManager in"); + size_t argc = 0; + napi_value thisVar = nullptr; + napi_value result = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); + NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); + + DeviceManagerNapi *deviceManagerWrapper = nullptr; + napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); + DMLog(DM_LOG_INFO, "ReleaseDeviceManager for bunderName %s", deviceManagerWrapper->bundleName_.c_str()); + int32_t ret = DeviceManager::GetInstance().UnInitDeviceManager(deviceManagerWrapper->bundleName_); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "ReleaseDeviceManager for bunderName %s failed, ret %d", + deviceManagerWrapper->bundleName_.c_str(), ret); + napi_create_uint32(env, ret, &result); + return result; + } + + g_deviceManagerMap.erase(deviceManagerWrapper->bundleName_); + g_initCallbackMap.erase(deviceManagerWrapper->bundleName_); + g_deviceStateCallbackMap.erase(deviceManagerWrapper->bundleName_); + g_discoverCallbackMap.erase(deviceManagerWrapper->bundleName_); + g_authCallbackMap.erase(deviceManagerWrapper->bundleName_); + napi_get_undefined(env, &result); + return result; +} + +void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo) +{ + napi_value resourceName; + napi_create_string_latin1(env, "createDeviceManagerCallback", NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work( + env, nullptr, resourceName, + [](napi_env env, void *data) { + (void)env; + AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data; + std::string bundleName = std::string(asCallbackInfo->bundleName); + std::shared_ptr initCallback = std::make_shared(bundleName); + if (DeviceManager::GetInstance().InitDeviceManager(bundleName, initCallback) != 0) { + DMLog(DM_LOG_ERROR, "InitDeviceManager for bunderName %s failed", bundleName.c_str()); + return; + } + g_initCallbackMap[bundleName] = initCallback; + asCallbackInfo->status = 0; + }, + [](napi_env env, napi_status status, void *data) { + (void)status; + AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data; + napi_value result[DM_NAPI_ARGS_TWO] = { 0 }; + napi_value ctor; + napi_value argv; + napi_get_reference_value(env, sConstructor_, &ctor); + napi_create_string_utf8(env, asCallbackInfo->bundleName, NAPI_AUTO_LENGTH, &argv); + napi_status ret = napi_new_instance(env, ctor, DM_NAPI_ARGS_ONE, &argv, &result[1]); + if (ret != napi_ok) { + DMLog(DM_LOG_ERROR, "Create DeviceManagerNapi for bunderName %s failed", asCallbackInfo->bundleName); + asCallbackInfo->status = -1; + } + + if (asCallbackInfo->status == 0) { + DMLog(DM_LOG_INFO, "InitDeviceManager for bunderName %s success", asCallbackInfo->bundleName); + napi_get_undefined(env, &result[0]); + napi_value callback = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(env, asCallbackInfo->callback, &callback); + napi_call_function(env, nullptr, callback, DM_NAPI_ARGS_TWO, &result[0], &callResult); + napi_delete_reference(env, asCallbackInfo->callback); + } else { + DMLog(DM_LOG_INFO, "InitDeviceManager for bunderName %s failed", asCallbackInfo->bundleName); + napi_value message = nullptr; + napi_create_object(env, &result[0]); + napi_create_int32(env, asCallbackInfo->status, &message); + napi_set_named_property(env, result[0], "code", message); + napi_get_undefined(env, &result[1]); + } + napi_delete_async_work(env, asCallbackInfo->asyncWork); + delete asCallbackInfo; + }, + (void *)asCallbackInfo, + &asCallbackInfo->asyncWork); + napi_queue_async_work(env, asCallbackInfo->asyncWork); +} + +napi_value DeviceManagerNapi::CreateDeviceManager(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "CreateDeviceManager in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); + NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_TWO, "Wrong number of arguments, required 2"); + + napi_valuetype bundleNameValueType = napi_undefined; + napi_typeof(env, argv[0], &bundleNameValueType); + NAPI_ASSERT(env, bundleNameValueType == napi_string, "type mismatch for parameter 0"); + + napi_valuetype funcValueType = napi_undefined; + napi_typeof(env, argv[1], &funcValueType); + NAPI_ASSERT(env, funcValueType == napi_function, "type mismatch for parameter 1"); + + auto *asCallbackInfo = new AsyncCallbackInfo(); + asCallbackInfo->env = env; + napi_get_value_string_utf8(env, argv[0], asCallbackInfo->bundleName, DM_NAPI_BUF_LENGTH - 1, + &asCallbackInfo->bundleNameLen); + napi_create_reference(env, argv[1], 1, &asCallbackInfo->callback); + + HandleCreateDmCallBack(env, asCallbackInfo); + + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value DeviceManagerNapi::Constructor(napi_env env, napi_callback_info info) +{ + DMLog(DM_LOG_INFO, "DeviceManagerNapi Constructor in"); + GET_PARAMS(env, info, DM_NAPI_ARGS_ONE); + NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_ONE, "Wrong number of arguments, required 1"); + + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[0], &valueType); + NAPI_ASSERT(env, valueType == napi_string, "type mismatch for parameter 1"); + + char bundleName[DM_NAPI_BUF_LENGTH] = { 0 }; + size_t typeLen = 0; + napi_get_value_string_utf8(env, argv[0], bundleName, sizeof(bundleName), &typeLen); + + DMLog(DM_LOG_INFO, "create DeviceManagerNapi for packageName:%s", bundleName); + DeviceManagerNapi *obj = new DeviceManagerNapi(env, thisVar); + obj->bundleName_ = std::string(bundleName); + g_deviceManagerMap[obj->bundleName_] = obj; + napi_wrap(env, thisVar, reinterpret_cast(obj), + [](napi_env env, void *data, void *hint) { + (void)env; + (void)hint; + DeviceManagerNapi *deviceManager = (DeviceManagerNapi *)data; + delete deviceManager; + }, + nullptr, &(obj->wrapper_)); + return thisVar; +} + +napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports) +{ + napi_value dmClass; + napi_property_descriptor dmProperties[] = { + DECLARE_NAPI_FUNCTION("release", ReleaseDeviceManager), + DECLARE_NAPI_FUNCTION("getTrustedDeviceListSync", GetTrustedDeviceListSync), + DECLARE_NAPI_FUNCTION("startDeviceDiscovery", StartDeviceDiscoverSync), + DECLARE_NAPI_FUNCTION("stopDeviceDiscovery", StopDeviceDiscoverSync), + DECLARE_NAPI_FUNCTION("authenticateDevice", AuthenticateDeviceSync), + DECLARE_NAPI_FUNCTION("on", JsOn), + DECLARE_NAPI_FUNCTION("off", JsOff) + }; + + napi_property_descriptor static_prop[] = { + DECLARE_NAPI_STATIC_FUNCTION("createDeviceManager", CreateDeviceManager), + }; + + DMLog(DM_LOG_DEBUG, "DeviceManagerNapi::Init() is called!"); + NAPI_CALL(env, + napi_define_class(env, DEVICE_MANAGER_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH, Constructor, nullptr, + sizeof(dmProperties) / sizeof(dmProperties[0]), dmProperties, &dmClass)); + NAPI_CALL(env, napi_create_reference(env, dmClass, 1, &sConstructor_)); + NAPI_CALL(env, napi_set_named_property(env, exports, DEVICE_MANAGER_NAPI_CLASS_NAME.c_str(), dmClass)); + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(static_prop) / sizeof(static_prop[0]), static_prop)); + DMLog(DM_LOG_INFO, "All props and functions are configured.."); + return exports; +} + +/* + * Function registering all props and functions of ohos.distributedhardware + */ +static napi_value Export(napi_env env, napi_value exports) +{ + DMLog(DM_LOG_INFO, "Export() is called!"); + DeviceManagerNapi::Init(env, exports); + return exports; +} + +/* + * module define + */ +static napi_module g_dmModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Export, + .nm_modname = "distributedhardware.devicemanager", + .nm_priv = ((void *)0), + .reserved = {0} + }; + +/* + * module register + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + DMLog(DM_LOG_INFO, "RegisterModule() is called!"); + napi_module_register(&g_dmModule); +} diff --git a/ohos.build b/ohos.build index 66b59c67a..4c5654c01 100644 --- a/ohos.build +++ b/ohos.build @@ -9,8 +9,10 @@ "header": { "header_base": "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", "header_files": [ - "device_manager_proxy.h", - "idevice_manager.h" + "device_manager.h", + "device_manager_callback.h", + "dm_device_info.h", + "dm_subscribe_info.h" ] } } diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 35ff65151..ab1b6ab90 100644 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -11,83 +11,176 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos.gni") +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") +} + import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -config("dmservice_config") { - visibility = [ ":*" ] - include_dirs = [ - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "include", - "include/softbus", - "include/authdemo", - "include/util", - "${common_path}/log/include", - "${common_path}/utils/include", - "${innerkits_path}/native_cpp/include", - "//base/security/deviceauth/interfaces/innerkits", - "//third_party/json/include", - "//base/startup/syspara_lite/adapter/native/syspara/include", - ] +if (defined(ohos_lite)) { + executable("devicemanagerservice") { + include_dirs = [ + "include", + "include/softbus", + "include/requestauth", + "include/auth", + "include/ipc", + "include/message", + "include/ipc/lite", + "include/encrypt", + "${common_path}/include/log", + "${common_path}/include/utils", + "${common_path}/include/utils/threadpool", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${common_path}/include/ipc/lite", + "${common_path}/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/lite", + ] + + include_dirs += [ + "//base/security/deviceauth/interfaces/innerkits", + "//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include", + "//utils/native/lite/include", + "//utils/system/safwk/native/include", + "//third_party/json/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr" + ] - cflags = [ - "-Wall", - "-Werror", - "-Wdate-time", - "-Wfloat-equal", - "-Wshadow", - "-Wformat=2", - "-fvisibility=hidden", - "-fdata-sections", - "-ffunction-sections", - "-Os", - ] + sources = [ + "${common_path}/src/log/device_manager_log.cpp", + "${common_path}/src/utils/anonymous_string.cpp", + "${common_path}/src/ipc/lite/ipc_cmd_register.cpp", + "src/ipc/lite/ipc_cmd_parser.cpp", + "src/ipc/lite/ipc_server_listener.cpp", + "src/ipc/lite/ipc_server_listenermgr.cpp", + "src/ipc/lite/ipc_server_main.cpp", + "src/ipc/lite/ipc_server_stub.cpp", + "src/ipc/ipc_server_adapter.cpp", + "src/ipc/ipc_server_listener_adapter.cpp", + "src/softbus/softbus_adapter.cpp", + "src/softbus/softbus_session.cpp", + "src/auth/hichain_connector.cpp", + "src/message/msg_codec.cpp", + "src/message/msg_common.cpp", + "src/message/msg_request_auth.cpp", + "src/message/msg_response_auth.cpp", + "src/message/msg_sync_group.cpp", + "src/requestauth/auth_manager.cpp", + "src/requestauth/request_session.cpp", + "src/encrypt/encrypt_utils.cpp", + ] - cflags_cc = [ - "-fvisibility-inlines-hidden", - "-Os", - ] -} + defines = [ + "LITE_DEVICE", + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerservice\"", + "LOG_DOMAIN=0xD004100", + ] + + cflags_cc = build_flags -ohos_shared_library("devicemanagerservice") { - sources = [ - "src/device_manager_service.cpp", - "src/device_manager_stub.cpp", - "src/device_manager_listener_proxy.cpp", - "src/softbus/softbus_adapter.cpp", - "src/authdemo/device_client_channel.cpp", - "src/authdemo/device_server_channel.cpp", - "src/authdemo/hichain_adapter.cpp", - "src/util/anonymous_string.cpp", - ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "//base/security/deviceauth/services:deviceauth_sdk", + "//base/startup/syspara_lite/frameworks/parameter/src:sysparam", + "//utils/native/lite:utils", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", + "//third_party/bounds_checking_function:libsec_shared", + "//third_party/mbedtls:mbedtls_shared", + ] + } +} else { + ohos_shared_library("devicemanagerservice") { + include_dirs = [ + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "include", + "include/softbus", + "include/requestauth", + "include/auth", + "include/encrypt", + "include/ipc", + "include/message", + "include/ipc/standard", + "${common_path}/include", + "${common_path}/include/log", + "${common_path}/include/utils", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${common_path}/include/ipc/standard", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "//base/security/deviceauth/interfaces/innerkits", + "//base/startup/syspara_lite/adapter/native/syspara/include", + "//third_party/json/include", + ] + + sources = [ + "${common_path}/src/log/device_manager_log.cpp", + "${common_path}/src/utils/anonymous_string.cpp", + "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", + "src/ipc/standard/ipc_cmd_parser.cpp", + "src/ipc/standard/ipc_server_client_proxy.cpp", + "src/ipc/standard/ipc_server_listener.cpp", + "src/ipc/standard/ipc_server_stub.cpp", + "src/ipc/ipc_server_adapter.cpp", + "src/ipc/ipc_server_listener_adapter.cpp", + "src/softbus/softbus_adapter.cpp", + "src/softbus/softbus_session.cpp", + "src/auth/hichain_connector.cpp", + "src/message/msg_codec.cpp", + "src/message/msg_common.cpp", + "src/message/msg_request_auth.cpp", + "src/message/msg_response_auth.cpp", + "src/message/msg_sync_group.cpp", + "src/requestauth/auth_manager.cpp", + "src/requestauth/request_session.cpp", + "src/encrypt/encrypt_utils.cpp", + ] - configs = [ ":dmservice_config" ] + deps = [ + "//utils/native/base:utils", + "${innerkits_path}/native_cpp:devicemanagersdk", + "//base/security/deviceauth/services:deviceauth_sdk", + ] - deps = [ - "//utils/native/base:utils", - "${innerkits_path}/native_cpp:devicemanagersdk", - "//base/security/deviceauth/services:deviceauth_sdk", - ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerservice\"", + "LOG_DOMAIN=0xD004100", + ] - defines = [ - "DH_LOG_TAG=\"devicemanager\"", - "LOG_DOMAIN=0xD004100", - ] + cflags_cc = build_flags - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_L2:samgr_proxy", - "dsoftbus_standard:softbus_client", - "startup_l2:syspara", - ] + external_deps = [ + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "appexecfwk_standard:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + "dsoftbus_standard:softbus_client", + "startup_l2:syspara", + ] - subsystem_name = "distributedhardware" + subsystem_name = "distributedhardware" - part_name = "device_manager_base" + part_name = "device_manager_base" + } } diff --git a/services/devicemanagerservice/include/authdemo/hichain_adapter.h b/services/devicemanagerservice/include/auth/hichain_connector.h similarity index 38% rename from services/devicemanagerservice/include/authdemo/hichain_adapter.h rename to services/devicemanagerservice/include/auth/hichain_connector.h index 55ca7e5b2..78053b29e 100644 --- a/services/devicemanagerservice/include/authdemo/hichain_adapter.h +++ b/services/devicemanagerservice/include/auth/hichain_connector.h @@ -1,114 +1,65 @@ -/* - * 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 OHOS_HICHAIN_ADAPTER_H -#define OHOS_HICHAIN_ADAPTER_H - -#include -#include -#include -#include -#include - -#include "device_auth.h" -#include "event_handler.h" -#include "nlohmann/json.hpp" -#include "thread_pool.h" - -#include "device_client_channel.h" -#include "device_server_channel.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -enum { - SUCCESS = 0, - GROUP_CREATE_FAILED = 1, - MEMBER_ADD_FAILED = 2, - CREATE_CHANNEL_FAILED = 3, -}; - -struct DeviceReqInfo { - std::string deviceId; - std::string ipAddr; - short port; -}; - -class BindCallback { -public: - virtual void onBindSuccess(std::string deviceId, const char* returnData) = 0; - virtual void onBindFailed(std::string deviceId, int32_t errorCode) = 0; - virtual void onUnBindSuccess(std::string /* deviceId */, const char* /* returnData */) {} - virtual void onUnBindFailed(std::string /* deviceId */, int32_t /* errorCode*/) {} - virtual ~BindCallback() {} -}; - -class HichainAuthCallBack { -public: - static bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); - static void onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); - static void onFinish(int64_t requestId, int operationCode, const char *returnData); - static void onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn); - static char* onBindRequest(int64_t requestId, int operationCode, const char *reqParams); -}; - -class HichainAdapter { -DECLARE_SINGLE_INSTANCE(HichainAdapter); -public: - int Init(); - - int32_t Bind(const DeviceReqInfo& devReqInfo, std::shared_ptr callback, bool sync = false); - - void OnBindSuccess(int64_t requestId, const char* returnData); - void OnBindFailed(int64_t requestId, int32_t errorCode); - - void UnBind(const std::string& deviceId); - void OnUnBindFinished(); - - bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); - - void OnGroupCreated(int64_t requestId, const char *groupInfo); - - char* OnBindRequest(int64_t requestId, int operationCode, const char *reqParams); - -private: - std::string GetGroupIdByName(int32_t groupType, const std::string& groupName); - int32_t CreateGroup(int64_t requestId); - int32_t AddMemeber(int64_t requestId, std::string& groupId, const std::string& pinCode); - int64_t GenRequestId(); - -private: - std::atomic requestIdIndex_ {0}; - std::map bindingDeviceMap_; - std::map> clientBindReqMap_; - std::map> bindCallBackMap_; - const DeviceGroupManager* deviceGroupManager_ = nullptr; - std::unique_ptr deviceServerInst_; - mutable ThreadPool threadPool_; - - DeviceAuthCallback deviceAuthCallback_ = { - .onTransmit = HichainAuthCallBack::onTransmit, - .onSessionKeyReturned = HichainAuthCallBack::onSessionKeyReturned, - .onFinish = HichainAuthCallBack::onFinish, - .onError = HichainAuthCallBack::onError, - .onRequest = HichainAuthCallBack::onBindRequest, - }; - - // call back for socket channel - std::function onError_; -}; -} // namespace DistributedHardware -} // namespace OHOS +/* + * 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 OHOS_HICHAIN_CONNECTOR_H +#define OHOS_HICHAIN_CONNECTOR_H + +#include +#include +#include + +#include "device_auth.h" + +#include "single_instance.h" +#include "msg_response_auth.h" + +namespace OHOS { +namespace DistributedHardware { +enum { + HICHAIN_SUCCESS = 0, + GROUP_CREATE_FAILED = 1, + MEMBER_ADD_FAILED = 2, + CREATE_CHANNEL_FAILED = 3, +}; + +class HichainAuthenCallBack { +public: + static bool onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); + static void onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); + static void onFinish(int64_t requestId, int operationCode, const char *returnData); + static void onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn); +}; + +class HichainConnector { +DECLARE_SINGLE_INSTANCE(HichainConnector); +public: + int Init(); + bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); + int32_t AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth); + void notifyHostOnResult(int errorCode); +private: + std::string GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth); + +private: + const DeviceGroupManager* deviceGroupManager_ = nullptr; + DeviceAuthCallback deviceAuthCallback_ = { + .onTransmit = nullptr, + .onFinish = HichainAuthenCallBack::onFinish, + .onError = HichainAuthenCallBack::onError, + }; +}; +} // namespace DistributedHardware +} // namespace OHOS #endif // OHOS_HICHAIN_ADAPTER_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/device_manager_listener_proxy.h b/services/devicemanagerservice/include/device_manager_listener_proxy.h deleted file mode 100644 index d32f7837a..000000000 --- a/services/devicemanagerservice/include/device_manager_listener_proxy.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DEVICE_MANAGER_LISTENER_PROXY_H -#define OHOS_DEVICE_MANAGER_LISTENER_PROXY_H - -#include "idevice_manager_listener.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerListenerProxy : public IRemoteProxy { -public: - explicit DeviceManagerListenerProxy(const sptr& impl) - : IRemoteProxy(impl) {}; - ~DeviceManagerListenerProxy() {}; - int32_t OnDeviceOnline(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceOffline(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceChanged(std::string &packageName, const DmDeviceInfo &deviceInfo) override; - int32_t OnDeviceFound(std::string &packageName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override; - int32_t OnDiscoverFailed(std::string &packageName, uint16_t subscribeId, int32_t failedReason) override; - int32_t OnDiscoverySuccess(std::string &packageName, uint16_t subscribeId) override; - int32_t OnAuthResult(std::string &packageName, std::string &deviceId, int32_t status, int32_t reason) override; -private: - bool WriteInterfaceToken(MessageParcel &data); - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_LISTENER_PROXY_H diff --git a/services/devicemanagerservice/include/device_manager_stub.h b/services/devicemanagerservice/include/device_manager_stub.h deleted file mode 100644 index db5555468..000000000 --- a/services/devicemanagerservice/include/device_manager_stub.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DEVICE_MANAGER_STUB_H -#define OHOS_DEVICE_MANAGER_STUB_H - -#include -#include "iremote_stub.h" -#include "idevice_manager.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceManagerStub : public IRemoteStub { -public: - DeviceManagerStub(); - ~DeviceManagerStub(); - int32_t OnRemoteRequest(uint32_t code, - MessageParcel &data, MessageParcel &reply, MessageOption &option) override; -private: - int32_t RegisterDeviceManagerListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t UnRegisterDeviceManagerListenerInner(MessageParcel &data, MessageParcel &reply); - int32_t RegisterDeviceStateCallbackInner(MessageParcel &data, MessageParcel &reply); - int32_t UnRegisterDeviceStateCallbackInner(MessageParcel &data, MessageParcel &reply); - int32_t GetTrustedDeviceListInner(MessageParcel &data, MessageParcel &reply); - int32_t StartDeviceDiscoveryInner(MessageParcel &data, MessageParcel &reply); - int32_t StopDeviceDiscoveryInner(MessageParcel &data, MessageParcel &reply); - int32_t AuthenticateDeviceInner(MessageParcel &data, MessageParcel &reply); - template - int32_t GetParcelableInfo(MessageParcel &reply, T &parcelableInfo); - bool EnforceInterceToken(MessageParcel &data); - using CmdProcFunc = int32_t (DeviceManagerStub::*)(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_STUB_H diff --git a/services/devicemanagerservice/include/encrypt/encrypt_utils.h b/services/devicemanagerservice/include/encrypt/encrypt_utils.h new file mode 100644 index 000000000..af370d8b9 --- /dev/null +++ b/services/devicemanagerservice/include/encrypt/encrypt_utils.h @@ -0,0 +1,63 @@ +/* + * 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 OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H +#define OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class EncryptUtils { +public: + static int32_t MbedtlsBase64Encode(uint8_t *dst, size_t dlen, size_t *olen, + const uint8_t *src, size_t slen); + static int32_t MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *olen, + const uint8_t *src, size_t slen); + static int32_t GetRandomData(uint8_t* randStr, uint32_t len); + static int32_t MbedtlsEncrypt(const uint8_t* plainText, int32_t plainTextLen, uint8_t* cipherText, + int32_t cipherTextLen, int32_t* outLen); + static int32_t MbedtlsDecrypt(const uint8_t* cipherText, int32_t cipherTextLen, uint8_t* plainText, + int32_t plainTextLen, int32_t* outLen); + /** + * szOut最后一位为结束符,比如 szOutLen=4 可能返回 "abc" + * @param szOutLen 至少2 + * @param numberOnly 是否只生成数据 如果为true 则期望返回随机数字 如果为否,则期望返回随机字符 + */ + static bool MbedtlsGenRandomStr(char* szOut, int32_t szOutLen, bool numberOnly); +private: + typedef struct DmCryptInfo { + const uint8_t* sessionkey; + int32_t sessionkeyLen; + const uint8_t* iv; + int32_t ivLen; + } DmCryptInfo; + + static void MbedtlsGenRootKey(uint8_t* szOut, int32_t szOutLen, int32_t* nOutLen); + static int32_t MbedtlsAesGcmDecrypt(DmCryptInfo* info, const uint8_t* cipherText, + uint32_t cipherTextSize, uint8_t* plain, uint32_t plainLen); + static int32_t MbedtlsAesGcmEncrypt(DmCryptInfo * info, const uint8_t* plainText, + uint32_t plainTextSize, uint8_t* cipherText, uint32_t cipherTextLen); + static void XORBlock(uint8_t* output, const uint8_t* input1, + const uint8_t* input2, const size_t block_size); + static void ByteRightMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, + int32_t count); + static void ByteLeftMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, + int32_t count); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/ipc/ipc_server_adapter.h b/services/devicemanagerservice/include/ipc/ipc_server_adapter.h new file mode 100644 index 000000000..9575f51ba --- /dev/null +++ b/services/devicemanagerservice/include/ipc/ipc_server_adapter.h @@ -0,0 +1,47 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_ADAPTER_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_ADAPTER_H + +#include + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" + +#include "hichain_connector.h" + +#include "single_instance.h" +#include "softbus_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServerAdapter { +DECLARE_SINGLE_INSTANCE(IpcServerAdapter); +public: + int32_t ModuleInit(); + int32_t GetTrustedDeviceList(std::string &pkgName, std::string &extra, DmDeviceInfo **info, int32_t *infoNum); + int32_t StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &dmSubscribeInfo); + int32_t StopDiscovery(std::string &pkgName, uint16_t subscribeId); + int32_t AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, + const DmAppImageInfo &imageInfo, std::string &extra); + int32_t CheckAuthentication(std::string &authPara); + static int32_t GenRandInt(int32_t minPinToken, int32_t maxPinToken); +private: + int32_t CheckParamValid(nlohmann::json &extraJson, const DmAppImageInfo &imageInfo); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_ADAPTER_H diff --git a/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h b/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h new file mode 100644 index 000000000..f18907818 --- /dev/null +++ b/services/devicemanagerservice/include/ipc/ipc_server_listener_adapter.h @@ -0,0 +1,42 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_ADAPTER_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_ADAPTER_H + +#include "discovery_service.h" + +#include "ipc_server_listener.h" + +#include "single_instance.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServerListenerAdapter { +DECLARE_SINGLE_INSTANCE(IpcServerListenerAdapter); +public: + void OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo); + void OnDeviceFound(std::string &pkgName, uint16_t originId, DmDeviceInfo &deviceInfo); + void OnDiscoverFailed(std::string &pkgName, uint16_t originId, DiscoveryFailReason failReason); + void OnDiscoverySuccess(std::string &pkgName, uint16_t originId); + void OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, uint32_t status, uint32_t reason); + void OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, int32_t flag); +private: + IpcServerListener ipcServerListener_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_ADAPTER_H diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h new file mode 100644 index 000000000..9503191aa --- /dev/null +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_listener.h @@ -0,0 +1,41 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H + +#include + +#include "ipc_req.h" +#include "ipc_rsp.h" + +#include "ipc_server_listenermgr.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServerListener { +public: + IpcServerListener() = default; + virtual ~IpcServerListener() = default; +public: + int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); + int32_t SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); +private: + void CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity); + int32_t GetIdentityByPkgName(std::string &name, SvcIdentity *svc); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h new file mode 100644 index 000000000..efa32c665 --- /dev/null +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h @@ -0,0 +1,50 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H + +#include +#include +#include +#include + +#include "liteipc_adapter.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +typedef struct CommonSvcId { + unsigned int handle; + unsigned int token; + unsigned int cookie; + IpcContext *ipcCtx; + unsigned int cbId; +}CommonSvcId; + +class IpcServerListenermgr { +DECLARE_SINGLE_INSTANCE(IpcServerListenermgr); +public: + int32_t RegisterListener(std::string &pkgName, const CommonSvcId *svcId); + int32_t GetListenerByPkgName(std::string &pkgName, CommonSvcId *svcId); + int32_t UnregisterListener(std::string &pkgName); + const std::map& GetAllListeners(); +private: + std::map dmListenerMap_; + std::mutex lock_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h new file mode 100644 index 000000000..4d74dafc9 --- /dev/null +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h @@ -0,0 +1,27 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H + +#include + +#include "liteipc_adapter.h" + +int32_t IpcServerStubInit(void); +int32_t RegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply); +int32_t UnRegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply); + +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h new file mode 100644 index 000000000..dc71cc7a9 --- /dev/null +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h @@ -0,0 +1,35 @@ +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_CLIENT_PROXY_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_CLIENT_PROXY_H + +#include "ipc_remote_broker.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServerClientProxy : public IRemoteProxy { +public: + explicit IpcServerClientProxy(const sptr& impl) + : IRemoteProxy(impl) {}; + ~IpcServerClientProxy() {}; + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_CLIENT_PROXY_H diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h new file mode 100644 index 000000000..077059845 --- /dev/null +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H + +#include + +#include "ipc_req.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcServerListener { +public: + IpcServerListener() = default; + virtual ~IpcServerListener() = default; +public: + int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); + int32_t SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h similarity index 44% rename from services/devicemanagerservice/include/device_manager_service.h rename to services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h index af19ab97e..34464e292 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h @@ -1,98 +1,76 @@ -/* - * 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 OHOS_DEVICE_MANAGER_SERVICE_H -#define OHOS_DEVICE_MANAGER_SERVICE_H - -#include -#include -#include -#include -#include -#include "system_ability.h" -#include "thread_pool.h" -#include "iremote_stub.h" -#include "idevice_manager.h" -#include "idevice_manager_listener.h" -#include "device_manager_stub.h" -#include "single_instance.h" -#include "hichain_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -enum class ServiceRunningState { - STATE_NOT_START, - STATE_RUNNING -}; - -enum DmBindStatus : uint32_t { - STATE_BIND_SUCCESS, - STATE_BIND_FAILD -}; - -class AppDeathRecipient : public IRemoteObject::DeathRecipient { -public: - void OnRemoteDied(const wptr& remote) override; - AppDeathRecipient() = default; - ~AppDeathRecipient() = default; -}; - -class HiChainBindCallback : public BindCallback { -public: - void onBindSuccess(std::string deviceId, const char* returnData) override; - void onBindFailed(std::string deviceId, int32_t errorCode) override; -}; - -class DeviceManagerService : public SystemAbility, public DeviceManagerStub { -friend class HiChainBindCallback; -DECLARE_SYSTEM_ABILITY(DeviceManagerService); -DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerService); -public: - DeviceManagerService(); - ~DeviceManagerService() = default; - void OnStart() override; - void OnStop() override; - ServiceRunningState QueryServiceState() const; - - int32_t GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) override; - int32_t RegisterDeviceManagerListener(std::string &packageName, sptr listener) override; - int32_t UnRegisterDeviceManagerListener(std::string &packageName) override; - int32_t RegisterDeviceStateCallback(std::string &packageName, std::string &extra) override; - int32_t UnRegisterDeviceStateCallback(std::string &packageName) override; - int32_t StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo) override; - int32_t StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) override; - int32_t AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, std::string &extra) override; - const std::map>& GetDmListener(); - const sptr GetDmListener(std::string packageName) const; - -private: - bool Init(); - void RegisterDeviceStateListener(); - -private: - bool registerToService_; - ServiceRunningState state_; - mutable ThreadPool threadPool_; - std::mutex listenerLock_; - std::shared_ptr hichainBindCallback_; - std::map> appRecipient_; - std::map> dmListener_; - std::map devStateCallbackParas_; - std::map authCallbackParas_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SERVICE_H +/* + * 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 OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H +#define OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H + +#include +#include +#include +#include +#include + +#include "nlohmann/json.hpp" + +#include "system_ability.h" +#include "thread_pool.h" +#include "iremote_stub.h" +#include "ipc_remote_broker.h" + +#include "single_instance.h" +#include "hichain_connector.h" + +namespace OHOS { +namespace DistributedHardware { +enum class ServiceRunningState { + STATE_NOT_START, + STATE_RUNNING +}; + +class AppDeathRecipient : public IRemoteObject::DeathRecipient { +public: + void OnRemoteDied(const wptr& remote) override; + AppDeathRecipient() = default; + ~AppDeathRecipient() = default; +}; + +class IpcServerStub : public SystemAbility, public IRemoteStub { +DECLARE_SYSTEM_ABILITY(IpcServerStub); +DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub); +public: + IpcServerStub(); + ~IpcServerStub() = default; + void OnStart() override; + void OnStop() override; + int32_t OnRemoteRequest(uint32_t code, + MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; + int32_t RegisterDeviceManagerListener(std::string &pkgName, sptr listener); + int32_t UnRegisterDeviceManagerListener(std::string &pkgName); + ServiceRunningState QueryServiceState() const; + const std::map>& GetDmListener(); + const sptr GetDmListener(std::string pkgName) const; +private: + bool Init(); +private: + bool registerToService_; + ServiceRunningState state_; + std::mutex listenerLock_; + std::map> appRecipient_; + std::map> dmListener_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H diff --git a/services/devicemanagerservice/include/message/msg_codec.h b/services/devicemanagerservice/include/message/msg_codec.h new file mode 100644 index 000000000..21348f1eb --- /dev/null +++ b/services/devicemanagerservice/include/message/msg_codec.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_MSG_CODEC_H +#define OHOS_MSG_CODEC_H + +#include +#include + +#include "nlohmann/json.hpp" + +#include "msg_request_auth.h" +#include "msg_sync_group.h" +#include "msg_response_auth.h" + +namespace OHOS { +namespace DistributedHardware { +class MsgCodec { +public: + static int32_t decodeMsgType(std::string &jsonStr); + static std::string encodeSyncGroup(std::vector &groupIdList, std::string &deviceId); + static std::vector encodeReqAppAuth(std::string &token, std::string hostPkg, std::string targetPkg, + const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras); + static std::shared_ptr decodeResponseAuth(std::string &jsonStr); +}; +} +} +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/message/msg_common.h b/services/devicemanagerservice/include/message/msg_common.h new file mode 100644 index 000000000..debe6113d --- /dev/null +++ b/services/devicemanagerservice/include/message/msg_common.h @@ -0,0 +1,49 @@ +/* + * 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 OHOS_MSG_COMMON_H +#define OHOS_MSG_COMMON_H + +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace DistributedHardware { +enum DmMsgType : int32_t { + MSG_TYPE_UNKNOWN = 0, + MSG_TYPE_REQ_AUTH = 100, + MSG_TYPE_INVITE_AUTH_INFO = 102, + MSG_TYPE_RESP_AUTH = 200, + MSG_TYPE_JOIN_AUTH_INFO = 201, + MSG_TYPE_CHANNEL_CLOSED = 300, + MSG_TYPE_SYNC_GROUP = 400, + MSG_TYPE_AUTH_BY_PIN = 500, +}; + +class MsgHead { +public: + MsgHead(): mMsgType(0), mItfVer("") {}; + MsgHead(int32_t msg): mMsgType(msg), mItfVer("") {}; + ~MsgHead() = default; + void encode(nlohmann::json &json); + static std::shared_ptr decode(nlohmann::json &json); + int32_t getMsgType(); +private: + int32_t mMsgType; + std::string mItfVer; +}; +} +} + +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/message/msg_request_auth.h b/services/devicemanagerservice/include/message/msg_request_auth.h new file mode 100644 index 000000000..34a25c9db --- /dev/null +++ b/services/devicemanagerservice/include/message/msg_request_auth.h @@ -0,0 +1,73 @@ +/* + * 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 OHOS_MSG_REQUEST_AUTH_H +#define OHOS_MSG_REQUEST_AUTH_H + +#include +#include + +#include "nlohmann/json.hpp" + +#include "msg_common.h" +#include "dm_device_info.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { +class MsgRequestAuth { +public: + MsgRequestAuth() {}; + MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, + const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras) : MsgRequestAuth( + token, hostPkgName, targetPkgName, GROUP_VISIBILITY_IS_PRIVATE, devReqInfo, imageInfo, extras) {}; + MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, + const int32_t groupVisibility, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, + std::string &extras); + std::vector encode(); + static std::shared_ptr decode(nlohmann::json &json, std::shared_ptr msgIn); + static void setThumbnailSize(nlohmann::json &json, std::shared_ptr msg); +private: + std::string toHexString(int32_t value); + std::string encodeDevInfo(); + static std::string stringSub(std::string &thumbStr, int32_t start, int32_t length); + int32_t getEncodedAppInfo(const uint8_t* dataSrc, size_t srcLen, std::string &outString); + static bool isMsgValid(std::shared_ptr msgIn, nlohmann::json &json, std::string &deviceId, + int32_t index); + static bool isAppInfoValid(nlohmann::json &json); + static void setAuthType(nlohmann::json &json, std::shared_ptr msg); +private: + std::shared_ptr mHead; + std::string mHostPkg; + std::string mTargetPkg; + std::string mDeviceName; + std::string mToken; + std::string mDeviceId; + std::string mDeviceType; + std::string mAppName; + std::string mAppDescription; + std::string mAppIcon; + std::string mAppThumbnail; + int32_t mAuthType; + int32_t mGroupVisibility; + int32_t mMsgSlice; + int32_t mMsgCnt = 0; + int32_t mThumbnailSize; +}; +} +} + + +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/message/msg_response_auth.h b/services/devicemanagerservice/include/message/msg_response_auth.h new file mode 100644 index 000000000..08fa0bb67 --- /dev/null +++ b/services/devicemanagerservice/include/message/msg_response_auth.h @@ -0,0 +1,56 @@ +/* + * 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 OHOS_MSG_RESPONSE_AUTH_H +#define OHOS_MSG_RESPONSE_AUTH_H + +#include +#include + +#include "nlohmann/json.hpp" + +#include "msg_common.h" + +namespace OHOS { +namespace DistributedHardware { +class MsgResponseAuth { +public: + MsgResponseAuth() = default; + ~MsgResponseAuth() = default; + void encode(nlohmann::json &jsonObj); + int32_t decode(nlohmann::json &jsonObj); + int32_t getReply(); + std::string getNetId(); + std::string getGroupId(); + std::string getDeviceId(); + std::string getGroupName(); + std::string getPinCode(); + void savePinCode(std::string pinCode); + long long getRequestId(); + std::vector getSyncGroupList(); +private: + std::shared_ptr mHead; + int32_t mReply; + std::string mNetId; + std::string mGroupId; + std::string mGroupName; + std::string mDeviceId; + std::string mPinCode; + long long mRequestId; + std::vector mSyncGroupList; +}; +} +} +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/message/msg_sync_group.h b/services/devicemanagerservice/include/message/msg_sync_group.h new file mode 100644 index 000000000..8c32e1d8d --- /dev/null +++ b/services/devicemanagerservice/include/message/msg_sync_group.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_MSG_SYNC_GROUP_H +#define OHOS_MSG_SYNC_GROUP_H + +#include +#include + +#include "nlohmann/json.hpp" + +#include "msg_common.h" + +namespace OHOS { +namespace DistributedHardware { +class MsgSyncGroup { +public: + MsgSyncGroup(std::vector &groupList, std::string &deviceId); + ~MsgSyncGroup() = default; + void encode(nlohmann::json &json); +private: + std::shared_ptr mHead; + std::string mDeviceId; + std::vector mGroupIdList; +}; +} +} +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/authdemo/device_client_channel.h b/services/devicemanagerservice/include/requestauth/auth_manager.h similarity index 34% rename from services/devicemanagerservice/include/authdemo/device_client_channel.h rename to services/devicemanagerservice/include/requestauth/auth_manager.h index dac934e17..12962b0ba 100644 --- a/services/devicemanagerservice/include/authdemo/device_client_channel.h +++ b/services/devicemanagerservice/include/requestauth/auth_manager.h @@ -1,53 +1,59 @@ -/* - * 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 OHOS_DEVICE_CLIENT_CHANNEL_H -#define OHOS_DEVICE_CLIENT_CHANNEL_H - -#include -#include - -#include "device_auth.h" - -namespace OHOS { -namespace DistributedHardware { -class DeviceClientChannel { -public: - DeviceClientChannel(int64_t requestId, const DeviceGroupManager& deviceGroupManager, - std::function onError) - : requestId_(requestId), socketFd_(-1), deviceGroupManager_(deviceGroupManager), onError_(onError) {} - ~DeviceClientChannel(); - - DeviceClientChannel()=delete; - DeviceClientChannel(const DeviceClientChannel&)=delete; - DeviceClientChannel &operator=(const DeviceClientChannel&)=delete; - -public: - int32_t Connect(const std::string& ip, short port); - bool Send(const char* data, const int32_t dataLen); - void Receive(void); - void OnDataReceived(const char* data, const int32_t dataLen); - void ResetConnection(); - -private: - int64_t requestId_; - int32_t socketFd_; - const DeviceGroupManager& deviceGroupManager_; - // call back for socket channel - std::function onError_; -}; -} -} +/* + * 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 OHOS_AUTH_MANAGER_H +#define OHOS_AUTH_MANAGER_H + +#include +#include + +#include "nlohmann/json.hpp" + +#include "single_instance.h" +#include "dm_device_info.h" +#include "request_session.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { + const std::string TAG = "DM_RequestAuth"; + const int32_t STATUS_INIT = 0; + const int32_t STATUS_DISCOVERYING = 1; +} + +class AuthManager { + DECLARE_SINGLE_INSTANCE(AuthManager); +public: + void authDeviceGroup(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, + std::string &extras); + void onReceiveMsg(long long channelId, std::string &message); + int32_t checkAuthentication(std::string &authPara); +private: + void syncDmPrivateGroup(std::string &message); + void authAppGroup(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, + std::string &extrasJson); + void onReceiveMessage(long long channelId, std::string &message, int32_t msgType); + bool canStartNewSession(); + void moveSessionToWaitScanMap(); + int32_t checkAuthenticationByPin(nlohmann::json &authJson); + void onPinInputResult(int32_t pinCode, int32_t pinToken); +private: + std::shared_ptr mPendingReqSessionPtr {nullptr}; + std::map> mWaitScanReqSessionMap = {}; + int32_t mBleStatus {STATUS_INIT}; +}; +} +} #endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager.h b/services/devicemanagerservice/include/requestauth/request_session.h similarity index 30% rename from interfaces/inner_kits/native_cpp/include/idevice_manager.h rename to services/devicemanagerservice/include/requestauth/request_session.h index b71235000..ce1290def 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager.h +++ b/services/devicemanagerservice/include/requestauth/request_session.h @@ -1,55 +1,72 @@ -/* - * 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 OHOS_DEVICE_MANAGER_INTERFACE_H -#define OHOS_DEVICE_MANAGER_INTERFACE_H - -#include "iremote_broker.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" - -namespace OHOS { -namespace DistributedHardware { -enum { - REGISTER_DEVICE_MANAGER_LISTENER = 0, - UNREGISTER_DEVICE_MANAGER_LISTENER = 1, - REGISTER_DEVICE_STATE_CALLBACK = 2, - UNREGISTER_DEVICE_STATE_CALLBACK = 3, - GET_TRUST_DEVICE_LIST = 4, - START_DEVICE_DISCOVER = 5, - STOP_DEVICE_DISCOVER = 6, - AUTHENTICATE_DEVICE = 7, -}; - -class IDeviceManager : public OHOS::IRemoteBroker { -public: - virtual ~IDeviceManager() {} - virtual int32_t GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) = 0; - virtual int32_t RegisterDeviceManagerListener(std::string &packageName, sptr listener) = 0; - virtual int32_t UnRegisterDeviceManagerListener(std::string &packageName) = 0; - virtual int32_t RegisterDeviceStateCallback(std::string &packageName, std::string &extra) = 0; - virtual int32_t UnRegisterDeviceStateCallback(std::string &packageName) = 0; - virtual int32_t StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo) = 0; - virtual int32_t StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) = 0; - virtual int32_t AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, - std::string &extra) = 0; - -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager"); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_INTERFACE_H +/* + * 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 OHOS_REQUEST_SESSION_H +#define OHOS_REQUEST_SESSION_H + +#include +#include + +#include "single_instance.h" +#include "dm_device_info.h" +#include "msg_response_auth.h" + +namespace OHOS { +namespace DistributedHardware { +class RequestSession { +public: + RequestSession(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, + std::string &extrasJson); + ~RequestSession() = default; + std::vector getRequestCommand(std::string &extrasJson); + void setPinToken(int32_t pinToken); + void setChannelId(long long channelId); + void release(); + bool isFinished(); + bool isMyChannelId(long long channelId); + void onReceiveMsg(std::string &msg); + bool isWaitingForScan(); + std::string getToken(); + bool isMyPinToken(int32_t pinToken); + void onReceivePinCode(int32_t pinCode); + void notifyHostAppAuthResult(int32_t errorCode); +private: + std::string getHostPkgName(); + std::string getTargetPkgName(); + int32_t getSessionType(); + void closeChannel(); + int32_t parseRespMsg(std::string &msg); + void syncDmPrivateGroup(std::vector &remoteGroupList); +private: + int32_t mSessionType; + int32_t mStatus; + std::string mHostPkgName; + std::string mTargetPkgName; + std::string mToken; + int32_t mPinToken; + DmDeviceInfo mDevInfo; + DmAppImageInfo mImageInfo; + long long mChannelId; + bool mIsChannelOpened {false}; + std::string mRemoteDeviceId; + std::string mRemoteNetId; + std::string mRemoteGroupId; + std::string mRemoteGroupName; + long long mRequestId; + std::shared_ptr responseMsgPtr_; +}; +} +} +#endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/softbus/softbus_adapter.h b/services/devicemanagerservice/include/softbus/softbus_adapter.h index 6d0ba83dc..2aeb2e6a7 100644 --- a/services/devicemanagerservice/include/softbus/softbus_adapter.h +++ b/services/devicemanagerservice/include/softbus/softbus_adapter.h @@ -1,85 +1,77 @@ -/* - * 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 OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H -#define OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H - -#include -#include -#include -#include "softbus_bus_center.h" -#include "discovery_service.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedHardware { -struct SubscribeInfoAdapter { - SubscribeInfo info; - uint16_t subscribeIdOrigin; - uint16_t subscribeIdPrefix; -}; - -class SoftbusAdapter { -DECLARE_SINGLE_INSTANCE(SoftbusAdapter); -public: - static int32_t GetSoftbusTrustDevices(const std::string &packageName, std::string &extra, - std::vector &deviceList); - void RegSoftBusDeviceStateListener(); - int32_t StartSoftbusDiscovery(std::string &packageName, DmSubscribeInfo &info); - int32_t StopSoftbusDiscovery(std::string &packageName, uint16_t subscribeId); - static void OnSoftbusDeviceOffline(NodeBasicInfo *info); - static void OnSoftBusDeviceOnline(NodeBasicInfo *info); - static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info); - static void OnSoftbusDeviceFound(const DeviceInfo *device); - static void OnSoftbusDiscoverFailed(int subscribeId, DiscoveryFailReason failReason); - static void OnSoftbusDiscoverySuccess(int subscribeId); - static void OnSoftbusJoinLNNResult(ConnectionAddr *addr, const char *networkId, int32_t retCode); - static void OnSoftbusLeaveLNNResult(const char *networkId, int32_t retCode); - const std::map>>& GetsubscribeInfos(); - int32_t SoftbusJoinLnn(std::string devId); - int32_t SoftbusLeaveLnn(std::string networkId); - int32_t GetConnectionIpAddr(std::string deviceId, std::string &ipAddr); - static bool IsDeviceOnLine(std::string &deviceId); - -private: - static void OnSoftBusDeviceStateChange(DmDeviceState state, NodeBasicInfo *info); - std::string GetPackageNameBySubscribeId(uint16_t subscribeId); - bool GetsubscribeIdAdapter(std::string packageName, int16_t originId, int32_t &adapterId); - bool GetPackageNameBySubscribeId(int32_t adapterId, std::string &packageName); - void SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo); - void RemoveDiscoverDeviceInfo(const std::string deviceId); - -private: - std::map>> subscribeInfos_; - std::map> discoverDeviceInfoMap_; - std::vector> discoverDeviceInfoVector_; - std::atomic subscribeIdPrefix {0}; - INodeStateCb softbusNodeStateCb = { - .events = EVENT_NODE_STATE_ONLINE | EVENT_NODE_STATE_OFFLINE | EVENT_NODE_STATE_INFO_CHANGED, - .onNodeOnline = OnSoftBusDeviceOnline, - .onNodeOffline = OnSoftbusDeviceOffline, - .onNodeBasicInfoChanged = OnSoftbusDeviceInfoChanged - }; - IDiscoveryCallback softbusDiscoverCallback = { - .OnDeviceFound = OnSoftbusDeviceFound, - .OnDiscoverFailed = OnSoftbusDiscoverFailed, - .OnDiscoverySuccess = OnSoftbusDiscoverySuccess - }; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H +/* + * 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 OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H +#define OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H + +#include +#include +#include +#include +#include "softbus_bus_center.h" +#include "discovery_service.h" +#include "dm_device_info.h" +#include "dm_subscribe_info.h" + +namespace OHOS { +namespace DistributedHardware { +class PublishServiceCallBack { +public: + static void OnPublishSuccess(int32_t publishId); + static void OnPublishFail(int32_t publishId, PublishFailReason reason); +}; + +class SoftbusAdapter { +public: + static int32_t Init(); + static int32_t GetTrustDevices(const std::string &pkgName, NodeBasicInfo **info, int32_t *infoNum); + static int32_t StartDiscovery(std::string &pkgName, SubscribeInfo *info); + static int32_t StopDiscovery(std::string &pkgName, uint16_t subscribeId); + static bool IsDeviceOnLine(std::string &deviceId); + static int32_t GetConnectionIpAddr(std::string deviceId, std::string &ipAddr); + static ConnectionAddr *GetConnectAddr(std::string deviceId); +public: + static void OnSoftBusDeviceOnline(NodeBasicInfo *info); + static void OnSoftbusDeviceOffline(NodeBasicInfo *info); + static void OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info); + static void OnSoftbusDeviceFound(const DeviceInfo *device); + static void OnSoftbusDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason); + static void OnSoftbusDiscoverySuccess(int32_t subscribeId); +private: + static bool GetsubscribeIdAdapter(std::string &pkgName, int16_t originId, int32_t &adapterId); + static bool GetpkgNameBySubscribeId(int32_t adapterId, std::string &pkgName); + static void SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo); + static void RemoveDiscoverDeviceInfo(const std::string deviceId); + static void NodeBasicInfoCopyToDmDevice(DmDeviceInfo& dmDeviceInfo, NodeBasicInfo& nodeBasicInfo); + static void DeviceInfoCopyToDmDevice(DmDeviceInfo& dmDeviceInfo, const DeviceInfo& deviceInfo); + static ConnectionAddr *GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type); +private: + struct SubscribeInfoAdapter { + SubscribeInfo info; + uint16_t subscribeIdOrigin; + uint16_t subscribeIdPrefix; + }; + static std::map>> subscribeInfos_; + static std::map> discoverDeviceInfoMap_; + static std::vector> discoverDeviceInfoVector_; + static uint16_t subscribeIdPrefix; + static std::mutex lock_; + static INodeStateCb softbusNodeStateCb; + static IDiscoveryCallback softbusDiscoverCallback; + static IPublishCallback servicePublishCallback; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_SOFTBUS_ADAPTER_H diff --git a/services/devicemanagerservice/include/softbus/softbus_session.h b/services/devicemanagerservice/include/softbus/softbus_session.h new file mode 100644 index 000000000..79d1165f3 --- /dev/null +++ b/services/devicemanagerservice/include/softbus/softbus_session.h @@ -0,0 +1,52 @@ +/* + * 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 OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H +#define OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H + +#include +#include +#include + +#include "session.h" +#include "single_instance.h" +#include "softbus_common.h" + +namespace OHOS { +namespace DistributedHardware { +class SoftbusSession { +DECLARE_SINGLE_INSTANCE_BASE(SoftbusSession); +public: + int32_t Start(); + int32_t OnSessionOpened(int32_t sessionId, int32_t result); + void OnSessionClosed(int32_t sessionId); + void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); + void CloseSession(int32_t sessionId); + int32_t SendMessages(const char *deviceId, std::vector &messages); + int32_t SendMsg(int32_t sessionId, std::string &message); +private: + SoftbusSession() {}; + ~SoftbusSession(); +private: + int32_t SendData(int32_t sessionId, const void *data, int32_t len); +private: + const char * PKG_NAME = "com.huawei.devicemanager"; + const char * SESSION_NAME = "com.huawei.devicemanager.resident"; + std::set sessionIdSet_; + std::vector messages_ {}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MANAGER_SOFTBUS_SESSION_H diff --git a/services/devicemanagerservice/src/auth/hichain_connector.cpp b/services/devicemanagerservice/src/auth/hichain_connector.cpp new file mode 100644 index 000000000..f23edbb64 --- /dev/null +++ b/services/devicemanagerservice/src/auth/hichain_connector.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hichain_connector.h" + +#include +#include +#include +#include + +#include "nlohmann/json.hpp" + +#include "parameter.h" + +#include "anonymous_string.h" +#include "device_manager_log.h" +#include "softbus_adapter.h" +#include "constants.h" +#include "ipc_server_listener_adapter.h" +#include "softbus_session.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { +const std::string DEVICE_ID = "DEVICE_ID"; +const std::string WIFI_IP = "WIFI_IP"; +const std::string WIFI_PORT = "WIFI_PORT"; +const std::string BR_MAC = "BR_MAC"; +const std::string BLE_MAC = "BLE_MAC"; +const std::string ETH_IP = "ETH_IP"; +const std::string ETH_PORT = "ETH_PORT"; +const std::string DEVICE_MANAGER_APP = "com.huawei.devicemanager"; +const std::string DEVICE_MANAGER_GROUPNAME = "DMPeerToPeerGroup"; +} + +IMPLEMENT_SINGLE_INSTANCE(HichainConnector); + +int HichainConnector::Init() +{ + DMLog(DM_LOG_INFO, "HichainConnector::init, init device auth service."); + InitDeviceAuthService(); + + deviceGroupManager_ = GetGmInstance(); + if (deviceGroupManager_ == nullptr) { + DMLog(DM_LOG_INFO, "HichainConnector::init, failed to init group manager!"); + return -1; + } + deviceGroupManager_->regCallback(DEVICE_MANAGER_APP.c_str(), &deviceAuthCallback_); + DMLog(DM_LOG_INFO, "HichainConnector::init, init hichain adapter success."); + return 0; +} + +int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth) +{ + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber"); + if (deviceGroupManager_ == nullptr) { + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber group manager is null."); + return -1; + } + + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + std::string connectInfo = GetConnectPara(deviceId, msgResponseAuth); + DMLog(DM_LOG_INFO, "connectInfo json string is: %s", connectInfo.c_str()); + + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_ID] = msgResponseAuth->getGroupId(); + jsonObj[FIELD_GROUP_TYPE] = PEER_TO_PEER_GROUP; + jsonObj[FIELD_PIN_CODE] = msgResponseAuth->getPinCode(); + jsonObj[FIELD_IS_ADMIN] = false; + jsonObj[FIELD_DEVICE_ID] = localDeviceId; + jsonObj[FIELD_GROUP_NAME] = msgResponseAuth->getGroupName(); + jsonObj[FIELD_CONNECT_PARAMS] = connectInfo.c_str(); + std::string tmpStr = jsonObj.dump(); + + DMLog(DM_LOG_INFO, "addParam json string is: %s", tmpStr.c_str()); + DMLog(DM_LOG_INFO, "requestId is: %lld", msgResponseAuth->getRequestId()); + DMLog(DM_LOG_INFO, "app name is: %s", DEVICE_MANAGER_APP.c_str()); + + return deviceGroupManager_->addMemberToGroup(msgResponseAuth->getRequestId(), DEVICE_MANAGER_APP.c_str(), + tmpStr.c_str()); +} + +std::string HichainConnector::GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth) +{ + ConnectionAddr * addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); + if (addrInfo == nullptr) { + DMLog(DM_LOG_ERROR, "HichainConnector::GetConnectPara addrInfo error"); + return ""; + } + + DMLog(DM_LOG_ERROR, "HichainConnector::GetConnectPara get addrInfo"); + nlohmann::json jsonPara; + jsonPara[DEVICE_ID] = msgResponseAuth->getDeviceId(); + if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_ETH) { + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is ETH"); + jsonPara[ETH_IP] = addrInfo->info.ip.ip; + jsonPara[ETH_PORT] = addrInfo->info.ip.port; + } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_WLAN) { + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is WIFI"); + jsonPara[WIFI_IP] = addrInfo->info.ip.ip; + jsonPara[WIFI_PORT] = addrInfo->info.ip.port; + } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_BR) { + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is br"); + jsonPara[BR_MAC] = addrInfo->info.br.brMac; + } else if (addrInfo->type == ConnectionAddrType::CONNECTION_ADDR_BLE) { + DMLog(DM_LOG_INFO, "HichainConnector::AddMemeber addr type is ble"); + jsonPara[BLE_MAC] = addrInfo->info.ble.bleMac; + } else { + DMLog(DM_LOG_ERROR, "HichainConnector::AddMemeber addrInfo not right"); + return ""; + } + return jsonPara.dump(); +} + +void HichainAuthenCallBack::onFinish(int64_t requestId, int operationCode, const char *returnData) +{ + DMLog(DM_LOG_INFO, "HichainAuthenCallBack::onFinish reqId:%lld, operation:%d.", requestId, operationCode); + if (operationCode == GroupOperationCode::MEMBER_JOIN) { + HichainConnector::GetInstance().notifyHostOnResult(SUCCESS); + } +} + +void HichainAuthenCallBack::onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn) +{ + (void)errorReturn; + DMLog(DM_LOG_INFO, "HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", + requestId, operationCode, errorCode); + HichainConnector::GetInstance().notifyHostOnResult(FAIL); +} + +void HichainConnector::notifyHostOnResult(int errorCode) +{ + DMLog(DM_LOG_INFO, "notify host result, errorcode: %d", errorCode); + std::string hostPkgName = "com.huawei.devicemanager"; + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + std::string deviceId = localDeviceId; + IpcServerListenerAdapter::GetInstance().OnCheckAuthResult(hostPkgName, deviceId, errorCode, 0); +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/authdemo/device_client_channel.cpp b/services/devicemanagerservice/src/authdemo/device_client_channel.cpp deleted file mode 100644 index f1ccaea7b..000000000 --- a/services/devicemanagerservice/src/authdemo/device_client_channel.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_client_channel.h" - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { - constexpr int32_t CLIENT_DATA_BUFFER_LENGTH = 2048; - const int32_t RECV_DATA_TIMEOUT = 5; - const int32_t REQUEST_ID_LENGTH = 10; -} - -DeviceClientChannel::~DeviceClientChannel() -{ - if (socketFd_ != -1) { - close(socketFd_); - socketFd_ = -1; - } -} - -int32_t DeviceClientChannel::Connect(const std::string& ip, short port) -{ - HILOGI("DeviceClientChannel::Connect begin to connect to server."); - int32_t socketFd = socket(AF_INET, SOCK_STREAM, 0); - if (socketFd == -1) { - HILOGE("DeviceClientChannel::Connect create socket failed, errMsg: %{public}s.", strerror(errno)); - return -1; - } - - struct sockaddr_in addr; - if (memset_s(&addr, sizeof(addr), 0, sizeof(addr)) != EOK) { - HILOGE("DeviceClientChannel::Connect error init addr."); - close(socketFd); - return -1; - } - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr(ip.c_str()); - addr.sin_port = htons(port); - - int32_t ret = connect(socketFd, (struct sockaddr*) &addr, sizeof(addr)); - if (ret == -1) { - HILOGE("DeviceClientChannel::Connect connet server failed, errMsg: %{public}s.", strerror(errno)); - close(socketFd); - return -1; - } - - socketFd_ = socketFd; - HILOGI("DeviceClientChannel::Connect connect to server, fd: %{public}d.", socketFd_); - - // wait five seconds, if recv none, release the connection - struct timeval timeout = {RECV_DATA_TIMEOUT, 0}; - setsockopt(socketFd_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval)); - return 0; -} - -bool DeviceClientChannel::Send(const char* data, const int32_t dataLen) -{ - // The client needs to add requestId to the header of the data - std::stringstream reqIdStr; - reqIdStr << requestId_; - - int32_t sendDataLen = dataLen + REQUEST_ID_LENGTH; - std::unique_ptr sendData = std::make_unique(sendDataLen); - if (memset_s(sendData.get(), sendDataLen, 0, sendDataLen) != EOK) { - HILOGE("DeviceClientChannel::Send error init send data."); - return false; - } - - if (memcpy_s(sendData.get(), sendDataLen, reqIdStr.str().c_str(), REQUEST_ID_LENGTH) != EOK) { - HILOGE("DeviceClientChannel::Send error init requestId."); - return false; - } - - if (memcpy_s(sendData.get() + REQUEST_ID_LENGTH, sendDataLen - REQUEST_ID_LENGTH, data, dataLen) != EOK) { - HILOGE("DeviceClientChannel::Send error init data."); - return false; - } - - int32_t ret = send(socketFd_, sendData.get(), sendDataLen, 0); - if (ret == -1) { - HILOGE("DeviceClientChannel::send data failed, errMsg: %{public}s.", strerror(errno)); - return false; - } - - HILOGI("DeviceClientChannel::send data, size:%{public}d.", ret); - return true; -} - -void DeviceClientChannel::Receive() -{ - HILOGI("DeviceClientChannel::Receive data, socketFd:%{public}d.", socketFd_); - char dataBuf[CLIENT_DATA_BUFFER_LENGTH] = {0}; - - while (socketFd_ != -1) { - (void)memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)); - int32_t rc = recv(socketFd_, dataBuf, sizeof(dataBuf), 0); - if (rc == 0) { - HILOGE("DeviceClientChannel::Receive error, client shutdown, socketFd_:%{public}d, errMsg: %{public}s.", - socketFd_, strerror(errno)); - close(socketFd_); - socketFd_ = -1; - break; - } else if (rc == -1 || rc == EAGAIN) { - HILOGE("DeviceClientChannel::Receive data failed, socketFd_:%{public}d, errMsg: %{public}s.", - socketFd_, strerror(errno)); - close(socketFd_); - socketFd_ = -1; - break; - } else { - HILOGI("DeviceClientChannel::Receive data, socketFd_:%{public}d, size:%{public}d.", socketFd_, rc); - OnDataReceived(dataBuf, rc); - } - } - HILOGI("DeviceClientChannel::Receive data end, socketFd:%{public}d.", socketFd_); -} - -void DeviceClientChannel::OnDataReceived(const char* data, const int32_t dataLen) -{ - int ret = deviceGroupManager_.processData(requestId_, (uint8_t *) data, dataLen); - HILOGI("DeviceClientChannel::OnDataReceived process data, ret:%{public}d, dataLen:%{public}d.", ret, dataLen); - if (ret != 0) { - close(socketFd_); - socketFd_ = -1; - onError_(requestId_, 0, ret, nullptr); - } -} - -void DeviceClientChannel::ResetConnection() -{ - HILOGI("DeviceClientChannel::ResetConnection bind finished, release connection."); - close(socketFd_); - socketFd_ = -1; -} -} -} \ No newline at end of file diff --git a/services/devicemanagerservice/src/authdemo/device_server_channel.cpp b/services/devicemanagerservice/src/authdemo/device_server_channel.cpp deleted file mode 100644 index af142ff3c..000000000 --- a/services/devicemanagerservice/src/authdemo/device_server_channel.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_server_channel.h" - -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#include - -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { - const int32_t DATA_BUFFER_LENGTH = 2048; - const int32_t REQUEST_ID_LENGTH = 10; - const int32_t LISTENING_QUEUE_LEN = 10; - const int64_t MIN_REQUEST_ID = 1000000000; - const int32_t RECV_DATA_TIMEOUT = 5; -} - -DeviceServerChannel::~DeviceServerChannel() -{ - if (socketFd_ != -1) { - close(socketFd_); - socketFd_ = -1; - } - - if (clientFd_ != -1) { - close(clientFd_); - clientFd_ = -1; - } -} - -int32_t DeviceServerChannel::Start(const int32_t port) -{ - HILOGI("DeviceServerChannel::Start begin to start server."); - if (port <= 0) { - HILOGE("DeviceServerChannel::start port is invalid."); - return -1; - } - - int32_t socketFd = socket(AF_INET, SOCK_STREAM, 0); - if (socketFd == -1) { - HILOGE("DeviceServerChannel::start create socket failed, errMsg: %{public}s.", strerror(errno)); - return -1; - } - - struct sockaddr_in addr; - if (memset_s(&addr, sizeof(addr), 0, sizeof(addr)) != EOK) { - HILOGE("DeviceServerChannel::Start error init addr."); - close(socketFd); - return -1; - } - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(port); - - int32_t ret = bind(socketFd, (struct sockaddr*) &addr, sizeof(addr)); - if (ret == -1) { - HILOGE("DeviceServerChannel::start bind addr failed, errMsg: %{public}s.", strerror(errno)); - close(socketFd); - return -1; - } - - socketFd_ = socketFd; - HILOGI("DeviceServerChannel::start bind addr success, fd:%{public}d.", socketFd_); - - ret = listen(socketFd_, LISTENING_QUEUE_LEN); - if (ret == -1) { - HILOGE("DeviceServerChannel::start listen port failed, errMsg: %{public}s.", strerror(errno)); - close(socketFd_); - socketFd_ = -1; - return -1; - } - - return 0; -} - -void DeviceServerChannel::Receive() -{ - HILOGI("DeviceServerChannel::receive begin to listen client connecting."); - struct sockaddr_in client_addr; - socklen_t len = sizeof(client_addr); - - while (true) { - int32_t fd = accept(socketFd_, (struct sockaddr*) &client_addr, &len); - if (fd == -1) { - HILOGE("DeviceServerChannel::receive accept connect failed, errMsg: %{public}s.", strerror(errno)); - continue; - } - - if (clientFd_ != -1) { - HILOGW("DeviceServerChannel::receive another client is connected, close new connect."); - close(fd); - continue; - } - - HILOGI("DeviceServerChannel::receive new client in."); - clientFd_ = fd; - - // wait five seconds, if recv none, release the connection - struct timeval timeout = {RECV_DATA_TIMEOUT, 0}; - setsockopt(clientFd_, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval)); - - // demo project, blocked here to receive data, informal solution, will be discard later - char dataBuf[DATA_BUFFER_LENGTH] = {0}; - while (clientFd_ != -1) { - if (memset_s(dataBuf, sizeof(dataBuf), 0, sizeof(dataBuf)) != EOK) { - HILOGE("DeviceServerChannel::receive error init data buf."); - close(clientFd_); - clientFd_ = -1; - break; - } - - int32_t rc = recv(clientFd_, dataBuf, sizeof(dataBuf), 0); - if (rc == 0) { - HILOGE("DeviceServerChannel::receive error, client shutdown."); - close(clientFd_); - clientFd_ = -1; - break; - } else if (rc == -1 || rc == EAGAIN) { - HILOGE("DeviceServerChannel::receive receive data failed, errMsg: %{public}s.", strerror(errno)); - close(clientFd_); - clientFd_ = -1; - break; - } else { - HILOGI("DeviceServerChannel::receive receive data, size:%{public}d.", rc); - OnDataReceived(dataBuf, rc); - } - } - } -} - -void DeviceServerChannel::OnDataReceived(const char* data, const int32_t dataLen) -{ - HILOGI("DeviceServerChannel::OnDataReceived dataLen:%{public}d.", dataLen); - if (dataLen < REQUEST_ID_LENGTH) { - HILOGI("DeviceServerChannel::OnDataReceived error, data is invalid."); - return; - } - - // the client adds requestId to the header of data, the server needs to parse the original data - char reqIdChar[REQUEST_ID_LENGTH + 1] = {0}; - (void)memcpy_s(reqIdChar, sizeof(reqIdChar), data, REQUEST_ID_LENGTH); - reqIdChar[REQUEST_ID_LENGTH] = '\0'; - int64_t requestId = strtoll(reqIdChar, nullptr, REQUEST_ID_LENGTH); - if (requestId < MIN_REQUEST_ID) { - HILOGI("DeviceServerChannel::OnDataReceived error, requestId is invalid."); - return; - } - - const char* newData = data + REQUEST_ID_LENGTH; - int len = dataLen - REQUEST_ID_LENGTH; - int ret = deviceGroupManager_.processData(requestId, (const uint8_t *) newData, len); - HILOGI("DeviceServerChannel::OnDataReceived process data, ret:%{public}d, dataLen:%{public}d.", ret, len); - if (ret != 0) { - onError_(requestId, 0, ret, nullptr); - close(clientFd_); - clientFd_ = -1; - } -} - -bool DeviceServerChannel::Send(const char* data, const int32_t dataLen) -{ - int32_t ret = send(clientFd_, data, dataLen, 0); - if (ret == -1) { - HILOGE("DeviceServerChannel::send failed,socket:%{public}d,errMsg: %{public}s.", clientFd_, strerror(errno)); - return false; - } - - HILOGI("DeviceServerChannel::send data,socket:%{public}d, size:%{public}d.", clientFd_, ret); - return true; -} - -void DeviceServerChannel::ResetConnection() -{ - HILOGI("DeviceServerChannel::ResetConnection bind finished, release connection."); - close(clientFd_); - clientFd_ = -1; -} -} -} \ No newline at end of file diff --git a/services/devicemanagerservice/src/authdemo/hichain_adapter.cpp b/services/devicemanagerservice/src/authdemo/hichain_adapter.cpp deleted file mode 100644 index 5ccc74020..000000000 --- a/services/devicemanagerservice/src/authdemo/hichain_adapter.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hichain_adapter.h" - -#include -#include -#include -#include - -#include "parameter.h" - -#include "anonymous_string.h" -#include "device_client_channel.h" -#include "device_manager_log.h" -#include "device_server_channel.h" - - -namespace OHOS { -namespace DistributedHardware { -namespace { -// demo solution, may has security issues, later will be replaced by a formal plan -const std::string PIN_CODE = ""; -const int32_t PORT = -1; - -const std::string DEVICE_MANAGER_APP = "ohos.distributedhardware.devicemanager"; -const std::string DEVICE_MANAGER_GROUPNAME = "DMPeerToPeerGroup"; - -const int64_t MIN_REQUEST_ID = 1000000000; -const int64_t MAX_REQUEST_ID = 9999999999; - -const int32_t DEVICE_UUID_LENGTH = 65; -const int32_t PEER_TO_PEER_GROUP = 256; -const int32_t FIELD_EXPIRE_TIME_VALUE = 90; - -const int32_t THREAD_POOL_NUMBER = 20; -} - -IMPLEMENT_SINGLE_INSTANCE(HichainAdapter); - -int HichainAdapter::Init() -{ - HILOGI("HichainAdapter::init, begin to init hichain adapter."); - if (threadPool_.GetThreadsNum() == 0) { - threadPool_.Start(THREAD_POOL_NUMBER); - } - - bindingDeviceMap_.clear(); - bindCallBackMap_.clear(); - clientBindReqMap_.clear(); - - // call back for socket channel - using std::placeholders::_1; - using std::placeholders::_2; - using std::placeholders::_3; - using std::placeholders::_4; - onError_ = std::bind(HichainAuthCallBack::onError, _1, _2, _3, _4); - - HILOGI("HichainAdapter::init, init device auth service."); - InitDeviceAuthService(); - - // get group auth manager instance, and register callback - deviceGroupManager_ = GetGmInstance(); - if (deviceGroupManager_ == nullptr) { - HILOGE("HichainAdapter::init, failed to init group manager!"); - return -1; - } - deviceGroupManager_->regCallback(DEVICE_MANAGER_APP.c_str(), &deviceAuthCallback_); - - HILOGI("HichainAdapter::init, start socket server channel."); - deviceServerInst_ = std::make_unique(*deviceGroupManager_, onError_); - if (deviceServerInst_->Start(PORT) == -1) { - HILOGE("HichainAdapter::init, failed to start server!"); - return -1; - } - - // start the server channel to receive data - auto receiveFunc = [this]() { - this->deviceServerInst_->Receive(); - }; - threadPool_.AddTask(receiveFunc); - - HILOGI("HichainAdapter::init, init hichain adapter success."); - return 0; -} - -int32_t HichainAdapter::Bind(const DeviceReqInfo& devReqInfo, std::shared_ptr callback, bool sync) -{ - (void)sync; - HILOGI("HichainAdapter::Bind, begin to bind device: %{public}s.", GetAnonyString(devReqInfo.deviceId).c_str()); - for (auto &item : bindingDeviceMap_) { - if (item.second == devReqInfo.deviceId) { - HILOGW("HichainAdapter::bind device is binding, update call back."); - } - } - - int64_t requestId = GenRequestId(); - std::shared_ptr clientChannel = - std::make_shared(requestId, *deviceGroupManager_, onError_); - if (clientChannel->Connect(devReqInfo.ipAddr, PORT) == -1) { - HILOGE("HichainAdapter::bind failed to connect to server, create channel failed."); - return CREATE_CHANNEL_FAILED; - } - - // start the client channel to recevice data - auto receiveFunc = [&clientChannel]() { - clientChannel->Receive(); - }; - threadPool_.AddTask(receiveFunc); - - std::string groupId = GetGroupIdByName(PEER_TO_PEER_GROUP, DEVICE_MANAGER_GROUPNAME); - if (groupId == "") { - HILOGE("HichainAdapter::bind group not exist, begin to create group."); - int32_t ret = CreateGroup(requestId); - if (ret != 0) { - HILOGE("HichainAdapter::bind faild to start create group task, ret: %{public}d.", ret); - return GROUP_CREATE_FAILED; - } - } else { - HILOGE("HichainAdapter::bind group exist, begin to add member."); - int ret = AddMemeber(requestId, groupId, PIN_CODE); - if (ret != 0) { - HILOGE("HichainAdapter::bind faild to start add member task, ret: %{public}d.", ret); - return MEMBER_ADD_FAILED; - } - } - - clientBindReqMap_[requestId] = clientChannel; - bindingDeviceMap_[requestId] = devReqInfo.deviceId; - bindCallBackMap_[requestId] = callback; - return SUCCESS; -} - -std::string HichainAdapter::GetGroupIdByName(int32_t groupType, const std::string& groupName) -{ - HILOGI("HichainAdapter::GetGroupIdByName get group info."); - if (deviceGroupManager_ == nullptr) { - HILOGE("HichainAdapter::GetGroupIdByName group manager is null."); - return ""; - } - - nlohmann::json reqParam; - reqParam[FIELD_GROUP_TYPE] = groupType; - reqParam[FIELD_GROUP_NAME] = groupName; - - char* returnGroupVec = nullptr; - uint32_t groupNum = 0; - int32_t ret = deviceGroupManager_->getGroupInfo(DEVICE_MANAGER_APP.c_str(), reqParam.dump().c_str(), - &returnGroupVec, &groupNum); - if (ret != 0) { - HILOGE("HichainAdapter::GetGroupIdByName failed to get group info, ret=%{public}d.", ret); - return ""; - } - - if (groupNum == 0) { - HILOGE("HichainAdapter::GetGroupIdByName group not exist, return empty."); - return ""; - } - - nlohmann::json groupObj = nlohmann::json::parse(returnGroupVec, nullptr, false); - if (groupObj.is_discarded()) { - HILOGE("HichainAdapter::GetGroupIdByName parse group info error, json invalid."); - return ""; - } - - for (auto& item : groupObj) { - if (item.contains(FIELD_GROUP_ID)) { - return item.at(FIELD_GROUP_ID); - } - } - - HILOGI("HichainAdapter::GetGroupIdByName group info not found, return empty"); - return ""; -} - -int32_t HichainAdapter::CreateGroup(int64_t requestId) -{ - HILOGE("HichainAdapter::CreateGroup requestId:%{public}lld.", requestId); - if (deviceGroupManager_ == nullptr) { - HILOGE("HichainAdapter::CreateGroup group manager is null."); - return -1; - } - - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_TYPE] = PEER_TO_PEER_GROUP; - jsonObj[FIELD_GROUP_NAME] = DEVICE_MANAGER_GROUPNAME; - - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - - jsonObj[FIELD_DEVICE_ID] = localDeviceId; - jsonObj[FIELD_USER_TYPE] = 0; - jsonObj[FIELD_GROUP_VISIBILITY] = -1; - jsonObj[FIELD_EXPIRE_TIME] = FIELD_EXPIRE_TIME_VALUE; - - return deviceGroupManager_->createGroup(requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str()); -} - -int32_t HichainAdapter::AddMemeber(int64_t requestId, std::string& groupId, const std::string& pinCode) -{ - HILOGE("HichainAdapter::AddMemeber requestId:%{public}lld.", requestId); - if (deviceGroupManager_ == nullptr) { - HILOGE("HichainAdapter::AddMemeber group manager is null."); - return -1; - } - - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_ID] = groupId; - jsonObj[FIELD_GROUP_TYPE] = PEER_TO_PEER_GROUP; - jsonObj[FIELD_PIN_CODE] = pinCode; - jsonObj[FIELD_IS_ADMIN] = true; - return deviceGroupManager_->addMemberToGroup(requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str()); -} - -bool HichainAdapter::OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) -{ - HILOGI("HichainAdapter::OnTransmit requestId:%{public}lld, size:%{public}d.", requestId, dataLen); - if (clientBindReqMap_.count(requestId) > 0) { - HILOGI("HichainAdapter::OnTransmit client send to server."); - return clientBindReqMap_[requestId]->Send((const char*) data, dataLen); - } else { - HILOGI("HichainAdapter::OnTransmit server send to client."); - return deviceServerInst_->Send((const char*) data, dataLen); - } -} - -void HichainAdapter::OnGroupCreated(int64_t requestId, const char *groupInfo) -{ - nlohmann::json jsonObject = nlohmann::json::parse(groupInfo); - if (jsonObject.find(FIELD_GROUP_ID) == jsonObject.end()) { - HILOGE("HichainAdapter::onGroupCreated failed to get groupId."); - OnBindFailed(requestId, GROUP_CREATE_FAILED); - return; - } - - std::string groupId = jsonObject.at(FIELD_GROUP_ID).get(); - HILOGI("HichainAdapter::onGroupCreated group create success,groupId:%{public}s.", GetAnonyString(groupId).c_str()); - - // group创建成功之后,需要添加把对端设备添加到创建好的群组中 - int ret = AddMemeber(requestId, groupId, PIN_CODE); - if (ret != 0) { - HILOGE("HichainAdapter::onGroupCreated faild to start add member task, ret: %{public}d.", ret); - OnBindFailed(requestId, MEMBER_ADD_FAILED); - return; - } -} - -char* HichainAdapter::OnBindRequest(int64_t requestId, int operationCode, const char *reqParams) -{ - (void)requestId; - (void)operationCode; - (void)reqParams; - - HILOGI("HichainAdapter::OnBindRequest."); - nlohmann::json jsonObj; - jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED; - jsonObj[FIELD_PIN_CODE] = PIN_CODE; - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - jsonObj[FIELD_DEVICE_ID] = localDeviceId; - - std::string jsonStr = jsonObj.dump(); - char *buffer = strdup(jsonStr.c_str()); - return buffer; -} - -void HichainAdapter::OnBindSuccess(int64_t requestId, const char* returnData) -{ - HILOGI("HichainAdapter::OnBindSuccess requestId:%{public}lld,dataLen:%{public}d.", requestId, strlen(returnData)); - if (bindCallBackMap_.count(requestId) == 1) { - bindCallBackMap_[requestId]->onBindSuccess(bindingDeviceMap_[requestId], returnData); - bindCallBackMap_.erase(requestId); - } - - if (clientBindReqMap_.count(requestId) == 1) { - clientBindReqMap_[requestId]->ResetConnection(); - clientBindReqMap_[requestId].reset(); - clientBindReqMap_.erase(requestId); - } - - if (bindingDeviceMap_.count(requestId) == 1) { - bindingDeviceMap_.erase(requestId); - } - - deviceServerInst_->ResetConnection(); -} - -int64_t HichainAdapter::GenRequestId() -{ - int64_t requestId = 0; - do { - requestId = (int64_t)requestIdIndex_ + MIN_REQUEST_ID; - if (requestId > MAX_REQUEST_ID) { - requestId = MIN_REQUEST_ID; - requestIdIndex_ = 0; - } else { - requestIdIndex_++; - } - } while (clientBindReqMap_.count(requestId) != 0); - return requestId; -} - -void HichainAdapter::OnBindFailed(int64_t requestId, int32_t errorCode) -{ - HILOGI("HichainAdapter::OnBindFailed requestId:%{public}lld, errorCode:%{public}d.", requestId, errorCode); - if (bindCallBackMap_.count(requestId) == 1) { - bindCallBackMap_[requestId]->onBindFailed(bindingDeviceMap_[requestId], errorCode); - bindCallBackMap_.erase(requestId); - } - - if (clientBindReqMap_.count(requestId) == 1) { - clientBindReqMap_[requestId].reset(); - clientBindReqMap_.erase(requestId); - } - - if (bindingDeviceMap_.count(requestId) == 1) { - bindingDeviceMap_.erase(requestId); - } -} - -void HichainAdapter::UnBind(const std::string& deviceId) -{ - // reserved interface, to be implemented - (void)deviceId; -} - -void HichainAdapter::OnUnBindFinished() -{ - // reserved interface, to be implemented -} - -bool HichainAuthCallBack::onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) -{ - HILOGI("HichainAuthCallBack::onTransmit requestId:%{public}lld,size:%{public}d.", requestId, dataLen); - return HichainAdapter::GetInstance().OnTransmit(requestId, data, dataLen); -} - -void HichainAuthCallBack::onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) -{ - (void)requestId; - (void)sessionKey; - HILOGI("HichainAuthCallBack::onSessionKeyReturned size:%{public}d.", sessionKeyLen); -} - -void HichainAuthCallBack::onFinish(int64_t requestId, int operationCode, const char *returnData) -{ - HILOGI("HichainAuthCallBack::onFinish reqId:%{public}lld, operation:%{public}d.", requestId, operationCode); - if (operationCode == GroupOperationCode::GROUP_CREATE) { - HichainAdapter::GetInstance().OnGroupCreated(requestId, returnData); - return; - } - - if (operationCode == GroupOperationCode::MEMBER_INVITE || operationCode == GroupOperationCode::MEMBER_JOIN) { - HichainAdapter::GetInstance().OnBindSuccess(requestId, returnData); - } -} - -void HichainAuthCallBack::onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn) -{ - (void)errorReturn; - HILOGI("HichainAuthCallBack::onError reqId:%{public}lld, operation:%{public}d, errorCode:%{public}d.", - requestId, operationCode, errorCode); - HichainAdapter::GetInstance().OnBindFailed(requestId, errorCode); -} - -char* HichainAuthCallBack::onBindRequest(int64_t requestId, int operationCode, const char *reqParams) -{ - HILOGI("HichainAuthCallBack::onBindRequest reqId:%{public}lld, operation: %{public}d.", requestId, operationCode); - return HichainAdapter::GetInstance().OnBindRequest(requestId, operationCode, reqParams); -} -} -} diff --git a/services/devicemanagerservice/src/device_manager_listener_proxy.cpp b/services/devicemanagerservice/src/device_manager_listener_proxy.cpp deleted file mode 100644 index d721ef705..000000000 --- a/services/devicemanagerservice/src/device_manager_listener_proxy.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager_listener_proxy.h" - -#include "ipc_types.h" - -#include "device_manager_log.h" - -namespace OHOS { -namespace DistributedHardware { -bool DeviceManagerListenerProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(DeviceManagerListenerProxy::GetDescriptor())) { - HILOGE("write interface token failed"); - return false; - } - return true; -} - -int32_t DeviceManagerListenerProxy::OnDeviceOnline(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&deviceInfo)) { - HILOGE("write deviceInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DEVICE_ONLINE, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDeviceOnline SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnDeviceOffline(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&deviceInfo)) { - HILOGE("write deviceInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DEVICE_OFFLINE, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDeviceOffline SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnDeviceChanged(std::string &packageName, const DmDeviceInfo &deviceInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&deviceInfo)) { - HILOGE("write deviceInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DEVICE_CHANGE, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDeviceChanged SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnDeviceFound(std::string &packageName, uint16_t subscribeId, - const DmDeviceInfo &deviceInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt16(subscribeId)) { - HILOGE("write subscribeId failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteParcelable(&deviceInfo)) { - HILOGE("write deviceInfo failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DEVICE_FOUND, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDeviceFound SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnDiscoverFailed(std::string &packageName, uint16_t subscribeId, - int32_t failedReason) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt16(subscribeId)) { - HILOGE("write subscribeId failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt32(failedReason)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DISCOVER_FAILED, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDiscoverFailed SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnDiscoverySuccess(std::string &packageName, uint16_t subscribeId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt16(subscribeId)) { - HILOGE("write subscribeId failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_DISCOVER_SUCCESS, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnDiscoverySuccess SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} - -int32_t DeviceManagerListenerProxy::OnAuthResult(std::string &packageName, std::string &deviceId, int32_t status, - int32_t reason) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote service null"); - return ERR_NULL_OBJECT; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(packageName)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteString(deviceId)) { - HILOGE("write packageName failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt32(status)) { - HILOGE("write status failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!data.WriteInt32(reason)) { - HILOGE("write reason failed"); - return ERR_FLATTEN_OBJECT; - } - - int32_t error = remote->SendRequest(ON_AUTH_RESULT, data, reply, option); - if (error != ERR_NONE) { - HILOGE("OnAuthResult SendRequest fail, error: %{public}d", error); - return error; - } - - return ERR_NONE; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp deleted file mode 100644 index 5da977ab7..000000000 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager_service.h" - -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "ipc_types.h" -#include "iservice_registry.h" -#include "string_ex.h" -#include "system_ability_definition.h" - -#include "anonymous_string.h" -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "softbus_adapter.h" - -#include "hichain_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { - const int32_t THREAD_POOL_TASK_NUM = 1; -} - -IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService); - -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DeviceManagerService::GetInstance()); - -DeviceManagerService::DeviceManagerService() : SystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, true) -{ - registerToService_ = false; - state_ = ServiceRunningState::STATE_NOT_START; - hichainBindCallback_ = std::make_shared(); -} - -void DeviceManagerService::OnStart() -{ - HILOGI("DeviceManagerService::OnStart start"); - if (state_ == ServiceRunningState::STATE_RUNNING) { - HILOGD("DeviceManagerService has already started."); - return; - } - if (!Init()) { - HILOGE("failed to init DeviceManagerService"); - return; - } - state_ = ServiceRunningState::STATE_RUNNING; -} - -bool DeviceManagerService::Init() -{ - HILOGI("DeviceManagerService::Init ready to init."); - if (!registerToService_) { - bool ret = Publish(this); - if (!ret) { - HILOGE("DeviceManagerService::Init Publish failed!"); - return false; - } - registerToService_ = true; - } - if (threadPool_.GetThreadsNum() == 0) { - threadPool_.Start(THREAD_POOL_TASK_NUM); - } - RegisterDeviceStateListener(); - return true; -} - -void DeviceManagerService::OnStop() -{ - HILOGI("DeviceManagerService::OnStop ready to stop service."); - state_ = ServiceRunningState::STATE_NOT_START; - registerToService_ = false; -} - -ServiceRunningState DeviceManagerService::QueryServiceState() const -{ - return state_; -} - -void DeviceManagerService::RegisterDeviceStateListener() -{ - auto registerFunc = []() { - SoftbusAdapter::GetInstance().RegSoftBusDeviceStateListener(); - HichainAdapter::GetInstance().Init(); - }; - threadPool_.AddTask(registerFunc); -} - -int32_t DeviceManagerService::RegisterDeviceManagerListener(std::string &packageName, sptr listener) -{ - if (packageName.empty() || listener == nullptr) { - HILOGE("Error: parameter invalid"); - return ERR_NULL_OBJECT; - } - - HILOGI("In, packageName: %{public}s", packageName.c_str()); - std::lock_guard autoLock(listenerLock_); - auto iter = dmListener_.find(packageName); - if (iter != dmListener_.end()) { - HILOGI("RegisterDeviceManagerListener: listener already exists"); - return ERR_NONE; - } - - sptr appRecipient = sptr(new AppDeathRecipient()); - if (!listener->AddDeathRecipient(appRecipient)) { - HILOGE("RegisterDeviceManagerListener: AddDeathRecipient Failed"); - } - dmListener_[packageName] = listener; - appRecipient_[packageName] = appRecipient; - return ERR_NONE; -} - -int32_t DeviceManagerService::UnRegisterDeviceManagerListener(std::string &packageName) -{ - if (packageName.empty()) { - HILOGE("Error: parameter invalid"); - return ERR_NULL_OBJECT; - } - - HILOGI("In, packageName: %{public}s", packageName.c_str()); - std::lock_guard autoLock(listenerLock_); - auto listenerIter = dmListener_.find(packageName); - if (listenerIter == dmListener_.end()) { - HILOGI("UnRegisterDeviceManagerListener: listener not exists"); - return ERR_NONE; - } - - auto recipientIter = appRecipient_.find(packageName); - if (recipientIter == appRecipient_.end()) { - HILOGI("UnRegisterDeviceManagerListener: appRecipient not exists"); - dmListener_.erase(packageName); - return ERR_NONE; - } - - auto listener = listenerIter->second; - auto appRecipient = recipientIter->second; - listener->RemoveDeathRecipient(appRecipient); - appRecipient_.erase(packageName); - dmListener_.erase(packageName); - return ERR_NONE; -} - -int32_t DeviceManagerService::RegisterDeviceStateCallback(std::string &packageName, std::string &extra) -{ - HILOGI("In, packageName: %{public}s", packageName.c_str()); - devStateCallbackParas_[packageName] = extra; - return ERR_NONE; -} - -int32_t DeviceManagerService::UnRegisterDeviceStateCallback(std::string &packageName) -{ - HILOGI("In, packageName: %{public}s", packageName.c_str()); - devStateCallbackParas_.erase(packageName); - return ERR_NONE; -} - -int32_t DeviceManagerService::GetTrustedDeviceList(std::string &packageName, std::string &extra, - std::vector &deviceList) -{ - HILOGI("In, packageName: %{public}s", packageName.c_str()); - return SoftbusAdapter::GetSoftbusTrustDevices(packageName, extra, deviceList); -} - -int32_t DeviceManagerService::StartDeviceDiscovery(std::string &packageName, DmSubscribeInfo &subscribeInfo) -{ - HILOGI("In, packageName: %{public}s, subscribeId %{public}d", packageName.c_str(), - (int32_t)subscribeInfo.subscribeId); - return SoftbusAdapter::GetInstance().StartSoftbusDiscovery(packageName, subscribeInfo); -} - -int32_t DeviceManagerService::StopDeviceDiscovery(std::string &packageName, uint16_t subscribeId) -{ - HILOGI("In, packageName: %{public}s, subscribeId %{public}d", packageName.c_str(), (int32_t)subscribeId); - return SoftbusAdapter::GetInstance().StopSoftbusDiscovery(packageName, subscribeId); -} - -int32_t DeviceManagerService::AuthenticateDevice(std::string &packageName, const DmDeviceInfo &deviceInfo, - std::string &extra) -{ - (void)extra; - - std::string deviceId = deviceInfo.deviceId; - if (SoftbusAdapter::IsDeviceOnLine(deviceId)) { - HILOGI("AuthenticateDevice, deviceId is already in trusted list, return."); - return ERR_DEVICEMANAGER_DEVICE_ALREADY_TRUSTED; - } - - DeviceReqInfo devReqInfo; - devReqInfo.deviceId = deviceId; - HILOGI("AuthenticateDevice In, packageName: %{public}s, deviceId %{public}s", packageName.c_str(), - GetAnonyString(deviceId).c_str()); - int32_t ret = SoftbusAdapter::GetInstance().GetConnectionIpAddr(deviceId, devReqInfo.ipAddr); - if (ret != ERR_OK) { - HILOGE("AuthenticateDevice Error: can not find ip by deviceId."); - return ret; - } - - authCallbackParas_[deviceId] = packageName; - return HichainAdapter::GetInstance().Bind(devReqInfo, hichainBindCallback_, false); -} - -const std::map>& DeviceManagerService::GetDmListener() -{ - return dmListener_; -} - -const sptr DeviceManagerService::GetDmListener(std::string packageName) const -{ - auto iter = dmListener_.find(packageName); - if (iter == dmListener_.end()) { - return nullptr; - } - auto remote = iter->second; - sptr dmListener = iface_cast(remote); - return dmListener; -} - -void AppDeathRecipient::OnRemoteDied(const wptr& remote) -{ - HILOGW("AppDeathRecipient: OnRemoteDied"); - std::map> listeners = DeviceManagerService::GetInstance().GetDmListener(); - std::string packageName; - for (auto iter : listeners) { - if (iter.second == remote.promote()) { - packageName = iter.first; - break; - } - } - - if (packageName.empty()) { - HILOGE("AppDeathRecipient: OnRemoteDied, no packageName matched"); - return; - } - - HILOGI("AppDeathRecipient: OnRemoteDied for %{public}s", packageName.c_str()); - DeviceManagerService::GetInstance().UnRegisterDeviceManagerListener(packageName); -} - - -void HiChainBindCallback::onBindSuccess(std::string deviceId, const char *returnData) -{ - (void)returnData; - HILOGI("onBindSuccess, DM bind succeed, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); - auto res = DeviceManagerService::GetInstance().authCallbackParas_; - auto iter = res.find(deviceId); - if (iter == res.end()) { - HILOGE("onBindSuccess deviceInfo not found by deviceId."); - return; - } - - std::string packageName = iter->second; - sptr dmListener = DeviceManagerService::GetInstance().GetDmListener(packageName); - if (dmListener != nullptr) { - dmListener->OnAuthResult(packageName, deviceId, DmBindStatus::STATE_BIND_SUCCESS, ERR_NONE); - } - - int32_t ret = SoftbusAdapter::GetInstance().SoftbusJoinLnn(deviceId); - HILOGI("onBindSuccess, DM bind succeed, joinlnn ret=%{public}d.", ret); -} - -void HiChainBindCallback::onBindFailed(std::string deviceId, int32_t errorCode) -{ - HILOGI("onBindFailed, DM bind failed, deviceId: %{public}s, errorCode: %{public}d", - GetAnonyString(deviceId).c_str(), errorCode); - auto res = DeviceManagerService::GetInstance().authCallbackParas_; - auto iter = res.find(deviceId); - if (iter == res.end()) { - HILOGE("onBindFailed deviceInfo not found by deviceId."); - return; - } - - std::string packageName = iter->second; - sptr dmListener = DeviceManagerService::GetInstance().GetDmListener(packageName); - - dmListener->OnAuthResult(packageName, deviceId, DmBindStatus::STATE_BIND_FAILD, errorCode); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_stub.cpp b/services/devicemanagerservice/src/device_manager_stub.cpp deleted file mode 100644 index 9ab1bf5ca..000000000 --- a/services/devicemanagerservice/src/device_manager_stub.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "device_manager_stub.h" - -#include "ipc_skeleton.h" -#include "ipc_types.h" - - -#include "device_manager_log.h" - -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -DeviceManagerStub::DeviceManagerStub() -{ - memberFuncMap_[GET_TRUST_DEVICE_LIST] = &DeviceManagerStub::GetTrustedDeviceListInner; - memberFuncMap_[REGISTER_DEVICE_MANAGER_LISTENER] = &DeviceManagerStub::RegisterDeviceManagerListenerInner; - memberFuncMap_[UNREGISTER_DEVICE_MANAGER_LISTENER] = &DeviceManagerStub::UnRegisterDeviceManagerListenerInner; - memberFuncMap_[REGISTER_DEVICE_STATE_CALLBACK] = &DeviceManagerStub::RegisterDeviceStateCallbackInner; - memberFuncMap_[UNREGISTER_DEVICE_STATE_CALLBACK] = &DeviceManagerStub::UnRegisterDeviceStateCallbackInner; - memberFuncMap_[START_DEVICE_DISCOVER] = &DeviceManagerStub::StartDeviceDiscoveryInner; - memberFuncMap_[STOP_DEVICE_DISCOVER] = &DeviceManagerStub::StopDeviceDiscoveryInner; - memberFuncMap_[AUTHENTICATE_DEVICE] = &DeviceManagerStub::AuthenticateDeviceInner; -} - -DeviceManagerStub::~DeviceManagerStub() -{ - memberFuncMap_.clear(); -} - -int32_t DeviceManagerStub::OnRemoteRequest(uint32_t code, - MessageParcel& data, MessageParcel &reply, MessageOption &option) -{ - HILOGI("code = %{public}d, flags= %{public}d.", code, option.GetFlags()); - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - if (!EnforceInterceToken(data)) { - HILOGE("interface token check failed!"); - return ERR_INVALID_STATE; - } - return (this->*memberFunc)(data, reply); - } - } - HILOGW("unsupport code: %{public}d", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t DeviceManagerStub::RegisterDeviceManagerListenerInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - sptr listener = data.ReadRemoteObject(); - int32_t result = RegisterDeviceManagerListener(packageName, listener); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::UnRegisterDeviceManagerListenerInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - int32_t result = UnRegisterDeviceManagerListener(packageName); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::RegisterDeviceStateCallbackInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - string extra = data.ReadString(); - HILOGI("packageName:%{public}s, extra:%{public}s", packageName.c_str(), extra.c_str()); - int32_t result = RegisterDeviceStateCallback(packageName, extra); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::UnRegisterDeviceStateCallbackInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - HILOGI("packageName:%{public}s", packageName.c_str()); - int32_t result = UnRegisterDeviceStateCallback(packageName); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::GetTrustedDeviceListInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - string extra = data.ReadString(); - HILOGI("packageName:%{public}s, extra:%{public}s", packageName.c_str(), extra.c_str()); - std::vector devInfos; - int32_t result = GetTrustedDeviceList(packageName, extra, devInfos); - reply.WriteInt32(devInfos.size()); - for (auto &it : devInfos) { - if (!reply.WriteParcelable(&it)) { - return ERR_INVALID_VALUE; - } - } - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -template -int32_t DeviceManagerStub::GetParcelableInfo(MessageParcel &reply, T &parcelableInfo) -{ - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { - HILOGE("readParcelableInfo failed"); - return ERR_INVALID_VALUE; - } - parcelableInfo = *info; - return ERR_NONE; -} - -int32_t DeviceManagerStub::StartDeviceDiscoveryInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - DmSubscribeInfo subscribeInfo; - int32_t result = GetParcelableInfo(data, subscribeInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - HILOGI("packageName:%{public}s, subscribeId: %{public}d", packageName.c_str(), subscribeInfo.subscribeId); - result = StartDeviceDiscovery(packageName, subscribeInfo); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::StopDeviceDiscoveryInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - uint16_t subscribeId = data.ReadInt32(); - HILOGI("packageName:%{public}s, subscribeId: %{public}d", packageName.c_str(), subscribeId); - int32_t result = StopDeviceDiscovery(packageName, subscribeId); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -int32_t DeviceManagerStub::AuthenticateDeviceInner(MessageParcel& data, MessageParcel& reply) -{ - string packageName = data.ReadString(); - DmDeviceInfo deviceInfo; - int32_t result = GetParcelableInfo(data, deviceInfo); - if (result != ERR_NONE) { - HILOGE("GetParcelableInfo fail, result: %{public}d", result); - reply.WriteInt32(result); - return result; - } - - string extra = data.ReadString(); - HILOGI("packageName:%{public}s, extra:%{public}s", packageName.c_str(), extra.c_str()); - result = AuthenticateDevice(packageName, deviceInfo, extra); - if (!reply.WriteInt32(result)) { - HILOGE("write result failed"); - return ERR_INVALID_VALUE; - } - return ERR_NONE; -} - -bool DeviceManagerStub::EnforceInterceToken(MessageParcel& data) -{ - u16string interfaceToken = data.ReadInterfaceToken(); - u16string descriptor = DeviceManagerStub::GetDescriptor(); - return interfaceToken == descriptor; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp new file mode 100644 index 000000000..4d1673db1 --- /dev/null +++ b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "encrypt_utils.h" + +#include "mbedtls/base64.h" +#include "mbedtls/gcm.h" +#include "mbedtls/md.h" + +#include "mbedtls/ctr_drbg.h" +#include "mbedtls/entropy.h" + +#include +#include +#include +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "securec.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { + const uint8_t HW_SESSION_KEY_LEN = 16; + const uint8_t HW_GCM_IV_LEN = 12; + const uint8_t HW_TAG_LEN = 16; + const uint8_t HW_KEY_BITS_UNIT = 8; + const uint8_t HW_RANDOM_KEY_LEN = 16; + const uint8_t HW_LEFT_COUNT = 3; + const uint8_t HW_RIGHT_COUNT = 5; + const uint8_t BUF_LEN = 32;// olen1是固定的,返回值是18; + //将C1,C2,C3放在不同的位置,目的:增加破译难度 + const char* STR_C1 = "s6nxSNjc/VhzXqwXAbKaGUFH"; + const char* STR_C2 = "C5bcOsfhejsEAfohXihU65yN"; + const char* STR_C3 = "lHhAYIiqUXQom9R0bl1o9Mvm"; +} +// 数据整体按字节向左位移 count 次 +void EncryptUtils::ByteLeftMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, int32_t count) +{ + if (len == 0 || data == 0) { + DMLog(DM_LOG_DEBUG, "invalid param"); + return; + } + count %= len; + if (memcpy_s(data, dataLen, inputData + count, len - count) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed.", __FUNCTION__, __LINE__); + } + if (memcpy_s(data + len - count, dataLen - len + count, inputData, count) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed.", __FUNCTION__, __LINE__); + } +} +// 数据整体按字节向右位移 count 次 +void EncryptUtils::ByteRightMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, int32_t count) +{ + if (len == 0 || data == 0) { + DMLog(DM_LOG_DEBUG, "invalid param"); + return; + } + count %= len; + if (memcpy_s(data + count, dataLen - count, inputData, len - count) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed.", __FUNCTION__, __LINE__); + } + if (memcpy_s(data, dataLen, inputData + len - count, count) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed.", __FUNCTION__, __LINE__); + } +} + +void EncryptUtils::XORBlock(uint8_t* output, const uint8_t* input1, const uint8_t* input2, + const size_t block_size) +{ + size_t idx; + for (idx = 0; idx < block_size; ++idx) { + output[idx] = input1[idx] ^ input2[idx]; + } +} + +int32_t EncryptUtils::MbedtlsAesGcmEncrypt(DmCryptInfo * info, const uint8_t* plainText, + uint32_t plainTextSize, uint8_t* cipherText, uint32_t cipherTextLen) +{ + if (info == nullptr || + (info->sessionkey == nullptr) || + (info->iv == nullptr) || + (plainText == nullptr) || + (plainTextSize == 0) || + cipherText == nullptr || + (cipherTextLen < plainTextSize + HW_TAG_LEN)) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + int32_t ret; + uint8_t tagBuf[HW_TAG_LEN] = {0}; + mbedtls_gcm_context aesContext; + mbedtls_gcm_init(&aesContext); + ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, info->sessionkey, + info->sessionkeyLen * HW_KEY_BITS_UNIT); + if (ret != 0) { + mbedtls_gcm_free(&aesContext); + return ENCRYPT_UTILS_GCM_SETKEY_FAILED; + } + + ret = mbedtls_gcm_crypt_and_tag(&aesContext, MBEDTLS_GCM_ENCRYPT, plainTextSize, info->iv, + HW_GCM_IV_LEN, nullptr, 0, plainText, cipherText, HW_TAG_LEN, tagBuf); + if (ret != 0) { + mbedtls_gcm_free(&aesContext); + return ENCRYPT_UTILS_GCM_CRYPT_FAILED; + } + + if (memcpy_s(cipherText + plainTextSize, cipherTextLen - plainTextSize, + tagBuf, HW_TAG_LEN) != DEVICEMANAGER_OK) { + mbedtls_gcm_free(&aesContext); + return DEVICEMANAGER_COPY_FAILED; + } + + mbedtls_gcm_free(&aesContext); + return (plainTextSize + HW_TAG_LEN); +} + +int32_t EncryptUtils::MbedtlsAesGcmDecrypt(DmCryptInfo* info, const uint8_t* cipherText, + uint32_t cipherTextSize, uint8_t* plain, uint32_t plainLen) +{ + if (info == nullptr || + (info->sessionkey == nullptr) || + (info->iv == nullptr) || + (cipherText == nullptr) || + (cipherTextSize <= HW_TAG_LEN) || + plain == nullptr || + (plainLen < cipherTextSize - HW_TAG_LEN)) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + mbedtls_gcm_context aesContext; + mbedtls_gcm_init(&aesContext); + int32_t ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, info->sessionkey, + info->sessionkeyLen * HW_KEY_BITS_UNIT); + if (ret != 0) { + mbedtls_gcm_free(&aesContext); + return ENCRYPT_UTILS_GCM_SETKEY_FAILED; + } + int32_t actualPlainLen = cipherTextSize - HW_TAG_LEN; + ret = mbedtls_gcm_auth_decrypt(&aesContext, actualPlainLen, info->iv, + HW_GCM_IV_LEN, nullptr, 0, cipherText + actualPlainLen, HW_TAG_LEN, cipherText, plain); + if (ret != 0) { + mbedtls_gcm_free(&aesContext); + return ENCRYPT_UTILS_GCM_AUTH_DECRYPT_FAILED; + } + mbedtls_gcm_free(&aesContext); + return actualPlainLen; +} + +void EncryptUtils::MbedtlsGenRootKey(uint8_t* szOut, int32_t szOutLen, int32_t* nOutLen) +{ + uint8_t buf[BUF_LEN] = {0}; + uint8_t bufx[BUF_LEN] = {0}; + uint8_t c1[BUF_LEN] = {0}; + uint8_t c2[BUF_LEN] = {0}; + uint8_t c3[BUF_LEN] = {0}; + size_t olen1 = 0; + size_t olen2 = 0; + size_t olen3 = 0; + MbedtlsBase64Decode(c1, sizeof(c1), &olen1, (const uint8_t*)STR_C1, strlen(STR_C1)); + MbedtlsBase64Decode(c2, sizeof(c2), &olen2, (const uint8_t*)STR_C2, strlen(STR_C2)); + MbedtlsBase64Decode(c3, sizeof(c3), &olen3, (const uint8_t*)STR_C3, strlen(STR_C3)); + if (olen1 != olen2 || + olen1 != olen3 || + olen1 >= BUF_LEN) { + DMLog(DM_LOG_ERROR, "invalid param"); + return; + } + ByteLeftMove(buf, BUF_LEN, c1, olen1, HW_LEFT_COUNT); + XORBlock(buf, buf, c2, olen1); + ByteRightMove(bufx, BUF_LEN, buf, olen1, HW_RIGHT_COUNT); + XORBlock(bufx, bufx, c3, olen1); + if ((size_t)szOutLen >= olen1) { + if (memcpy_s(szOut, szOutLen, bufx, olen1) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); + } + szOutLen = olen1; + } else { + szOutLen = 0; + } + if (nOutLen) { + *nOutLen = szOutLen; + } +} + +int32_t EncryptUtils::MbedtlsBase64Encode(uint8_t *dst, size_t dlen, size_t *olen, + const uint8_t *src, size_t slen ){ + return mbedtls_base64_encode(dst,dlen,olen,src,slen); +} + +int32_t EncryptUtils::MbedtlsBase64Decode( uint8_t *dst, size_t dlen, size_t *olen, + const uint8_t *src, size_t slen ){ + return mbedtls_base64_decode(dst,dlen,olen,src,slen); +} + +int32_t EncryptUtils::GetRandomData(uint8_t* randStr, uint32_t len) +{ + mbedtls_entropy_context* entropy = nullptr; + mbedtls_ctr_drbg_context* ctrDrbg = nullptr; + int32_t ret = DEVICEMANAGER_OK; + do { + if (randStr == nullptr || len == 0) { + break; + } + entropy = (mbedtls_entropy_context*)malloc(sizeof(mbedtls_entropy_context)); + if (entropy == nullptr) { + break; + } + ctrDrbg = (mbedtls_ctr_drbg_context*)malloc(sizeof(mbedtls_ctr_drbg_context)); + if (ctrDrbg == nullptr) { + break; + } + mbedtls_ctr_drbg_init(ctrDrbg); + mbedtls_entropy_init(entropy); + ret = mbedtls_ctr_drbg_seed(ctrDrbg, mbedtls_entropy_func, entropy, nullptr, 0); + if (ret != 0) { + break; + } + ret = mbedtls_ctr_drbg_random(ctrDrbg, randStr, len); + if (ret != 0) { + break; + } + ret = DEVICEMANAGER_OK; + } while (0); + if (entropy != nullptr) { + free(entropy); + } + if (ctrDrbg != nullptr) { + free(ctrDrbg); + } + return ret; +} + +int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t* plainText, int plainTextLen, uint8_t* cipherText, + int cipherTextLen, int* outLen) +{ + uint8_t rootKey[24] = {0}; + uint8_t session[HW_SESSION_KEY_LEN] = {0}; + uint8_t iv[12] = {0}; + uint8_t randomKey[HW_RANDOM_KEY_LEN] = {0}; + int32_t rootKeyLen = 0; + int32_t ret = DEVICEMANAGER_OK; + uint8_t K[MBEDTLS_MD_MAX_SIZE] = {0}; + + GetRandomData(randomKey, sizeof(randomKey)); + MbedtlsGenRootKey(rootKey, sizeof(rootKey), &rootKeyLen); + if (plainText == nullptr || plainTextLen <= 0 || cipherText == nullptr || cipherTextLen <= 0) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + if ((plainTextLen + HW_RANDOM_KEY_LEN) > cipherTextLen) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + // 用rootKey加密随机值 得到session和iv + mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), rootKey, rootKeyLen, randomKey, + sizeof(randomKey), K); + if (memcpy_s(session, sizeof(session), K, HW_SESSION_KEY_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); + return DEVICEMANAGER_COPY_FAILED; + } + if (memcpy_s(iv, sizeof(iv), K + HW_SESSION_KEY_LEN, HW_GCM_IV_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); + return DEVICEMANAGER_COPY_FAILED; + } + DmCryptInfo info = { session,HW_SESSION_KEY_LEN,iv,HW_GCM_IV_LEN }; + ret = MbedtlsAesGcmEncrypt(&info, plainText, plainTextLen, cipherText + HW_RANDOM_KEY_LEN, + cipherTextLen - HW_RANDOM_KEY_LEN); + if (ret <= 0) { + return ENCRYPT_UTILS_AES_GCM_ENCRYPT_FAILED; + } + // 拼接随机值和密文 + if (memcpy_s(cipherText, HW_RANDOM_KEY_LEN, randomKey, HW_RANDOM_KEY_LEN) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_COPY_FAILED; + } + if (outLen) { + *outLen = ret + HW_RANDOM_KEY_LEN; + } + return DEVICEMANAGER_OK; +} + +int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t* cipherText, int32_t cipherTextLen, uint8_t* plainText, + int32_t plainTextLen, int32_t* outLen) +{ + uint8_t rootKey[24] = {0}; + uint8_t session[HW_SESSION_KEY_LEN] = {0}; + uint8_t iv[12] = {0}; + const uint8_t* randomKey = cipherText; + int32_t rootKeyLen = 0; + int32_t ret = DEVICEMANAGER_OK; + uint8_t K[MBEDTLS_MD_MAX_SIZE] = {0}; + + if (plainText == nullptr || plainTextLen <= 0 || cipherText == nullptr || cipherTextLen <= 0) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + if (cipherTextLen > HW_RANDOM_KEY_LEN && (cipherTextLen - HW_RANDOM_KEY_LEN) > plainTextLen) { + return ENCRYPT_UTILS_INVALID_PARAM; + } + MbedtlsGenRootKey(rootKey, sizeof(rootKey), &rootKeyLen); + mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), rootKey, rootKeyLen, randomKey, + HW_RANDOM_KEY_LEN, K); + if (memcpy_s(session, sizeof(session), K, HW_SESSION_KEY_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); + return DEVICEMANAGER_COPY_FAILED; + } + if (memcpy_s(iv, sizeof(iv), K + HW_SESSION_KEY_LEN, HW_GCM_IV_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); + return DEVICEMANAGER_COPY_FAILED; + } + + DmCryptInfo info = {session, HW_SESSION_KEY_LEN, iv, HW_GCM_IV_LEN}; + ret = MbedtlsAesGcmDecrypt(&info, cipherText + HW_RANDOM_KEY_LEN, cipherTextLen - HW_RANDOM_KEY_LEN, + plainText, plainTextLen); + if (ret <= 0) { + return ENCRYPT_UTILS_AES_GCM_DECRYPT_FAILED; + } + if (outLen) { + *outLen = ret; + } + return DEVICEMANAGER_OK; +} + +bool EncryptUtils::MbedtlsGenRandomStr(char* szOut, int32_t szOutLen, bool numberOnly) +{ + if (szOut == nullptr || szOutLen <= 2) { + return false; + } + szOut[--szOutLen] = 0; + GetRandomData((uint8_t*)szOut, szOutLen); + const int NUMBER_COUNT = 10; + const int ALPHA_COUNT = 26; + int M = numberOnly ? NUMBER_COUNT : (NUMBER_COUNT + 2 * ALPHA_COUNT); + for (int i = 0; i < szOutLen; i++) { + // 0~9,A~Z,a~z + unsigned int idx = ((unsigned int)szOut[i] % M); + char base; + if (idx < NUMBER_COUNT) { + base = '0'; + } else if (idx >= NUMBER_COUNT && idx < (NUMBER_COUNT + ALPHA_COUNT)) { + base = 'A'; + idx -= NUMBER_COUNT; + } else { + base = 'a'; + idx -= (NUMBER_COUNT + ALPHA_COUNT); + } + szOut[i] = base + idx; + } + return true; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp b/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp new file mode 100644 index 000000000..5cbd3b318 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "securec.h" + +#include "anonymous_string.h" +#include "auth_manager.h" +#include "constants.h" +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "encrypt_utils.h" +#include "ipc_server_adapter.h" +#include "ipc_server_listener.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcServerAdapter); + +int32_t IpcServerAdapter::CheckParamValid(nlohmann::json &extraJson, const DmAppImageInfo &imageInfo) +{ + if (!extraJson.contains(APP_NAME_KEY) || + !extraJson.contains(APP_DESCRIPTION_KEY) || + !extraJson.contains(AUTH_TYPE)) { + DMLog(DM_LOG_ERROR, "Invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + + std::string appName = extraJson[APP_NAME_KEY]; + std::string appDescription = extraJson[APP_DESCRIPTION_KEY]; + + if (appName.empty() || appDescription.empty()) { + DMLog(DM_LOG_ERROR, "Invalid app image info"); + return DEVICEMANAGER_INVALID_VALUE; + } + if (extraJson[AUTH_TYPE] != AUTH_TYPE_PIN) { + DMLog(DM_LOG_ERROR, "invalid auth type, only support pin auth"); + return DEVICEMANAGER_INVALID_VALUE; + } + extraJson[PIN_TOKEN] = IpcServerAdapter::GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN); + return DEVICEMANAGER_OK; +} + +int32_t IpcServerAdapter::GenRandInt(int32_t randMin, int32_t randMax) +{ + std::random_device randDevice; + std::mt19937 genRand(randDevice()); + std::uniform_int_distribution disRand(randMin, randMax); + return disRand(genRand); +} + +int32_t IpcServerAdapter::ModuleInit() +{ + if (SoftbusAdapter::Init() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "softbus adapter init failed"); + return DEVICEMANAGER_INIT_FAILED; + } + if (HichainConnector::GetInstance().Init() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "hichain connector init failed"); + return DEVICEMANAGER_INIT_FAILED; + } + return DEVICEMANAGER_OK; +} + +int32_t IpcServerAdapter::GetTrustedDeviceList(std::string &pkgName, std::string &extra, + DmDeviceInfo **info, int32_t *infoNum) +{ + DMLog(DM_LOG_INFO, "In, pkgName: %s", pkgName.c_str()); + NodeBasicInfo *nodeInfo = nullptr; + int32_t ret = SoftbusAdapter::GetTrustDevices(pkgName, &nodeInfo, infoNum); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "DM_GetSoftbusTrustDevices failed with ret %d", ret); + return ret; + } + *info = nullptr; + if (*infoNum > 0) { + *info = (DmDeviceInfo *)malloc(sizeof(DmDeviceInfo) * (*infoNum)); + } + for (int32_t i = 0; i < *infoNum; ++i) { + NodeBasicInfo *nodeBasicInfo = nodeInfo + i; + DmDeviceInfo * deviceInfo = *info + i; + + (void)memcpy_s(deviceInfo->deviceId, sizeof(deviceInfo->deviceId), nodeBasicInfo->networkId, + std::min(sizeof(deviceInfo->deviceId), sizeof(nodeBasicInfo->networkId))); + (void)memcpy_s(deviceInfo->deviceName, sizeof(deviceInfo->deviceName), nodeBasicInfo->deviceName, + std::min(sizeof(deviceInfo->deviceName), sizeof(nodeBasicInfo->deviceName))); + deviceInfo->deviceTypeId = (DMDeviceType)nodeBasicInfo->deviceTypeId; + } + FreeNodeInfo(nodeInfo); + DMLog(DM_LOG_INFO, "success, pkgName:%s, deviceCount %d", pkgName.c_str(), *infoNum); + return DEVICEMANAGER_OK; +} + +int32_t IpcServerAdapter::StartDeviceDiscovery(std::string &pkgName, DmSubscribeInfo &dmSubscribeInfo) +{ + DMLog(DM_LOG_INFO, "In, pkgName: %s, subscribeId %d", pkgName.c_str(), + (int32_t)dmSubscribeInfo.subscribeId); + + DMLog(DM_LOG_INFO, "capability: %s", dmSubscribeInfo.capability); + SubscribeInfo subscribeInfo; + + subscribeInfo.subscribeId = dmSubscribeInfo.subscribeId; + subscribeInfo.mode = (DiscoverMode)dmSubscribeInfo.mode; + subscribeInfo.medium = (ExchanageMedium)dmSubscribeInfo.medium; + subscribeInfo.freq = (ExchangeFreq)dmSubscribeInfo.freq; + subscribeInfo.isSameAccount = dmSubscribeInfo.isSameAccount; + subscribeInfo.isWakeRemote = dmSubscribeInfo.isWakeRemote; + subscribeInfo.capability = dmSubscribeInfo.capability; + subscribeInfo.capabilityData = nullptr; + subscribeInfo.dataLen = 0; + return SoftbusAdapter::StartDiscovery(pkgName, &subscribeInfo); +} + +int32_t IpcServerAdapter::StopDiscovery(std::string &pkgName, uint16_t subscribeId) +{ + DMLog(DM_LOG_INFO, "In, pkgName: %s, subscribeId %d", pkgName.c_str(), (int32_t)subscribeId); + return SoftbusAdapter::StopDiscovery(pkgName, subscribeId); +} + +int32_t IpcServerAdapter::AuthenticateDevice(std::string &pkgName, const DmDeviceInfo &deviceInfo, + const DmAppImageInfo &imageInfo, std::string &extra) +{ + if (pkgName.empty() || extra.empty()) { + DMLog(DM_LOG_ERROR, "invalid para"); + return DEVICEMANAGER_INVALID_VALUE; + } + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "AuthenticateDevice extra jsonStr error"); + return DEVICEMANAGER_INVALID_VALUE; + } + int32_t ret = CheckParamValid(jsonObject, imageInfo); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "AuthenticateDevice para invalid, ret %d", ret); + return ret; + } + DMLog(DM_LOG_INFO, "AuthenticateDevice In, pkgName: %s, deviceId %s", pkgName.c_str(), + GetAnonyString(deviceInfo.deviceId).c_str()); + + AuthManager::GetInstance().authDeviceGroup(pkgName, deviceInfo, imageInfo, extra); + return DEVICEMANAGER_OK; +} + +int32_t IpcServerAdapter::CheckAuthentication(std::string &authPara) +{ + if (authPara.empty()) { + DMLog(DM_LOG_INFO, " DeviceManagerIpcAdapter::CheckAuthentication check authPara failed"); + return DEVICEMANAGER_INVALID_VALUE; + } + return AuthManager::GetInstance().checkAuthentication(authPara); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp b/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp new file mode 100644 index 000000000..1fcdd777a --- /dev/null +++ b/services/devicemanagerservice/src/ipc/ipc_server_listener_adapter.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_listener_adapter.h" + +#include + +#include "securec.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "anonymous_string.h" + +#include "ipc_notify_auth_result_req.h" +#include "ipc_notify_check_auth_result_req.h" +#include "ipc_notify_device_found_req.h" +#include "ipc_notify_device_state_req.h" +#include "ipc_notify_discover_result_req.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcServerListenerAdapter); + +void IpcServerListenerAdapter::OnDeviceStateChange(DmDeviceState state, DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "OnDeviceStateChange"); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetDeviceState(state); + pReq->SetDeviceInfo(deviceInfo); + ipcServerListener_.SendAll(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); +} + +void IpcServerListenerAdapter::OnDeviceFound(std::string &pkgName, uint16_t originId, + DmDeviceInfo &deviceInfo) +{ + DMLog(DM_LOG_INFO, "call OnDeviceFound for %s, originId %d, deviceId %s", + pkgName.c_str(), originId, GetAnonyString(std::string(deviceInfo.deviceId)).c_str()); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetSubscribeId(originId); + pReq->SetDeviceInfo(deviceInfo); + ipcServerListener_.SendRequest(SERVER_DEVICE_FOUND, pReq, pRsp); +} + +void IpcServerListenerAdapter::OnDiscoverFailed(std::string &pkgName, uint16_t originId, + DiscoveryFailReason failReason) +{ + DMLog(DM_LOG_INFO, "OnDiscoverFailed"); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetSubscribeId(originId); + pReq->SetResult(failReason); + ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); +} + +void IpcServerListenerAdapter::OnDiscoverySuccess(std::string &pkgName, uint16_t originId) +{ + DMLog(DM_LOG_INFO, "OnDiscoverySuccess"); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetSubscribeId(originId); + pReq->SetResult(DEVICEMANAGER_OK); + ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); +} + +void IpcServerListenerAdapter::OnAuthResult(std::string &pkgName, std::string &deviceId, int32_t pinToken, + uint32_t status, uint32_t reason) +{ + DMLog(DM_LOG_INFO, "%s, package: %s, deviceId: %s", __FUNCTION__, pkgName.c_str(), + GetAnonyString(deviceId).c_str()); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetDeviceId(deviceId); + pReq->SetPinToken(pinToken); + pReq->SetStatus(status); + pReq->SetReason(reason); + ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); +} + +void IpcServerListenerAdapter::OnCheckAuthResult(std::string &pkgName, std::string &deviceId, int32_t resultCode, + int32_t flag) +{ + DMLog(DM_LOG_INFO, "OnCheckResult, deviceId: %s, errorCode: %d", + GetAnonyString(deviceId).c_str(), resultCode); + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + + pReq->SetPkgName(pkgName); + pReq->SetDeviceId(deviceId); + pReq->SetResult(resultCode); + pReq->SetFlag(flag); + ipcServerListener_.SendRequest(SERVER_CHECK_AUTH_RESULT, pReq, pRsp); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp new file mode 100644 index 000000000..30edc35f5 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +#include "ipc_def.h" +#include "ipc_notify_auth_result_req.h" +#include "ipc_notify_check_auth_result_req.h" +#include "ipc_notify_device_found_req.h" +#include "ipc_notify_device_state_req.h" +#include "ipc_notify_discover_result_req.h" +#include "ipc_server_adapter.h" +#include "ipc_server_stub.h" + +namespace OHOS { +namespace DistributedHardware { +ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + int32_t deviceState = pReq->GetDeviceState(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushInt32(&request, deviceState); + IpcIoPushFlatObj(&request, &deviceInfo, sizeof(DmDeviceInfo)); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushUint16(&request, subscribeId); + IpcIoPushFlatObj(&request, &deviceInfo, sizeof(DmDeviceInfo)); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + int32_t result = pReq->GetResult(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushUint16(&request, subscribeId); + IpcIoPushInt32(&request, result); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string deviceId = pReq->GetDeviceId(); + int32_t pinToken = pReq->GetPinToken(); + int32_t status = pReq->GetStatus(); + int32_t reason = pReq->GetReason(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushString(&request, deviceId.c_str()); + IpcIoPushInt32(&request, pinToken); + IpcIoPushInt32(&request, status); + IpcIoPushInt32(&request, reason); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_CHECK_AUTH_RESULT, std::shared_ptr pBaseReq, IpcIo& request, + uint8_t *buffer, size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string deviceId = pReq->GetDeviceId(); + int32_t result = pReq->GetResult(); + int32_t flag = pReq->GetFlag(); + + IpcIoInit(&request, buffer, buffLen, 0); + IpcIoPushString(&request, pkgName.c_str()); + IpcIoPushString(&request, deviceId.c_str()); + IpcIoPushInt32(&request, result); + IpcIoPushInt32(&request, flag); + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_CHECK_AUTH_RESULT, IpcIo& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(IpcIoPopInt32(&reply)); + return DEVICEMANAGER_OK; +} + +ON_IPC_SERVER_CMD(GET_TRUST_DEVICE_LIST, void *origin, IpcIo &req, IpcIo &reply) +{ + DMLog(DM_LOG_INFO, "enter GetTrustedDeviceList."); + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&req, &len); + std::string extra = (const char *)IpcIoPopString(&req, &len); + DmDeviceInfo *info = nullptr; + int32_t infoNum = 0; + int32_t ret = IpcServerAdapter::GetInstance().GetTrustedDeviceList(pkgName, extra, &info, &infoNum); + IpcIoPushInt32(&reply, infoNum); + if (infoNum > 0) { + IpcIoPushFlatObj(&reply, info, sizeof(DmDeviceInfo) * infoNum); + free(info); + } + IpcIoPushInt32(&reply, ret); +} + +ON_IPC_SERVER_CMD(REGISTER_DEVICE_MANAGER_LISTENER, void *origin, IpcIo &req, IpcIo &reply) +{ + RegisterDeviceManagerListener(origin, &req, &reply); +} + +ON_IPC_SERVER_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, void *origin, IpcIo &req, IpcIo &reply) +{ + UnRegisterDeviceManagerListener(origin, &req, &reply); +} + +ON_IPC_SERVER_CMD(START_DEVICE_DISCOVER, void *origin, IpcIo &req, IpcIo &reply) +{ + DMLog(DM_LOG_INFO, "StartDeviceDiscovery service listener."); + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&req, &len); + uint32_t size = 0; + DmSubscribeInfo *pDmSubscribeInfo = (DmSubscribeInfo*)IpcIoPopFlatObj(&req, &size); + + int32_t ret = IpcServerAdapter::GetInstance().StartDeviceDiscovery(pkgName, *pDmSubscribeInfo); + IpcIoPushInt32(&reply, ret); +} + +ON_IPC_SERVER_CMD(STOP_DEVICE_DISCOVER, void *origin, IpcIo &req, IpcIo &reply) +{ + DMLog(DM_LOG_INFO, "StopDeviceDiscovery service listener."); + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&req, &len); + uint16_t subscribeId = IpcIoPopUint16(&req); + int32_t ret = IpcServerAdapter::GetInstance().StopDiscovery(pkgName, subscribeId); + IpcIoPushInt32(&reply, ret); +} + +ON_IPC_SERVER_CMD(AUTHENTICATE_DEVICE, void *origin, IpcIo &req, IpcIo &reply) +{ + DMLog(DM_LOG_INFO, "AuthenticateDevice service listener."); + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(&req, &len); + size_t extraLen = 0; + std::string extra = (const char *)IpcIoPopString(&req, &extraLen); + uint32_t size; + DmDeviceInfo *deviceInfo = (DmDeviceInfo*)IpcIoPopFlatObj(&req, &size); + DmAppImageInfo imageInfo; + int32_t ret = IpcServerAdapter::GetInstance().AuthenticateDevice(pkgName, *deviceInfo, imageInfo, extra); + IpcIoPushInt32(&reply, ret); +} + +ON_IPC_SERVER_CMD(CHECK_AUTHENTICATION, void *origin, IpcIo &req, IpcIo &reply) +{ + DMLog(DM_LOG_INFO, "CheckAuthentication service listener."); + size_t authParaLen = 0; + std::string authPara = (const char *)IpcIoPopString(&req, &authParaLen); + int32_t ret = IpcServerAdapter::GetInstance().CheckAuthentication(authPara); + IpcIoPushInt32(&reply, ret); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_listener.cpp new file mode 100644 index 000000000..01063b4e3 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_listener.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_listener.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" + +#include "ipc_cmd_register.h" +#include "ipc_def.h" +#include "ipc_server_listenermgr.h" +#include "ipc_server_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcServerListener::CommonSvcToIdentity(CommonSvcId *svcId, SvcIdentity *identity) +{ + identity->handle = svcId->handle; + identity->token = svcId->token; + identity->cookie = svcId->cookie; +#ifdef __LINUX__ + identity->ipcContext = svcId->ipcCtx; +#endif +} + +int32_t IpcServerListener::GetIdentityByPkgName(std::string &name, SvcIdentity *svc) +{ + CommonSvcId svcId; + if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(name, &svcId) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "get identity failed."); + return DEVICEMANAGER_FAILED; + } + CommonSvcToIdentity(&svcId, svc); + return DEVICEMANAGER_OK; +} + +int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + std::string pkgName = req->GetPkgName(); + SvcIdentity svc; + if (GetIdentityByPkgName(pkgName, &svc) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "ondevice found callback get listener failed."); + return DEVICEMANAGER_FAILED; + } + + IpcIo io; + uint8_t data[MAX_DM_IPC_LEN] = {0}; + if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_DEBUG, "SetRequest failed cmdCode:%d", cmdCode); + return DEVICEMANAGER_FAILED; + } + if (::SendRequest(nullptr, svc, cmdCode, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_DEBUG, "SendRequest failed cmdCode:%d", cmdCode); + } + return DEVICEMANAGER_OK; +} + +int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + const std::map& listenerMap = IpcServerListenermgr::GetInstance().GetAllListeners(); + for (auto &kv : listenerMap) { + SvcIdentity svc; + IpcIo io; + uint8_t data[MAX_DM_IPC_LEN] = {0}; + if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, io, data, MAX_DM_IPC_LEN) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_DEBUG, "SetRequest failed cmdCode:%d", cmdCode); + continue; + } + CommonSvcId svcId = kv.second; + CommonSvcToIdentity(&svcId, &svc); + if (::SendRequest(nullptr, svc, cmdCode, &io, nullptr, LITEIPC_FLAG_ONEWAY, nullptr) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_DEBUG, "SendRequest failed cmdCode:%d", cmdCode); + } + } + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp new file mode 100644 index 000000000..032c2054b --- /dev/null +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_listenermgr.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcServerListenermgr); + +int32_t IpcServerListenermgr::RegisterListener(std::string &pkgName, const CommonSvcId *svcId) +{ + if (pkgName == "" || svcId == nullptr) { + DMLog(DM_LOG_ERROR, "invalid param"); + return DEVICEMANAGER_FAILED; + } + DMLog(DM_LOG_INFO, "new listener register:%s", pkgName.c_str()); + std::lock_guard autoLock(lock_); + dmListenerMap_[pkgName] = *svcId; + return DEVICEMANAGER_OK; +} + +int32_t IpcServerListenermgr::GetListenerByPkgName(std::string &pkgName, CommonSvcId *svcId) +{ + if (pkgName == "" || svcId == nullptr) { + DMLog(DM_LOG_ERROR, "invalid param"); + return DEVICEMANAGER_FAILED; + } + std::lock_guard autoLock(lock_); + std::map::iterator iter = dmListenerMap_.find(pkgName); + + if (iter == dmListenerMap_.end()) { + DMLog(DM_LOG_ERROR, "listener not found for pkg:%s", pkgName.c_str()); + return DEVICEMANAGER_FAILED; + } + *svcId = iter->second; + return DEVICEMANAGER_OK; +} + +int32_t IpcServerListenermgr::UnregisterListener(std::string &pkgName) +{ + std::lock_guard autoLock(lock_); + dmListenerMap_.erase(pkgName); + return DEVICEMANAGER_OK; +} + +const std::map& IpcServerListenermgr::GetAllListeners() +{ + return dmListenerMap_; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp new file mode 100644 index 000000000..fd13e62fd --- /dev/null +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "device_manager_log.h" +#include "device_manager_errno.h" + +#include "ipc_server_stub.h" +#include "ipc_server_adapter.h" + +namespace { + const int32_t DM_SERVICE_INIT_DELAY = 5; +} + +using namespace OHOS::DistributedHardware; + +static void InitAll() +{ + sleep(DM_SERVICE_INIT_DELAY); + if (IpcServerStubInit() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "IpcServerStubInit failed"); + return; + } + if (IpcServerAdapter::GetInstance().ModuleInit() != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "module init failed"); + return; + } + DMLog(DM_LOG_INFO, "DM ipc server Init success"); +} + +int32_t main(int32_t argc, char* argv[]) +{ + InitAll(); + while (1) { + pause(); + } + return 0; +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp new file mode 100644 index 000000000..78324ffa8 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_stub.h" + +#include "securec.h" + +#include "liteipc_adapter.h" +#include "ohos_init.h" +#include "samgr_lite.h" +#include "iproxy_server.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" +#include "dm_subscribe_info.h" + +#include "ipc_cmd_register.h" +#include "ipc_def.h" +#include "ipc_server_listenermgr.h" +#include "ipc_server_adapter.h" + +namespace { + const int32_t WAIT_FOR_SERVER = 2; + const int32_t STACK_SIZE = 0x800; + const int32_t QUEUE_SIZE = 20; +} + +using namespace OHOS::DistributedHardware; + +typedef struct { + INHERIT_SERVER_IPROXY; +} DefaultFeatureApi; + +typedef struct { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} DeviceManagerSamgrService; + +static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, void *arg) +{ + if (arg == NULL) { + DMLog(DM_LOG_ERROR, "package name is NULL."); + return DEVICEMANAGER_INVALID_PARAM; + } + CommonSvcId svcId = {0}; + std::string pkgName = (const char *)arg; + if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "not found client by package name."); + free(arg); + arg = NULL; + return DEVICEMANAGER_FAILED; + } + IpcServerListenermgr::GetInstance().UnregisterListener(pkgName); + free(arg); + arg = NULL; +#ifdef __LINUX__ + BinderRelease(svcId.ipcCtx, svcId.handle); +#endif + SvcIdentity sid = {0}; + sid.handle = svcId.handle; + sid.token = svcId.token; + sid.cookie = svcId.cookie; + UnregisterDeathCallback(sid, svcId.cbId); + + return DEVICEMANAGER_OK; +} + +int32_t RegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply) +{ + DMLog(DM_LOG_INFO, "register service listener."); + size_t len = 0; + int32_t ret = DEVICEMANAGER_OK; + uint8_t *name = IpcIoPopString(req, &len); + SvcIdentity *svc = IpcIoPopSvc(req); + if (name == NULL || svc == NULL || len == 0) { + DMLog(DM_LOG_ERROR, "get para failed"); + IpcIoPushInt32(reply, ret); + return DEVICEMANAGER_OK; + } + + CommonSvcId svcId = {0}; + svcId.handle = svc->handle; + svcId.token = svc->token; + svcId.cookie = svc->cookie; + + SvcIdentity sid = *svc; +#ifdef __LINUX__ + svcId.ipcCtx = svc->ipcContext; + BinderAcquire(svcId.ipcCtx, svcId.handle); + free(svc); + svc = NULL; +#endif + + char *pkgName = (char *)malloc(len + 1); + if (pkgName == NULL) { + DMLog(DM_LOG_ERROR, "malloc failed!"); + IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); + return DEVICEMANAGER_FAILED; + } + if (strcpy_s(pkgName, len + 1, (const char *)name) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "strcpy_s failed!"); + free(pkgName); + IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); + return DEVICEMANAGER_FAILED; + } + uint32_t cbId = 0; + RegisterDeathCallback(NULL, sid, DeathCb, pkgName, &cbId); + svcId.cbId = cbId; + std::string strPkgName = (const char *)name; + ret = IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); + IpcIoPushInt32(reply, ret); + return DEVICEMANAGER_OK; +} + +int32_t UnRegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply) +{ + DMLog(DM_LOG_INFO, "unregister service listener."); + size_t len = 0; + std::string pkgName = (const char *)IpcIoPopString(req, &len); + if (pkgName == "" || len == 0) { + DMLog(DM_LOG_ERROR, "get para failed"); + return DEVICEMANAGER_FAILED; + } + + CommonSvcId svcId = {0}; + if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "not found listener by package name."); + return DEVICEMANAGER_FAILED; + } + int32_t ret = IpcServerListenermgr::GetInstance().UnregisterListener(pkgName); + if (ret == DEVICEMANAGER_OK) { +#ifdef __LINUX__ + BinderRelease(svcId.ipcCtx, svcId.handle); +#endif + SvcIdentity sid = {0}; + sid.handle = svcId.handle; + sid.token = svcId.token; + sid.cookie = svcId.cookie; + ret = UnregisterDeathCallback(sid, svcId.cbId); + } + IpcIoPushInt32(reply, ret); + return DEVICEMANAGER_OK; +} + +static const char *GetName(Service *service) +{ + (void)service; + return DEVICE_MANAGER_SERVICE_NAME; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + if (service == NULL) { + DMLog(DM_LOG_WARN, "invalid param"); + return FALSE; + } + + DeviceManagerSamgrService *mgrService = (DeviceManagerSamgrService *)service; + mgrService->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *request) +{ + if ((service == NULL) || (request == NULL)) { + DMLog(DM_LOG_WARN, "invalid param"); + return FALSE; + } + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, STACK_SIZE, QUEUE_SIZE, SHARED_TASK}; + return config; +} + +int32_t OnRemoteRequest(IServerProxy *iProxy, int funcId, void *origin, + IpcIo *req, IpcIo * reply) +{ + DMLog(DM_LOG_INFO, "Receive funcId:%d", funcId); + return IpcCmdRegister::GetInstance().OnIpcServerCmd(funcId, origin, *req, *reply); +} + +void __attribute__((weak)) HOS_SystemInit(void) +{ + SAMGR_Bootstrap(); + return; +} + +int32_t IpcServerStubInit(void) +{ + HOS_SystemInit(); + return DEVICEMANAGER_OK; +} + +void DevMgrSvcInit(void) +{ + sleep(WAIT_FOR_SERVER); + static DeviceManagerSamgrService service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + SERVER_IPROXY_IMPL_BEGIN, + .Invoke = OnRemoteRequest, + IPROXY_END, + }; + + if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) { + DMLog(DM_LOG_ERROR, "%s, RegisterService failed", DEVICE_MANAGER_SERVICE_NAME); + return; + } + if (!SAMGR_GetInstance()->RegisterDefaultFeatureApi(DEVICE_MANAGER_SERVICE_NAME, GET_IUNKNOWN(service))) { + DMLog(DM_LOG_ERROR, "%s, RegisterDefaultFeatureApi failed", DEVICE_MANAGER_SERVICE_NAME); + return; + } + DMLog(DM_LOG_INFO, "%s, init success", DEVICE_MANAGER_SERVICE_NAME); +} +SYSEX_SERVICE_INIT(DevMgrSvcInit); diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp new file mode 100644 index 000000000..f1c221a70 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_cmd_register.h" +#include "ipc_def.h" +#include "ipc_notify_auth_result_req.h" +#include "ipc_notify_check_auth_result_req.h" +#include "ipc_notify_device_found_req.h" +#include "ipc_notify_device_state_req.h" +#include "ipc_notify_discover_result_req.h" +#include "ipc_server_adapter.h" +#include "ipc_server_stub.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +namespace OHOS { +namespace DistributedHardware { +ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + int32_t deviceState = pReq->GetDeviceState(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(deviceState)) { + DMLog(DM_LOG_ERROR, "write state failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) { + DMLog(DM_LOG_ERROR, "write deviceInfo failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt16(subscribeId)) { + DMLog(DM_LOG_ERROR, "write subscribeId failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteRawData(&deviceInfo, sizeof(DmDeviceInfo))) { + DMLog(DM_LOG_ERROR, "write deviceInfo failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + int32_t result = pReq->GetResult(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt16(subscribeId)) { + DMLog(DM_LOG_ERROR, "write subscribeId failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string deviceId = pReq->GetDeviceId(); + int32_t pinToken = pReq->GetPinToken(); + int32_t status = pReq->GetStatus(); + int32_t reason = pReq->GetReason(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteString(deviceId)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(pinToken)) { + DMLog(DM_LOG_ERROR, "write pinToken failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(status)) { + DMLog(DM_LOG_ERROR, "write status failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(reason)) { + DMLog(DM_LOG_ERROR, "write reason failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_SET_REQUEST(SERVER_CHECK_AUTH_RESULT, std::shared_ptr pBaseReq, MessageParcel& data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string deviceId = pReq->GetDeviceId(); + int32_t result = pReq->GetResult(); + int32_t flag = pReq->GetFlag(); + if (!data.WriteString(pkgName)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteString(deviceId)) { + DMLog(DM_LOG_ERROR, "write pkgName failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + if (!data.WriteInt32(flag)) { + DMLog(DM_LOG_ERROR, "write flag failed"); + return DEVICEMANAGER_FLATTEN_OBJECT; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_CHECK_AUTH_RESULT, MessageParcel& reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string extra = data.ReadString(); + DMLog(DM_LOG_INFO, "pkgName:%s, extra:%s", pkgName.c_str(), extra.c_str()); + DmDeviceInfo *info = nullptr; + int32_t infoNum = 0; + int32_t result = IpcServerAdapter::GetInstance().GetTrustedDeviceList(pkgName, extra, &info, &infoNum); + reply.WriteInt32(infoNum); + if (infoNum > 0 && info != nullptr) { + if (!reply.WriteRawData(info, sizeof(DmDeviceInfo) * infoNum)) { + DMLog(DM_LOG_ERROR, "write subscribeInfo failed"); + } + free(info); + } + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + sptr listener = data.ReadRemoteObject(); + int32_t result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int32_t result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(START_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + DmSubscribeInfo *subscribeInfo = (DmSubscribeInfo *)data.ReadRawData(sizeof(DmSubscribeInfo)); + DMLog(DM_LOG_INFO, "pkgName:%s, subscribeId: %d", pkgName.c_str(), subscribeInfo->subscribeId); + int32_t result = IpcServerAdapter::GetInstance().StartDeviceDiscovery(pkgName, *subscribeInfo); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(STOP_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + uint16_t subscribeId = data.ReadInt32(); + DMLog(DM_LOG_INFO, "pkgName:%s, subscribeId: %d", pkgName.c_str(), subscribeId); + int32_t result = IpcServerAdapter::GetInstance().StopDiscovery(pkgName, subscribeId); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string extra = data.ReadString(); + DmDeviceInfo *deviceInfo = (DmDeviceInfo *)data.ReadRawData(sizeof(DmDeviceInfo)); + DmAppImageInfo imageInfo; + + imageInfo.appIconLen = data.ReadInt32(); + imageInfo.appThumbnailLen = data.ReadInt32(); + imageInfo.appIcon = imageInfo.appIconLen > 0? (const uint8_t *)data.ReadRawData(imageInfo.appIconLen) : nullptr; + imageInfo.appThumbnail = + imageInfo.appThumbnailLen > 0? (const uint8_t *)data.ReadRawData(imageInfo.appThumbnailLen) : nullptr; + DMLog(DM_LOG_INFO, "pkgName:%s, extra:%s", pkgName.c_str(), extra.c_str()); + int32_t result = IpcServerAdapter::GetInstance().AuthenticateDevice(pkgName, *deviceInfo, imageInfo, extra); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} + +ON_IPC_CMD(CHECK_AUTHENTICATION, MessageParcel &data, MessageParcel &reply) +{ + std::string authPara = data.ReadString(); + int32_t result = IpcServerAdapter::GetInstance().CheckAuthentication(authPara); + if (!reply.WriteInt32(result)) { + DMLog(DM_LOG_ERROR, "write result failed"); + return DEVICEMANAGER_WRITE_FAILED; + } + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp new file mode 100644 index 000000000..02ad480e0 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_client_proxy.h" + +#include "ipc_types.h" + +#include "ipc_cmd_register.h" +#include "ipc_def.h" +#include "device_manager_log.h" +#include "device_manager_errno.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcServerClientProxy::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DMLog(DM_LOG_ERROR, "remote service null"); + return DEVICEMANAGER_NULLPTR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DEVICEMANAGER_OK) { + return DEVICEMANAGER_FAILED; + } + if (remote->SendRequest(cmdCode, data, reply, option) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "SendRequest fail, cmd:%d", cmdCode); + return DEVICEMANAGER_IPC_FAILED; + } + return IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp new file mode 100644 index 000000000..5134f011d --- /dev/null +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_listener.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +#include "ipc_server_stub.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + std::string pkgName = req->GetPkgName(); + sptr listener = IpcServerStub::GetInstance().GetDmListener(pkgName); + if (listener == nullptr) { + DMLog(DM_LOG_INFO, "cannot get listener for package:%s.", pkgName.c_str()); + return DEVICEMANAGER_NULLPTR; + } + return listener->SendCmd(cmdCode, req, rsp); +} + +int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + std::map> listeners = IpcServerStub::GetInstance().GetDmListener(); + for (auto iter : listeners) { + auto pkgName = iter.first; + auto remote = iter.second; + req->SetPkgName(pkgName); + sptr listener = iface_cast(remote); + listener->SendCmd(cmdCode, req, rsp); + } + return DEVICEMANAGER_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp new file mode 100644 index 000000000..8175b8715 --- /dev/null +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ipc_server_stub.h" + +#include +#include + +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iservice_registry.h" +#include "string_ex.h" +#include "system_ability_definition.h" + +#include "device_manager_errno.h" +#include "device_manager_log.h" + +#include "ipc_server_adapter.h" +#include "ipc_cmd_register.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(IpcServerStub); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&IpcServerStub::GetInstance()); + +IpcServerStub::IpcServerStub() : SystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, true) +{ + registerToService_ = false; + state_ = ServiceRunningState::STATE_NOT_START; +} + +void IpcServerStub::OnStart() +{ + DMLog(DM_LOG_INFO, "IpcServerStub::OnStart start"); + if (state_ == ServiceRunningState::STATE_RUNNING) { + DMLog(DM_LOG_DEBUG, "IpcServerStub has already started."); + return; + } + if (!Init()) { + DMLog(DM_LOG_ERROR, "failed to init IpcServerStub"); + return; + } + state_ = ServiceRunningState::STATE_RUNNING; +} + +bool IpcServerStub::Init() +{ + DMLog(DM_LOG_INFO, "IpcServerStub::Init ready to init."); + if (!registerToService_) { + bool ret = Publish(this); + if (!ret) { + DMLog(DM_LOG_ERROR, "IpcServerStub::Init Publish failed!"); + return false; + } + registerToService_ = true; + } + + std::thread {[] { + IpcServerAdapter::GetInstance().ModuleInit(); + }}.detach(); + return true; +} + +void IpcServerStub::OnStop() +{ + DMLog(DM_LOG_INFO, "IpcServerStub::OnStop ready to stop service."); + state_ = ServiceRunningState::STATE_NOT_START; + registerToService_ = false; +} + +int32_t IpcServerStub::OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel &reply, MessageOption &option) +{ + DMLog(DM_LOG_INFO, "code = %d, flags= %d.", code, option.GetFlags()); + int32_t ret = DEVICEMANAGER_OK; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply); + if (ret == DEVICEMANAGER_IPC_NOT_REGISTER_FUNC) { + DMLog(DM_LOG_WARN, "unsupport code: %d", code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return ret; +} + +int32_t IpcServerStub::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +{ + return DEVICEMANAGER_OK; +} + +ServiceRunningState IpcServerStub::QueryServiceState() const +{ + return state_; +} + +int32_t IpcServerStub::RegisterDeviceManagerListener(std::string &pkgName, sptr listener) +{ + if (pkgName.empty() || listener == nullptr) { + DMLog(DM_LOG_ERROR, "Error: parameter invalid"); + return DEVICEMANAGER_NULLPTR; + } + + DMLog(DM_LOG_INFO, "In, pkgName: %s", pkgName.c_str()); + std::lock_guard autoLock(listenerLock_); + auto iter = dmListener_.find(pkgName); + if (iter != dmListener_.end()) { + DMLog(DM_LOG_INFO, "RegisterDeviceManagerListener: listener already exists"); + return DEVICEMANAGER_OK; + } + + sptr appRecipient = sptr(new AppDeathRecipient()); + if (!listener->AddDeathRecipient(appRecipient)) { + DMLog(DM_LOG_ERROR, "RegisterDeviceManagerListener: AddDeathRecipient Failed"); + } + dmListener_[pkgName] = listener; + appRecipient_[pkgName] = appRecipient; + return DEVICEMANAGER_OK; +} + +int32_t IpcServerStub::UnRegisterDeviceManagerListener(std::string &pkgName) +{ + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "Error: parameter invalid"); + return DEVICEMANAGER_NULLPTR; + } + + DMLog(DM_LOG_INFO, "In, pkgName: %s", pkgName.c_str()); + std::lock_guard autoLock(listenerLock_); + auto listenerIter = dmListener_.find(pkgName); + if (listenerIter == dmListener_.end()) { + DMLog(DM_LOG_INFO, "UnRegisterDeviceManagerListener: listener not exists"); + return DEVICEMANAGER_OK; + } + + auto recipientIter = appRecipient_.find(pkgName); + if (recipientIter == appRecipient_.end()) { + DMLog(DM_LOG_INFO, "UnRegisterDeviceManagerListener: appRecipient not exists"); + dmListener_.erase(pkgName); + return DEVICEMANAGER_OK; + } + + auto listener = listenerIter->second; + auto appRecipient = recipientIter->second; + listener->RemoveDeathRecipient(appRecipient); + appRecipient_.erase(pkgName); + dmListener_.erase(pkgName); + return DEVICEMANAGER_OK; +} + +const std::map>& IpcServerStub::GetDmListener() +{ + return dmListener_; +} + +const sptr IpcServerStub::GetDmListener(std::string pkgName) const +{ + auto iter = dmListener_.find(pkgName); + if (iter == dmListener_.end()) { + return nullptr; + } + auto remote = iter->second; + sptr dmListener = iface_cast(remote); + return dmListener; +} + +void AppDeathRecipient::OnRemoteDied(const wptr& remote) +{ + DMLog(DM_LOG_WARN, "AppDeathRecipient: OnRemoteDied"); + std::map> listeners = IpcServerStub::GetInstance().GetDmListener(); + std::string pkgName; + for (auto iter : listeners) { + if (iter.second == remote.promote()) { + pkgName = iter.first; + break; + } + } + if (pkgName.empty()) { + DMLog(DM_LOG_ERROR, "AppDeathRecipient: OnRemoteDied, no pkgName matched"); + return; + } + DMLog(DM_LOG_INFO, "AppDeathRecipient: OnRemoteDied for %s", pkgName.c_str()); + IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/devicemanagerservice/src/message/msg_codec.cpp b/services/devicemanagerservice/src/message/msg_codec.cpp new file mode 100644 index 000000000..c3938b3ed --- /dev/null +++ b/services/devicemanagerservice/src/message/msg_codec.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "msg_codec.h" +#include "msg_common.h" + +#include "constants.h" +#include "device_manager_log.h" +#include "device_manager_errno.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t MsgCodec::decodeMsgType(std::string &jsonStr) +{ + nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "decodeMsgType jsonStr error"); + } + MsgHead mMsgHead; + auto msgHeadPtr = mMsgHead.decode(jsonObject); + if (msgHeadPtr == nullptr) { + DMLog(DM_LOG_ERROR, "mMsgHead decode error"); + return DEVICEMANAGER_NULLPTR; + } + return msgHeadPtr->getMsgType(); +} + +std::string MsgCodec::encodeSyncGroup(std::vector &groupIdList, std::string &deviceId) +{ + nlohmann::json jsonObject; + MsgSyncGroup mMsgSyncGroup(groupIdList, deviceId); + mMsgSyncGroup.encode(jsonObject); + return jsonObject.dump(); +} + +std::vector MsgCodec::encodeReqAppAuth(std::string &token, std::string hostPkg, std::string targetPkg, + const DmDeviceInfo& devReqInfo,const DmAppImageInfo &imageInfo, std::string &extras) +{ + MsgRequestAuth mMsgRequestAuth(token, hostPkg, targetPkg, devReqInfo, imageInfo, extras); + return mMsgRequestAuth.encode(); +} + +std::shared_ptr MsgCodec::decodeResponseAuth(std::string &jsonStr) +{ + nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "decodeResponseAuth jsonStr error"); + } + std::shared_ptr msgResponseAuthPtr = std::make_shared(); + if (msgResponseAuthPtr->decode(jsonObject) == 0) { + return msgResponseAuthPtr; + } + return nullptr; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/message/msg_common.cpp b/services/devicemanagerservice/src/message/msg_common.cpp new file mode 100644 index 000000000..3a4c5d886 --- /dev/null +++ b/services/devicemanagerservice/src/message/msg_common.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "msg_common.h" +#include "device_manager_log.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { +void MsgHead::encode(nlohmann::json &json) +{ + json[TAG_VER] = DM_ITF_VER; + json[TAG_TYPE] = mMsgType; +} + +std::shared_ptr MsgHead::decode(nlohmann::json &json) +{ + if (json.contains(TAG_TYPE) == false || json.contains(TAG_VER) == false) { + DMLog(DM_LOG_ERROR, "err json string"); + return nullptr; + } + + auto msgHeadPtr = std::make_shared(); + msgHeadPtr->mItfVer = json[TAG_VER]; + + if (DM_ITF_VER.compare(msgHeadPtr->mItfVer) == 0) { + msgHeadPtr->mMsgType = json[TAG_TYPE]; + } else { + DMLog(DM_LOG_ERROR, "msg head version mismatch"); + msgHeadPtr->mMsgType = DmMsgType::MSG_TYPE_UNKNOWN; + } + return msgHeadPtr; +} + +int32_t MsgHead::getMsgType() +{ + return mMsgType; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/message/msg_request_auth.cpp b/services/devicemanagerservice/src/message/msg_request_auth.cpp new file mode 100644 index 000000000..4ec7dbe2f --- /dev/null +++ b/services/devicemanagerservice/src/message/msg_request_auth.cpp @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "constants.h" +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "encrypt_utils.h" +#include "msg_request_auth.h" +#include "parameter.h" +#include "softbus_session.h" + +namespace OHOS { +namespace DistributedHardware { +MsgRequestAuth::MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, + const int32_t groupVisibility, const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, + std::string &extras) +{ + DMLog(DM_LOG_INFO, "MsgRequestAuth construction started"); + nlohmann::json jsonObject = nlohmann::json::parse(extras, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "MsgRequestAuth error"); + return; + } + if (!jsonObject.contains(APP_NAME_KEY) || !jsonObject.contains(APP_DESCRIPTION_KEY)) { + DMLog(DM_LOG_ERROR, "MsgRequestAuth, err json string"); + return; + } + + mAuthType = jsonObject.contains(AUTH_TYPE) ? (int32_t)jsonObject[AUTH_TYPE] : AUTH_TYPE_QR; + mHead = std::make_shared(mAuthType == AUTH_TYPE_QR ? DmMsgType::MSG_TYPE_REQ_AUTH : + DmMsgType::MSG_TYPE_AUTH_BY_PIN); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + mDeviceName = devReqInfo.deviceName; + mDeviceId = localDeviceId; + mToken = token; + mHostPkg = hostPkgName; + mTargetPkg = targetPkgName; + mGroupVisibility = groupVisibility; + mAppName = jsonObject[APP_NAME_KEY]; + mAppDescription = jsonObject[APP_DESCRIPTION_KEY]; + + std::string appIconStr = ""; + getEncodedAppInfo((uint8_t *)imageInfo.appIcon, imageInfo.appIconLen, appIconStr); + + std::string appThumbStr = ""; + getEncodedAppInfo((uint8_t *)imageInfo.appThumbnail, imageInfo.appThumbnailLen, appThumbStr); + + mAppIcon = appIconStr; + mAppThumbnail = appThumbStr; + mDeviceType = toHexString(devReqInfo.deviceTypeId); + DMLog(DM_LOG_INFO, "MsgRequestAuth construction completed"); +} + +int32_t MsgRequestAuth::getEncodedAppInfo(const uint8_t* dataSrc, size_t srcLen, std::string &outString) +{ + DMLog(DM_LOG_INFO, "MsgRequestAuth getEncodedAppInfo started"); + if (srcLen == 0 || dataSrc == nullptr) { + DMLog(DM_LOG_ERROR, "data string is empty"); + return DEVICEMANAGER_OK; + } + size_t outLen = 0; + char *tmpBuf = (char *)calloc(sizeof(char), THUMB_MAX_LEN); + if (tmpBuf == nullptr) { + DMLog(DM_LOG_ERROR, "getEncodedAppInfoString: malloc mem error"); + return DEVICEMANAGER_MALLOC_ERROR; + } + EncryptUtils::MbedtlsBase64Encode((uint8_t *)tmpBuf, THUMB_MAX_LEN, &outLen, dataSrc, srcLen); + if (outLen > THUMB_MAX_LEN) { + DMLog(DM_LOG_ERROR, "encode appIcon error"); + free(tmpBuf); + return ENCODE_DATA_ERROR; + } + outString = tmpBuf; + free(tmpBuf); + tmpBuf = nullptr; + DMLog(DM_LOG_INFO, "MsgRequestAuth getEncodedAppInfo completed"); + return DEVICEMANAGER_OK; +} + +std::string MsgRequestAuth::encodeDevInfo() +{ + DMLog(DM_LOG_INFO, "MsgRequestAuth encodeDevInfo started"); + nlohmann::json jsonObj; + mHead->encode(jsonObj); + jsonObj[TAG_SLICE_NUM] = mMsgSlice; + jsonObj[TAG_INDEX] = 0; + jsonObj[TAG_REQUESTER] = mDeviceName; + jsonObj[TAG_DEVICE_ID] = mDeviceId; + jsonObj[TAG_DEVICE_TYPE] = mDeviceType; + jsonObj[TAG_TOKEN] = mToken; + jsonObj[TAG_VISIBILITY] = mGroupVisibility; + if (mGroupVisibility == GROUP_VISIBILITY_IS_PRIVATE) { + jsonObj[TAG_TARGET] = mTargetPkg; + jsonObj[TAG_HOST] = mHostPkg; + } + jsonObj[TAG_APP_NAME] = mAppName; + jsonObj[TAG_APP_DESCRIPTION] = mAppDescription; + jsonObj[TAG_APP_ICON] = mAppIcon; + jsonObj[TAG_THUMBNAIL_SIZE] = mAppThumbnail.size(); + jsonObj[TAG_AUTH_TYPE] = mAuthType; + DMLog(DM_LOG_INFO, "MsgRequestAuth encodeDevInfo completed"); + return jsonObj.dump(); +} + +std::vector MsgRequestAuth::encode() +{ + DMLog(DM_LOG_INFO, "MsgRequestAuth encode started"); + std::vector jsonStrs; + int32_t thumbnailSlice = + (mAppThumbnail.size() / MSG_MAX_SIZE) + ((mAppThumbnail.size() % MSG_MAX_SIZE) == 0 ? 0 : 1); + mMsgSlice = thumbnailSlice + 1; + jsonStrs.push_back(encodeDevInfo()); + for (int32_t idx = 0; idx < thumbnailSlice; idx++) { + nlohmann::json jsonObj; + mHead->encode(jsonObj); + jsonObj[TAG_SLICE_NUM] = mMsgSlice; + jsonObj[TAG_INDEX] = idx + 1; + jsonObj[TAG_DEVICE_ID] = mDeviceId; + jsonObj[TAG_THUMBNAIL_SIZE] = mAppThumbnail.size(); + jsonObj[TAG_APP_THUMBNAIL] = stringSub(mAppThumbnail, idx * MSG_MAX_SIZE, MSG_MAX_SIZE); + jsonStrs.push_back(jsonObj.dump()); + } + DMLog(DM_LOG_INFO, "MsgRequestAuth encode completed"); + return jsonStrs; +} + +std::shared_ptr MsgRequestAuth::decode(nlohmann::json &json, std::shared_ptr msgIn) +{ + if (!json.contains(TAG_INDEX) || !json.contains(TAG_DEVICE_ID) || !json.contains(TAG_SLICE_NUM)) { + DMLog(DM_LOG_ERROR, "err json string, first time"); + return nullptr; + } + int32_t idx = json[TAG_INDEX]; + std::string deviceId = json[TAG_DEVICE_ID]; + if (!isMsgValid(msgIn, json, deviceId, idx)) { + auto inValidMsg = std::make_shared(); + inValidMsg->mMsgSlice = FAIL; + return inValidMsg; + } + + std::shared_ptr msg = msgIn; + if (msgIn->mMsgCnt == msgIn->mMsgSlice) { + msg = std::make_shared(); + } + msg->mHead = MsgHead::decode(json); + msg->mMsgSlice = json[TAG_SLICE_NUM]; + if (idx == 0) { + if (!json.contains(TAG_REQUESTER) || !json.contains(TAG_DEVICE_TYPE) || !json.contains(TAG_TOKEN) || + !json.contains(TAG_VISIBILITY) || !json.contains(TAG_APP_NAME) || !json.contains(TAG_APP_DESCRIPTION) || + !json.contains(TAG_APP_ICON)) { + DMLog(DM_LOG_ERROR, "err json string, second time"); + return nullptr; + } + msg->mDeviceName = json[TAG_REQUESTER]; + msg->mDeviceId = deviceId; + msg->mDeviceType = json[TAG_DEVICE_TYPE]; + msg->mToken = json[TAG_TOKEN]; + msg->mGroupVisibility = json[TAG_VISIBILITY]; + if (msg->mGroupVisibility == GROUP_VISIBILITY_IS_PRIVATE) { + if (!json.contains(TAG_TARGET) || !json.contains(TAG_HOST)) { + DMLog(DM_LOG_ERROR, "err json string, third time"); + return nullptr; + } + msg->mTargetPkg = json[TAG_TARGET]; + msg->mHostPkg = json[TAG_HOST]; + } + msg->mAppName = json[TAG_APP_NAME]; + msg->mAppDescription = json[TAG_APP_DESCRIPTION]; + msg->mAppIcon = json[TAG_APP_ICON]; + setThumbnailSize(json, msg); + setAuthType(json, msg); + } else { + setThumbnailSize(json, msg); + msg->mDeviceId = deviceId; + if (!json.contains(TAG_APP_THUMBNAIL)) { + DMLog(DM_LOG_ERROR, "err json string, TAG_APP_THUMBNAIL not exit"); + return nullptr; + } + std::string src = json[TAG_APP_THUMBNAIL]; + if (msg->mAppThumbnail.size() < src.size() + (idx - 1) * MSG_MAX_SIZE) { + auto inValidMsg = std::make_shared(); + inValidMsg->mMsgSlice = FAIL; + return inValidMsg; + } + msg->mAppThumbnail += stringSub(src, (idx - 1) * MSG_MAX_SIZE, MSG_MAX_SIZE); + } + msg->mMsgCnt++; + return msg; +} + +bool MsgRequestAuth::isMsgValid(std::shared_ptr msgIn, nlohmann::json &json, + std::string &deviceId, int32_t index) +{ + if (msgIn != nullptr && msgIn->mMsgCnt != msgIn->mMsgSlice && !deviceId.compare(msgIn->mDeviceId)) { + DMLog(DM_LOG_ERROR, "isMsgValid, msgIn error"); + return false; + } + + if (!json.contains(TAG_THUMBNAIL_SIZE)) { + DMLog(DM_LOG_ERROR, "isMsgValid, err json string"); + return false; + } + + if (index < 0 || index >= DES_SLICE_MAX_NUM) { + DMLog(DM_LOG_ERROR, "index err"); + return false; + } + + if (index == 0) { + return isAppInfoValid(json); + } else { + int32_t thumbnailSlice = json[TAG_THUMBNAIL_SIZE]; + if (thumbnailSlice > THUMB_MAX_LEN || thumbnailSlice < 0) { + DMLog(DM_LOG_ERROR, "isMsgValid, thumbnailSlice error"); + return false; + } + } + return true; +} + +bool MsgRequestAuth::isAppInfoValid(nlohmann::json &json) +{ + if (json[TAG_APP_ICON].size() > ICON_MAX_LEN) { + DMLog(DM_LOG_ERROR, "isAppInfoValid, mAppIcon size error"); + return false; + } + + int32_t thumbnailSize = json[TAG_THUMBNAIL_SIZE]; + if (thumbnailSize > THUMB_MAX_LEN || thumbnailSize < 0) { + DMLog(DM_LOG_ERROR, "isAppInfoValid, thumbnailSize error"); + return false; + } + return true; +} + +void MsgRequestAuth::setAuthType(nlohmann::json &json, std::shared_ptr msg) +{ + int32_t authType = json.contains(TAG_AUTH_TYPE) ? (int32_t)json[TAG_AUTH_TYPE] : AUTH_TYPE_QR; + if (authType != AUTH_TYPE_QR && authType != AUTH_TYPE_PIN) { + authType = AUTH_TYPE_QR; + } + msg->mAuthType = authType; +} + +void MsgRequestAuth::setThumbnailSize(nlohmann::json &json, std::shared_ptr msg) +{ + if (!json.contains(TAG_THUMBNAIL_SIZE)) { + DMLog(DM_LOG_ERROR, "setThumbnailSize, err json string"); + return ; + } + int32_t thumbnailSlice = json[TAG_THUMBNAIL_SIZE]; + if (msg->mThumbnailSize == 0) { + msg->mThumbnailSize = thumbnailSlice; + msg->mAppThumbnail = ""; + } +} + +std::string MsgRequestAuth::stringSub(std::string &thumbStr, int32_t start, int32_t length) +{ + int32_t copyLen = start + length > (int32_t)thumbStr.size() ? (thumbStr.size() - start) : length; + std::string ret; + ret.assign(thumbStr, start, copyLen); + return ret; +} + +std::string MsgRequestAuth::toHexString(int32_t value) +{ + std::stringstream ioss; + std::string tmpStr; + ioss << std::setiosflags(std::ios::uppercase) << std::hex << value; + ioss >> tmpStr; + return tmpStr; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/message/msg_response_auth.cpp b/services/devicemanagerservice/src/message/msg_response_auth.cpp new file mode 100644 index 000000000..58bc423f1 --- /dev/null +++ b/services/devicemanagerservice/src/message/msg_response_auth.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "msg_response_auth.h" +#include "device_manager_log.h" +#include "device_manager_errno.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { +void MsgResponseAuth::encode(nlohmann::json &jsonObj) +{ + MsgHead msgHead; + mHead = msgHead.decode(jsonObj); + jsonObj[TAG_REPLY] = mReply; + jsonObj[TAG_DEVICE_ID] = mDeviceId; + jsonObj[TAG_GROUPIDS] = mSyncGroupList; + if (mReply == SESSION_REPLY_ACCEPT) { + jsonObj[TAG_NET_ID] = mNetId; + jsonObj[TAG_REQUEST_ID] = mRequestId; + jsonObj[TAG_GROUP_ID] = mGroupId; + jsonObj[TAG_GROUP_NAME] = mGroupName; + } +} + +int32_t MsgResponseAuth::decode(nlohmann::json &jsonObj) +{ + DMLog(DM_LOG_INFO, "MsgResponseAuth decode started"); + if (!jsonObj.contains(TAG_REPLY) || !jsonObj.contains(TAG_DEVICE_ID) || !jsonObj.contains(TAG_GROUPIDS)) { + DMLog(DM_LOG_ERROR, "MsgResponseAuth::decode, err json string, first time"); + return MSG_DECODE_PARA_FAILED; + } + + MsgHead msgHead; + mHead = msgHead.decode(jsonObj); + mReply = jsonObj[TAG_REPLY]; + mDeviceId = jsonObj[TAG_DEVICE_ID]; + std::vector groupList = jsonObj[TAG_GROUPIDS]; + for (auto str : groupList) { + mSyncGroupList.push_back(str); + } + + if (mReply == SESSION_REPLY_ACCEPT) { + if (!jsonObj.contains(TAG_NET_ID) || !jsonObj.contains(TAG_GROUP_ID) || !jsonObj.contains(TAG_GROUP_NAME) || + !jsonObj.contains(TAG_REQUEST_ID)) { + DMLog(DM_LOG_ERROR, "MsgResponseAuth::decode, err json string, second time"); + return MSG_DECODE_PARA_FAILED; + } + mNetId = jsonObj[TAG_NET_ID]; + mGroupId = jsonObj[TAG_GROUP_ID]; + mGroupName = jsonObj[TAG_GROUP_NAME]; + mRequestId = jsonObj[TAG_REQUEST_ID]; + } + DMLog(DM_LOG_INFO, "MsgResponseAuth decode completed"); + return DEVICEMANAGER_OK; +} + +int32_t MsgResponseAuth::getReply() +{ + return mReply; +} + +std::string MsgResponseAuth::getNetId() +{ + return mNetId; +} + +std::string MsgResponseAuth::getGroupId() +{ + return mGroupId; +} + +std::string MsgResponseAuth::getDeviceId() +{ + return mDeviceId; +} + +std::string MsgResponseAuth::getGroupName() +{ + return mGroupName; +} + +long long MsgResponseAuth::getRequestId() +{ + return mRequestId; +} + +std::vector MsgResponseAuth::getSyncGroupList() +{ + return mSyncGroupList; +} + +std::string MsgResponseAuth::getPinCode() +{ + return mPinCode; +} + +void MsgResponseAuth::savePinCode(std::string pinCode) +{ + mPinCode = pinCode; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/message/msg_sync_group.cpp b/services/devicemanagerservice/src/message/msg_sync_group.cpp new file mode 100644 index 000000000..d2c13567b --- /dev/null +++ b/services/devicemanagerservice/src/message/msg_sync_group.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "msg_sync_group.h" +#include "device_manager_log.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { +MsgSyncGroup::MsgSyncGroup(std::vector &groupList, std::string &deviceId) +{ + DMLog(DM_LOG_INFO, "MsgSyncGroup construction started"); + mHead = std::make_shared(DmMsgType::MSG_TYPE_SYNC_GROUP); + for (auto str: groupList) { + mGroupIdList.push_back(str); + } + mDeviceId = deviceId; + DMLog(DM_LOG_INFO, "MsgSyncGroup construction completed"); +} + +void MsgSyncGroup::encode(nlohmann::json &json) +{ + mHead->encode(json); + json[TAG_DEVICE_ID] = mDeviceId; + json[TAG_GROUPIDS] = mGroupIdList; +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/requestauth/auth_manager.cpp b/services/devicemanagerservice/src/requestauth/auth_manager.cpp new file mode 100644 index 000000000..4255f5207 --- /dev/null +++ b/services/devicemanagerservice/src/requestauth/auth_manager.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auth_manager.h" +#include "constants.h" +#include "msg_codec.h" +#include "device_manager_log.h" +#include "msg_codec.h" +#include "device_manager_errno.h" +#include "softbus_session.h" +#include "encrypt_utils.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(AuthManager); + +void AuthManager::authDeviceGroup(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, + const DmAppImageInfo &imageInfo, std::string &extras) +{ + authAppGroup(hostPkgName, devReqInfo, imageInfo, extras); +} + +void AuthManager::onReceiveMsg(long long channelId, std::string &message) +{ + int32_t msgType = MsgCodec::decodeMsgType(message); + DMLog(DM_LOG_INFO, "message type is, %d", msgType); + switch (msgType) { + case MSG_TYPE_RESP_AUTH: + onReceiveMessage(channelId, message, msgType); + break; + default: + DMLog(DM_LOG_INFO, "msgType not support yet"); + break; + } +} + +void AuthManager::authAppGroup(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, + const DmAppImageInfo &imageInfo, std::string &extrasJson) +{ + DMLog(DM_LOG_INFO, "AuthManager::authAppGroup started"); + nlohmann::json jsonObject = nlohmann::json::parse(extrasJson, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "extrasJson error"); + return; + } + if (!jsonObject.contains(AUTH_TYPE)) { + DMLog(DM_LOG_ERROR, "authAppGroup extrasJson error"); + return; + } + + if (!canStartNewSession()) { + DMLog(DM_LOG_ERROR, "previous session not completed yet"); + mPendingReqSessionPtr->notifyHostAppAuthResult(ERROR_DUPLICATE_REQUEST); + return; + } + auto curSessionPtr = std::make_shared(hostPkgName, devReqInfo, imageInfo, extrasJson); + if (jsonObject[AUTH_TYPE] == AUTH_TYPE_PIN) { + int32_t pinTokenVal = 0; + if (jsonObject.contains(PIN_TOKEN)) { + pinTokenVal = jsonObject[PIN_TOKEN]; + DMLog(DM_LOG_ERROR, "pinToken value is %d", pinTokenVal); + } + curSessionPtr->setPinToken(pinTokenVal); + } + mPendingReqSessionPtr = curSessionPtr; + std::vector msgInfo = curSessionPtr->getRequestCommand(extrasJson); + int32_t channelId = SoftbusSession::GetInstance().SendMessages(devReqInfo.deviceId, msgInfo); + if (channelId > 0) { + DMLog(DM_LOG_INFO, "open channel succeed, save channelId"); + mPendingReqSessionPtr->setChannelId(channelId); + return; + } + DMLog(DM_LOG_ERROR, "open channel failed, close this session"); + mPendingReqSessionPtr->release(); + mPendingReqSessionPtr->notifyHostAppAuthResult(ERROR_START_REMOTE_DM); + mPendingReqSessionPtr = nullptr; +} + +bool AuthManager::canStartNewSession() +{ + if (mPendingReqSessionPtr == nullptr || mPendingReqSessionPtr->isFinished()) { + return true; + } + return false; +} + +void AuthManager::onReceiveMessage(long long channelId, std::string &message, int32_t msgType) +{ + DMLog(DM_LOG_INFO, "AuthManager::onReceiveMessage started"); + if (msgType == MSG_TYPE_RESP_AUTH) { + DMLog(DM_LOG_ERROR, "message type is MSG_TYPE_RESP_AUTH"); + if (mPendingReqSessionPtr == nullptr || !mPendingReqSessionPtr->isMyChannelId(channelId)) { + DMLog(DM_LOG_ERROR, "receive error message"); + return ; + } + mPendingReqSessionPtr->onReceiveMsg(message); + if (mPendingReqSessionPtr->isWaitingForScan()) { + DMLog(DM_LOG_ERROR, "move Session To Wait Scan Map "); + moveSessionToWaitScanMap(); + } + } else { + DMLog(DM_LOG_ERROR, "error message type"); + } +} + +void AuthManager::moveSessionToWaitScanMap() +{ + DMLog(DM_LOG_ERROR, "AuthManager::moveSessionToWaitScanMap"); + mWaitScanReqSessionMap[mPendingReqSessionPtr->getToken()] = mPendingReqSessionPtr; + mPendingReqSessionPtr = nullptr; +} + +int32_t AuthManager::checkAuthentication(std::string &authPara) +{ + DMLog(DM_LOG_INFO, "AuthManager::checkAuthentication started"); + nlohmann::json authJson = nlohmann::json::parse(authPara, nullptr, false); + if (authJson.is_discarded()) { + DMLog(DM_LOG_ERROR, "HichainAdapter::GetGroupIdByName parse group info error, json invalid."); + return AUTH_PARA_INVALID; + } + if (!authJson.contains(AUTH_TYPE) || authJson[AUTH_TYPE] != AUTH_TYPE_PIN) { + DMLog(DM_LOG_ERROR, "error authPara msg"); + return AUTH_PARA_INVALID; + } + DMLog(DM_LOG_INFO, "PIN Code Auth"); + return checkAuthenticationByPin(authJson); +} + +int32_t AuthManager::checkAuthenticationByPin(nlohmann::json &authJson) +{ + int32_t pinCode = authJson.contains(PIN_CODE_KEY) ? (int32_t)authJson[PIN_CODE_KEY] : DEFAULT_PIN_CODE; + int32_t pinToken = authJson.contains(PIN_TOKEN) ? (int32_t)authJson[PIN_TOKEN] : DEFAULT_PIN_TOKEN; + if (pinCode < MIN_PIN_CODE || pinCode >= (MIN_PIN_CODE + MAX_PIN_CODE)) { + DMLog(DM_LOG_ERROR, "pinCode err, pinCode is : %d", pinCode); + return PIN_CODE_CHECK_FAILED; + } + + if (pinToken < MIN_PIN_TOKEN || pinToken >= (MIN_PIN_TOKEN + MAX_PIN_TOKEN)) { + DMLog(DM_LOG_ERROR, "pinToken err, pinToken is : %d", pinToken); + return PIN_TOKEN_CHECK_FAILED; + } + DMLog(DM_LOG_INFO, "checkAuthenticationByPin authPara valid, pinCode: %d, pinToken: %d", pinCode, pinToken); + onPinInputResult(pinCode, pinToken); + DMLog(DM_LOG_INFO, "checkAuthenticationByPin authPara end"); + return DEVICEMANAGER_OK; +} + +void AuthManager::onPinInputResult(int32_t pinCode, int32_t pinToken) +{ + DMLog(DM_LOG_ERROR, "AuthManager::onPinInputResult"); + for (auto iter = mWaitScanReqSessionMap.begin(); iter != mWaitScanReqSessionMap.end(); iter++) { + auto requestSessionPtr = iter->second; + if (requestSessionPtr != nullptr && requestSessionPtr->isMyPinToken(pinToken)) { + DMLog(DM_LOG_INFO, "AuthManager:: onPinInputResult"); + requestSessionPtr->onReceivePinCode(pinCode); + } + } +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/requestauth/request_session.cpp b/services/devicemanagerservice/src/requestauth/request_session.cpp new file mode 100644 index 000000000..0d8023071 --- /dev/null +++ b/services/devicemanagerservice/src/requestauth/request_session.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "nlohmann/json.hpp" + +#include "request_session.h" +#include "constants.h" +#include "device_manager_log.h" +#include "msg_codec.h" +#include "device_manager_errno.h" +#include "ipc_server_adapter.h" +#include "encrypt_utils.h" +#include "softbus_adapter.h" +#include "ipc_server_listener_adapter.h" +#include "hichain_connector.h" +#include "softbus_session.h" + +namespace OHOS { +namespace DistributedHardware { +enum StatusType : int32_t { + STATUS_INIT = 0, + STATUS_WAITING_REPLY = 2, + STATUS_WATING_SCAN_OR_INPUT = 3, + STATUS_WAITING_ADD_GROUP = 4, + STATUS_FINISH = 6, +}; + +RequestSession::RequestSession(std::string &hostPkgName, const DmDeviceInfo& devReqInfo, + const DmAppImageInfo &imageInfo, std::string &extrasJson) +{ + DMLog(DM_LOG_INFO, "RequestSession construction started"); + nlohmann::json jsonObject = nlohmann::json::parse(extrasJson, nullptr, false); + if (jsonObject.is_discarded()) { + DMLog(DM_LOG_ERROR, "extrasJson error"); + } + + if (!jsonObject.contains(TARGET_PKG_NAME_KEY)) { + DMLog(DM_LOG_ERROR, "TARGET_PKG_NAME is not in extrasJson"); + } + std::string targetPkgName = jsonObject[TARGET_PKG_NAME_KEY]; + mSessionType = SESSION_TYPE_IS_APP_AUTH; + mDevInfo = devReqInfo; + mImageInfo = imageInfo; + mHostPkgName = hostPkgName; + mTargetPkgName = targetPkgName; + mStatus = StatusType::STATUS_INIT; + mPinToken = IpcServerAdapter::GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN); + char randStr[TOKEN_LEN] = {0}; + bool res = EncryptUtils::MbedtlsGenRandomStr(randStr, sizeof(randStr), false); + if (res == false) { + DMLog(DM_LOG_ERROR, "get Random string failed"); + mToken = ""; + return; + } + mToken = randStr; + DMLog(DM_LOG_INFO, "RequestSession construction completed"); +} + +std::vector RequestSession::getRequestCommand(std::string &extrasJson) +{ + return MsgCodec::encodeReqAppAuth(mToken, mHostPkgName, mTargetPkgName, mDevInfo, mImageInfo, extrasJson); +} + +void RequestSession::setPinToken(int32_t pinToken) +{ + mPinToken = pinToken; +} + +bool RequestSession::isWaitingForScan() +{ + return mStatus == StatusType::STATUS_WATING_SCAN_OR_INPUT; +} + +std::string RequestSession::getToken() +{ + return mToken; +} + +bool RequestSession::isMyPinToken(int32_t pinToken) { + return pinToken == mPinToken; +} + +void RequestSession::onReceivePinCode(int32_t pinCode) +{ + if (mStatus != StatusType::STATUS_WATING_SCAN_OR_INPUT) { + DMLog(DM_LOG_ERROR, "mStatus is incorrect, mStatus: %d", mStatus); + return; + } + + std::stringstream pinCodeStream; + pinCodeStream << pinCode; + std::string pinCodeStr = pinCodeStream.str(); + DMLog(DM_LOG_INFO, "received pin code, %d", pinCode); + + responseMsgPtr_->savePinCode(pinCodeStr); + HichainConnector::GetInstance().AddMemeber(mDevInfo.deviceId, responseMsgPtr_); + mStatus = StatusType::STATUS_WAITING_ADD_GROUP; +} + +bool RequestSession::isFinished() +{ + if (mStatus == StatusType::STATUS_INIT || mStatus == StatusType::STATUS_FINISH) { + return true; + } + return false; +} + +bool RequestSession::isMyChannelId(long long channelId) +{ + return channelId == mChannelId; +} + +void RequestSession::onReceiveMsg(std::string &msg) +{ + if (mStatus != StatusType::STATUS_WAITING_REPLY) { + DMLog(DM_LOG_ERROR, "StatusType is not waiting reply"); + return ; + } + int32_t reply = parseRespMsg(msg); + DMLog(DM_LOG_INFO, "reply is : %d", reply); + if (reply == SESSION_REPLY_ACCEPT) { + mStatus = StatusType::STATUS_WATING_SCAN_OR_INPUT; + closeChannel(); + } else { + release(); + } + notifyHostAppAuthResult(reply); +} + +std::string RequestSession::getHostPkgName() +{ + return mHostPkgName; +} + +std::string RequestSession::getTargetPkgName() +{ + return mTargetPkgName; +} + +int32_t RequestSession::getSessionType() +{ + return mSessionType; +} + +void RequestSession::release() +{ + if (mStatus == StatusType::STATUS_FINISH || mStatus == StatusType::STATUS_INIT) { + DMLog(DM_LOG_INFO, "session is already closed"); + return; + } + DMLog(DM_LOG_INFO, "close this session"); + mStatus = StatusType::STATUS_FINISH; + closeChannel(); +} + +void RequestSession::closeChannel() +{ + if (mIsChannelOpened) { + SoftbusSession::GetInstance().CloseSession(mChannelId); + DMLog(DM_LOG_ERROR, "RequestSession:: close the channel"); + mIsChannelOpened = false; + } +} + +int32_t RequestSession::parseRespMsg(std::string &msg) +{ + DMLog(DM_LOG_INFO, "parseRespMsg started"); + auto msgResponseAuthPtr = MsgCodec::decodeResponseAuth(msg); + if (msgResponseAuthPtr == nullptr) { + DMLog(DM_LOG_ERROR, "decodeResponseAuth error"); + return SESSION_REPLY_UNKNOWN; + } + responseMsgPtr_ = msgResponseAuthPtr; + int32_t reply = msgResponseAuthPtr->getReply(); + mRemoteDeviceId = msgResponseAuthPtr->getDeviceId(); + if (reply == SESSION_REPLY_ACCEPT) { + mRemoteNetId = msgResponseAuthPtr->getNetId(); + mRemoteGroupId = msgResponseAuthPtr->getGroupId(); + mRemoteGroupName = msgResponseAuthPtr->getGroupName(); + mRequestId = msgResponseAuthPtr->getRequestId(); + + auto remoteGroupList = msgResponseAuthPtr->getSyncGroupList(); + syncDmPrivateGroup(remoteGroupList); + DMLog(DM_LOG_INFO, "user accepted the auth"); + } + DMLog(DM_LOG_INFO, "parseRespMsg completed"); + return reply; +} + +void RequestSession::setChannelId(long long channelId) +{ + mChannelId = channelId; + mIsChannelOpened = true; + mStatus = StatusType::STATUS_WAITING_REPLY; +} + +void RequestSession::syncDmPrivateGroup(std::vector &remoteGroupList) +{ + // TODO: getLocalGroups from hichainAdapter by (remoteGroupList, mRemoteDeviceId) + DMLog(DM_LOG_INFO, "RequestSession::syncDmPrivateGroup started"); + std::vector localGroups = {}; + std::string synGroupMsg = MsgCodec::encodeSyncGroup(localGroups, mRemoteDeviceId); + SoftbusSession::GetInstance().SendMsg(mChannelId, synGroupMsg); + DMLog(DM_LOG_INFO, "RequestSession::syncDmPrivateGroup completed"); +} + +void RequestSession::notifyHostAppAuthResult(int32_t errorCode) +{ + if (mSessionType == SESSION_TYPE_IS_APP_AUTH) { + std::string deviceId = mDevInfo.deviceId; + IpcServerListenerAdapter::GetInstance().OnAuthResult(mHostPkgName, deviceId, mPinToken, mStatus, errorCode); + DMLog(DM_LOG_INFO, "notify host result, errorcode: %d", errorCode); + } else { + DMLog(DM_LOG_ERROR, "wrong session type: %d", errorCode); + } +} +} +} \ No newline at end of file diff --git a/services/devicemanagerservice/src/softbus/softbus_adapter.cpp b/services/devicemanagerservice/src/softbus/softbus_adapter.cpp index 17f72e881..a5963ae46 100644 --- a/services/devicemanagerservice/src/softbus/softbus_adapter.cpp +++ b/services/devicemanagerservice/src/softbus/softbus_adapter.cpp @@ -1,524 +1,519 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "softbus_adapter.h" - -#include -#include -#include -#include - -#include - -#include "dm_device_info.h" - -#include "anonymous_string.h" -#include "device_manager_errno.h" -#include "device_manager_log.h" -#include "device_manager_service.h" - -namespace OHOS { -namespace DistributedHardware { -namespace { -const std::string DEVICE_MANAGER_PACKAGE_NAME = "ohos.distributedhardware.devicemanager"; -const int32_t CHECK_INTERVAL = 100000; // 100ms -const int32_t SUBSCRIBE_ID_PREFIX_LEN = 16; -const int32_t SUBSCRIBE_ID_MASK = 0x0000FFFF; -const int32_t DISCOVER_DEVICEINFO_MAX_SIZE = 20; -} - -IMPLEMENT_SINGLE_INSTANCE(SoftbusAdapter); -void SoftbusAdapter::OnSoftBusDeviceOnline(NodeBasicInfo *info) -{ - if (info == nullptr) { - HILOGE("SoftbusAdapter::OnSoftBusDeviceOnline NodeBasicInfo is nullptr"); - return; - } - - std::string networkId = info->networkId; - HILOGI("device online, networkId: %{public}s", GetAnonyString(networkId).c_str()); - OnSoftBusDeviceStateChange(DmDeviceState::DEVICE_STATE_ONLINE, info); - - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info->networkId, - NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); - if (ret != ERR_OK) { - HILOGE("GetNodeKeyInfo failed"); - return; - } - std::string deviceId = (char *)udid; - SoftbusAdapter::GetInstance().RemoveDiscoverDeviceInfo(deviceId); -} - -void SoftbusAdapter::OnSoftbusDeviceOffline(NodeBasicInfo *info) -{ - if (info == nullptr) { - HILOGE("SoftbusAdapter::OnSoftbusDeviceOffline NodeBasicInfo is nullptr"); - return; - } - - std::string networkId = info->networkId; - HILOGI("device offline, networkId: %{public}s", GetAnonyString(networkId).c_str()); - OnSoftBusDeviceStateChange(DmDeviceState::DEVICE_STATE_OFFLINE, info); -} - -void SoftbusAdapter::OnSoftBusDeviceStateChange(DmDeviceState state, NodeBasicInfo *info) -{ - DmDeviceInfo deviceInfo; - deviceInfo.deviceId = info->networkId; - deviceInfo.deviceName = info->deviceName; - deviceInfo.deviceTypeId = (DMDeviceType)info->deviceTypeId; - - std::map> listeners = DeviceManagerService::GetInstance().GetDmListener(); - for (auto iter : listeners) { - auto packageName = iter.first; - auto remote = iter.second; - sptr dmListener = iface_cast(remote); - if (state == DmDeviceState::DEVICE_STATE_ONLINE) { - HILOGI("SoftbusAdapter::OnSoftBusDeviceStateChange listenr handle device online."); - dmListener->OnDeviceOnline(packageName, deviceInfo); - } else { - HILOGI("SoftbusAdapter::OnSoftBusDeviceStateChange listenr handle device offline."); - dmListener->OnDeviceOffline(packageName, deviceInfo); - } - } -} - -void SoftbusAdapter::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) -{ - HILOGI("SoftbusAdapter::OnSoftbusDeviceInfoChanged."); - // currently do nothing - (void)type; - (void)info; -} - -void SoftbusAdapter::OnSoftbusDeviceFound(const DeviceInfo *device) -{ - if (device == nullptr) { - HILOGE("deviceinfo is null"); - return; - } - - std::string deviceId = device->devId; - HILOGI("SoftbusAdapter::OnSoftbusDeviceFound device %{public}s found.", GetAnonyString(deviceId).c_str()); - if (IsDeviceOnLine(deviceId)) { - return; - } - - SoftbusAdapter::GetInstance().SaveDiscoverDeviceInfo(device); - DmDeviceInfo deviceInfo; - deviceInfo.deviceId = deviceId; - deviceInfo.deviceName = device->devName; - deviceInfo.deviceTypeId = (DMDeviceType)device->devType; - - // currently, only care ddmpCapability - if (!((device->capabilityBitmap[0] >> DDMP_CAPABILITY_BITMAP) & 0x1)) { - HILOGE("capBitmap Invalid, not contain ddmpCap"); - return; - } - - auto subscribeInfos = SoftbusAdapter::GetInstance().GetsubscribeInfos(); - for (auto iter = subscribeInfos.begin(); iter != subscribeInfos.end(); iter++) { - auto subInfovector = iter->second; - for (auto vectorIter = subInfovector.begin(); vectorIter != subInfovector.end(); ++vectorIter) { - auto info = vectorIter->get(); - HILOGI("subscribe info capability:%{public}s.", info->info.capability); - if (strcmp(DM_CAPABILITY_DDMP.c_str(), info->info.capability) != 0) { - HILOGE("subscribe info capability invalid."); - } - std::string packageName = iter->first; - sptr listener = DeviceManagerService::GetInstance().GetDmListener(packageName); - if (listener == nullptr) { - HILOGI("cannot get listener for package:%{public}s.", packageName.c_str()); - continue; - } - - uint16_t originId = (uint16_t)(((uint32_t)info->info.subscribeId) & SUBSCRIBE_ID_MASK); - HILOGI("call OnDeviceFound for %{public}s, originId %{public}d, deviceId %{public}s", - packageName.c_str(), originId, GetAnonyString(deviceInfo.deviceId).c_str()); - listener->OnDeviceFound(packageName, originId, deviceInfo); - } - } -} - -void SoftbusAdapter::OnSoftbusDiscoverFailed(int subscribeId, DiscoveryFailReason failReason) -{ - HILOGI("In, subscribeId %{public}d, failReason %{public}d", subscribeId, (int32_t)failReason); - std::string packageName; - if (!SoftbusAdapter::GetInstance().GetPackageNameBySubscribeId(subscribeId, packageName)) { - HILOGE("OnSoftbusDiscoverFailed: packageName not found"); - return; - } - sptr listener = DeviceManagerService::GetInstance().GetDmListener(packageName); - if (listener == nullptr) { - HILOGE("OnSoftbusDiscoverFailed: listener not found for packageName %{public}s", packageName.c_str()); - return; - } - uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); - listener->OnDiscoverFailed(packageName, originId, (int32_t)failReason); -} - -void SoftbusAdapter::OnSoftbusDiscoverySuccess(int subscribeId) -{ - HILOGI("In, subscribeId %{public}d", subscribeId); - std::string packageName; - if (!SoftbusAdapter::GetInstance().GetPackageNameBySubscribeId(subscribeId, packageName)) { - HILOGE("OnSoftbusDiscoverySuccess: packageName not found"); - return; - } - sptr listener = DeviceManagerService::GetInstance().GetDmListener(packageName); - if (listener == nullptr) { - HILOGE("OnSoftbusDiscoverySuccess: listener not found for packageName %{public}s", packageName.c_str()); - return; - } - uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); - listener->OnDiscoverySuccess(packageName, originId); -} - -void SoftbusAdapter::OnSoftbusJoinLNNResult(ConnectionAddr *addr, const char *networkId, int32_t retCode) -{ - (void)addr; - if (retCode != 0) { - HILOGE("OnSoftbusJoinLNNResult: failed, retCode %{public}d", retCode); - return; - } - - if (networkId == nullptr) { - HILOGE("OnSoftbusJoinLNNResult: success, but networkId is nullptr"); - return; - } - - std::string netIdStr = networkId; - HILOGI("OnSoftbusJoinLNNResult: success, networkId %{public}s, retCode %{public}d", - GetAnonyString(netIdStr).c_str(), retCode); -} - -void SoftbusAdapter::OnSoftbusLeaveLNNResult(const char *networkId, int32_t retCode) -{ - if (retCode != 0) { - HILOGE("OnSoftbusLeaveLNNResult: failed, retCode %{public}d", retCode); - return; - } - - if (networkId == nullptr) { - HILOGE("OnSoftbusLeaveLNNResult: success, but networkId is nullptr"); - return; - } - - std::string netIdStr = networkId; - HILOGI("OnSoftbusLeaveLNNResult: success, networkId %{public}s, retCode %{public}d", - GetAnonyString(netIdStr).c_str(), retCode); -} - -int32_t SoftbusAdapter::GetSoftbusTrustDevices(const std::string &packageName, std::string &extra, - std::vector &deviceList) -{ - // extra not used yet - (void) packageName; - (void) extra; - - HILOGI("GetSoftbusTrustDevices start, packageName: %{public}s", packageName.c_str()); - NodeBasicInfo *info = nullptr; - int32_t infoNum = 0; - int32_t ret = GetAllNodeDeviceInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &info, &infoNum); - if (ret != 0) { - HILOGE("GetAllNodeDeviceInfo failed with ret %{public}d", ret); - return ret; - } - - for (int32_t i = 0; i < infoNum; i++) { - NodeBasicInfo *nodeBasicInfo = info + i; - if (nodeBasicInfo == nullptr) { - HILOGE("nodeBasicInfo is empty for index %{public}d, infoNum %{public}d.", i, infoNum); - continue; - } - DmDeviceInfo deviceInfo; - deviceInfo.deviceId = nodeBasicInfo->networkId; - deviceInfo.deviceName = nodeBasicInfo->deviceName; - deviceInfo.deviceTypeId = (DMDeviceType)nodeBasicInfo->deviceTypeId; - deviceList.push_back(deviceInfo); - } - FreeNodeInfo(info); - HILOGI("success, packageName: %{public}s, deviceCount %{public}d", packageName.c_str(), deviceList.size()); - return ERR_OK; -} - -bool SoftbusAdapter::IsDeviceOnLine(std::string &deviceId) -{ - std::vector deviceList; - std::string extra = ""; - if (GetSoftbusTrustDevices(DEVICE_MANAGER_PACKAGE_NAME, extra, deviceList) != ERR_OK) { - HILOGE("SoftbusAdapter::IsDeviceOnLine GetSoftbusTrustDevices failed"); - return false; - } - - for (auto iter = deviceList.begin(); iter != deviceList.end(); ++iter) { - std::string& networkId = iter->deviceId; - if (networkId == deviceId) { - HILOGI("SoftbusAdapter::IsDeviceOnLine devccie %{public}s online", GetAnonyString(deviceId).c_str()); - return true; - } - - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), networkId.c_str(), - NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); - if (ret != ERR_OK) { - HILOGE("SoftbusAdapter::IsDeviceOnLine GetNodeKeyInfo failed"); - return false; - } - - if (strcmp((char *)udid, deviceId.c_str()) == 0) { - HILOGI("SoftbusAdapter::IsDeviceOnLine devccie %{public}s online", GetAnonyString(deviceId).c_str()); - return true; - } - } - return false; -} - -void SoftbusAdapter::RegSoftBusDeviceStateListener() -{ - int32_t ret; - int32_t retryTimes = 0; - do { - ret = RegNodeDeviceStateCb(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &softbusNodeStateCb); - if (ret != ERR_OK) { - ++retryTimes; - HILOGE("RegNodeDeviceStateCb failed with ret %{public}d, retryTimes %{public}d", ret, retryTimes); - usleep(CHECK_INTERVAL); - } - } while (ret != ERR_OK); - HILOGI("RegNodeDeviceStateCb success."); -} - -int32_t SoftbusAdapter::StartSoftbusDiscovery(std::string &packageName, DmSubscribeInfo &info) -{ - std::shared_ptr subinfo = nullptr; - if (subscribeInfos_.find(packageName) == subscribeInfos_.end()) { - subscribeInfos_[packageName] = {}; - } - - auto iter = subscribeInfos_.find(packageName); - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->subscribeIdOrigin == info.subscribeId) { - subinfo = *vectorIter; - break; - } - } - - if (subinfo == nullptr) { - subinfo = std::make_shared(); - subinfo->subscribeIdOrigin = info.subscribeId; - subinfo->subscribeIdPrefix = subscribeIdPrefix++; - subinfo->info.subscribeId = (subinfo->subscribeIdPrefix << SUBSCRIBE_ID_PREFIX_LEN) | info.subscribeId; - subinfo->info.mode = (DiscoverMode)info.mode; - subinfo->info.medium = (ExchanageMedium)info.medium; - subinfo->info.freq = (ExchangeFreq)info.freq; - subinfo->info.isSameAccount = info.isSameAccount; - subinfo->info.isWakeRemote = info.isWakeRemote; - subinfo->info.capability = info.capability.c_str(); - subinfo->info.capabilityData = nullptr; - subinfo->info.dataLen = 0; - } - - if (vectorIter == subinfoVector.end()) { - subinfoVector.push_back(subinfo); - } - - HILOGI("StartDiscovery, packageName: %{public}s, subscribeId %{public}d, prefix %{public}d, origin %{public}d", - packageName.c_str(), subinfo->info.subscribeId, subinfo->subscribeIdPrefix, subinfo->subscribeIdOrigin); - int ret = StartDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &subinfo->info, &softbusDiscoverCallback); - if (ret != ERR_OK) { - HILOGE("StartDiscovery failed with ret %{public}d.", ret); - } - return ret; -} - -bool SoftbusAdapter::GetPackageNameBySubscribeId(int32_t adapterId, std::string &packageName) -{ - for (auto iter = subscribeInfos_.begin(); iter != subscribeInfos_.end(); ++iter) { - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->info.subscribeId == adapterId) { - packageName = iter->first; - return true; - } - } - } - return false; -} - -bool SoftbusAdapter::GetsubscribeIdAdapter(std::string packageName, int16_t originId, int32_t &adapterId) -{ - HILOGI("GetsubscribeIdAdapter in, packageName: %{public}s, originId:%{public}d", packageName.c_str(), - (int32_t)originId); - auto iter = subscribeInfos_.find(packageName); - if (iter == subscribeInfos_.end()) { - HILOGE("subscribeInfo not find for packageName: %{public}s", packageName.c_str()); - return false; - } - - std::vector> &subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - for (; vectorIter != subinfoVector.end(); ++vectorIter) { - if (vectorIter->get()->subscribeIdOrigin == originId) { - HILOGE("find adapterId:%{public}d for packageName: %{public}s, originId:%{public}d", - vectorIter->get()->info.subscribeId, packageName.c_str(), (int32_t)originId); - adapterId = vectorIter->get()->info.subscribeId; - return true; - } - } - HILOGE("subscribe not find. packageName: %{public}s, originId:%{public}d", packageName.c_str(), (int32_t)originId); - return false; -} - -int32_t SoftbusAdapter::StopSoftbusDiscovery(std::string &packageName, uint16_t subscribeId) -{ - int32_t subscribeIdAdapter = -1; - if (!GetsubscribeIdAdapter(packageName, subscribeId, subscribeIdAdapter)) { - HILOGE("StopDiscovery failed, subscribeId not match"); - return ERR_INVALID_OPERATION; - } - - HILOGI("StopDiscovery begin, packageName: %{public}s, subscribeId:%{public}d, subscribeIdAdapter:%{public}d", - packageName.c_str(), (int32_t)subscribeId, subscribeIdAdapter); - int ret = StopDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), subscribeIdAdapter); - if (ret != ERR_OK) { - HILOGE("StopDiscovery failed with ret %{public}d", ret); - return ret; - } - - auto iter = subscribeInfos_.find(packageName); - auto subinfoVector = iter->second; - auto vectorIter = subinfoVector.begin(); - while (vectorIter != subinfoVector.end()) { - if (vectorIter->get()->subscribeIdOrigin == subscribeId) { - vectorIter = subinfoVector.erase(vectorIter); - break; - } else { - ++vectorIter; - } - } - if (subinfoVector.empty()) { - subscribeInfos_.erase(packageName); - } - HILOGI("SoftbusAdapter::StopSoftbusDiscovery completed, packageName: %{public}s", packageName.c_str()); - return ERR_OK; -} - -int32_t SoftbusAdapter::SoftbusJoinLnn(std::string devId) -{ - auto iter = discoverDeviceInfoMap_.find(devId); - if (iter == discoverDeviceInfoMap_.end()) { - HILOGE("SoftbusAdapter::SoftbusJoinLnn deviceInfo not found: %{public}s", GetAnonyString(devId).c_str()); - return ERR_INVALID_OPERATION; - } - - DeviceInfo *deviceInfo = iter->second.get(); - if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { - HILOGE("deviceInfo addrNum not valid, addrNum %{public}d", deviceInfo->addrNum); - return ERR_DEVICEMANAGER_OPERATION_FAILED; - } - - for (unsigned int i = 0; i < deviceInfo->addrNum; i++) { - // currently, only support CONNECT_ADDR_WLAN - if (deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_WLAN && - deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_ETH) { - continue; - } - - HILOGI("SoftbusAdapter::SoftbusJoinLnn call softbus JoinLNN."); - return JoinLNN(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &deviceInfo->addr[i], OnSoftbusJoinLNNResult); - } - - return ERR_DEVICEMANAGER_OPERATION_FAILED; -} - -int32_t SoftbusAdapter::SoftbusLeaveLnn(std::string networkId) -{ - return LeaveLNN(networkId.c_str(), OnSoftbusLeaveLNNResult); -} - -int32_t SoftbusAdapter::GetConnectionIpAddr(std::string deviceId, std::string &ipAddr) -{ - auto iter = discoverDeviceInfoMap_.find(deviceId); - if (iter == discoverDeviceInfoMap_.end()) { - HILOGE("deviceInfo not found by deviceId %{public}s", GetAnonyString(deviceId).c_str()); - return ERR_INVALID_OPERATION; - } - - DeviceInfo *deviceInfo = iter->second.get(); - if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { - HILOGE("deviceInfo addrNum not valid, addrNum %{public}d", deviceInfo->addrNum); - return ERR_DEVICEMANAGER_OPERATION_FAILED; - } - - for (unsigned int i = 0; i < deviceInfo->addrNum; ++i) { - // currently, only support CONNECT_ADDR_WLAN - if (deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_WLAN && - deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_ETH) { - continue; - } - ipAddr = deviceInfo->addr[i].info.ip.ip; - HILOGI("SoftbusAdapter::GetConnectionIpAddr get ip ok."); - return ERR_OK; - } - HILOGE("failed to get ipAddr for deviceId %{public}s", GetAnonyString(deviceId).c_str()); - return ERR_DEVICEMANAGER_OPERATION_FAILED; -} - -const std::map>>& SoftbusAdapter::GetsubscribeInfos() -{ - return subscribeInfos_; -} - -void SoftbusAdapter::SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo) -{ - std::shared_ptr info = std::make_shared(); - DeviceInfo *infoPtr = info.get(); - if (memcpy_s(infoPtr, sizeof(DeviceInfo), deviceInfo, sizeof(DeviceInfo)) != 0) { - HILOGE("SoftbusAdapter::SaveDiscoverDeviceInfo failed."); - return; - } - - std::string deviceId = deviceInfo->devId; - discoverDeviceInfoMap_[deviceId] = info; - discoverDeviceInfoVector_.push_back(info); - - // Remove the earliest element when reached the max size - if (discoverDeviceInfoVector_.size() == DISCOVER_DEVICEINFO_MAX_SIZE) { - auto iter = discoverDeviceInfoVector_.begin(); - std::string delDevId = iter->get()->devId; - discoverDeviceInfoMap_.erase(delDevId); - discoverDeviceInfoVector_.erase(iter); - } -} - -void SoftbusAdapter::RemoveDiscoverDeviceInfo(const std::string deviceId) -{ - discoverDeviceInfoMap_.erase(deviceId); - auto iter = discoverDeviceInfoVector_.begin(); - while (iter != discoverDeviceInfoVector_.end()) { - if (strcmp(iter->get()->devId, deviceId.c_str()) == 0) { - iter = discoverDeviceInfoVector_.erase(iter); - } else { - ++iter; - } - } -} -} // namespace DistributedHardware -} // namespace OHOS +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "softbus_adapter.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include "softbus_bus_center.h" + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" + +#include "anonymous_string.h" +#include "device_manager_errno.h" +#include "device_manager_log.h" +#include "softbus_session.h" +#include "system_ability_definition.h" + +#include "ipc_server_listener_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { +const std::string DEVICE_MANAGER_PACKAGE_NAME = "com.huawei.devicemanager"; +const int32_t CHECK_INTERVAL = 100000; // 100ms +const int32_t SUBSCRIBE_ID_PREFIX_LEN = 16; +const int32_t SUBSCRIBE_ID_MASK = 0x0000FFFF; +const int32_t DISCOVER_DEVICEINFO_MAX_SIZE = 20; +} +std::map>> SoftbusAdapter::subscribeInfos_; +std::map> SoftbusAdapter::discoverDeviceInfoMap_; +std::vector> SoftbusAdapter::discoverDeviceInfoVector_; +uint16_t SoftbusAdapter::subscribeIdPrefix = 0; +std::mutex SoftbusAdapter::lock_; +INodeStateCb SoftbusAdapter::softbusNodeStateCb = { + .events = EVENT_NODE_STATE_ONLINE | EVENT_NODE_STATE_OFFLINE | EVENT_NODE_STATE_INFO_CHANGED, + .onNodeOnline = OnSoftBusDeviceOnline, + .onNodeOffline = OnSoftbusDeviceOffline, + .onNodeBasicInfoChanged = OnSoftbusDeviceInfoChanged +}; +IDiscoveryCallback SoftbusAdapter::softbusDiscoverCallback = { + .OnDeviceFound = OnSoftbusDeviceFound, + .OnDiscoverFailed = OnSoftbusDiscoverFailed, + .OnDiscoverySuccess = OnSoftbusDiscoverySuccess +}; +IPublishCallback SoftbusAdapter::servicePublishCallback = { + .OnPublishSuccess = PublishServiceCallBack::OnPublishSuccess, + .OnPublishFail = PublishServiceCallBack::OnPublishFail +}; + +void SoftbusAdapter::RemoveDiscoverDeviceInfo(const std::string deviceId) +{ + discoverDeviceInfoMap_.erase(deviceId); + auto iter = discoverDeviceInfoVector_.begin(); + while (iter != discoverDeviceInfoVector_.end()) { + if (strcmp(iter->get()->devId, deviceId.c_str()) == 0) { + iter = discoverDeviceInfoVector_.erase(iter); + } else { + ++iter; + } + } +} + +void SoftbusAdapter::OnSoftBusDeviceOnline(NodeBasicInfo *info) +{ + if (info == nullptr) { + DMLog(DM_LOG_ERROR, "OnSoftBusDeviceOnline NodeBasicInfo is nullptr"); + return; + } + DmDeviceInfo dmDeviceInfo; + + NodeBasicInfoCopyToDmDevice(dmDeviceInfo, *info); + IpcServerListenerAdapter::GetInstance().OnDeviceStateChange(DmDeviceState::DEVICE_STATE_ONLINE, dmDeviceInfo); + + uint8_t udid[UDID_BUF_LEN] = {0}; + int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info->networkId, + NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "GetNodeKeyInfo failed"); + return; + } + std::string deviceId = (char *)udid; + DMLog(DM_LOG_INFO, "device online, deviceId: %s", GetAnonyString(deviceId).c_str()); + RemoveDiscoverDeviceInfo(deviceId); +} + +void SoftbusAdapter::OnSoftbusDeviceOffline(NodeBasicInfo *info) +{ + if (info == nullptr) { + DMLog(DM_LOG_ERROR, "OnSoftbusDeviceOffline NodeBasicInfo is nullptr"); + return; + } + DmDeviceInfo dmDeviceInfo; + + NodeBasicInfoCopyToDmDevice(dmDeviceInfo, *info); + IpcServerListenerAdapter::GetInstance().OnDeviceStateChange(DmDeviceState::DEVICE_STATE_OFFLINE, dmDeviceInfo); +} + +void SoftbusAdapter::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) +{ + DMLog(DM_LOG_INFO, "OnSoftbusDeviceInfoChanged."); + // currently do nothing + (void)type; + (void)info; +} + +void SoftbusAdapter::SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo) +{ + std::shared_ptr info = std::make_shared(); + DeviceInfo *infoPtr = info.get(); + if (memcpy_s(infoPtr, sizeof(DeviceInfo), deviceInfo, sizeof(DeviceInfo)) != 0) { + DMLog(DM_LOG_ERROR, "SoftbusAdapter::SaveDiscoverDeviceInfo failed."); + return; + } + + std::string deviceId = deviceInfo->devId; + discoverDeviceInfoMap_[deviceId] = info; + discoverDeviceInfoVector_.push_back(info); + + // Remove the earliest element when reached the max size + if (discoverDeviceInfoVector_.size() == DISCOVER_DEVICEINFO_MAX_SIZE) { + auto iter = discoverDeviceInfoVector_.begin(); + std::string delDevId = iter->get()->devId; + discoverDeviceInfoMap_.erase(delDevId); + discoverDeviceInfoVector_.erase(iter); + } +} + +void SoftbusAdapter::OnSoftbusDeviceFound(const DeviceInfo *device) +{ + if (device == nullptr) { + DMLog(DM_LOG_ERROR, "deviceinfo is null"); + return; + } + + std::string deviceId = device->devId; + DMLog(DM_LOG_INFO, "SoftbusAdapter::OnSoftbusDeviceFound device %s found.", GetAnonyString(deviceId).c_str()); + if (IsDeviceOnLine(deviceId)) { + return; + } + + SaveDiscoverDeviceInfo(device); + for (auto iter = subscribeInfos_.begin(); iter != subscribeInfos_.end(); ++iter) { + auto subInfovector = iter->second; + for (auto vectorIter = subInfovector.begin(); vectorIter != subInfovector.end(); ++vectorIter) { + auto info = vectorIter->get(); + DMLog(DM_LOG_INFO, "subscribe info capability:%s.", info->info.capability); + if (strcmp(DM_CAPABILITY_OSD, info->info.capability) != 0) { + DMLog(DM_LOG_ERROR, "subscribe info capability invalid."); + } + uint16_t originId = (uint16_t)(((uint32_t)info->info.subscribeId) & SUBSCRIBE_ID_MASK); + std::string strPkgName = iter->first; + DmDeviceInfo dmDeviceInfo; + + DeviceInfoCopyToDmDevice(dmDeviceInfo, *device); + IpcServerListenerAdapter::GetInstance().OnDeviceFound(strPkgName, originId, dmDeviceInfo); + } + } +} + +bool SoftbusAdapter::GetpkgNameBySubscribeId(int32_t adapterId, std::string &pkgName) +{ + for (auto iter = subscribeInfos_.begin(); iter != subscribeInfos_.end(); ++iter) { + std::vector> &subinfoVector = iter->second; + auto vectorIter = subinfoVector.begin(); + for (; vectorIter != subinfoVector.end(); ++vectorIter) { + if (vectorIter->get()->info.subscribeId == adapterId) { + pkgName = iter->first; + return true; + } + } + } + return false; +} + +void SoftbusAdapter::OnSoftbusDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason) +{ + DMLog(DM_LOG_INFO, "In, subscribeId %d, failReason %d", subscribeId, (int32_t)failReason); + std::string pkgName; + if (!GetpkgNameBySubscribeId(subscribeId, pkgName)) { + DMLog(DM_LOG_ERROR, "OnSoftbusDiscoverFailed: pkgName not found"); + return; + } + + uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); + IpcServerListenerAdapter::GetInstance().OnDiscoverFailed(pkgName, originId, failReason); +} + +void SoftbusAdapter::OnSoftbusDiscoverySuccess(int32_t subscribeId) +{ + DMLog(DM_LOG_INFO, "In, subscribeId %d", subscribeId); + std::string pkgName; + if (!GetpkgNameBySubscribeId(subscribeId, pkgName)) { + DMLog(DM_LOG_ERROR, "OnSoftbusDiscoverySuccess: pkgName not found"); + return; + } + uint16_t originId = (uint16_t)(((uint32_t)subscribeId) & SUBSCRIBE_ID_MASK); + IpcServerListenerAdapter::GetInstance().OnDiscoverySuccess(pkgName, originId); +} + +bool SoftbusAdapter::GetsubscribeIdAdapter(std::string& pkgName, int16_t originId, int32_t &adapterId) +{ + DMLog(DM_LOG_INFO, "GetsubscribeIdAdapter in, pkgName: %s, originId:%d", pkgName.c_str(), + (int32_t)originId); + auto iter = subscribeInfos_.find(pkgName); + if (iter == subscribeInfos_.end()) { + DMLog(DM_LOG_ERROR, "subscribeInfo not find for pkgName: %s", pkgName.c_str()); + return false; + } + + std::vector> &subinfoVector = iter->second; + auto vectorIter = subinfoVector.begin(); + for (; vectorIter != subinfoVector.end(); ++vectorIter) { + if (vectorIter->get()->subscribeIdOrigin == originId) { + DMLog(DM_LOG_ERROR, "find adapterId:%d for pkgName: %s, originId:%d", + vectorIter->get()->info.subscribeId, pkgName.c_str(), (int32_t)originId); + adapterId = vectorIter->get()->info.subscribeId; + return true; + } + } + DMLog(DM_LOG_ERROR, "subscribe not find. pkgName: %s, originId:%d", pkgName.c_str(), (int32_t)originId); + return false; +} + +int32_t SoftbusAdapter::Init() +{ + int32_t ret; + int32_t retryTimes = 0; + do { + ret = RegNodeDeviceStateCb(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &softbusNodeStateCb); + if (ret != DEVICEMANAGER_OK) { + ++retryTimes; + DMLog(DM_LOG_ERROR, "RegNodeDeviceStateCb failed with ret %d, retryTimes %d", ret, retryTimes); + usleep(CHECK_INTERVAL); + } + } while (ret != DEVICEMANAGER_OK); + DMLog(DM_LOG_INFO, "RegNodeDeviceStateCb success."); + SoftbusSession::GetInstance().Start(); + + PublishInfo dmPublishInfo; + dmPublishInfo.publishId = DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID; + dmPublishInfo.mode = DiscoverMode::DISCOVER_MODE_ACTIVE; + dmPublishInfo.medium = ExchanageMedium::AUTO; + dmPublishInfo.freq = ExchangeFreq::HIGH; + dmPublishInfo.capability = DM_CAPABILITY_OSD; + dmPublishInfo.capabilityData = nullptr; + dmPublishInfo.dataLen = 0; + ret = PublishService(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &dmPublishInfo, &servicePublishCallback); + DMLog(DM_LOG_INFO, "service publish result is : %d", ret); + return ret; +} + +int32_t SoftbusAdapter::GetTrustDevices(const std::string &pkgName, NodeBasicInfo **info, int32_t *infoNum) +{ + DMLog(DM_LOG_INFO, "DM_GetSoftbusTrustDevices start, pkgName: %s", pkgName.c_str()); + int32_t ret = GetAllNodeDeviceInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), info, infoNum); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "GetAllNodeDeviceInfo failed with ret %d", ret); + return ret; + } + DMLog(DM_LOG_INFO, "success, pkgName: %s, deviceCount %d", pkgName.c_str(), *infoNum); + return DEVICEMANAGER_OK; +} + +int32_t SoftbusAdapter::StartDiscovery(std::string &pkgName, SubscribeInfo *info) +{ + std::shared_ptr subinfo = nullptr; + if (subscribeInfos_.find(pkgName) == subscribeInfos_.end()) { + subscribeInfos_[pkgName] = {}; + } + + auto iter = subscribeInfos_.find(pkgName); + std::vector> &subinfoVector = iter->second; + auto vectorIter = subinfoVector.begin(); + for (; vectorIter != subinfoVector.end(); ++vectorIter) { + if (vectorIter->get()->subscribeIdOrigin == info->subscribeId) { + subinfo = *vectorIter; + break; + } + } + if (subinfo == nullptr) { + std::lock_guard autoLock(lock_); + subinfo = std::make_shared(); + subinfo->subscribeIdOrigin = info->subscribeId; + subinfo->subscribeIdPrefix = subscribeIdPrefix++; + subinfo->info = *info; + subinfo->info.subscribeId = (subinfo->subscribeIdPrefix << SUBSCRIBE_ID_PREFIX_LEN) | info->subscribeId; + } + if (vectorIter == subinfoVector.end()) { + subinfoVector.push_back(subinfo); + } + DMLog(DM_LOG_INFO, "StartDiscovery, pkgName: %s, subscribeId %d, prefix %d, origin %d", + pkgName.c_str(), subinfo->info.subscribeId, subinfo->subscribeIdPrefix, subinfo->subscribeIdOrigin); + DMLog(DM_LOG_INFO, "Capability: %s", subinfo->info.capability); + int32_t ret = ::StartDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &subinfo->info, &softbusDiscoverCallback); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "StartDiscovery failed with ret %d.", ret); + return DEVICEMANAGER_DISCOVERY_FAILED; + } + return DEVICEMANAGER_OK; +} + +int32_t SoftbusAdapter::StopDiscovery(std::string &pkgName, uint16_t subscribeId) +{ + int32_t subscribeIdAdapter = -1; + if (!GetsubscribeIdAdapter(pkgName, subscribeId, subscribeIdAdapter)) { + DMLog(DM_LOG_ERROR, "StopDiscovery failed, subscribeId not match"); + return DEVICEMANAGER_FAILED; + } + + DMLog(DM_LOG_INFO, "StopDiscovery begin, pkgName: %s, subscribeId:%d, subscribeIdAdapter:%d", + pkgName.c_str(), (int32_t)subscribeId, subscribeIdAdapter); + int32_t ret = ::StopDiscovery(DEVICE_MANAGER_PACKAGE_NAME.c_str(), subscribeIdAdapter); + if (ret != 0) { + DMLog(DM_LOG_ERROR, "StopDiscovery failed with ret %d", ret); + return ret; + } + + auto iter = subscribeInfos_.find(pkgName); + auto subinfoVector = iter->second; + auto vectorIter = subinfoVector.begin(); + while (vectorIter != subinfoVector.end()) { + if (vectorIter->get()->subscribeIdOrigin == subscribeId) { + vectorIter = subinfoVector.erase(vectorIter); + break; + } else { + ++vectorIter; + } + } + if (subinfoVector.empty()) { + subscribeInfos_.erase(pkgName); + } + DMLog(DM_LOG_INFO, "DM_StopSoftbusDiscovery completed, pkgName: %s", pkgName.c_str()); + return DEVICEMANAGER_OK; +} + +bool SoftbusAdapter::IsDeviceOnLine(std::string &deviceId) +{ + NodeBasicInfo *info = nullptr; + int32_t infoNum = 0; + + if (GetTrustDevices(DEVICE_MANAGER_PACKAGE_NAME.c_str(), &info, &infoNum) != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "DM_IsDeviceOnLine DM_GetSoftbusTrustDevices failed"); + return false; + } + + bool bDeviceOnline = false; + for (int32_t i = 0; i < infoNum; ++i) { + NodeBasicInfo *nodeBasicInfo = info + i; + if (nodeBasicInfo == nullptr) { + DMLog(DM_LOG_ERROR, "nodeBasicInfo is empty for index %d, infoNum %d.", i, infoNum); + continue; + } + std::string networkId = nodeBasicInfo->networkId; + if (networkId == deviceId) { + DMLog(DM_LOG_INFO, "DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); + bDeviceOnline = true; + break; + } + uint8_t udid[UDID_BUF_LEN] = {0}; + int32_t ret = GetNodeKeyInfo(DEVICE_MANAGER_PACKAGE_NAME.c_str(), networkId.c_str(), + NodeDeivceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_ERROR, "DM_IsDeviceOnLine GetNodeKeyInfo failed"); + break; + } + + if (strcmp((char *)udid, deviceId.c_str()) == 0) { + DMLog(DM_LOG_INFO, "DM_IsDeviceOnLine devccie %s online", GetAnonyString(deviceId).c_str()); + bDeviceOnline = true; + break; + } + } + FreeNodeInfo(info); + return bDeviceOnline; +} + +int32_t SoftbusAdapter::GetConnectionIpAddr(std::string deviceId, std::string &ipAddr) +{ + auto iter = discoverDeviceInfoMap_.find(deviceId); + if (iter == discoverDeviceInfoMap_.end()) { + DMLog(DM_LOG_ERROR, "deviceInfo not found by deviceId %s", GetAnonyString(deviceId).c_str()); + return DEVICEMANAGER_FAILED; + } + + DeviceInfo *deviceInfo = iter->second.get(); + if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { + DMLog(DM_LOG_ERROR, "deviceInfo addrNum not valid, addrNum %d", deviceInfo->addrNum); + return DEVICEMANAGER_FAILED; + } + + for (unsigned int i = 0; i < deviceInfo->addrNum; ++i) { + // currently, only support CONNECT_ADDR_WLAN + if (deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_WLAN && + deviceInfo->addr[i].type != ConnectionAddrType::CONNECTION_ADDR_ETH) { + continue; + } + ipAddr = deviceInfo->addr[i].info.ip.ip; + DMLog(DM_LOG_INFO, "DM_GetConnectionIpAddr get ip ok."); + return DEVICEMANAGER_OK; + } + DMLog(DM_LOG_ERROR, "failed to get ipAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + return DEVICEMANAGER_FAILED; +} + + +//eth 》 wlan >> ble >> br +ConnectionAddr *SoftbusAdapter::GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type) +{ + if (deviceInfo == nullptr) { + return nullptr; + } + + for (unsigned int i = 0; i < deviceInfo->addrNum; ++i) { + if (deviceInfo->addr[i].type == type) { + return &deviceInfo->addr[i]; + } + } + + return nullptr; +} + +ConnectionAddr *SoftbusAdapter::GetConnectAddr(std::string deviceId) +{ + auto iter = discoverDeviceInfoMap_.find(deviceId); + if (iter == discoverDeviceInfoMap_.end()) { + DMLog(DM_LOG_ERROR, "deviceInfo not found by deviceId %s", GetAnonyString(deviceId).c_str()); + return nullptr; + } + + DeviceInfo *deviceInfo = iter->second.get(); + if (deviceInfo->addrNum <= 0 || deviceInfo->addrNum >= CONNECTION_ADDR_MAX) { + DMLog(DM_LOG_ERROR, "deviceInfo addrNum not valid, addrNum %d", deviceInfo->addrNum); + return nullptr; + } + + ConnectionAddr *addr = nullptr; + addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_ETH); + if (addr != nullptr) { + DMLog(DM_LOG_INFO, "get ETH ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + DMLog(DM_LOG_INFO, "get ETH ConnectionAddr, ip: %s, port: %d", addr->info.ip.ip, addr->info.ip.port); + return addr; + } + + addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_WLAN); + if (addr != nullptr) { + DMLog(DM_LOG_INFO, "get WLAN ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + DMLog(DM_LOG_INFO, "get WLAN ConnectionAddr, ip: %s, port: %d", addr->info.ip.ip, addr->info.ip.port); + return addr; + } + + addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_BLE); + if (addr != nullptr) { + DMLog(DM_LOG_INFO, "get BLE ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + DMLog(DM_LOG_INFO, "get BLE ConnectionAddr, ip: %s, port: %d", addr->info.ip.ip, addr->info.ip.port); + return addr; + } + + addr = GetConnectAddrByType(deviceInfo, ConnectionAddrType::CONNECTION_ADDR_BR); + if (addr != nullptr) { + DMLog(DM_LOG_INFO, "get BR ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + DMLog(DM_LOG_INFO, "get BR ConnectionAddr, ip: %s, port: %d", addr->info.ip.ip, addr->info.ip.port); + return addr; + } + + DMLog(DM_LOG_ERROR, "failed to get ConnectionAddr for deviceId %s", GetAnonyString(deviceId).c_str()); + return nullptr; +} + +void SoftbusAdapter::NodeBasicInfoCopyToDmDevice(DmDeviceInfo& dmDeviceInfo, NodeBasicInfo& nodeBasicInfo) +{ + (void)memset_s(&dmDeviceInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)); + (void)memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), nodeBasicInfo.networkId, + std::min(sizeof(dmDeviceInfo.deviceId), sizeof(nodeBasicInfo.networkId))); + (void)memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), nodeBasicInfo.deviceName, + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))); + dmDeviceInfo.deviceTypeId = (DMDeviceType)nodeBasicInfo.deviceTypeId; +} + +void SoftbusAdapter::DeviceInfoCopyToDmDevice(DmDeviceInfo& dmDeviceInfo, const DeviceInfo& deviceInfo) +{ + (void)memset_s(&dmDeviceInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)); + (void)memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), deviceInfo.devId, + std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))); + (void)memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), deviceInfo.devName, + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))); + dmDeviceInfo.deviceTypeId = (DMDeviceType)deviceInfo.devType; +} + +void PublishServiceCallBack::OnPublishSuccess(int32_t publishId) +{ + DMLog(DM_LOG_INFO, "service publish succeed, publishId: %d", publishId); +} + +void PublishServiceCallBack::OnPublishFail(int32_t publishId, PublishFailReason reason) +{ + DMLog(DM_LOG_INFO, "service publish failed, publishId: %d, reason: %d", publishId, reason); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/softbus/softbus_session.cpp b/services/devicemanagerservice/src/softbus/softbus_session.cpp new file mode 100644 index 000000000..2b2284e38 --- /dev/null +++ b/services/devicemanagerservice/src/softbus/softbus_session.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "softbus_session.h" +#include "softbus_adapter.h" + +#include "device_manager_log.h" +#include "device_manager_errno.h" +#include "auth_manager.h" +#include "encrypt_utils.h" +#include "constants.h" +#include "session.h" +#include "inner_session.h" + +namespace OHOS { +namespace DistributedHardware { +static int32_t SessionOpened(int32_t sessionId, int32_t result) +{ + return SoftbusSession::GetInstance().OnSessionOpened(sessionId, result); +} + +static void SessionClosed(int32_t sessionId) +{ + SoftbusSession::GetInstance().OnSessionClosed(sessionId); +} + +static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + SoftbusSession::GetInstance().GetInstance().OnBytesReceived(sessionId, data, dataLen); +} + +static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + DMLog(DM_LOG_INFO, "sessionId:%d, dataLen:%d", sessionId, dataLen); +} + +static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param) +{ + DMLog(DM_LOG_INFO, "sessionId:%d", sessionId); +} + +IMPLEMENT_SINGLE_INSTANCE(SoftbusSession); + +SoftbusSession::~SoftbusSession() +{ + (void)RemoveSessionServer(PKG_NAME, SESSION_NAME); +} + +int32_t SoftbusSession::Start() +{ + DMLog(DM_LOG_INFO, "SoftbusSession start"); + ISessionListener iSessionListener = { + .OnSessionOpened = SessionOpened, + .OnSessionClosed = SessionClosed, + .OnBytesReceived = BytesReceived, + .OnMessageReceived = MessageReceived, + .OnStreamReceived = StreamReceived + }; + int32_t ret = CreateSessionServer(PKG_NAME, SESSION_NAME, &iSessionListener); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_DEBUG, "CreateSessionServer failed"); + return DEVICEMANAGER_CREATE_SESSION_SERVER_FAILED; + } + return DEVICEMANAGER_OK; +} + +int32_t SoftbusSession::OnSessionOpened(int32_t sessionId, int32_t result) +{ + if (result == DEVICEMANAGER_OK) { + DMLog(DM_LOG_INFO, "session open succeed"); + for (auto msg : messages_) { + int32_t ret = SendMsg(sessionId, msg); + if (ret != DEVICEMANAGER_OK) { + DMLog(DM_LOG_INFO, "send message failed"); + return ret; + } + } + } else { + DMLog(DM_LOG_INFO, " open session failed"); + } + return DEVICEMANAGER_OK; +} + +void SoftbusSession::OnSessionClosed(int32_t sessionId) +{ + DMLog(DM_LOG_INFO, "OnSessionClosed, sessionId:%d", sessionId); +} + +void SoftbusSession::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + DMLog(DM_LOG_INFO, "OnBytesReceived, sessionId:%d, dataLen:%d", sessionId, dataLen); + if (sessionId < 0 || data == nullptr || dataLen <= 0) { + DMLog(DM_LOG_INFO, "OnBytesReceived param check failed"); + return; + } + + uint8_t * buf = (uint8_t *)calloc(sizeof(uint8_t), dataLen + 1); + if (buf == nullptr) { + DMLog(DM_LOG_ERROR, "SendMsg: malloc memory failed"); + return; + } + + int32_t outLen = 0; + int32_t ret = EncryptUtils::MbedtlsDecrypt((const uint8_t*)data, dataLen, buf, dataLen, &outLen); + if (ret != DEVICEMANAGER_OK || outLen > (int32_t)dataLen) { + DMLog(DM_LOG_ERROR, "MbedtlsDecrypt data failed"); + free(buf); + return; + } + + std::string message = (char *)buf; + AuthManager::GetInstance().onReceiveMsg(sessionId, message); + free(buf); + return; +} + +void SoftbusSession::CloseSession(int32_t sessionId) +{ + DMLog(DM_LOG_INFO, "CloseSession in"); + ::CloseSession(sessionId); +} + +int32_t SoftbusSession::SendData(int32_t sessionId, const void *data, int32_t len) +{ + DMLog(DM_LOG_INFO, "in, datalen:%d", len); + int32_t ret = DEVICEMANAGER_FAILED; + if (sessionIdSet_.count(sessionId) > 0) { + ret = SendBytes(sessionId, data, len); + if (ret != DEVICEMANAGER_OK) { + return DEVICEMANAGER_FAILED; + } + } else { + DMLog(DM_LOG_INFO, "in, datalen:%d", len); + } + return ret; +} + +// send message by sessionId (channel opened) +int32_t SoftbusSession::SendMsg(int32_t sessionId, std::string &message) +{ + DMLog(DM_LOG_ERROR, "start SendMsg"); + uint8_t * buf = (uint8_t *)calloc(sizeof(uint8_t), (MSG_MAX_SIZE + ENCRYPT_TAG_LEN)); + if (buf == nullptr) { + DMLog(DM_LOG_ERROR, "SendMsg: malloc memory failed"); + return DEVICEMANAGER_MALLOC_ERROR; + } + int32_t outLen = 0; + int32_t ret = EncryptUtils::MbedtlsEncrypt((const uint8_t*)message.c_str(), message.size(), buf, MSG_MAX_SIZE, + &outLen); + if (ret != DEVICEMANAGER_OK || outLen > MSG_MAX_SIZE) { + DMLog(DM_LOG_ERROR, "MbedtlsEncrypt data failed"); + free(buf); + return ENCRYPT_UTILS_AES_GCM_ENCRYPT_FAILED; + } + ret = SendData(sessionId, buf, outLen); + free(buf); + return ret; +} + +// send message while the channel is not opend +int32_t SoftbusSession::SendMessages(const char *deviceId, std::vector &message) +{ + DMLog(DM_LOG_ERROR, "open channel and start SendMsg"); + int32_t sessionId; + messages_ = message; + ConnectionAddr * addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); + if (addrInfo == nullptr) { + DMLog(DM_LOG_ERROR, "GetConnectAddr error"); + return DEVICEMANAGER_FAILED; + } + + sessionId = ::OpenAuthSession(SESSION_NAME, addrInfo, 1, nullptr); + if (sessionId < 0) { + DMLog(DM_LOG_ERROR, "open session error, ret:%d", sessionId); + return sessionId; + } + sessionIdSet_.insert(sessionId); + DMLog(DM_LOG_INFO, "opened auth session is:%d", sessionId); + return sessionId; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee From 24820b0832a1698993cc2062d02f2011b2984e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 6 Sep 2021 16:23:49 +0800 Subject: [PATCH 2/4] support L1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- BUILD.gn | 2 +- common/include/ipc/lite/ipc_cmd_register.h | 12 +-- common/include/utils/single_instance.h | 21 ++--- common/src/ipc/lite/ipc_cmd_register.cpp | 4 +- common/src/log/device_manager_log.cpp | 77 ++++++++++-------- device_manager.7z | Bin 56365 -> 0 bytes .../native_cpp/include/dm_device_info.h | 4 +- .../include/auth/hichain_connector.h | 3 +- .../include/encrypt/encrypt_utils.h | 34 ++++---- .../include/ipc/lite/ipc_server_stub.h | 4 +- .../src/encrypt/encrypt_utils.cpp | 52 ++++++------ .../src/ipc/lite/ipc_cmd_parser.cpp | 18 ++-- .../src/ipc/lite/ipc_server_stub.cpp | 21 ++--- .../src/ipc/standard/ipc_server_listener.cpp | 2 - .../src/message/msg_request_auth.cpp | 6 +- .../src/requestauth/request_session.cpp | 12 +-- .../src/softbus/softbus_session.cpp | 7 ++ 17 files changed, 143 insertions(+), 136 deletions(-) delete mode 100644 device_manager.7z diff --git a/BUILD.gn b/BUILD.gn index d9945174c..97ca938d1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,4 +19,4 @@ if (defined(ohos_lite)) { "interfaces/inner_kits/native_cpp:devicemanagersdk", ] } -} \ No newline at end of file +} diff --git a/common/include/ipc/lite/ipc_cmd_register.h b/common/include/ipc/lite/ipc_cmd_register.h index 26f542335..8b887827b 100644 --- a/common/include/ipc/lite/ipc_cmd_register.h +++ b/common/include/ipc/lite/ipc_cmd_register.h @@ -66,8 +66,8 @@ namespace DistributedHardware { IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ static void IpcCmdProcess##cmdCode(paraA, paraB, paraC) \ -#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB, paraC) \ - static void IpcServerCmdProcess##cmdCode(paraA, paraB, paraC); \ +#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB) \ + static void IpcServerCmdProcess##cmdCode(paraA, paraB); \ class IpcRegisterServerCmdProcessFunc##cmdCode \ { \ public: \ @@ -77,16 +77,16 @@ namespace DistributedHardware { } \ }; \ IpcRegisterServerCmdProcessFunc##cmdCode g_IpcRegisterServerCmdProcessFunc##cmdCode; \ - static void IpcServerCmdProcess##cmdCode(paraA, paraB, paraC) + static void IpcServerCmdProcess##cmdCode(paraA, paraB) using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, IpcIo& request, uint8_t *buffer, size_t bufferLen); using ReadResponseFunc = int32_t (*)(IpcIo& reply, std::shared_ptr pBaseRsp); using OnIpcCmdFunc = void (*)(IpcIo &reply, const IpcContext &ctx, void *ipcMsg); -using OnIpcServerCmdFunc = void (*)(void *origin, IpcIo &req, IpcIo &reply); +using OnIpcServerCmdFunc = void (*)(IpcIo &req, IpcIo &reply); class IpcCmdRegister { -DECLARE_SINGLE_INSTANCE(IpcCmdRegister); +DECLARE_SINGLE_INSTANCE(IpcCmdRegister); public: void RegisterSetRequestFunc(int32_t cmdCode, SetIpcRequestFunc setIpcRequestFunc) { @@ -108,7 +108,7 @@ public: uint8_t *buffer, size_t buffLen); int32_t ReadResponse(int32_t cmdCode, IpcIo& reply, std::shared_ptr pBaseRsp); int32_t OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext &ctx, void *ipcMsg); - int32_t OnIpcServerCmd(int32_t cmdCode, void *origin, IpcIo &req, IpcIo &reply); + int32_t OnIpcServerCmd(int32_t cmdCode, IpcIo &req, IpcIo &reply); private: std::unordered_map setIpcRequestFuncMap_; std::unordered_map readResponseFuncMap_; diff --git a/common/include/utils/single_instance.h b/common/include/utils/single_instance.h index 0eeb3853e..eff1206fc 100644 --- a/common/include/utils/single_instance.h +++ b/common/include/utils/single_instance.h @@ -25,23 +25,14 @@ private: \ className(const className&) = delete; \ className& operator= (const className&) = delete; \ className(className&&) = delete; \ - className& operator= (className&&) = delete; \ + className& operator= (className&&) = delete \ -#define DECLARE_SINGLE_INSTANCE(className) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() = default; \ - ~className() = default; \ - -#define DECLARE_SINGLE_INSTANCE_INIT(className, funcName) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() \ - { \ - funcName(); \ - }; \ - ~className() = default; \ +#define DECLARE_SINGLE_INSTANCE(className) \ + DECLARE_SINGLE_INSTANCE_BASE(className); \ +private: \ + className() = default; \ + ~className() = default \ #define IMPLEMENT_SINGLE_INSTANCE(className) \ className & className::GetInstance() \ diff --git a/common/src/ipc/lite/ipc_cmd_register.cpp b/common/src/ipc/lite/ipc_cmd_register.cpp index c4d823288..a1238fb6e 100644 --- a/common/src/ipc/lite/ipc_cmd_register.cpp +++ b/common/src/ipc/lite/ipc_cmd_register.cpp @@ -55,14 +55,14 @@ int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext return DEVICEMANAGER_OK; } -int32_t IpcCmdRegister::OnIpcServerCmd(int32_t cmdCode, void *origin, IpcIo &req, IpcIo &reply) +int32_t IpcCmdRegister::OnIpcServerCmd(int32_t cmdCode, IpcIo &req, IpcIo &reply) { auto onIpcServerCmdMapIter = onIpcServerCmdFuncMap_.find(cmdCode); if (onIpcServerCmdMapIter == onIpcServerCmdFuncMap_.end()) { DMLog(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; } - (onIpcServerCmdMapIter->second)(origin, req, reply); + (onIpcServerCmdMapIter->second)(req, reply); return DEVICEMANAGER_OK; } } // namespace DistributedHardware diff --git a/common/src/log/device_manager_log.cpp b/common/src/log/device_manager_log.cpp index 786e7efd3..8ae1748da 100644 --- a/common/src/log/device_manager_log.cpp +++ b/common/src/log/device_manager_log.cpp @@ -21,60 +21,69 @@ #ifdef HI_LOG_ENABLE #include "hilog/log.h" - -#define DMLOGD(buf) ((void)HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, \ - DH_LOG_TAG, "%{public}s:", buf)) -#define DMLOGE(buf) ((void)HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, \ - DH_LOG_TAG, "%{public}s:", buf)) -#define DMLOGI(buf) ((void)HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, \ - DH_LOG_TAG, "%{public}s:", buf)) -#define DMLOGW(buf) ((void)HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, \ - DH_LOG_TAG, "%{public}s:", buf)) - #else - -#include +#include #include - -#define DMLOGD(buf) printf("[D][" DH_LOG_TAG "]:%s\n", buf) -#define DMLOGE(buf) printf("[E][" DH_LOG_TAG "]:%s\n", buf) -#define DMLOGI(buf) printf("[I][" DH_LOG_TAG "]:%s\n", buf) -#define DMLOGW(buf) printf("[W][" DH_LOG_TAG "]:%s\n", buf) - #endif namespace OHOS { namespace DistributedHardware { -void DMLog(DMLogLevel logLevel, const char *fmt, ...) +static void DMLogOut(DMLogLevel logLevel, const char *logBuf) { - char logBuf[LOG_MAX_LEN] = {0}; - va_list arg; - int32_t ret = 0; - - (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); - va_start(arg, fmt); - ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); - va_end(arg); - if (ret < 0) { - DMLOGE("DM log length error."); - return; +#ifdef HI_LOG_ENABLE + LogLevel hiLogLevel = LOG_INFO; + switch (logLevel) { + case DM_LOG_DEBUG: + hiLogLevel = LOG_DEBUG; + break; + case DM_LOG_INFO: + hiLogLevel = LOG_INFO; + break; + case DM_LOG_WARN: + hiLogLevel = LOG_WARN; + break; + case DM_LOG_ERROR: + hiLogLevel = LOG_ERROR; + break; + default: + break; } + (void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DH_LOG_TAG, "%{public}s:", logBuf); +#else switch (logLevel) { case DM_LOG_DEBUG: - DMLOGD(logBuf); + printf("[D][" DH_LOG_TAG "]:%s\n", logBuf); break; case DM_LOG_INFO: - DMLOGI(logBuf); + printf("[I][" DH_LOG_TAG "]:%s\n", logBuf); break; case DM_LOG_WARN: - DMLOGW(logBuf); + printf("[W][" DH_LOG_TAG "]:%s\n", logBuf); break; case DM_LOG_ERROR: - DMLOGE(logBuf); + printf("[E][" DH_LOG_TAG "]:%s\n", logBuf); break; default: break; } +#endif } + +void DMLog(DMLogLevel logLevel, const char *fmt, ...) +{ + char logBuf[LOG_MAX_LEN] = {0}; + va_list arg; + int32_t ret = 0; + + (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + va_start(arg, fmt); + ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); + va_end(arg); + if (ret < 0) { + DMLogOut(logLevel, "DM log length error."); + return; + } + DMLogOut(logLevel, logBuf); } +} // namespace DistributedHardware } // namespace OHOS diff --git a/device_manager.7z b/device_manager.7z deleted file mode 100644 index 005a80189be1aed9a264978657fe114853c80b59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56365 zcmV(yKue?1nAk} zDSxux&LXecNxQ6x>I$qdFAUPqZ9bcMTGm3L@)x@OUGqFOW~o0YegUP)B-CO)d0@`6 zMMl*M$^QW&)2`1UgoWrXR=PAnTrwth-JppG@M-HgWwk0h_T?PQv6E>i12^TFyfFK? z^`CS9Z(->@Ca4|~Qu;?#AKBGgS?8h0FO*j#h8%hvCN1;}i|?^7Df)dkA0OlNIS2dv zv}Ej6^@d+C;!1fV;I~a;7(WC~2WLQKjy~tQoS>;If)0`yuY}$bcw?mIxPOz7aJUEP zTRP@~lR*qp0y~e~Ad`0I=5$jQ>LTs|F9i)ZMq#m5dRSDH*|DVHLGL&sC(fOpCB_hz zSr(DX-4UNtO>fA|>!{4}vW0={#>wCb6=4BstHPzVv@J`Qux@Z+seK}J{iOZ&Ik8er zh{#y$0s`Nx8ag=Y@qKDZRUhB}1v%T*YGNN-*#$rzJu17p(q*ZXgTX&aQBu}OE^m%L zRHUr25mP$E5>DJ#S|&#=2kYO%cAkB*YaK*E=hu)2NNyzB-;DsV54ucjUX942uFlt< zAuZPMN_Pv5e1pQ{<{W+{Hthz&=O9qk zbwXX=d5jZ`x#GX=MkZsx4IB4T91F7Rg7Cg6V;X+Q^j1)C(HQ#AdIR&rN;f>Wp1_9l zxqwkXV$OT99_SiDi}?``^_}UMa@g8RuDaqAyDj-r`}u9T(AFan3{NKSH#osT*&353 z0-4WKymIjPrW;ayqGp4jCu(Cp&6>;l5?86Y%XAV;zStmgmM45jKst;tcFex4eRg{w zMW4<_L}sULMOgYSTS-e6y4LH5{-e+rL zC^ga?I8Pu@i)mcSqnnWtQ?E02V8CRASDw7CEGaJQTcK6x(Lt|+vLBrVV_6+EO_Wx$wY7P{> zo0cm&d6JEvo@&Tn7)6~CNWK{%9WVuz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*Htn5^-7wvi1m?E%f)37`b6!dbvqtV%UHx)v5oA6yNxtvBj?w3y`);B#SCYfDWx z088MT_ePq%P0~ZlCQ%UA23Q^kqBtMjNPPGA`bYocpmPZNYGV%jFw z2KBt#(f`m$EU;qFNz&1z<0bKVes{jDBJnWSK diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 555750589..b1afc8e72 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -52,9 +52,9 @@ typedef struct DmDeviceInfo { typedef struct DmAppImageInfo { int32_t appIconLen; - const uint8_t* appIcon; + const uint8_t *appIcon; int32_t appThumbnailLen; - const uint8_t* appThumbnail; + const uint8_t *appThumbnail; }DmAppImageInfo; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/auth/hichain_connector.h b/services/devicemanagerservice/include/auth/hichain_connector.h index 78053b29e..bca27e894 100644 --- a/services/devicemanagerservice/include/auth/hichain_connector.h +++ b/services/devicemanagerservice/include/auth/hichain_connector.h @@ -51,9 +51,8 @@ public: void notifyHostOnResult(int errorCode); private: std::string GetConnectPara(std::string deviceId, std::shared_ptr msgResponseAuth); - private: - const DeviceGroupManager* deviceGroupManager_ = nullptr; + const DeviceGroupManager *deviceGroupManager_ = nullptr; DeviceAuthCallback deviceAuthCallback_ = { .onTransmit = nullptr, .onFinish = HichainAuthenCallBack::onFinish, diff --git a/services/devicemanagerservice/include/encrypt/encrypt_utils.h b/services/devicemanagerservice/include/encrypt/encrypt_utils.h index af370d8b9..e73c3a536 100644 --- a/services/devicemanagerservice/include/encrypt/encrypt_utils.h +++ b/services/devicemanagerservice/include/encrypt/encrypt_utils.h @@ -27,35 +27,35 @@ public: const uint8_t *src, size_t slen); static int32_t MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *olen, const uint8_t *src, size_t slen); - static int32_t GetRandomData(uint8_t* randStr, uint32_t len); - static int32_t MbedtlsEncrypt(const uint8_t* plainText, int32_t plainTextLen, uint8_t* cipherText, - int32_t cipherTextLen, int32_t* outLen); - static int32_t MbedtlsDecrypt(const uint8_t* cipherText, int32_t cipherTextLen, uint8_t* plainText, - int32_t plainTextLen, int32_t* outLen); + static int32_t GetRandomData(uint8_t *randStr, uint32_t len); + static int32_t MbedtlsEncrypt(const uint8_t *plainText, int32_t plainTextLen, uint8_t *cipherText, + int32_t cipherTextLen, int32_t *outLen); + static int32_t MbedtlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText, + int32_t plainTextLen, int32_t *outLen); /** * szOut最后一位为结束符,比如 szOutLen=4 可能返回 "abc" * @param szOutLen 至少2 * @param numberOnly 是否只生成数据 如果为true 则期望返回随机数字 如果为否,则期望返回随机字符 */ - static bool MbedtlsGenRandomStr(char* szOut, int32_t szOutLen, bool numberOnly); + static bool MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly); private: typedef struct DmCryptInfo { - const uint8_t* sessionkey; + const uint8_t *sessionkey; int32_t sessionkeyLen; - const uint8_t* iv; + const uint8_t *iv; int32_t ivLen; } DmCryptInfo; - static void MbedtlsGenRootKey(uint8_t* szOut, int32_t szOutLen, int32_t* nOutLen); - static int32_t MbedtlsAesGcmDecrypt(DmCryptInfo* info, const uint8_t* cipherText, - uint32_t cipherTextSize, uint8_t* plain, uint32_t plainLen); - static int32_t MbedtlsAesGcmEncrypt(DmCryptInfo * info, const uint8_t* plainText, - uint32_t plainTextSize, uint8_t* cipherText, uint32_t cipherTextLen); - static void XORBlock(uint8_t* output, const uint8_t* input1, - const uint8_t* input2, const size_t block_size); - static void ByteRightMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, + static void MbedtlsGenRootKey(uint8_t *szOut, int32_t szOutLen, int32_t *nOutLen); + static int32_t MbedtlsAesGcmDecrypt(DmCryptInfo *info, const uint8_t *cipherText, + uint32_t cipherTextSize, uint8_t *plain, uint32_t plainLen); + static int32_t MbedtlsAesGcmEncrypt(DmCryptInfo *info, const uint8_t *plainText, + uint32_t plainTextSize, uint8_t *cipherText, uint32_t cipherTextLen); + static void XORBlock(uint8_t *output, const uint8_t *input1, + const uint8_t *input2, const size_t block_size); + static void ByteRightMove(uint8_t *data, size_t dataLen, const uint8_t *inputData, int32_t len, int32_t count); - static void ByteLeftMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, + static void ByteLeftMove(uint8_t *data, size_t dataLen, const uint8_t *inputData, int32_t len, int32_t count); }; } // namespace DistributedHardware diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h index 4d74dafc9..80618756b 100644 --- a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h @@ -21,7 +21,7 @@ #include "liteipc_adapter.h" int32_t IpcServerStubInit(void); -int32_t RegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply); -int32_t UnRegisterDeviceManagerListener(void *origin, IpcIo *req, IpcIo *reply); +int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply); +int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply); #endif // OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H diff --git a/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp index 4d1673db1..13bd348b8 100644 --- a/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp +++ b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp @@ -39,14 +39,14 @@ namespace { const uint8_t HW_RANDOM_KEY_LEN = 16; const uint8_t HW_LEFT_COUNT = 3; const uint8_t HW_RIGHT_COUNT = 5; - const uint8_t BUF_LEN = 32;// olen1是固定的,返回值是18; - //将C1,C2,C3放在不同的位置,目的:增加破译难度 + const uint8_t BUF_LEN = 32; + // 将C1,C2,C3放在不同的位置,目的:增加破译难度 const char* STR_C1 = "s6nxSNjc/VhzXqwXAbKaGUFH"; const char* STR_C2 = "C5bcOsfhejsEAfohXihU65yN"; const char* STR_C3 = "lHhAYIiqUXQom9R0bl1o9Mvm"; } // 数据整体按字节向左位移 count 次 -void EncryptUtils::ByteLeftMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, int32_t count) +void EncryptUtils::ByteLeftMove(uint8_t *data, size_t dataLen, const uint8_t *inputData, int32_t len, int32_t count) { if (len == 0 || data == 0) { DMLog(DM_LOG_DEBUG, "invalid param"); @@ -61,7 +61,7 @@ void EncryptUtils::ByteLeftMove(uint8_t* data, size_t dataLen, const uint8_t* in } } // 数据整体按字节向右位移 count 次 -void EncryptUtils::ByteRightMove(uint8_t* data, size_t dataLen, const uint8_t* inputData, int32_t len, int32_t count) +void EncryptUtils::ByteRightMove(uint8_t *data, size_t dataLen, const uint8_t *inputData, int32_t len, int32_t count) { if (len == 0 || data == 0) { DMLog(DM_LOG_DEBUG, "invalid param"); @@ -76,7 +76,7 @@ void EncryptUtils::ByteRightMove(uint8_t* data, size_t dataLen, const uint8_t* i } } -void EncryptUtils::XORBlock(uint8_t* output, const uint8_t* input1, const uint8_t* input2, +void EncryptUtils::XORBlock(uint8_t *output, const uint8_t *input1, const uint8_t *input2, const size_t block_size) { size_t idx; @@ -85,8 +85,8 @@ void EncryptUtils::XORBlock(uint8_t* output, const uint8_t* input1, const uint8_ } } -int32_t EncryptUtils::MbedtlsAesGcmEncrypt(DmCryptInfo * info, const uint8_t* plainText, - uint32_t plainTextSize, uint8_t* cipherText, uint32_t cipherTextLen) +int32_t EncryptUtils::MbedtlsAesGcmEncrypt(DmCryptInfo *info, const uint8_t *plainText, + uint32_t plainTextSize, uint8_t *cipherText, uint32_t cipherTextLen) { if (info == nullptr || (info->sessionkey == nullptr) || @@ -125,8 +125,8 @@ int32_t EncryptUtils::MbedtlsAesGcmEncrypt(DmCryptInfo * info, const uint8_t* pl return (plainTextSize + HW_TAG_LEN); } -int32_t EncryptUtils::MbedtlsAesGcmDecrypt(DmCryptInfo* info, const uint8_t* cipherText, - uint32_t cipherTextSize, uint8_t* plain, uint32_t plainLen) +int32_t EncryptUtils::MbedtlsAesGcmDecrypt(DmCryptInfo *info, const uint8_t *cipherText, + uint32_t cipherTextSize, uint8_t *plain, uint32_t plainLen) { if (info == nullptr || (info->sessionkey == nullptr) || @@ -156,7 +156,7 @@ int32_t EncryptUtils::MbedtlsAesGcmDecrypt(DmCryptInfo* info, const uint8_t* cip return actualPlainLen; } -void EncryptUtils::MbedtlsGenRootKey(uint8_t* szOut, int32_t szOutLen, int32_t* nOutLen) +void EncryptUtils::MbedtlsGenRootKey(uint8_t *szOut, int32_t szOutLen, int32_t *nOutLen) { uint8_t buf[BUF_LEN] = {0}; uint8_t bufx[BUF_LEN] = {0}; @@ -193,29 +193,31 @@ void EncryptUtils::MbedtlsGenRootKey(uint8_t* szOut, int32_t szOutLen, int32_t* } int32_t EncryptUtils::MbedtlsBase64Encode(uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen ){ - return mbedtls_base64_encode(dst,dlen,olen,src,slen); + const uint8_t *src, size_t slen) +{ + return mbedtls_base64_encode(dst, dlen, olen, src, slen); } -int32_t EncryptUtils::MbedtlsBase64Decode( uint8_t *dst, size_t dlen, size_t *olen, - const uint8_t *src, size_t slen ){ - return mbedtls_base64_decode(dst,dlen,olen,src,slen); +int32_t EncryptUtils::MbedtlsBase64Decode(uint8_t *dst, size_t dlen, size_t *olen, + const uint8_t *src, size_t slen) +{ + return mbedtls_base64_decode(dst, dlen, olen, src, slen); } -int32_t EncryptUtils::GetRandomData(uint8_t* randStr, uint32_t len) +int32_t EncryptUtils::GetRandomData(uint8_t *randStr, uint32_t len) { - mbedtls_entropy_context* entropy = nullptr; - mbedtls_ctr_drbg_context* ctrDrbg = nullptr; + mbedtls_entropy_context *entropy = nullptr; + mbedtls_ctr_drbg_context *ctrDrbg = nullptr; int32_t ret = DEVICEMANAGER_OK; do { if (randStr == nullptr || len == 0) { break; } - entropy = (mbedtls_entropy_context*)malloc(sizeof(mbedtls_entropy_context)); + entropy = (mbedtls_entropy_context *)malloc(sizeof(mbedtls_entropy_context)); if (entropy == nullptr) { break; } - ctrDrbg = (mbedtls_ctr_drbg_context*)malloc(sizeof(mbedtls_ctr_drbg_context)); + ctrDrbg = (mbedtls_ctr_drbg_context *)malloc(sizeof(mbedtls_ctr_drbg_context)); if (ctrDrbg == nullptr) { break; } @@ -240,8 +242,8 @@ int32_t EncryptUtils::GetRandomData(uint8_t* randStr, uint32_t len) return ret; } -int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t* plainText, int plainTextLen, uint8_t* cipherText, - int cipherTextLen, int* outLen) +int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t *plainText, int plainTextLen, uint8_t *cipherText, + int cipherTextLen, int *outLen) { uint8_t rootKey[24] = {0}; uint8_t session[HW_SESSION_KEY_LEN] = {0}; @@ -286,8 +288,8 @@ int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t* plainText, int plainTextLen, return DEVICEMANAGER_OK; } -int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t* cipherText, int32_t cipherTextLen, uint8_t* plainText, - int32_t plainTextLen, int32_t* outLen) +int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText, + int32_t plainTextLen, int32_t *outLen) { uint8_t rootKey[24] = {0}; uint8_t session[HW_SESSION_KEY_LEN] = {0}; @@ -327,7 +329,7 @@ int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t* cipherText, int32_t cipherTe return DEVICEMANAGER_OK; } -bool EncryptUtils::MbedtlsGenRandomStr(char* szOut, int32_t szOutLen, bool numberOnly) +bool EncryptUtils::MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly) { if (szOut == nullptr || szOutLen <= 2) { return false; diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp index 30edc35f5..f48541c6c 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp @@ -140,7 +140,7 @@ ON_IPC_READ_RESPONSE(SERVER_CHECK_AUTH_RESULT, IpcIo& reply, std::shared_ptr req, std::shared_ptr rsp) diff --git a/services/devicemanagerservice/src/message/msg_request_auth.cpp b/services/devicemanagerservice/src/message/msg_request_auth.cpp index 4ec7dbe2f..da4510515 100644 --- a/services/devicemanagerservice/src/message/msg_request_auth.cpp +++ b/services/devicemanagerservice/src/message/msg_request_auth.cpp @@ -194,9 +194,9 @@ std::shared_ptr MsgRequestAuth::decode(nlohmann::json &json, std } std::string src = json[TAG_APP_THUMBNAIL]; if (msg->mAppThumbnail.size() < src.size() + (idx - 1) * MSG_MAX_SIZE) { - auto inValidMsg = std::make_shared(); - inValidMsg->mMsgSlice = FAIL; - return inValidMsg; + auto inValidRequestMsg = std::make_shared(); + inValidRequestMsg->mMsgSlice = FAIL; + return inValidRequestMsg; } msg->mAppThumbnail += stringSub(src, (idx - 1) * MSG_MAX_SIZE, MSG_MAX_SIZE); } diff --git a/services/devicemanagerservice/src/requestauth/request_session.cpp b/services/devicemanagerservice/src/requestauth/request_session.cpp index 0d8023071..bc9bb48a7 100644 --- a/services/devicemanagerservice/src/requestauth/request_session.cpp +++ b/services/devicemanagerservice/src/requestauth/request_session.cpp @@ -30,7 +30,7 @@ namespace OHOS { namespace DistributedHardware { -enum StatusType : int32_t { +enum StatusType { STATUS_INIT = 0, STATUS_WAITING_REPLY = 2, STATUS_WATING_SCAN_OR_INPUT = 3, @@ -46,13 +46,13 @@ RequestSession::RequestSession(std::string &hostPkgName, const DmDeviceInfo& dev if (jsonObject.is_discarded()) { DMLog(DM_LOG_ERROR, "extrasJson error"); } - + if (!jsonObject.contains(TARGET_PKG_NAME_KEY)) { DMLog(DM_LOG_ERROR, "TARGET_PKG_NAME is not in extrasJson"); } std::string targetPkgName = jsonObject[TARGET_PKG_NAME_KEY]; mSessionType = SESSION_TYPE_IS_APP_AUTH; - mDevInfo = devReqInfo; + mDevInfo = devReqInfo; mImageInfo = imageInfo; mHostPkgName = hostPkgName; mTargetPkgName = targetPkgName; @@ -61,9 +61,9 @@ RequestSession::RequestSession(std::string &hostPkgName, const DmDeviceInfo& dev char randStr[TOKEN_LEN] = {0}; bool res = EncryptUtils::MbedtlsGenRandomStr(randStr, sizeof(randStr), false); if (res == false) { - DMLog(DM_LOG_ERROR, "get Random string failed"); - mToken = ""; - return; + DMLog(DM_LOG_ERROR, "get Random string failed"); + mToken = ""; + return; } mToken = randStr; DMLog(DM_LOG_INFO, "RequestSession construction completed"); diff --git a/services/devicemanagerservice/src/softbus/softbus_session.cpp b/services/devicemanagerservice/src/softbus/softbus_session.cpp index 2b2284e38..5dc77db64 100644 --- a/services/devicemanagerservice/src/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/softbus/softbus_session.cpp @@ -43,11 +43,18 @@ static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen) { + (void)sessionId; + (void)data; + (void)dataLen; DMLog(DM_LOG_INFO, "sessionId:%d, dataLen:%d", sessionId, dataLen); } static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param) { + (void)sessionId; + (void)data; + (void)ext; + (void)param; DMLog(DM_LOG_INFO, "sessionId:%d", sessionId); } -- Gitee From 9fc33c1b00c3d779e4f92823b744f0df2ab59a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 6 Sep 2021 16:44:05 +0800 Subject: [PATCH 3/4] support L1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- .../src/ipc/standard/ipc_server_listener.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp index a50ab3b76..5134f011d 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp @@ -18,6 +18,8 @@ #include "device_manager_errno.h" #include "device_manager_log.h" +#include "ipc_server_stub.h" + namespace OHOS { namespace DistributedHardware { int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -- Gitee From 5cd6bace8c3c965cdb6308ff50c3d3a045049c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 6 Sep 2021 19:58:01 +0800 Subject: [PATCH 4/4] support L1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- common/include/constants.h | 2 +- common/include/ipc/ipc_def.h | 2 +- common/include/ipc/lite/ipc_cmd_register.h | 2 +- ...ication_req.h => ipc_check_authenticate_req.h} | 0 .../ipc/model/ipc_notify_auth_result_req.h | 2 +- .../ipc/model/ipc_notify_check_auth_result_req.h | 2 +- .../ipc/model/ipc_notify_discover_result_req.h | 2 +- common/include/ipc/model/ipc_rsp.h | 2 +- common/include/ipc/model/ipc_stop_discovery_req.h | 2 +- common/include/ipc/standard/ipc_cmd_register.h | 2 +- common/src/log/device_manager_log.cpp | 2 +- common/src/utils/anonymous_string.cpp | 9 +++------ devicemanager.gni | 2 +- .../native_cpp/include/device_manager_callback.h | 2 +- .../native_cpp/include/dm_device_info.h | 8 +++----- .../native_cpp/include/dm_subscribe_info.h | 2 +- .../native_cpp/include/ipc/ipc_client.h | 2 +- .../native_cpp/include/ipc/ipc_client_proxy.h | 2 +- .../include/ipc/lite/ipc_client_manager.h | 2 +- .../include/ipc/lite/ipc_client_server_proxy.h | 2 +- .../native_cpp/include/ipc/lite/ipc_client_stub.h | 2 +- .../include/ipc/standard/ipc_client_manager.h | 4 ++-- .../ipc/standard/ipc_client_server_proxy.h | 6 +++--- .../include/ipc/standard/ipc_client_stub.h | 4 ++-- .../include/ipc/standard/ipc_remote_broker.h | 6 +++--- .../native_cpp/src/device_manager_impl.cpp | 2 +- .../src/ipc/lite/ipc_client_server_proxy.cpp | 4 ---- .../native_cpp/src/ipc/lite/ipc_cmd_parser.cpp | 2 +- .../src/ipc/standard/ipc_client_manager.cpp | 2 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 2 +- services/devicemanagerservice/BUILD.gn | 4 ++-- .../include/auth/hichain_connector.h | 2 +- .../include/encrypt/encrypt_utils.h | 2 +- .../include/ipc/lite/ipc_server_listenermgr.h | 2 +- .../include/ipc/lite/ipc_server_stub.h | 2 +- .../ipc/standard/ipc_server_client_proxy.h | 4 ++-- .../include/ipc/standard/ipc_server_listener.h | 2 +- .../include/ipc/standard/ipc_server_stub.h | 4 ++-- .../include/message/{msg_common.h => msg_head.h} | 5 ++--- .../include/message/msg_request_auth.h | 4 ++-- .../include/message/msg_response_auth.h | 2 +- .../include/message/msg_sync_group.h | 2 +- .../include/softbus/softbus_session.h | 6 +++--- .../src/auth/hichain_connector.cpp | 2 +- .../src/encrypt/encrypt_utils.cpp | 15 +++++++-------- .../src/ipc/ipc_server_adapter.cpp | 2 +- .../src/ipc/lite/ipc_server_listenermgr.cpp | 1 - .../src/ipc/lite/ipc_server_main.cpp | 10 +++++----- .../src/ipc/lite/ipc_server_stub.cpp | 5 ++++- .../src/ipc/standard/ipc_server_listener.cpp | 4 ++-- .../src/ipc/standard/ipc_server_stub.cpp | 4 ++-- .../src/message/msg_codec.cpp | 4 ++-- .../src/message/{msg_common.cpp => msg_head.cpp} | 2 +- .../src/message/msg_request_auth.cpp | 8 ++++---- .../src/requestauth/auth_manager.cpp | 6 +++--- .../src/requestauth/request_session.cpp | 3 +-- .../src/softbus/softbus_adapter.cpp | 9 +++++---- .../src/softbus/softbus_session.cpp | 8 ++++---- 58 files changed, 100 insertions(+), 109 deletions(-) rename common/include/ipc/model/{ipc_check_authentication_req.h => ipc_check_authenticate_req.h} (100%) rename services/devicemanagerservice/include/message/{msg_common.h => msg_head.h} (96%) rename services/devicemanagerservice/src/message/{msg_common.cpp => msg_head.cpp} (98%) diff --git a/common/include/constants.h b/common/include/constants.h index 7a09f0e47..27d4f74bf 100644 --- a/common/include/constants.h +++ b/common/include/constants.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_CONSTANTS_H #define OHOS_DEVICE_MANAGER_CONSTANTS_H -#include +#include #include namespace OHOS { diff --git a/common/include/ipc/ipc_def.h b/common/include/ipc/ipc_def.h index 200090b5b..033fbe4dc 100644 --- a/common/include/ipc/ipc_def.h +++ b/common/include/ipc/ipc_def.h @@ -29,7 +29,7 @@ public: \ className(const className&) = delete; \ className& operator= (const className&) = delete; \ className(className&&) = delete; \ - className& operator= (className&&) = delete; \ + className& operator= (className&&) = delete \ #define DECLARE_IPC_INTERFACE(className) \ DECLARE_IPC_MODEL(className) diff --git a/common/include/ipc/lite/ipc_cmd_register.h b/common/include/ipc/lite/ipc_cmd_register.h index 8b887827b..c8b3c510a 100644 --- a/common/include/ipc/lite/ipc_cmd_register.h +++ b/common/include/ipc/lite/ipc_cmd_register.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H #define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H -#include +#include #include #include "liteipc_adapter.h" diff --git a/common/include/ipc/model/ipc_check_authentication_req.h b/common/include/ipc/model/ipc_check_authenticate_req.h similarity index 100% rename from common/include/ipc/model/ipc_check_authentication_req.h rename to common/include/ipc/model/ipc_check_authenticate_req.h diff --git a/common/include/ipc/model/ipc_notify_auth_result_req.h b/common/include/ipc/model/ipc_notify_auth_result_req.h index b7119a893..5fb8e53f7 100644 --- a/common/include/ipc/model/ipc_notify_auth_result_req.h +++ b/common/include/ipc/model/ipc_notify_auth_result_req.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H #define OHOS_DEVICE_MANAGER_IPC_NOTIFY_AUTH_RESULT_REQ_H -#include +#include #include "ipc_req.h" diff --git a/common/include/ipc/model/ipc_notify_check_auth_result_req.h b/common/include/ipc/model/ipc_notify_check_auth_result_req.h index f20f28582..f98db1e21 100644 --- a/common/include/ipc/model/ipc_notify_check_auth_result_req.h +++ b/common/include/ipc/model/ipc_notify_check_auth_result_req.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H #define OHOS_DEVICE_MANAGER_IPC_NOTIFY_CHECK_AUTH_RESULT_REQ_H -#include +#include #include "ipc_req.h" diff --git a/common/include/ipc/model/ipc_notify_discover_result_req.h b/common/include/ipc/model/ipc_notify_discover_result_req.h index 1eb3f5b08..00ea2e5d8 100644 --- a/common/include/ipc/model/ipc_notify_discover_result_req.h +++ b/common/include/ipc/model/ipc_notify_discover_result_req.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H #define OHOS_DEVICE_MANAGER_IPC_NOTIFY_DISCOVER_RESULT_REQ_H -#include +#include #include "ipc_req.h" diff --git a/common/include/ipc/model/ipc_rsp.h b/common/include/ipc/model/ipc_rsp.h index 28791359b..14394280b 100644 --- a/common/include/ipc/model/ipc_rsp.h +++ b/common/include/ipc/model/ipc_rsp.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_RSP_H #define OHOS_DEVICE_MANAGER_IPC_RSP_H -#include +#include #include "ipc_def.h" diff --git a/common/include/ipc/model/ipc_stop_discovery_req.h b/common/include/ipc/model/ipc_stop_discovery_req.h index 90cf69cd1..3497ec6f3 100644 --- a/common/include/ipc/model/ipc_stop_discovery_req.h +++ b/common/include/ipc/model/ipc_stop_discovery_req.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H #define OHOS_DEVICE_MANAGER_IPC_STOP_DISCOVERY_REQ_H -#include +#include #include "ipc_req.h" diff --git a/common/include/ipc/standard/ipc_cmd_register.h b/common/include/ipc/standard/ipc_cmd_register.h index d2f5e8563..19252933c 100644 --- a/common/include/ipc/standard/ipc_cmd_register.h +++ b/common/include/ipc/standard/ipc_cmd_register.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H #define OHOS_DEVICE_MANAGER_IPC_CMD_PARSER_H -#include +#include #include #include "iremote_broker.h" diff --git a/common/src/log/device_manager_log.cpp b/common/src/log/device_manager_log.cpp index 8ae1748da..b1af38d1f 100644 --- a/common/src/log/device_manager_log.cpp +++ b/common/src/log/device_manager_log.cpp @@ -23,7 +23,7 @@ #include "hilog/log.h" #else #include -#include +#include #endif namespace OHOS { diff --git a/common/src/utils/anonymous_string.cpp b/common/src/utils/anonymous_string.cpp index 4b7ccaa0c..c3fdd4f3e 100644 --- a/common/src/utils/anonymous_string.cpp +++ b/common/src/utils/anonymous_string.cpp @@ -19,15 +19,11 @@ namespace OHOS { namespace DistributedHardware { -namespace { - const int INT32_STRING_LENGTH = 40; +std::string GetAnonyString(const std::string &value) +{ const int INT32_SHORT_ID_LENGTH = 20; const int INT32_PLAINTEXT_LENGTH = 4; const int INT32_MIN_ID_LENGTH = 3; -} - -std::string GetAnonyString(const std::string &value) -{ std::string res; std::string tmpStr("******"); int32_t strLen = value.length(); @@ -50,6 +46,7 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { + const int INT32_STRING_LENGTH = 40; char tempBuffer[INT32_STRING_LENGTH] = ""; int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); if (secRet <= 0) { diff --git a/devicemanager.gni b/devicemanager.gni index 722a50bbb..aaf2c93d0 100644 --- a/devicemanager.gni +++ b/devicemanager.gni @@ -23,4 +23,4 @@ innerkits_path = "${devicemanager_path}/interfaces/inner_kits" build_flags = [ "-Werror", "-Wall", - ] \ No newline at end of file + ] diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 40b650323..112008358 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_CALLBACK_H #define OHOS_DEVICE_MANAGER_CALLBACK_H -#include +#include #include #include "dm_device_info.h" diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b1afc8e72..8794faf47 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -16,12 +16,10 @@ #ifndef OHOS_DEVICE_MANAGER_DEVICE_INFO_H #define OHOS_DEVICE_MANAGER_DEVICE_INFO_H -#include +#include -#define DM_MAX_DEVICE_ID_LEN 96 -#define DM_MAX_DEVICE_NAME_LEN 65 -#define DM_APPICON_MAX_LEN 32*1024 -#define DM_APPTHUMBNAIL_MAX_LEN 153*1024 +#define DM_MAX_DEVICE_ID_LEN (96) +#define DM_MAX_DEVICE_NAME_LEN (65) namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h index 64181e1fd..b907e89f5 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h @@ -58,7 +58,7 @@ typedef enum DmExchangeFreq { DM_FREQ_BUTT } DmExchangeFreq; -const static char * DM_CAPABILITY_OSD = "osdCapability"; +const static char *DM_CAPABILITY_OSD = "osdCapability"; typedef struct DmSubscribeInfo { /** Service ID */ diff --git a/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h index 8fc50aae9..818746ff7 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_H -#include +#include #include #include diff --git a/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h index eedac7566..faa9e1a4b 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/ipc_client_proxy.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_PROXY_H -#include +#include #include #include "ipc_client.h" diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h index ca27cd4c4..997b5d39b 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_manager.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H -#include +#include #include #include diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h index c13ffc602..d7497c55c 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_server_proxy.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H -#include +#include #include #include diff --git a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h index a9cec772d..672e4cb89 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/lite/ipc_client_stub.h @@ -17,7 +17,7 @@ #define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H #include -#include +#include #include "liteipc_adapter.h" diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h index b029b22a8..0953a363e 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_MANAGER_H -#include +#include #include #include #include @@ -50,7 +50,7 @@ private: private: std::mutex lock_; std::map> dmListener_; - sptr dmInterface_ {nullptr}; + sptr dmInterface_ {nullptr}; sptr dmRecipient_ {nullptr}; }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h index 6c60aea5e..46c2f9389 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_SERVER_PROXY_H -#include +#include #include #include "iremote_proxy.h" @@ -26,9 +26,9 @@ namespace OHOS { namespace DistributedHardware { -class IpcClientServerProxy : public IRemoteProxy { +class IpcClientServerProxy : public IRemoteProxy { public: - explicit IpcClientServerProxy(const sptr& impl) : IRemoteProxy(impl) {}; + explicit IpcClientServerProxy(const sptr& impl) : IRemoteProxy(impl) {}; ~IpcClientServerProxy() {}; int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; private: diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h index 70f27ebab..1340ab88c 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H #define OHOS_DEVICE_MANAGER_IPC_CLIENT_STUB_H -#include +#include #include #include "iremote_stub.h" @@ -28,7 +28,7 @@ namespace OHOS { namespace DistributedHardware { -class IpcClientStub : public IRemoteStub { +class IpcClientStub : public IRemoteStub { public: IpcClientStub() {}; ~IpcClientStub() {}; diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h index dfb7cc5a8..b2b8618c7 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H #define OHOS_DEVICE_MANAGER_IPC_REMOTE_BROKER_H -#include +#include #include #include "iremote_broker.h" @@ -26,9 +26,9 @@ namespace OHOS { namespace DistributedHardware { -class IIpcRemoteBroker : public OHOS::IRemoteBroker { +class IpcRemoteBroker : public OHOS::IRemoteBroker { public: - virtual ~IIpcRemoteBroker() {} + virtual ~IpcRemoteBroker() {} virtual int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) = 0; public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager"); diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 8690be875..88d10bcc1 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -21,7 +21,7 @@ #include "constants.h" #include "ipc_authenticate_device_req.h" -#include "ipc_check_authentication_req.h" +#include "ipc_check_authenticate_req.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_rsp.h" diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp index 7594a1f5b..c4a90d3ea 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_server_proxy.cpp @@ -15,10 +15,6 @@ #include "ipc_client_server_proxy.h" -#include - -#include "securec.h" - #include "device_manager_log.h" #include "device_manager_errno.h" #include "device_manager_notify.h" diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index ed8768a8d..607572c17 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -29,7 +29,7 @@ #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_authenticate_device_req.h" -#include "ipc_check_authentication_req.h" +#include "ipc_check_authenticate_req.h" namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index dd9835764..6c09a177e 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -61,7 +61,7 @@ int32_t IpcClientManager::ClientInit() if (!object->AddDeathRecipient(dmRecipient_)) { DMLog(DM_LOG_ERROR, "InitDeviceManagerService: AddDeathRecipient Failed"); } - dmInterface_ = iface_cast(object); + dmInterface_ = iface_cast(object); DMLog(DM_LOG_INFO, "DeviceManager::InitDeviceManagerService completed"); return DEVICEMANAGER_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 537d87240..bea004514 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -28,7 +28,7 @@ #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_authenticate_device_req.h" -#include "ipc_check_authentication_req.h" +#include "ipc_check_authenticate_req.h" namespace OHOS { namespace DistributedHardware { diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index ab1b6ab90..a5aaae459 100644 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -73,7 +73,7 @@ if (defined(ohos_lite)) { "src/softbus/softbus_session.cpp", "src/auth/hichain_connector.cpp", "src/message/msg_codec.cpp", - "src/message/msg_common.cpp", + "src/message/msg_head.cpp", "src/message/msg_request_auth.cpp", "src/message/msg_response_auth.cpp", "src/message/msg_sync_group.cpp", @@ -144,7 +144,7 @@ if (defined(ohos_lite)) { "src/softbus/softbus_session.cpp", "src/auth/hichain_connector.cpp", "src/message/msg_codec.cpp", - "src/message/msg_common.cpp", + "src/message/msg_head.cpp", "src/message/msg_request_auth.cpp", "src/message/msg_response_auth.cpp", "src/message/msg_sync_group.cpp", diff --git a/services/devicemanagerservice/include/auth/hichain_connector.h b/services/devicemanagerservice/include/auth/hichain_connector.h index bca27e894..cf16ac0d9 100644 --- a/services/devicemanagerservice/include/auth/hichain_connector.h +++ b/services/devicemanagerservice/include/auth/hichain_connector.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include "device_auth.h" diff --git a/services/devicemanagerservice/include/encrypt/encrypt_utils.h b/services/devicemanagerservice/include/encrypt/encrypt_utils.h index e73c3a536..f5d66ad32 100644 --- a/services/devicemanagerservice/include/encrypt/encrypt_utils.h +++ b/services/devicemanagerservice/include/encrypt/encrypt_utils.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H #define OHOS_DEVICE_MANAGER_ENCRYPT_UTILS_H -#include +#include #include namespace OHOS { diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h index efa32c665..5257268c6 100644 --- a/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_listenermgr.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H #define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_MGR_H -#include +#include #include #include #include diff --git a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h index 80618756b..66c264a9f 100644 --- a/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h +++ b/services/devicemanagerservice/include/ipc/lite/ipc_server_stub.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H #define OHOS_DEVICE_MANAGER_IPC_SERVER_STUB_H -#include +#include #include "liteipc_adapter.h" diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h index dc71cc7a9..24684bbce 100644 --- a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h @@ -21,10 +21,10 @@ namespace OHOS { namespace DistributedHardware { -class IpcServerClientProxy : public IRemoteProxy { +class IpcServerClientProxy : public IRemoteProxy { public: explicit IpcServerClientProxy(const sptr& impl) - : IRemoteProxy(impl) {}; + : IRemoteProxy(impl) {}; ~IpcServerClientProxy() {}; int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; private: diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h index 077059845..3737b7cde 100644 --- a/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_listener.h @@ -16,7 +16,7 @@ #ifndef OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H #define OHOS_DEVICE_MANAGER_IPC_SERVER_LISTENER_H -#include +#include #include "ipc_req.h" #include "ipc_rsp.h" diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h index 34464e292..65b975a7d 100644 --- a/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h @@ -46,7 +46,7 @@ public: ~AppDeathRecipient() = default; }; -class IpcServerStub : public SystemAbility, public IRemoteStub { +class IpcServerStub : public SystemAbility, public IRemoteStub { DECLARE_SYSTEM_ABILITY(IpcServerStub); DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub); public: @@ -61,7 +61,7 @@ public: int32_t UnRegisterDeviceManagerListener(std::string &pkgName); ServiceRunningState QueryServiceState() const; const std::map>& GetDmListener(); - const sptr GetDmListener(std::string pkgName) const; + const sptr GetDmListener(std::string pkgName) const; private: bool Init(); private: diff --git a/services/devicemanagerservice/include/message/msg_common.h b/services/devicemanagerservice/include/message/msg_head.h similarity index 96% rename from services/devicemanagerservice/include/message/msg_common.h rename to services/devicemanagerservice/include/message/msg_head.h index debe6113d..03dd4f59a 100644 --- a/services/devicemanagerservice/include/message/msg_common.h +++ b/services/devicemanagerservice/include/message/msg_head.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_MSG_COMMON_H -#define OHOS_MSG_COMMON_H +#ifndef OHOS_MSG_HEAD_H +#define OHOS_MSG_HEAD_H #include "nlohmann/json.hpp" @@ -45,5 +45,4 @@ private: }; } } - #endif \ No newline at end of file diff --git a/services/devicemanagerservice/include/message/msg_request_auth.h b/services/devicemanagerservice/include/message/msg_request_auth.h index 34a25c9db..214f183ca 100644 --- a/services/devicemanagerservice/include/message/msg_request_auth.h +++ b/services/devicemanagerservice/include/message/msg_request_auth.h @@ -21,7 +21,7 @@ #include "nlohmann/json.hpp" -#include "msg_common.h" +#include "msg_head.h" #include "dm_device_info.h" #include "constants.h" @@ -43,7 +43,7 @@ private: std::string toHexString(int32_t value); std::string encodeDevInfo(); static std::string stringSub(std::string &thumbStr, int32_t start, int32_t length); - int32_t getEncodedAppInfo(const uint8_t* dataSrc, size_t srcLen, std::string &outString); + int32_t getEncodedAppInfo(const uint8_t *dataSrc, size_t srcLen, std::string &outString); static bool isMsgValid(std::shared_ptr msgIn, nlohmann::json &json, std::string &deviceId, int32_t index); static bool isAppInfoValid(nlohmann::json &json); diff --git a/services/devicemanagerservice/include/message/msg_response_auth.h b/services/devicemanagerservice/include/message/msg_response_auth.h index 08fa0bb67..5e67b0997 100644 --- a/services/devicemanagerservice/include/message/msg_response_auth.h +++ b/services/devicemanagerservice/include/message/msg_response_auth.h @@ -21,7 +21,7 @@ #include "nlohmann/json.hpp" -#include "msg_common.h" +#include "msg_head.h" namespace OHOS { namespace DistributedHardware { diff --git a/services/devicemanagerservice/include/message/msg_sync_group.h b/services/devicemanagerservice/include/message/msg_sync_group.h index 8c32e1d8d..0bd66d5a5 100644 --- a/services/devicemanagerservice/include/message/msg_sync_group.h +++ b/services/devicemanagerservice/include/message/msg_sync_group.h @@ -21,7 +21,7 @@ #include "nlohmann/json.hpp" -#include "msg_common.h" +#include "msg_head.h" namespace OHOS { namespace DistributedHardware { diff --git a/services/devicemanagerservice/include/softbus/softbus_session.h b/services/devicemanagerservice/include/softbus/softbus_session.h index 79d1165f3..071c222af 100644 --- a/services/devicemanagerservice/include/softbus/softbus_session.h +++ b/services/devicemanagerservice/include/softbus/softbus_session.h @@ -31,7 +31,7 @@ DECLARE_SINGLE_INSTANCE_BASE(SoftbusSession); public: int32_t Start(); int32_t OnSessionOpened(int32_t sessionId, int32_t result); - void OnSessionClosed(int32_t sessionId); + void OnSessionClosed(int32_t sessionId); void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); void CloseSession(int32_t sessionId); int32_t SendMessages(const char *deviceId, std::vector &messages); @@ -42,8 +42,8 @@ private: private: int32_t SendData(int32_t sessionId, const void *data, int32_t len); private: - const char * PKG_NAME = "com.huawei.devicemanager"; - const char * SESSION_NAME = "com.huawei.devicemanager.resident"; + const char *PKG_NAME = "com.huawei.devicemanager"; + const char *SESSION_NAME = "com.huawei.devicemanager.resident"; std::set sessionIdSet_; std::vector messages_ {}; }; diff --git a/services/devicemanagerservice/src/auth/hichain_connector.cpp b/services/devicemanagerservice/src/auth/hichain_connector.cpp index f23edbb64..3529a74ea 100644 --- a/services/devicemanagerservice/src/auth/hichain_connector.cpp +++ b/services/devicemanagerservice/src/auth/hichain_connector.cpp @@ -95,7 +95,7 @@ int32_t HichainConnector::AddMemeber(std::string deviceId, std::shared_ptr msgResponseAuth) { - ConnectionAddr * addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); + ConnectionAddr *addrInfo = SoftbusAdapter::GetConnectAddr(deviceId); if (addrInfo == nullptr) { DMLog(DM_LOG_ERROR, "HichainConnector::GetConnectPara addrInfo error"); return ""; diff --git a/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp index 13bd348b8..bc43e64da 100644 --- a/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp +++ b/services/devicemanagerservice/src/encrypt/encrypt_utils.cpp @@ -22,9 +22,8 @@ #include "mbedtls/ctr_drbg.h" #include "mbedtls/entropy.h" -#include -#include -#include +#include +#include #include "device_manager_errno.h" #include "device_manager_log.h" #include "securec.h" @@ -41,9 +40,9 @@ namespace { const uint8_t HW_RIGHT_COUNT = 5; const uint8_t BUF_LEN = 32; // 将C1,C2,C3放在不同的位置,目的:增加破译难度 - const char* STR_C1 = "s6nxSNjc/VhzXqwXAbKaGUFH"; - const char* STR_C2 = "C5bcOsfhejsEAfohXihU65yN"; - const char* STR_C3 = "lHhAYIiqUXQom9R0bl1o9Mvm"; + const char *STR_C1 = "s6nxSNjc/VhzXqwXAbKaGUFH"; + const char *STR_C2 = "C5bcOsfhejsEAfohXihU65yN"; + const char *STR_C3 = "lHhAYIiqUXQom9R0bl1o9Mvm"; } // 数据整体按字节向左位移 count 次 void EncryptUtils::ByteLeftMove(uint8_t *data, size_t dataLen, const uint8_t *inputData, int32_t len, int32_t count) @@ -272,7 +271,7 @@ int32_t EncryptUtils::MbedtlsEncrypt(const uint8_t *plainText, int plainTextLen, DMLog(DM_LOG_ERROR, "%s:%d copy failed", __FUNCTION__, __LINE__); return DEVICEMANAGER_COPY_FAILED; } - DmCryptInfo info = { session,HW_SESSION_KEY_LEN,iv,HW_GCM_IV_LEN }; + DmCryptInfo info = {session, HW_SESSION_KEY_LEN, iv, HW_GCM_IV_LEN}; ret = MbedtlsAesGcmEncrypt(&info, plainText, plainTextLen, cipherText + HW_RANDOM_KEY_LEN, cipherTextLen - HW_RANDOM_KEY_LEN); if (ret <= 0) { @@ -294,7 +293,7 @@ int32_t EncryptUtils::MbedtlsDecrypt(const uint8_t *cipherText, int32_t cipherTe uint8_t rootKey[24] = {0}; uint8_t session[HW_SESSION_KEY_LEN] = {0}; uint8_t iv[12] = {0}; - const uint8_t* randomKey = cipherText; + const uint8_t *randomKey = cipherText; int32_t rootKeyLen = 0; int32_t ret = DEVICEMANAGER_OK; uint8_t K[MBEDTLS_MD_MAX_SIZE] = {0}; diff --git a/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp b/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp index 5cbd3b318..a69d7c982 100644 --- a/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp +++ b/services/devicemanagerservice/src/ipc/ipc_server_adapter.cpp @@ -90,7 +90,7 @@ int32_t IpcServerAdapter::GetTrustedDeviceList(std::string &pkgName, std::string } for (int32_t i = 0; i < *infoNum; ++i) { NodeBasicInfo *nodeBasicInfo = nodeInfo + i; - DmDeviceInfo * deviceInfo = *info + i; + DmDeviceInfo *deviceInfo = *info + i; (void)memcpy_s(deviceInfo->deviceId, sizeof(deviceInfo->deviceId), nodeBasicInfo->networkId, std::min(sizeof(deviceInfo->deviceId), sizeof(nodeBasicInfo->networkId))); diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp index 032c2054b..0528d1986 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_listenermgr.cpp @@ -42,7 +42,6 @@ int32_t IpcServerListenermgr::GetListenerByPkgName(std::string &pkgName, CommonS } std::lock_guard autoLock(lock_); std::map::iterator iter = dmListenerMap_.find(pkgName); - if (iter == dmListenerMap_.end()) { DMLog(DM_LOG_ERROR, "listener not found for pkg:%s", pkgName.c_str()); return DEVICEMANAGER_FAILED; diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp index fd13e62fd..21ce5c7d9 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include +#include #include #include "device_manager_log.h" @@ -22,14 +22,12 @@ #include "ipc_server_stub.h" #include "ipc_server_adapter.h" -namespace { - const int32_t DM_SERVICE_INIT_DELAY = 5; -} - using namespace OHOS::DistributedHardware; static void InitAll() { + const int32_t DM_SERVICE_INIT_DELAY = 5; + sleep(DM_SERVICE_INIT_DELAY); if (IpcServerStubInit() != DEVICEMANAGER_OK) { DMLog(DM_LOG_ERROR, "IpcServerStubInit failed"); @@ -44,6 +42,8 @@ static void InitAll() int32_t main(int32_t argc, char* argv[]) { + (void)argc; + (void)argv; InitAll(); while (1) { pause(); diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index d3c081009..55510d1c6 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -51,6 +51,9 @@ struct DeviceManagerSamgrService { static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, void *arg) { + (void)context; + (void)ipcMsg; + (void)data; if (arg == NULL) { DMLog(DM_LOG_ERROR, "package name is NULL."); return DEVICEMANAGER_INVALID_PARAM; @@ -190,7 +193,7 @@ static TaskConfig GetTaskConfig(Service *service) } static int32_t OnRemoteRequest(IServerProxy *iProxy, int funcId, void *origin, - IpcIo *req, IpcIo * reply) + IpcIo *req, IpcIo *reply) { DMLog(DM_LOG_INFO, "Receive funcId:%d", funcId); (void)origin; diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp index 5134f011d..2da7ba95a 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp @@ -25,7 +25,7 @@ namespace DistributedHardware { int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { std::string pkgName = req->GetPkgName(); - sptr listener = IpcServerStub::GetInstance().GetDmListener(pkgName); + sptr listener = IpcServerStub::GetInstance().GetDmListener(pkgName); if (listener == nullptr) { DMLog(DM_LOG_INFO, "cannot get listener for package:%s.", pkgName.c_str()); return DEVICEMANAGER_NULLPTR; @@ -40,7 +40,7 @@ int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, auto pkgName = iter.first; auto remote = iter.second; req->SetPkgName(pkgName); - sptr listener = iface_cast(remote); + sptr listener = iface_cast(remote); listener->SendCmd(cmdCode, req, rsp); } return DEVICEMANAGER_OK; diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index 8175b8715..deaf5d123 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -164,14 +164,14 @@ const std::map>& IpcServerStub::GetDmListener() return dmListener_; } -const sptr IpcServerStub::GetDmListener(std::string pkgName) const +const sptr IpcServerStub::GetDmListener(std::string pkgName) const { auto iter = dmListener_.find(pkgName); if (iter == dmListener_.end()) { return nullptr; } auto remote = iter->second; - sptr dmListener = iface_cast(remote); + sptr dmListener = iface_cast(remote); return dmListener; } diff --git a/services/devicemanagerservice/src/message/msg_codec.cpp b/services/devicemanagerservice/src/message/msg_codec.cpp index c3938b3ed..2129e0b39 100644 --- a/services/devicemanagerservice/src/message/msg_codec.cpp +++ b/services/devicemanagerservice/src/message/msg_codec.cpp @@ -14,7 +14,7 @@ */ #include "msg_codec.h" -#include "msg_common.h" +#include "msg_head.h" #include "constants.h" #include "device_manager_log.h" @@ -46,7 +46,7 @@ std::string MsgCodec::encodeSyncGroup(std::vector &groupIdList, std } std::vector MsgCodec::encodeReqAppAuth(std::string &token, std::string hostPkg, std::string targetPkg, - const DmDeviceInfo& devReqInfo,const DmAppImageInfo &imageInfo, std::string &extras) + const DmDeviceInfo& devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras) { MsgRequestAuth mMsgRequestAuth(token, hostPkg, targetPkg, devReqInfo, imageInfo, extras); return mMsgRequestAuth.encode(); diff --git a/services/devicemanagerservice/src/message/msg_common.cpp b/services/devicemanagerservice/src/message/msg_head.cpp similarity index 98% rename from services/devicemanagerservice/src/message/msg_common.cpp rename to services/devicemanagerservice/src/message/msg_head.cpp index 3a4c5d886..25df59656 100644 --- a/services/devicemanagerservice/src/message/msg_common.cpp +++ b/services/devicemanagerservice/src/message/msg_head.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "msg_common.h" +#include "msg_head.h" #include "device_manager_log.h" #include "constants.h" diff --git a/services/devicemanagerservice/src/message/msg_request_auth.cpp b/services/devicemanagerservice/src/message/msg_request_auth.cpp index da4510515..c25171e8c 100644 --- a/services/devicemanagerservice/src/message/msg_request_auth.cpp +++ b/services/devicemanagerservice/src/message/msg_request_auth.cpp @@ -67,7 +67,7 @@ MsgRequestAuth::MsgRequestAuth(std::string &token, std::string hostPkgName, std: DMLog(DM_LOG_INFO, "MsgRequestAuth construction completed"); } -int32_t MsgRequestAuth::getEncodedAppInfo(const uint8_t* dataSrc, size_t srcLen, std::string &outString) +int32_t MsgRequestAuth::getEncodedAppInfo(const uint8_t *dataSrc, size_t srcLen, std::string &outString) { DMLog(DM_LOG_INFO, "MsgRequestAuth getEncodedAppInfo started"); if (srcLen == 0 || dataSrc == nullptr) { @@ -182,7 +182,7 @@ std::shared_ptr MsgRequestAuth::decode(nlohmann::json &json, std } msg->mAppName = json[TAG_APP_NAME]; msg->mAppDescription = json[TAG_APP_DESCRIPTION]; - msg->mAppIcon = json[TAG_APP_ICON]; + msg->mAppIcon = json[TAG_APP_ICON]; setThumbnailSize(json, msg); setAuthType(json, msg); } else { @@ -192,7 +192,7 @@ std::shared_ptr MsgRequestAuth::decode(nlohmann::json &json, std DMLog(DM_LOG_ERROR, "err json string, TAG_APP_THUMBNAIL not exit"); return nullptr; } - std::string src = json[TAG_APP_THUMBNAIL]; + std::string src = json[TAG_APP_THUMBNAIL]; if (msg->mAppThumbnail.size() < src.size() + (idx - 1) * MSG_MAX_SIZE) { auto inValidRequestMsg = std::make_shared(); inValidRequestMsg->mMsgSlice = FAIL; @@ -262,7 +262,7 @@ void MsgRequestAuth::setThumbnailSize(nlohmann::json &json, std::shared_ptrmThumbnailSize == 0) { diff --git a/services/devicemanagerservice/src/requestauth/auth_manager.cpp b/services/devicemanagerservice/src/requestauth/auth_manager.cpp index 4255f5207..ed712df8a 100644 --- a/services/devicemanagerservice/src/requestauth/auth_manager.cpp +++ b/services/devicemanagerservice/src/requestauth/auth_manager.cpp @@ -59,7 +59,7 @@ void AuthManager::authAppGroup(std::string &hostPkgName, const DmDeviceInfo& dev DMLog(DM_LOG_ERROR, "authAppGroup extrasJson error"); return; } - + if (!canStartNewSession()) { DMLog(DM_LOG_ERROR, "previous session not completed yet"); mPendingReqSessionPtr->notifyHostAppAuthResult(ERROR_DUPLICATE_REQUEST); @@ -103,7 +103,7 @@ void AuthManager::onReceiveMessage(long long channelId, std::string &message, in DMLog(DM_LOG_ERROR, "message type is MSG_TYPE_RESP_AUTH"); if (mPendingReqSessionPtr == nullptr || !mPendingReqSessionPtr->isMyChannelId(channelId)) { DMLog(DM_LOG_ERROR, "receive error message"); - return ; + return; } mPendingReqSessionPtr->onReceiveMsg(message); if (mPendingReqSessionPtr->isWaitingForScan()) { @@ -165,7 +165,7 @@ void AuthManager::onPinInputResult(int32_t pinCode, int32_t pinToken) if (requestSessionPtr != nullptr && requestSessionPtr->isMyPinToken(pinToken)) { DMLog(DM_LOG_INFO, "AuthManager:: onPinInputResult"); requestSessionPtr->onReceivePinCode(pinCode); - } + } } } } diff --git a/services/devicemanagerservice/src/requestauth/request_session.cpp b/services/devicemanagerservice/src/requestauth/request_session.cpp index bc9bb48a7..74f941e6f 100644 --- a/services/devicemanagerservice/src/requestauth/request_session.cpp +++ b/services/devicemanagerservice/src/requestauth/request_session.cpp @@ -127,7 +127,7 @@ void RequestSession::onReceiveMsg(std::string &msg) { if (mStatus != StatusType::STATUS_WAITING_REPLY) { DMLog(DM_LOG_ERROR, "StatusType is not waiting reply"); - return ; + return; } int32_t reply = parseRespMsg(msg); DMLog(DM_LOG_INFO, "reply is : %d", reply); @@ -209,7 +209,6 @@ void RequestSession::setChannelId(long long channelId) void RequestSession::syncDmPrivateGroup(std::vector &remoteGroupList) { - // TODO: getLocalGroups from hichainAdapter by (remoteGroupList, mRemoteDeviceId) DMLog(DM_LOG_INFO, "RequestSession::syncDmPrivateGroup started"); std::vector localGroups = {}; std::string synGroupMsg = MsgCodec::encodeSyncGroup(localGroups, mRemoteDeviceId); diff --git a/services/devicemanagerservice/src/softbus/softbus_adapter.cpp b/services/devicemanagerservice/src/softbus/softbus_adapter.cpp index a5963ae46..17b630837 100644 --- a/services/devicemanagerservice/src/softbus/softbus_adapter.cpp +++ b/services/devicemanagerservice/src/softbus/softbus_adapter.cpp @@ -46,7 +46,8 @@ const int32_t SUBSCRIBE_ID_PREFIX_LEN = 16; const int32_t SUBSCRIBE_ID_MASK = 0x0000FFFF; const int32_t DISCOVER_DEVICEINFO_MAX_SIZE = 20; } -std::map>> SoftbusAdapter::subscribeInfos_; +std::map>> + SoftbusAdapter::subscribeInfos_; std::map> SoftbusAdapter::discoverDeviceInfoMap_; std::vector> SoftbusAdapter::discoverDeviceInfoVector_; uint16_t SoftbusAdapter::subscribeIdPrefix = 0; @@ -142,7 +143,7 @@ void SoftbusAdapter::SaveDiscoverDeviceInfo(const DeviceInfo *deviceInfo) std::string delDevId = iter->get()->devId; discoverDeviceInfoMap_.erase(delDevId); discoverDeviceInfoVector_.erase(iter); - } + } } void SoftbusAdapter::OnSoftbusDeviceFound(const DeviceInfo *device) @@ -423,7 +424,7 @@ int32_t SoftbusAdapter::GetConnectionIpAddr(std::string deviceId, std::string &i } -//eth 》 wlan >> ble >> br +// eth 》 wlan >> ble >> br ConnectionAddr *SoftbusAdapter::GetConnectAddrByType(DeviceInfo *deviceInfo, ConnectionAddrType type) { if (deviceInfo == nullptr) { @@ -432,7 +433,7 @@ ConnectionAddr *SoftbusAdapter::GetConnectAddrByType(DeviceInfo *deviceInfo, Con for (unsigned int i = 0; i < deviceInfo->addrNum; ++i) { if (deviceInfo->addr[i].type == type) { - return &deviceInfo->addr[i]; + return &deviceInfo->addr[i]; } } diff --git a/services/devicemanagerservice/src/softbus/softbus_session.cpp b/services/devicemanagerservice/src/softbus/softbus_session.cpp index 5dc77db64..30731b109 100644 --- a/services/devicemanagerservice/src/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/softbus/softbus_session.cpp @@ -113,7 +113,7 @@ void SoftbusSession::OnBytesReceived(int32_t sessionId, const void *data, uint32 return; } - uint8_t * buf = (uint8_t *)calloc(sizeof(uint8_t), dataLen + 1); + uint8_t *buf = (uint8_t *)calloc(sizeof(uint8_t), dataLen + 1); if (buf == nullptr) { DMLog(DM_LOG_ERROR, "SendMsg: malloc memory failed"); return; @@ -158,13 +158,13 @@ int32_t SoftbusSession::SendData(int32_t sessionId, const void *data, int32_t le int32_t SoftbusSession::SendMsg(int32_t sessionId, std::string &message) { DMLog(DM_LOG_ERROR, "start SendMsg"); - uint8_t * buf = (uint8_t *)calloc(sizeof(uint8_t), (MSG_MAX_SIZE + ENCRYPT_TAG_LEN)); + uint8_t *buf = (uint8_t *)calloc(sizeof(uint8_t), (MSG_MAX_SIZE + ENCRYPT_TAG_LEN)); if (buf == nullptr) { DMLog(DM_LOG_ERROR, "SendMsg: malloc memory failed"); return DEVICEMANAGER_MALLOC_ERROR; } int32_t outLen = 0; - int32_t ret = EncryptUtils::MbedtlsEncrypt((const uint8_t*)message.c_str(), message.size(), buf, MSG_MAX_SIZE, + int32_t ret = EncryptUtils::MbedtlsEncrypt((const uint8_t *)message.c_str(), message.size(), buf, MSG_MAX_SIZE, &outLen); if (ret != DEVICEMANAGER_OK || outLen > MSG_MAX_SIZE) { DMLog(DM_LOG_ERROR, "MbedtlsEncrypt data failed"); @@ -182,7 +182,7 @@ int32_t SoftbusSession::SendMessages(const char *deviceId, std::vector