diff --git a/commondependency/BUILD.gn b/commondependency/BUILD.gn index b6cd6ccfe37b8f6657bd55492e352eb287d7d4f4..037d7142b8fbc31e8c4a4e3204146b38772c0861 100644 --- a/commondependency/BUILD.gn +++ b/commondependency/BUILD.gn @@ -54,10 +54,7 @@ ohos_shared_library("devicemanagerdependency") { if (os_account_part_exists) { defines += [ "OS_ACCOUNT_PART_EXISTS" ] - external_deps += [ - "os_account:libaccountkits", - "os_account:os_account_innerkits", - ] + external_deps += [ "os_account:os_account_innerkits" ] } subsystem_name = "distributedhardware" diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 08de7883ea8ee8412453c02b95b722abc6ef2274..d03c9f34ead1ced4a19d1d42ae2cf7c7f86c9034 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -16,10 +16,6 @@ #define OHOS_DM_DEVICEPROFILE_CONNECTOR_H #include #include "access_control_profile.h" -#include "accessee.h" -#include "accesser.h" -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_enums.h" #include "dm_device_info.h" #include "single_instance.h" @@ -86,12 +82,41 @@ typedef struct DmOfflineParam { namespace OHOS { namespace DistributedHardware { -class DeviceProfileConnector { -DECLARE_SINGLE_INSTANCE_BASE(DeviceProfileConnector); +class IDeviceProfileConnector { public: - DeviceProfileConnector(); - ~DeviceProfileConnector(); + virtual ~IDeviceProfileConnector() {} + virtual std::vector GetAccessControlProfile() = 0; + virtual uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId) = 0; + virtual int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee) = 0; + virtual int32_t UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId) = 0; + virtual std::map GetAppTrustDeviceList(const std::string &pkgName, + const std::string &deviceId) = 0; + virtual DmOfflineParam GetOfflineParamFromAcl(std::string trustDeviceId, std::string requestDeviceId) = 0; + virtual std::vector GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, + std::string trustUdid) = 0; + virtual std::vector SyncAclByBindType(std::string pkgName, std::vector bindTypeVec, + std::string localDeviceId, std::string targetDeviceId) = 0; + virtual int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isonline, int32_t &authForm) = 0; + virtual int32_t DeleteAccessControlList(int32_t userId, std::string &accountId) = 0; + virtual DmOfflineParam DeleteAccessControlList(std::string pkgName, std::string localDeviceId, + std::string remoteDeviceId) = 0; + virtual std::vector GetPkgNameFromAcl(std::string &localDeviceId, std::string &targetDeviceId) = 0; + virtual bool CheckIdenticalAccount(int32_t userId, const std::string &accountId) = 0; + virtual int32_t DeleteP2PAccessControlList(int32_t userId, std::string &accountId) = 0; + virtual bool CheckSrcDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0; + virtual bool CheckSinkDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0; + virtual int32_t DeleteTimeOutAcl(const std::string &deviceId) = 0; + virtual int32_t GetTrustNumber(const std::string &deviceId) = 0; + virtual bool CheckDeviceIdInAcl(const std::string &pkgName, const std::string &deviceId) = 0; + virtual bool CheckPkgnameInAcl(std::string pkgName, std::string localDeviceId, std::string remoteDeviceId) = 0; + virtual std::vector CompareBindType(std::vector profiles, + std::string pkgName, std::vector &sinkBindType, std::string localDeviceId, + std::string targetDeviceId) = 0; +}; +class DeviceProfileConnector : public IDeviceProfileConnector { + DECLARE_SINGLE_INSTANCE(DeviceProfileConnector); +public: std::vector GetAccessControlProfile(); uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId); int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee); @@ -127,6 +152,9 @@ private: void ProcessBindType(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo paramInfo, std::vector &sinkBindType, std::vector &bindTypeIndex, uint32_t index); }; + +extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); +using CreateDpConnectorFuncPtr = IDeviceProfileConnector *(*)(void); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICEPROFILE_CONNECTOR_H diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index a9f76f20da3055647f3a73162b275b17eeb566be..8fbec8cfc88d0585f52b2d6e630c1ed27cf5bbc3 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -21,21 +21,12 @@ #include "dm_softbus_adapter_crypto.h" #include "multiple_user_connector.h" +#include "distributed_device_profile_client.h" using namespace OHOS::DistributedDeviceProfile; namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DeviceProfileConnector); -DeviceProfileConnector::DeviceProfileConnector() -{ - LOGD("DeviceProfileConnector constructor."); -} - -DeviceProfileConnector::~DeviceProfileConnector() -{ - LOGD("DeviceProfileConnector destructor."); -} - std::vector DeviceProfileConnector::GetAccessControlProfile() { LOGI("GetAccessControlProfile start."); @@ -662,5 +653,10 @@ bool DeviceProfileConnector::CheckPkgnameInAcl(std::string pkgName, std::string } return false; } + +IDeviceProfileConnector *CreateDpConnectorInstance() +{ + return &DeviceProfileConnector::GetInstance(); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index c48a0b3027bb403245e8f065ec678150060f9813..c740fb0dc344f44a3056c0e7d05991abe7ddef71 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -169,7 +169,6 @@ if (defined(ohos_lite)) { ] deps = [ - "${devicemanager_path}/commondependency:devicemanagerdependency", "${utils_path}:devicemanagerutils", "//third_party/mbedtls:mbedtls_shared", ] diff --git a/services/service/include/discovery/discovery_manager.h b/services/service/include/discovery/discovery_manager.h index c814368ec879602fe40422e4d001351a0a5b0c07..666677723f850e338f2d1b1652c2ee5fee765c6e 100644 --- a/services/service/include/discovery/discovery_manager.h +++ b/services/service/include/discovery/discovery_manager.h @@ -17,7 +17,9 @@ #define OHOS_DISCOVERY_MANAGER_H #include - +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "deviceprofile_connector.h" +#endif #include "discovery_filter.h" #include "idevice_manager_service_listener.h" #include "dm_timer.h" @@ -49,6 +51,11 @@ public: int32_t EnableDiscoveryListener(const std::string &pkgName, const std::map &discoverParam, const std::map &filterOptions); int32_t DisableDiscoveryListener(const std::string &pkgName, const std::map &extraParam); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + static IDeviceProfileConnector* GetCommonDependencyObj(); + static bool IsCommonDependencyReady(); + static bool CloseCommonDependencyObj(); +#endif private: void StartDiscoveryTimer(); @@ -69,6 +76,11 @@ private: std::shared_ptr listener_; std::queue discoveryQueue_; std::map discoveryContextMap_; +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + static bool isSoLoaded_; + static IDeviceProfileConnector *dpConnector_; + static void *dpConnectorHandle_; +#endif }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 2203480e65dcf277a99e231cc25d8687b9da6144..5fdbbf6cf89986c47b4a8dc77b58eeca57bae26b 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -752,6 +752,7 @@ int32_t DeviceManagerService::UnRegisterUiStateCallback(const std::string &pkgNa bool DeviceManagerService::IsDMServiceImplReady() { + LOGI("DeviceManagerService::IsDMServiceImplReady"); std::lock_guard lock(isImplLoadLock_); if (isImplsoLoaded_ && (dmServiceImpl_ != nullptr)) { return true; diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index f10ddc5d49781b6894c63d4d67b1ed29286823cc..bb95c9f561a529e4e989a0a86f29244e8047e025 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -15,11 +15,9 @@ #include "discovery_manager.h" +#include #include -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -#include "deviceprofile_connector.h" -#endif #include "discovery_filter.h" #include "dm_anonymous.h" #include "dm_constants.h" @@ -33,6 +31,13 @@ const uint16_t DM_INVALID_FLAG_ID = 0; constexpr const char* LNN_DISC_CAPABILITY = "capability"; constexpr const char* DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:discovery"; const std::string TYPE_MINE = "findDeviceMode"; +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +static std::mutex comDependencyLoadLock; +constexpr const char* LIB_DM_COMDENPENDENCY_NAME = "libdevicemanagerdependency.z.so"; +bool DiscoveryManager::isSoLoaded_ = false; +IDeviceProfileConnector* DiscoveryManager::dpConnector_ = nullptr; +void* DiscoveryManager::dpConnectorHandle_ = nullptr; +#endif DiscoveryManager::DiscoveryManager(std::shared_ptr softbusListener, std::shared_ptr listener) : softbusListener_(softbusListener), listener_(listener) @@ -42,6 +47,9 @@ DiscoveryManager::DiscoveryManager(std::shared_ptr softbusListe DiscoveryManager::~DiscoveryManager() { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + CloseCommonDependencyObj(); +#endif LOGI("DiscoveryManager destructor."); } @@ -383,12 +391,72 @@ int32_t DiscoveryManager::GetDeviceAclParam(const std::string &pkgName, std::str discoveryInfo.pkgname = pkgName; discoveryInfo.localDeviceId = requestDeviceId; discoveryInfo.remoteDeviceIdHash = deviceId; - if (DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm) != DM_OK) { - LOGE("GetDeviceAclParam failed."); - return ERR_DM_FAILED; + if (DiscoveryManager::IsCommonDependencyReady() && DiscoveryManager::GetCommonDependencyObj() != nullptr) { + if (DiscoveryManager::GetCommonDependencyObj()->GetDeviceAclParam(discoveryInfo, isonline, authForm) != DM_OK) { + LOGE("GetDeviceAclParam failed."); + return ERR_DM_FAILED; + } } #endif return DM_OK; } + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +IDeviceProfileConnector* DiscoveryManager::GetCommonDependencyObj() +{ + return dpConnector_; +} + +bool DiscoveryManager::IsCommonDependencyReady() +{ + LOGI("DiscoveryManager::IsCommonDependencyReady."); + std::lock_guard lock(comDependencyLoadLock); + if (isSoLoaded_ && dpConnector_ != nullptr && dpConnectorHandle_ != nullptr) { + LOGI("IsCommonDependencyReady already."); + return true; + } + char path[PATH_MAX + 1] = {0x00}; + std::string soName = std::string(DM_LIB_LOAD_PATH) + std::string(LIB_DM_COMDENPENDENCY_NAME); + if ((soName.length() == 0) || (soName.length() > PATH_MAX) || (realpath(soName.c_str(), path) == nullptr)) { + LOGE("File %s canonicalization failed.", soName.c_str()); + return false; + } + dpConnectorHandle_ = dlopen(path, RTLD_NOW | RTLD_NODELETE); + if (dpConnectorHandle_ == nullptr) { + LOGE("load libdevicemanagerdependency so %s failed, errMsg: %s.", soName.c_str(), dlerror()); + return false; + } + auto func = (CreateDpConnectorFuncPtr)dlsym(dpConnectorHandle_, "CreateDpConnectorInstance"); + if (dlerror() != nullptr || func == nullptr) { + dlclose(dpConnectorHandle_); + LOGE("Create object function is not exist."); + return false; + } + dpConnector_ = func(); + isSoLoaded_ = true; + LOGI("IsCommonDependencyReady success."); + return true; +} + +bool DiscoveryManager::CloseCommonDependencyObj() +{ + LOGI("DiscoveryManager::CloseCommonDependencyObj start."); + std::lock_guard lock(comDependencyLoadLock); + if (!isSoLoaded_ && (dpConnector_ == nullptr) && (dpConnectorHandle_ == nullptr)) { + return true; + } + + int32_t ret = dlclose(dpConnectorHandle_); + if (ret != 0) { + LOGE("close libdevicemanagerdependency failed ret = %d.", ret); + return false; + } + isSoLoaded_ = false; + dpConnector_ = nullptr; + dpConnectorHandle_ = nullptr; + LOGI("close libdevicemanagerdependency so success."); + return true; +} +#endif } // namespace DistributedHardware } // namespace OHOS diff --git a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn index 4517f9b77b3c5c2f9fb183fced62f04ebda69813..b00bebcff6e9cedabe1475d37605c51ca52b7f06 100644 --- a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn @@ -68,6 +68,8 @@ ohos_fuzztest("AuthenticateDeviceServiceFuzzTest") { external_deps = [ "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn index 630a5c6f438d81e5161bde77edca1cd1f1f8c3da..2c3b2e169559c5f616badb8aacad04236270cdab 100644 --- a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -69,6 +69,8 @@ ohos_fuzztest("DeviceManagerServiceFuzzTest") { external_deps = [ "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn index c80293936943611133181782f246ac06c9a4651a..77c749a1d3188c4811e3b00d7987af72c06b49c0 100644 --- a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn @@ -63,6 +63,8 @@ ohos_fuzztest("GetTrustedDeviceListServiceFuzzTest") { external_deps = [ "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn index 75e39dfc9013533316989f7568e74f843c2ba634..b8a137ed7e8770cd616c875bcf7ceded0f16a257 100644 --- a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn @@ -63,6 +63,8 @@ ohos_fuzztest("ShiftLNNGearDeviceServiceFuzzTest") { external_deps = [ "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "ipc:ipc_single", "safwk:system_ability_fwk", ] diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index e603c91f1dcae7cd37fd6e592895a5ab2176fdb5..cdb7ebb92d22ebb5b977332053a2918c9ce6eafd 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -429,7 +429,11 @@ ohos_unittest("UTTest_ipc_server_stub") { deps = [ ":device_manager_test_common" ] - external_deps = [ "device_auth:deviceauth_sdk" ] + external_deps = [ + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] } ## UnitTest UTTest_ipc_server_stub }}} @@ -928,6 +932,8 @@ ohos_static_library("device_manager_test_common") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", "hilog:libhilog",