From 49aab973a79f3f9b1ba9cfff5b976e6fcbcca145 Mon Sep 17 00:00:00 2001 From: junyi233 Date: Tue, 4 Apr 2023 02:45:03 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85dbms=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: junyi233 --- README_zh.md | 69 ++++++++++++++++++ bundle.json | 14 ++-- dbms.gni | 7 +- interfaces/inner_api/BUILD.gn | 0 .../include/distributed_bms_interface.h | 0 .../inner_api/include/distributed_bms_proxy.h | 0 .../inner_api/src/distributed_bms_proxy.cpp | 0 .../kits/js/distributebundlemgr/BUILD.gn | 0 .../distributed_bundle_mgr.cpp | 0 .../distributed_bundle_mgr.h | 0 .../js/distributebundlemgr/native_module.cpp | 0 interfaces/kits/js/distributedBundle/BUILD.gn | 0 .../distributedBundle/distributed_bundle.cpp | 0 .../js/distributedBundle/distributed_bundle.h | 0 .../distributed_bundle_unsupported.cpp | 0 .../js/distributedBundle/native_module.cpp | 0 services/dbms/BUILD.gn | 2 + .../dbms/include/account_manager_helper.h | 0 services/dbms/include/dbms_device_manager.h | 45 ++++++++++++ services/dbms/include/distributed_bms.h | 9 ++- services/dbms/include/distributed_bms_host.h | 0 .../dbms/include/distributed_data_storage.h | 0 services/dbms/include/distributed_monitor.h | 0 services/dbms/include/event_report.h | 0 services/dbms/include/image_compress.h | 0 services/dbms/sa_profile/402.json | 0 services/dbms/sa_profile/BUILD.gn | 0 services/dbms/sa_profile/distributedbms.cfg | 0 services/dbms/src/account_manager_helper.cpp | 0 services/dbms/src/dbms_device_manager.cpp | 71 +++++++++++++++++++ services/dbms/src/distributed_bms.cpp | 18 +++++ services/dbms/src/distributed_bms_host.cpp | 0 .../dbms/src/distributed_data_storage.cpp | 10 +-- services/dbms/src/event_report.cpp | 0 services/dbms/src/image_compress.cpp | 0 services/dbms/test/BUILD.gn | 0 .../unittest/dbms_services_kit_test/BUILD.gn | 2 + .../dbms_services_kit_test.cpp | 41 ++++++++++- .../distributed_bms_host_test/BUILD.gn | 6 +- .../distributed_bms_host_test.cpp | 0 .../mock_distributed_bms_interface.cpp | 0 .../mock_distributed_bms_interface.h | 0 42 files changed, 275 insertions(+), 19 deletions(-) create mode 100644 README_zh.md mode change 100644 => 100755 interfaces/inner_api/BUILD.gn mode change 100644 => 100755 interfaces/inner_api/include/distributed_bms_interface.h mode change 100644 => 100755 interfaces/inner_api/include/distributed_bms_proxy.h mode change 100644 => 100755 interfaces/inner_api/src/distributed_bms_proxy.cpp mode change 100644 => 100755 interfaces/kits/js/distributebundlemgr/BUILD.gn mode change 100644 => 100755 interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.cpp mode change 100644 => 100755 interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.h mode change 100644 => 100755 interfaces/kits/js/distributebundlemgr/native_module.cpp mode change 100644 => 100755 interfaces/kits/js/distributedBundle/BUILD.gn mode change 100644 => 100755 interfaces/kits/js/distributedBundle/distributed_bundle.cpp mode change 100644 => 100755 interfaces/kits/js/distributedBundle/distributed_bundle.h mode change 100644 => 100755 interfaces/kits/js/distributedBundle/distributed_bundle_unsupported.cpp mode change 100644 => 100755 interfaces/kits/js/distributedBundle/native_module.cpp mode change 100644 => 100755 services/dbms/BUILD.gn mode change 100644 => 100755 services/dbms/include/account_manager_helper.h create mode 100644 services/dbms/include/dbms_device_manager.h mode change 100644 => 100755 services/dbms/include/distributed_bms.h mode change 100644 => 100755 services/dbms/include/distributed_bms_host.h mode change 100644 => 100755 services/dbms/include/distributed_data_storage.h mode change 100644 => 100755 services/dbms/include/distributed_monitor.h mode change 100644 => 100755 services/dbms/include/event_report.h mode change 100644 => 100755 services/dbms/include/image_compress.h mode change 100644 => 100755 services/dbms/sa_profile/402.json mode change 100644 => 100755 services/dbms/sa_profile/BUILD.gn mode change 100644 => 100755 services/dbms/sa_profile/distributedbms.cfg mode change 100644 => 100755 services/dbms/src/account_manager_helper.cpp create mode 100644 services/dbms/src/dbms_device_manager.cpp mode change 100644 => 100755 services/dbms/src/distributed_bms.cpp mode change 100644 => 100755 services/dbms/src/distributed_bms_host.cpp mode change 100644 => 100755 services/dbms/src/distributed_data_storage.cpp mode change 100644 => 100755 services/dbms/src/event_report.cpp mode change 100644 => 100755 services/dbms/src/image_compress.cpp mode change 100644 => 100755 services/dbms/test/BUILD.gn mode change 100644 => 100755 services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn mode change 100644 => 100755 services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp mode change 100644 => 100755 services/dbms/test/unittest/distributed_bms_host_test/BUILD.gn mode change 100644 => 100755 services/dbms/test/unittest/distributed_bms_host_test/distributed_bms_host_test.cpp mode change 100644 => 100755 services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.cpp mode change 100644 => 100755 services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.h diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..319133a --- /dev/null +++ b/README_zh.md @@ -0,0 +1,69 @@ +# **分布式包管理服务(DBMS)** + +## 简介 + +分布式包管理服务负责管理跨设备的组件调度和任务管理,实现跨设备RPC的能力,可以按需获取跨设备指定语言的资源。 + +## 目录 + +``` +foundation/bundlemanager/distributed_bundle_framework +├── interfaces +│ ├── inner_api # 内部接口存放目录 +│ └── kits/js # JS应用接口 +│ ├── distributebundlemgr +│ └── distributedBundle +├── services/dbms # dbms服务框架代码 +└── services/dbms/test # 测试目录 +``` + +## 说明 +### 获取远程设备AbilityInfo信息 +getRemoteAbilityInfo获取由elementName指定的远程设备上的应用的AbilityInfo信息(callback形式) + +* **参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | + | elementName | [ElementName](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-bundleManager-elementName.md) | 是 | ElementName信息。 | + | callback | AsyncCallback<[RemoteAbilityInfo](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-bundleManager-remoteAbilityInfo.md)> | 是 | 回调函数,调用成功返回err为null,data为RemoteAbilityInfo对象;调用失败err为错误对象, data为undefined。 | + +* **错误码:** + + 以下错误码的详细介绍请参见[ohos.bundle错误码](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/errorcodes/errorcode-bundle.md)。 + + | 错误码ID | 错误信息 | + | -------- | ---------------------------------------- | + | 17700001 | The specified bundle name is not found. | + | 17700003 | The specified ability name is not found. | + | 17700007 | The specified device ID is not found. | + | 17700027 | The distributed service is not running. | + +* **示例:** + +```ts + try { + distributedBundle.getRemoteAbilityInfo( + { + deviceId: '1', + bundleName: 'com.example.application', + abilityName: 'EntryAbility' + }, (err, data) => { + if (err) { + console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`); + } else { + console.info('Operation succeed:' + JSON.stringify(data)); + } + }); + } catch (err) { + console.log(`Operation failed: error code is ${err.code} and error message is ${err.message}`); + } + ``` + +* **指南:** + + 更多开发指导可参考[**示例文档**](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-distributedBundleManager.md) + +## 相关仓 + +[bundlemanager_bundle_framework](https://gitee.com/openharmony/bundlemanager_bundle_framework) diff --git a/bundle.json b/bundle.json index 02e65e7..e738c8a 100644 --- a/bundle.json +++ b/bundle.json @@ -4,7 +4,7 @@ "version": "3.1", "license": "Apache 2.0", "segment": { - "destPath": "foundation/bundlemanager/distributed_bundle_framework" + "destPath": "foundation/bundlemanager/bundle_framework/distributed_bundle_framework" }, "component": { "name": "distributed_bundle_framework", @@ -43,24 +43,24 @@ }, "build": { "sub_component": [ - "//foundation/bundlemanager/distributed_bundle_framework:inner_api_target", - "//foundation/bundlemanager/distributed_bundle_framework:jsapi_target", - "//foundation/bundlemanager/distributed_bundle_framework:dbms_target" + "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework:inner_api_target", + "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework:jsapi_target", + "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework:dbms_target" ], "inner_kits": [ { "header": { - "header_base": "//foundation/bundlemanager/distributed_bundle_framework/interfaces/inner_api/include", + "header_base": "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework/interfaces/inner_api/include", "header_files": [ "distributed_bms_interface.h", "distributed_bms_proxy.h" ] }, - "name": "//foundation/bundlemanager/distributed_bundle_framework/interfaces/inner_api:dbms_fwk" + "name": "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework/interfaces/inner_api:dbms_fwk" } ], "test": [ - "//foundation/bundlemanager/distributed_bundle_framework:test_target" + "//foundation/bundlemanager/bundle_framework/distributed_bundle_framework:test_target" ] } } diff --git a/dbms.gni b/dbms.gni index 0ea9825..571a6bd 100644 --- a/dbms.gni +++ b/dbms.gni @@ -11,14 +11,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -bundlemanager_path = "//foundation/bundlemanager" -bundle_framework_path = "${bundlemanager_path}/bundle_framework" +bundle_framework_path = "//foundation/bundlemanager/bundle_framework" common_path = "${bundle_framework_path}/common" dbms_inner_api_path = - "${bundlemanager_path}/distributed_bundle_framework/interfaces/inner_api" + "${bundle_framework_path}/distributed_bundle_framework/interfaces/inner_api" dbms_services_path = - "${bundlemanager_path}/distributed_bundle_framework/services/dbms" + "${bundle_framework_path}/distributed_bundle_framework/services/dbms" kits_path = "${bundle_framework_path}/interfaces/kits" declare_args() { diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn old mode 100644 new mode 100755 diff --git a/interfaces/inner_api/include/distributed_bms_interface.h b/interfaces/inner_api/include/distributed_bms_interface.h old mode 100644 new mode 100755 diff --git a/interfaces/inner_api/include/distributed_bms_proxy.h b/interfaces/inner_api/include/distributed_bms_proxy.h old mode 100644 new mode 100755 diff --git a/interfaces/inner_api/src/distributed_bms_proxy.cpp b/interfaces/inner_api/src/distributed_bms_proxy.cpp old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributebundlemgr/BUILD.gn b/interfaces/kits/js/distributebundlemgr/BUILD.gn old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.cpp b/interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.cpp old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.h b/interfaces/kits/js/distributebundlemgr/distributed_bundle_mgr.h old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributebundlemgr/native_module.cpp b/interfaces/kits/js/distributebundlemgr/native_module.cpp old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributedBundle/BUILD.gn b/interfaces/kits/js/distributedBundle/BUILD.gn old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributedBundle/distributed_bundle.cpp b/interfaces/kits/js/distributedBundle/distributed_bundle.cpp old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributedBundle/distributed_bundle.h b/interfaces/kits/js/distributedBundle/distributed_bundle.h old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributedBundle/distributed_bundle_unsupported.cpp b/interfaces/kits/js/distributedBundle/distributed_bundle_unsupported.cpp old mode 100644 new mode 100755 diff --git a/interfaces/kits/js/distributedBundle/native_module.cpp b/interfaces/kits/js/distributedBundle/native_module.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/BUILD.gn b/services/dbms/BUILD.gn old mode 100644 new mode 100755 index 784f32c..0fd9d83 --- a/services/dbms/BUILD.gn +++ b/services/dbms/BUILD.gn @@ -27,6 +27,7 @@ config("distributed_bms_config") { ohos_shared_library("libdbms") { sources = [ "src/account_manager_helper.cpp", + "src/dbms_device_manager.cpp", "src/distributed_bms.cpp", "src/distributed_bms_host.cpp", "src/distributed_data_storage.cpp", @@ -53,6 +54,7 @@ ohos_shared_library("libdbms") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", "hicollie_native:libhicollie", "hiviewdfx_hilog_native:libhilog", "i18n:intl_util", diff --git a/services/dbms/include/account_manager_helper.h b/services/dbms/include/account_manager_helper.h old mode 100644 new mode 100755 diff --git a/services/dbms/include/dbms_device_manager.h b/services/dbms/include/dbms_device_manager.h new file mode 100644 index 0000000..b0fb715 --- /dev/null +++ b/services/dbms/include/dbms_device_manager.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_DEVICE_MANAGER_H +#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_DEVICE_MANAGER_H + +#include +#include + +#include "device_manager_callback.h" +#include "dm_device_info.h" +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace AppExecFwk { +class DbmsDeviceManager { +public: + DbmsDeviceManager(); + int32_t GetUdidByNetworkId(const std::string &netWorkId, std::string &udid); + +private: + bool InitDeviceManager(); + std::shared_ptr initCallback_; + mutable std::mutex isInitMutex_; + bool isInit_ = false; + +class DeviceInitCallBack : public DistributedHardware::DmInitCallback { + void OnRemoteDied() override; +}; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_DEVICE_MANAGER_H \ No newline at end of file diff --git a/services/dbms/include/distributed_bms.h b/services/dbms/include/distributed_bms.h old mode 100644 new mode 100755 index b7d2159..ba1469d --- a/services/dbms/include/distributed_bms.h +++ b/services/dbms/include/distributed_bms.h @@ -20,6 +20,7 @@ #include "bundle_info.h" #include "bundle_mgr_interface.h" +#include "dbms_device_manager.h" #include "distributed_bms_host.h" #include "distributed_monitor.h" #include "if_system_ability_manager.h" @@ -36,6 +37,7 @@ class DistributedBms : public SystemAbility, public DistributedBmsHost { public: OHOS::sptr GetBundleMgr(); + OHOS::sptr GetDeviceManager(); /** * @brief get remote ability info * @param elementName Indicates the elementName. @@ -109,7 +111,7 @@ public: */ int32_t GetAbilityInfos(const std::vector &elementNames, const std::string &localeInfo, std::vector &remoteAbilityInfos) override; - + bool GetDistributedBundleInfo(const std::string &networkId, const std::string &bundleName, DistributedBundleInfo &distributedBundleInfo) override; @@ -123,6 +125,8 @@ public: int32_t GetDistributedBundleName(const std::string &networkId, uint32_t accessTokenId, std::string &bundleName) override; + int32_t GetUdidByNetworkId(const std::string &networkId, std::string &udid); + /** * @brief Start the bundle manager service. * @return @@ -133,12 +137,15 @@ public: * @return */ virtual void OnStop() override; + private: OHOS::sptr bundleMgr_; + std::shared_ptr dbmsDeviceManager_; std::shared_ptr distributedSub_; std::mutex bundleMgrMutex_; void Init(); + void InitDeviceManager(); bool GetMediaBase64(std::unique_ptr &data, int64_t fileLength, std::string &imageType, std::string &value); std::unique_ptr LoadResourceFile(std::string &path, int &len); diff --git a/services/dbms/include/distributed_bms_host.h b/services/dbms/include/distributed_bms_host.h old mode 100644 new mode 100755 diff --git a/services/dbms/include/distributed_data_storage.h b/services/dbms/include/distributed_data_storage.h old mode 100644 new mode 100755 diff --git a/services/dbms/include/distributed_monitor.h b/services/dbms/include/distributed_monitor.h old mode 100644 new mode 100755 diff --git a/services/dbms/include/event_report.h b/services/dbms/include/event_report.h old mode 100644 new mode 100755 diff --git a/services/dbms/include/image_compress.h b/services/dbms/include/image_compress.h old mode 100644 new mode 100755 diff --git a/services/dbms/sa_profile/402.json b/services/dbms/sa_profile/402.json old mode 100644 new mode 100755 diff --git a/services/dbms/sa_profile/BUILD.gn b/services/dbms/sa_profile/BUILD.gn old mode 100644 new mode 100755 diff --git a/services/dbms/sa_profile/distributedbms.cfg b/services/dbms/sa_profile/distributedbms.cfg old mode 100644 new mode 100755 diff --git a/services/dbms/src/account_manager_helper.cpp b/services/dbms/src/account_manager_helper.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/src/dbms_device_manager.cpp b/services/dbms/src/dbms_device_manager.cpp new file mode 100644 index 0000000..5ec3e85 --- /dev/null +++ b/services/dbms/src/dbms_device_manager.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dbms_device_manager.h" + +#include "app_log_wrapper.h" +#include "bundle_constants.h" +#include "device_manager.h" +#include "service_control.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { + const std::string DISTRIBUTED_BUNDLE_NAME = "distributed_bundle_framework"; + const std::string SERVICES_NAME = "d-bms"; +} + +DbmsDeviceManager::DbmsDeviceManager() +{ + APP_LOGI("DbmsDeviceManager instance is created"); +} + +bool DbmsDeviceManager::InitDeviceManager() +{ + std::lock_guard lock(isInitMutex_); + if (isInit_) { + APP_LOGI("device manager already init"); + return true; + } + + initCallback_ = std::make_shared(); + int32_t ret = + DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(DISTRIBUTED_BUNDLE_NAME, initCallback_); + if (ret != 0) { + APP_LOGE("init device manager failed, ret:%{public}d", ret); + return false; + } + isInit_ = true; + APP_LOGI("register device manager success"); + return true; +} + +void DbmsDeviceManager::DeviceInitCallBack::OnRemoteDied() +{ + APP_LOGI("DeviceInitCallBack OnRemoteDied"); +} + +int32_t DbmsDeviceManager::GetUdidByNetworkId(const std::string &netWorkId, std::string &udid) +{ + APP_LOGI("GetUdidByNetworkId"); + if (!InitDeviceManager()) { + return -1; + } + return DistributedHardware::DeviceManager::GetInstance().GetUdidByNetworkId( + DISTRIBUTED_BUNDLE_NAME, netWorkId, udid); +} +} +} \ No newline at end of file diff --git a/services/dbms/src/distributed_bms.cpp b/services/dbms/src/distributed_bms.cpp old mode 100644 new mode 100755 index 8ea53a2..8e22013 --- a/services/dbms/src/distributed_bms.cpp +++ b/services/dbms/src/distributed_bms.cpp @@ -139,6 +139,7 @@ void DistributedBms::OnStop() void DistributedBms::Init() { APP_LOGI("DistributedBms: Init"); + InitDeviceManager(); DistributedDataStorage::GetInstance(); if (distributedSub_ == nullptr) { EventFwk::MatchingSkills matchingSkills; @@ -158,6 +159,14 @@ void DistributedBms::Init() DistributedDataStorage::GetInstance()->UpdateDistributedData(userId); } +void DistributedBms::InitDeviceManager() +{ + if (dbmsDeviceManager_ == nullptr) { + APP_LOGI("Create device manager"); + dbmsDeviceManager_ = std::make_shared(); + } +} + OHOS::sptr DistributedBms::GetBundleMgr() { if (bundleMgr_ == nullptr) { @@ -179,6 +188,15 @@ OHOS::sptr DistributedBms::GetBundleMgr() return bundleMgr_; } +int32_t DistributedBms::GetUdidByNetworkId(const std::string &networkId, std::string &udid) +{ + if (dbmsDeviceManager_ == nullptr) { + APP_LOGI("deviceManager_ is nullptr"); + InitDeviceManager(); + } + return dbmsDeviceManager_->GetUdidByNetworkId(networkId, udid); +} + static OHOS::sptr GetDistributedBundleMgr(const std::string &deviceId) { auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/services/dbms/src/distributed_bms_host.cpp b/services/dbms/src/distributed_bms_host.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/src/distributed_data_storage.cpp b/services/dbms/src/distributed_data_storage.cpp old mode 100644 new mode 100755 index c82a1ab..6d1dc6f --- a/services/dbms/src/distributed_data_storage.cpp +++ b/services/dbms/src/distributed_data_storage.cpp @@ -306,12 +306,12 @@ bool DistributedDataStorage::GetLocalUdid(std::string &udid) int32_t DistributedDataStorage::GetUdidByNetworkId(const std::string &networkId, std::string &udid) { - auto bundleMgr = DelayedSingleton::GetInstance()->GetBundleMgr(); - if (bundleMgr == nullptr) { - APP_LOGE("Get bundleMgr shared_ptr nullptr"); - return -1; + auto dbms = DelayedSingleton::GetInstance(); + if (dbms == nullptr) { + APP_LOGE("dbms is null"); + return Constants::INVALID_UDID; } - return bundleMgr->GetUdidByNetworkId(networkId, udid); + return dbms->GetUdidByNetworkId(networkId, udid); } DistributedBundleInfo DistributedDataStorage::ConvertToDistributedBundleInfo(const BundleInfo &bundleInfo) diff --git a/services/dbms/src/event_report.cpp b/services/dbms/src/event_report.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/src/image_compress.cpp b/services/dbms/src/image_compress.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/test/BUILD.gn b/services/dbms/test/BUILD.gn old mode 100644 new mode 100755 diff --git a/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn b/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn old mode 100644 new mode 100755 index ddf72d7..ae7d581 --- a/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn +++ b/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("DbmsServicesKitTest") { sources = [ "${dbms_inner_api_path}/src/distributed_bms_proxy.cpp", "${dbms_services_path}/src/account_manager_helper.cpp", + "${dbms_services_path}/src/dbms_device_manager.cpp", "${dbms_services_path}/src/distributed_bms.cpp", "${dbms_services_path}/src/distributed_bms_host.cpp", "${dbms_services_path}/src/distributed_data_storage.cpp", @@ -47,6 +48,7 @@ ohos_unittest("DbmsServicesKitTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", "hicollie_native:libhicollie", "hiviewdfx_hilog_native:libhilog", "i18n:intl_util", diff --git a/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp b/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp old mode 100644 new mode 100755 index e147dd4..0ba2a5f --- a/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp +++ b/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp @@ -23,6 +23,7 @@ #include #include "appexecfwk_errors.h" +#include "dbms_device_manager.h" #include "distributed_ability_info.h" #include "distributed_bms.h" #include "distributed_bms_interface.h" @@ -1444,7 +1445,6 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0074, Function | SmallTest | L } } - /** * @tc.number: DbmsServicesKitTest * @tc.name: test GetDistributedBundleName @@ -1462,4 +1462,43 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0075, Function | SmallTest | L } } +/** + * @tc.number: InitDeviceManager_0100 + * @tc.name: test InitDeviceManager + * @tc.desc: isInit_ is true, return true. + */ +HWTEST_F(DbmsServicesKitTest, InitDeviceManager_0100, Function | SmallTest | Level0) +{ + DbmsDeviceManager deviceManager; + deviceManager.isInit_ = true; + bool res = deviceManager.InitDeviceManager(); + EXPECT_TRUE(res); +} + +/** + * @tc.number: InitDeviceManager_0200 + * @tc.name: test InitDeviceManager + * @tc.desc: isInit_ is false, return true. + */ +HWTEST_F(DbmsServicesKitTest, InitDeviceManager_0200, Function | SmallTest | Level0) +{ + DbmsDeviceManager deviceManager; + deviceManager.isInit_ = false; + bool res = deviceManager.InitDeviceManager(); + EXPECT_TRUE(res); +} + +/** + * @tc.number: GetUdidByNetworkId_0100 + * @tc.name: test GetUdidByNetworkId + * @tc.desc: GetUdidByNetworkId is false + */ +HWTEST_F(DbmsServicesKitTest, GetUdidByNetworkId_0100, Function | SmallTest | Level0) +{ + DbmsDeviceManager deviceManager; + std::string netWorkId = EMPTY_STRING; + std::string uid = EMPTY_STRING; + auto ret = deviceManager.GetUdidByNetworkId(netWorkId, uid); + EXPECT_FALSE(ret == -1); +} } // OHOS \ No newline at end of file diff --git a/services/dbms/test/unittest/distributed_bms_host_test/BUILD.gn b/services/dbms/test/unittest/distributed_bms_host_test/BUILD.gn old mode 100644 new mode 100755 index 76bb0cb..fd327ec --- a/services/dbms/test/unittest/distributed_bms_host_test/BUILD.gn +++ b/services/dbms/test/unittest/distributed_bms_host_test/BUILD.gn @@ -20,7 +20,10 @@ ohos_unittest("DistributedBmsHostTest") { module_out_path = module_output_path include_dirs = [ "${dbms_services_path}/include" ] - sources = [ "${dbms_services_path}/src/distributed_bms_host.cpp" ] + sources = [ + "${dbms_services_path}/src/dbms_device_manager.cpp", + "${dbms_services_path}/src/distributed_bms_host.cpp", + ] sources += [ "distributed_bms_host_test.cpp", @@ -42,6 +45,7 @@ ohos_unittest("DistributedBmsHostTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", "hicollie_native:libhicollie", "hiviewdfx_hilog_native:libhilog", "i18n:intl_util", diff --git a/services/dbms/test/unittest/distributed_bms_host_test/distributed_bms_host_test.cpp b/services/dbms/test/unittest/distributed_bms_host_test/distributed_bms_host_test.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.cpp b/services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.cpp old mode 100644 new mode 100755 diff --git a/services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.h b/services/dbms/test/unittest/distributed_bms_host_test/mock_distributed_bms_interface.h old mode 100644 new mode 100755 -- Gitee